fix: 参数配置列新增使用config_rule规制默认值

This commit is contained in:
TsMask
2023-12-01 19:27:34 +08:00
parent cc234ee081
commit 9d0daca765

View File

@@ -815,21 +815,22 @@ function arrayChildAddOk(from: Record<string, any>) {
/**多列表新增行数据初始化 */
function arrayAddInit(data: any[], dataRule: any) {
const len = data.length;
let lastItme: Record<string, any> = {};
let newIndex = 0;
// 无数据时生成临时记录
if (len === 0) {
lastItme = dataRule;
} else {
lastItme = data[len - 1];
// 有数据时取得最后的index
if (data.length !== 0) {
const lastFrom = Object.assign({}, JSON.parse(JSON.stringify(data.at(-1))));
if (lastFrom.record.length > 0) {
newIndex = parseInt(lastFrom.key);
}
}
const from = Object.assign({}, JSON.parse(JSON.stringify(lastItme)));
for (const row of from.record) {
const ruleFrom = Object.assign({}, JSON.parse(JSON.stringify(dataRule)));
for (const row of ruleFrom.record) {
const value = row.value;
if (row.name === 'index') {
if (len !== 0 && value !== '') {
newIndex = parseInt(value) + 1;
if (newIndex !== 0) {
newIndex += 1;
} else {
newIndex = parseInt(value);
}
@@ -837,65 +838,17 @@ function arrayAddInit(data: any[], dataRule: any) {
newIndex = 0;
}
row.value = newIndex;
from.key = newIndex;
from.title = `Index-${newIndex}`;
ruleFrom.key = newIndex;
ruleFrom.title = `Index-${newIndex}`;
continue;
}
// 子嵌套的不初始
if (row.array) {
row.value = null;
row.value = [];
continue;
}
const type = row.type;
const filter = row.filter;
switch (type) {
case 'int':
if (filter && filter.indexOf('~') !== -1) {
const filterArr = filter.split('~');
const minInt = parseInt(filterArr[0]);
row.value = minInt;
} else {
row.value = 0;
}
break;
case 'enum':
if (filter && filter.indexOf('{') === 0) {
let filterJson: Record<string, any> = {};
try {
filterJson = JSON.parse(filter); //string---json
} catch (error) {
console.error(error);
}
row.value = Object.keys(filterJson)[0];
} else {
row.value = '0';
}
break;
case 'bool':
if (filter && filter.indexOf('{') === 0) {
let filterJson: Record<string, any> = {};
try {
filterJson = JSON.parse(filter); //string---json
} catch (error) {
console.error(error);
}
row.value = Object.keys(filterJson)[0];
} else {
row.value = false;
}
break;
case 'ipv4':
case 'ipv6':
case 'regex':
default:
row.value = '';
break;
}
}
return from;
return ruleFrom;
}
/**规则校验 */