This commit is contained in:
sjl
2024-12-26 09:28:19 +08:00
parent 2e17531c52
commit 6ce58e86ad
12 changed files with 414 additions and 48 deletions

View File

@@ -12,13 +12,24 @@
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="sort" label="序号" width="60" />
<el-table-column prop="type" label="电能质量检测指标类型" min-width="340">
<el-table-column prop="type" label="误差类型" min-width="180">
<template #default="{ row }">
<el-cascader style="min-width: 350px;"
:options="options"
v-model="row.type"
<el-cascader style="min-width: 180px;"
:options="errorOptions"
v-model="row.errorType"
:props="{ checkStrictly: false, emitPath: false }"
placeholder="请选择指标类型"/>
placeholder="请选择误差类型"
@change="handleErrorTypeChange($event, row)"/>
</template>
</el-table-column>
<el-table-column prop="type" label="脚本类型" min-width="230">
<template #default="{ row }">
<el-cascader style="min-width: 230px;"
:options="scriptOptions"
v-model="row.scriptType"
:props="{ checkStrictly: false, emitPath: false }"
placeholder="请选择脚本类型"
/>
</template>
</el-table-column>
<el-table-column label="起止范围" >
@@ -110,7 +121,12 @@
const isStartValueDisabled = ref<{ [key: number]: boolean }>({});
const isEndValueDisabled = ref<{ [key: number]: boolean }>({});
const props = defineProps({
options: {
errorOptions: {
type: Array as PropType<CascaderOption[]>,
required: true
},
scriptOptions: {
type: Array as PropType<CascaderOption[]>,
required: true
},
@@ -121,6 +137,36 @@
}
});
// const aaa = 'Freq_Deviation_Freq''FREQ' -
const handleErrorTypeChange = (value: any, row: any) =>{
// 使用示例
const matchedRow = findRowById(row, props.errorOptions);
row.scriptType = value;
}
// 假设 props.errorOptions 是一个数组,每个元素可能包含 children 属性
const findRowById = (id: string, options: any[]): any | null => {
for (const option of options) {
if (option.value === id) {
return option;
}
if (option.children && option.children.length > 0) {
const result = findRowById(id, option.children);
if (result) {
return result;
}
}
}
return null;
};
// 监听 props.tableData 的变化,确保每次数据变化时都重新设置 sort
watch(() => props.tableData, async (newTableData) => {
for (let i = 0; i < newTableData.length; i++) {
@@ -180,7 +226,8 @@ const handleEndFlagChange = (row: ErrorSystem.ErrorSystemDetail, value: number)
conditionType: conditionTypes.length > 0 ? Number(conditionTypes[3].value) : 0, // 设置默认值为第一个选项的值
errorValueType:errorValueTypes.length > 0 ? Number(errorValueTypes[0].value) : 0, // 设置默认值为第一个选项的值
errorSysId: "",
type: "",
errorType: "",
scriptType: "",
maxErrorValue: 0
};

View File

@@ -1,5 +1,5 @@
<template>
<el-dialog :title="dialogTitle" v-model='dialogVisible' @close="close" v-bind="dialogBig" width="1400px">
<el-dialog :title="dialogTitle" v-model='dialogVisible' @close="close" v-bind="dialogBig" width="1500px">
<el-tabs type="border-card">
<el-tab-pane label="基础信息">
<div >
@@ -35,7 +35,7 @@
</el-tabs>
<ErrorSystemDetailTable :tableData="tableData" :options="options" @updateTableData="handleTableDataUpdate" />
<ErrorSystemDetailTable :tableData="tableData" :errorOptions="errorOptions" :scriptOptions="scriptOptions" @updateTableData="handleTableDataUpdate" />
<template #footer>
<div >
@@ -63,7 +63,8 @@
const dialogFormRef = ref()
const dictStore = useDictStore()
const tableData = ref<ErrorSystem.ErrorSystemDetail[]>([]);
const options: Ref<CascaderOption[]> = ref([]); // 修改这里
const errorOptions: Ref<CascaderOption[]> = ref([]); // 修改这里
const scriptOptions: Ref<CascaderOption[]> = ref([]); // 修改这里
const handleTableDataUpdate = (newTableData: ErrorSystem.ErrorSystemDetail[]) => {
tableData.value = newTableData;
@@ -174,9 +175,35 @@ const handleTableDataUpdate = (newTableData: ErrorSystem.ErrorSystemDetail[]) =>
secondLevelOptions.push(...option.children);
}
});
// 将第二层节点赋值给 options.value
options.value = secondLevelOptions;
errorOptions.value = secondLevelOptions;
const dictCode2 = '脚本-误差'; // 替换为实际需要的字典代码
const resDictTree2: Dict.ResDictTree = {
name: dictCode2,
id: '',
pid: '',
pids: '',
code: '',
sort: 0
};
const result2 = await getDictTreeList(resDictTree2);
const allOptions2 = convertToOptions(result2.data as Dict.ResDictTree[]);
// 提取第二层节点
const secondLevelOptions2: any[] = [];
allOptions2.forEach(option => {
if (option.children && option.children.length > 0) {
secondLevelOptions2.push(...option.children);
}
});
// 将第二层节点赋值给 options.value
scriptOptions.value = secondLevelOptions2;
};
// 转换函数
@@ -184,6 +211,7 @@ const handleTableDataUpdate = (newTableData: ErrorSystem.ErrorSystemDetail[]) =>
return dictTree.map(item => ({
value: item.id,
label: item.name,
code: item.code,
children: item.children ? convertToOptions(item.children) : undefined
}));
};