fix: 参数配置修复根据规则取值导致的类型问题

This commit is contained in:
TsMask
2023-12-12 11:09:09 +08:00
parent 8199e16a17
commit 1c3e6db4bc

View File

@@ -316,17 +316,21 @@ watch(
function arrayEdit(rowIndex: Record<string, any>) {
const item = arrayState.data.find((s: any) => s.key === rowIndex.value);
if (!item) return;
const from = arrayEditInit(item, arrayState.dataRule);
// 处理信息
const row: Record<string, any> = {};
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<string, any>) {
const item = arrayChildState.data.find((s: any) => s.key === rowIndex.value);
if (!item) return;
const from = arrayEditInit(item, arrayChildState.dataRule);
// 处理信息
const row: Record<string, any> = {};
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<string, any>) {
});
}
/**多列表编辑行数据初始化 */
function arrayEditInit(data: Record<string, any>, 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"
>
<!-- 多列新增操作 -->
<template #title v-if="treeState.selectNode.method !== 'get'">
<template #title>
<a-space :size="16" align="center">
<a-button
type="primary"
@click.prevent="arrayAdd()"
size="small"
v-if="treeState.selectNode.method !== 'get'"
>
<template #icon> <PlusOutlined /> </template>
{{ t('common.addText') }}
</a-button>
<TableColumnsDnd
type="ghost"
:columns="[...arrayState.columns]"
:columns="treeState.selectNode.method === 'get' ? [...arrayState.columns.filter((s:any)=>s.key !== 'index')] : arrayState.columns"
v-model:columns-dnd="arrayState.columnsDnd"
></TableColumnsDnd>
</a-space>