fix: 参数配置列新增使用config_rule规制默认值
This commit is contained in:
@@ -815,21 +815,22 @@ function arrayChildAddOk(from: Record<string, any>) {
|
|||||||
|
|
||||||
/**多列表新增行数据初始化 */
|
/**多列表新增行数据初始化 */
|
||||||
function arrayAddInit(data: any[], dataRule: any) {
|
function arrayAddInit(data: any[], dataRule: any) {
|
||||||
const len = data.length;
|
|
||||||
let lastItme: Record<string, any> = {};
|
|
||||||
let newIndex = 0;
|
let newIndex = 0;
|
||||||
// 无数据时生成临时记录
|
|
||||||
if (len === 0) {
|
// 有数据时取得最后的index
|
||||||
lastItme = dataRule;
|
if (data.length !== 0) {
|
||||||
} else {
|
const lastFrom = Object.assign({}, JSON.parse(JSON.stringify(data.at(-1))));
|
||||||
lastItme = data[len - 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;
|
const value = row.value;
|
||||||
if (row.name === 'index') {
|
if (row.name === 'index') {
|
||||||
if (len !== 0 && value !== '') {
|
if (newIndex !== 0) {
|
||||||
newIndex = parseInt(value) + 1;
|
newIndex += 1;
|
||||||
} else {
|
} else {
|
||||||
newIndex = parseInt(value);
|
newIndex = parseInt(value);
|
||||||
}
|
}
|
||||||
@@ -837,65 +838,17 @@ function arrayAddInit(data: any[], dataRule: any) {
|
|||||||
newIndex = 0;
|
newIndex = 0;
|
||||||
}
|
}
|
||||||
row.value = newIndex;
|
row.value = newIndex;
|
||||||
from.key = newIndex;
|
ruleFrom.key = newIndex;
|
||||||
from.title = `Index-${newIndex}`;
|
ruleFrom.title = `Index-${newIndex}`;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 子嵌套的不初始
|
// 子嵌套的不初始
|
||||||
if (row.array) {
|
if (row.array) {
|
||||||
row.value = null;
|
row.value = [];
|
||||||
continue;
|
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 ruleFrom;
|
||||||
return from;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**规则校验 */
|
/**规则校验 */
|
||||||
|
|||||||
Reference in New Issue
Block a user