From 2feb9eafd061c34098a4b59bbf6f845c6bf74533 Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期一, 21 七月 2025 11:15:49 +0800
Subject: [PATCH] 添加深克隆
---
utils/common.js | 67 ++++++++++++++++++++++++++++++++-
1 files changed, 64 insertions(+), 3 deletions(-)
diff --git a/utils/common.js b/utils/common.js
index fd03b44..d3dd163 100644
--- a/utils/common.js
+++ b/utils/common.js
@@ -126,6 +126,67 @@
}
};
}
+
+ deepClone(target, map = new WeakMap()) {
+ // 澶勭悊鍘熷鍊煎拰鍑芥暟(typeof 鏁扮粍浼氳繑鍥瀘bject)
+ if (typeof target !== 'object' || target === null) {
+ return target;
+ }
+
+ // 澶勭悊寰幆寮曠敤
+ if (map.has(target)) {
+ return map.get(target);
+ }
+
+ let clone;
+
+ // 澶勭悊鏁扮粍
+ if (Array.isArray(target)) {
+ clone = [];
+ map.set(target, clone);
+ target.forEach((item, index) => {
+ clone[index] = deepClone(item, map);
+ });
+ return clone;
+ }
+
+ // 澶勭悊鏃ユ湡瀵硅薄
+ if (target instanceof Date) {
+ clone = new Date(target.getTime());
+ map.set(target, clone);
+ return clone;
+ }
+
+ // 澶勭悊姝e垯琛ㄨ揪寮�
+ if (target instanceof RegExp) {
+ clone = new RegExp(target);
+ map.set(target, clone);
+ return clone;
+ }
+
+ // 澶勭悊鍑芥暟 (鐩存帴浣跨敤鍑芥暟鐨勫紩鐢�)
+ if (typeof target === 'function') {
+ return target;
+ }
+
+ // 澶勭悊鍏朵粬瀵硅薄锛堟櫘閫氬璞°�佺被瀹炰緥绛夛級
+ clone = Object.create(Object.getPrototypeOf(target));
+ map.set(target, clone);
+
+ // 鑾峰彇鎵�鏈夊睘鎬э紙鍖呮嫭 Symbol 绫诲瀷锛�
+ const allKeys = [...Object.getOwnPropertyNames(target), ...Object.getOwnPropertySymbols(target)];
+
+ allKeys.forEach(key => {
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
+ if (descriptor && descriptor.enumerable) {
+ // 閫掑綊澶嶅埗灞炴�у��
+ clone[key] = deepClone(target[key], map);
+ }
+ });
+
+ return clone;
+ }
+
// uni-app 浣跨敤 灏佽璇锋眰鍑芥暟 浣跨敤浼犵粺鍑芥暟褰撲綔鍥炶皟闇�瑕佷紶that锛岀澶村嚱鏁颁笉闇�瑕�
doRequest(url, data, resFunction, errFunction, method, that) {
that = that || this;
@@ -176,11 +237,11 @@
}
// uni-app 鎾斁闊抽灏佽
- playSound(e){
+ playSound(e) {
const innerAudioContext = uni.createInnerAudioContext();
- if(e == 1){
+ if (e == 1) {
innerAudioContext.src = '/static/success.wav';
- }else{
+ } else {
innerAudioContext.src = '/static/jingbao.wav';
}
innerAudioContext.play(); // 鎾斁闊抽
--
Gitblit v1.9.1