diff --git a/src/assets/js/utils/objectUtils.js b/src/assets/js/utils/objectUtils.js new file mode 100644 index 000000000..202214e70 --- /dev/null +++ b/src/assets/js/utils/objectUtils.js @@ -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; +} diff --git a/src/views/ebiz/productFlowImprove/components/CalculatePremium.vue b/src/views/ebiz/productFlowImprove/components/CalculatePremium.vue index 9c80c4a99..8b44d2f95 100644 --- a/src/views/ebiz/productFlowImprove/components/CalculatePremium.vue +++ b/src/views/ebiz/productFlowImprove/components/CalculatePremium.vue @@ -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') {