diff --git a/src/views/configManage/configParamTreeTable/index.vue b/src/views/configManage/configParamTreeTable/index.vue index e6240911..1ced1e95 100644 --- a/src/views/configManage/configParamTreeTable/index.vue +++ b/src/views/configManage/configParamTreeTable/index.vue @@ -316,17 +316,21 @@ watch( function arrayEdit(rowIndex: Record) { const item = arrayState.data.find((s: any) => s.key === rowIndex.value); if (!item) return; - + const from = arrayEditInit(item, arrayState.dataRule); + // 处理信息 const row: Record = {}; - for (const v of item.record) { + for (const v of from.record) { + if (Array.isArray(v.array)) { + continue; + } row[v.name] = Object.assign({}, v); } modalState.from = row; modalState.type = 'arrayEdit'; - modalState.title = `${treeState.selectNode.topDisplay} ${item.title}`; - modalState.key = item.key; - modalState.data = item.record.filter((v: any) => !Array.isArray(v.array)); + modalState.title = `${treeState.selectNode.topDisplay} ${from.title}`; + modalState.key = from.key; + modalState.data = from.record.filter((v: any) => !Array.isArray(v.array)); modalState.visible = true; // 关闭嵌套 @@ -433,13 +437,6 @@ function arrayAdd() { if (Array.isArray(v.array)) { continue; } - // 根据规则类型转值 - if (['enum', 'int'].includes(v.type)) { - v.value = Number(v.value); - } - if ('bool' === v.type) { - v.value = Boolean(v.value); - } row[v.name] = Object.assign({}, v); } @@ -644,17 +641,21 @@ function arrayChildExpandClose() { function arrayChildEdit(rowIndex: Record) { const item = arrayChildState.data.find((s: any) => s.key === rowIndex.value); if (!item) return; - + const from = arrayEditInit(item, arrayChildState.dataRule); + // 处理信息 const row: Record = {}; - for (const v of item.record) { + for (const v of from.record) { + if (Array.isArray(v.array)) { + continue; + } row[v.name] = Object.assign({}, v); } modalState.from = row; modalState.type = 'arrayChildEdit'; - modalState.title = `${arrayChildState.title} ${item.title}`; - modalState.key = item.key; - modalState.data = item.record.filter((v: any) => !Array.isArray(v.array)); + modalState.title = `${arrayChildState.title} ${from.title}`; + modalState.key = from.key; + modalState.data = from.record.filter((v: any) => !Array.isArray(v.array)); modalState.visible = true; } @@ -821,6 +822,35 @@ function arrayChildAddOk(from: Record) { }); } +/**多列表编辑行数据初始化 */ +function arrayEditInit(data: Record, dataRule: any) { + const dataFrom = data.record; + const ruleFrom = Object.assign({}, JSON.parse(JSON.stringify(dataRule))); + for (const row of ruleFrom.record) { + // 子嵌套的不初始 + if (row.array) { + row.value = []; + continue; + } + // 查找项的值 + const item = dataFrom.find((s: any) => s.name === row.name); + if (!item) { + continue; + } + // 根据规则类型转值 + if (['enum', 'int'].includes(row.type)) { + row.value = Number(item.value); + } else if ('bool' === row.type) { + row.value = Boolean(item.value); + } else { + row.value = item.value; + } + } + ruleFrom.key = data.key; + ruleFrom.title = data.title; + return ruleFrom; +} + /**多列表新增行数据初始化 */ function arrayAddInit(data: any[], dataRule: any) { let newIndex = 0; @@ -835,6 +865,11 @@ function arrayAddInit(data: any[], dataRule: any) { const ruleFrom = Object.assign({}, JSON.parse(JSON.stringify(dataRule))); for (const row of ruleFrom.record) { + // 子嵌套的不初始 + if (row.array) { + row.value = []; + continue; + } const value = row.value; if (row.name === 'index') { if (newIndex !== 0) { @@ -850,10 +885,12 @@ function arrayAddInit(data: any[], dataRule: any) { ruleFrom.title = `Index-${newIndex}`; continue; } - // 子嵌套的不初始 - if (row.array) { - row.value = []; - continue; + // 根据规则类型转值 + if (['enum', 'int'].includes(row.type)) { + row.value = Number(row.value); + } + if ('bool' === row.type) { + row.value = Boolean(row.value); } } return ruleFrom; @@ -1277,19 +1314,20 @@ onMounted(() => { v-model:expanded-row-keys="arrayState.arrayChildExpandKeys" > -