This commit is contained in:
yunkexin 2024-03-26 11:37:08 +08:00
commit c42d48ebfb

View File

@ -249,7 +249,9 @@ class BI013RiskAnalysisModel extends React.Component {
// 你可以根据params执行任何你想做的操作例如 // 你可以根据params执行任何你想做的操作例如
if (params.componentType === 'series') { if (params.componentType === 'series') {
if (params.name == '一级') { 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 == '二级') { } else if (params.name == '二级') {
that.subtractRandomNotLessThanSelf(that.state.ret.Data.CHARTLIST[1]); that.subtractRandomNotLessThanSelf(that.state.ret.Data.CHARTLIST[1]);
} else if (params.name == '三级') { } else if (params.name == '三级') {
@ -872,37 +874,23 @@ class BI013RiskAnalysisModel extends React.Component {
}, true); }, true);
} }
}; };
subtractRandomNotLessThanSelf = (data) => { subtractRandomNotLessThanSelf = (obj) => {
function getRandomNotLessThan(num) { function getRandomNotLessThan(num) {
return Math.floor(Math.random() * num) + num; return Math.floor(Math.random() * num);
} }
for (let key in obj) {
// 处理数组的情况 if (Array.isArray(obj[key])) {
if (Array.isArray(data)) { obj[key] = obj[key].map(number => {
return data.map(item => { if (typeof number === 'number') {
if (typeof item === 'number') { const randomSubtraction = getRandomNotLessThan(number);
const randomSubtraction = getRandomNotLessThan(item); return Math.floor(number - randomSubtraction); // 确保结果也为整数
return item - randomSubtraction; } else {
} return number;
// 同样地这里假设对象有一个名为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;
} }
return obj;
} }
//显示详情弹窗 //显示详情弹窗