From 610ef6fc11ac43eb3a414af18b12f006224d29ba Mon Sep 17 00:00:00 2001 From: wjn Date: Tue, 26 Mar 2024 09:53:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=81=94=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomPages/BI/BI013RiskAnalysisModel.js | 46 +++++++------------ 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/src/components/CustomPages/BI/BI013RiskAnalysisModel.js b/src/components/CustomPages/BI/BI013RiskAnalysisModel.js index fe54219..6d65433 100644 --- a/src/components/CustomPages/BI/BI013RiskAnalysisModel.js +++ b/src/components/CustomPages/BI/BI013RiskAnalysisModel.js @@ -249,7 +249,9 @@ class BI013RiskAnalysisModel extends React.Component { // 你可以根据params执行任何你想做的操作,例如: if (params.componentType === 'series') { if (params.name == '一级') { - that.chart13(that.subtractRandomNotLessThanSelf(that.state.ret.Data.CHARTLIST[1])) + let newData = that.state.ret.Data.CHARTLIST[1]; + that.subtractRandomNotLessThanSelf(newData); + that.chart13(newData) } else if (params.name == '二级') { that.subtractRandomNotLessThanSelf(that.state.ret.Data.CHARTLIST[1]); } else if (params.name == '三级') { @@ -872,37 +874,23 @@ class BI013RiskAnalysisModel extends React.Component { }, true); } }; - subtractRandomNotLessThanSelf = (data) => { + subtractRandomNotLessThanSelf = (obj) => { function getRandomNotLessThan(num) { - return Math.floor(Math.random() * num) + num; + return Math.floor(Math.random() * num); } - - // 处理数组的情况 - if (Array.isArray(data)) { - return data.map(item => { - if (typeof item === 'number') { - const randomSubtraction = getRandomNotLessThan(item); - return item - randomSubtraction; - } - // 同样地,这里假设对象有一个名为value的数字属性需要处理 - else if (typeof item === 'object' && typeof item.value === 'number') { - const randomSubtraction = getRandomNotLessThan(item.value); - return { ...item, value: item.value - randomSubtraction }; - } - else { - return item; - } - }); - } - // 处理非数组但为数字的情况 - else if (typeof data === 'number') { - const randomSubtraction = getRandomNotLessThan(data); - return data - randomSubtraction; - } - // 其他情况返回原数据 - else { - return data; + for (let key in obj) { + if (Array.isArray(obj[key])) { + obj[key] = obj[key].map(number => { + if (typeof number === 'number') { + const randomSubtraction = getRandomNotLessThan(number); + return Math.floor(number - randomSubtraction); // 确保结果也为整数 + } else { + return number; + } + }); + } } + return obj; } //显示详情弹窗