fix: 修复部分手机无法使用 structuredClone 的错误

- 添加替代方法 deepClone
This commit is contained in:
hz
2025-11-03 10:03:05 +08:00
parent 98c01fc855
commit ca6caee7de
2 changed files with 46 additions and 2 deletions

View File

@@ -0,0 +1,43 @@
export function deepClone(obj, hash = new WeakMap()) {
// 处理 null 或 undefined
if (obj === null || typeof obj !== 'object') {
return obj;
}
// 处理循环引用
if (hash.has(obj)) {
return hash.get(obj);
}
// 处理 Date 对象
if (obj instanceof Date) {
return new Date(obj);
}
// 处理 RegExp 对象
if (obj instanceof RegExp) {
return new RegExp(obj.source, obj.flags);
}
// 处理数组
if (Array.isArray(obj)) {
const clonedArr = [];
hash.set(obj, clonedArr);
obj.forEach((item, index) => {
clonedArr[index] = deepClone(item, hash);
});
return clonedArr;
}
// 处理普通对象
if (typeof obj === 'object') {
const clonedObj = {};
hash.set(obj, clonedObj);
Object.keys(obj).forEach(key => {
clonedObj[key] = deepClone(obj[key], hash);
});
return clonedObj;
}
return obj;
}

View File

@@ -466,6 +466,7 @@ import { trial } from '@/api/ebiz/common/common'
import { syncLocalstorageData } from '@/assets/js/syncLocalstorageData'
import { validateRelationshipToInsured } from '@/views/ebiz/productFlowImprove/components/js/relationshipToInsured'
import TotalPremium from '@/views/ebiz/saleFlowProImprove/components/TotalPremium.vue'
import { deepClone } from '@/assets/js/utils/objectUtils'
const DUTY_DEFAULT_MUTIPLE = 1000
const DUTY_DEFAULT_MIN = 10000
@@ -804,7 +805,7 @@ export default {
// 构建需要的参数
/*global structuredClone*/
let resultData = structuredClone(productDetail)
let resultData =(window.structuredClone? structuredClone: deepClone)(productDetail)
const riskProductCode = productDetailCode
resultData = resultData.trialDTOS[0]
@@ -892,7 +893,7 @@ export default {
localStorage.chooseProducts = JSON.stringify(productsData)
// this.jumpTo()
this.chooseProducts = structuredClone(productsData)
this.chooseProducts = (window.structuredClone? structuredClone: deepClone)(productsData)
this.chooseProducts.forEach((item, index) => {
if (item.isCrossChannel === '1') {