This commit is contained in:
caozehui
2024-11-29 16:29:26 +08:00
parent 6d34bcfde7
commit a249e5e185
3 changed files with 58 additions and 17 deletions

View File

@@ -32,4 +32,13 @@ export namespace TestSource {
export interface ResTestSourcePage extends ResPage<ResTestSource> { export interface ResTestSourcePage extends ResPage<ResTestSource> {
} }
export interface ParameterType{
id:string;
sourceParamType:string;
sourceParamDesc:string;
sourceParamValue:string;
sort:number;
pId:string;
children?:ParameterType[];
}
} }

View File

@@ -37,39 +37,57 @@
import { useDictStore } from '@/stores/modules/dict' import { useDictStore } from '@/stores/modules/dict'
import ParameterPopup from '@/views/machine/testSource/components/parameterPopup.vue'; import ParameterPopup from '@/views/machine/testSource/components/parameterPopup.vue';
import { onMounted, reactive, ref, watch } from 'vue' import { onMounted, reactive, ref, watch } from 'vue'
import {map} from "lodash";
const parameterPopup = ref() const parameterPopup = ref()
const dictStore = useDictStore() const dictStore = useDictStore()
// ProTable 实例 // ProTable 实例
const proTable = ref<ProTableInstance>() const proTable = ref<ProTableInstance>()
const tableData = ref<any[]>([]) const tableData = ref<any[]>([])
const props = defineProps<{ const props = defineProps<{
data: TestSource.ResTestSource | null; parameterStr: string;
}>(); }>();
let originalParameterArr: TestSource.ParameterType[] = []
onMounted(() => { onMounted(() => {
getTableList(); getTableList();
}) })
watch(() => props.data, (newData) => { watch(() => props.parameterStr, (newData) => {
if (newData) { if (newData) {
getTableList(); getTableList();
} }
}) })
const getTableList = () => { const getTableList = () => {
if (props.data) { if (props.parameterStr) {
// 处理传递过来的数据 originalParameterArr =JSON.parse(props.parameterStr)
let newParams = props.data.parameter ? JSON.parse(props.data.parameter) : {}; tableData.value = getTreeData(originalParameterArr)
// 确保 newParams 是一个数组
if (!Array.isArray(newParams)) {
newParams = [newParams];
}
const apiData = newParams;
tableData.value = apiData;
} }
}; };
const getTreeData = (data: TestSource.ParameterType[]): TestSource.ParameterType[] => {
const result: TestSource.ParameterType[] = []// 最终返回的树形结构数据
//不能修改原数组,所以需要深拷贝
const copyData = JSON.parse(JSON.stringify(data))
const map = new Map<string, TestSource.ParameterType>();
copyData.forEach(item => {
map.set(item.id, item);
});
for (const item of copyData) {
let parent = map.get(item.pId);
if (parent) {
if (!parent.children) {
parent.children = [];
}
parent.children.push(item);
} else {
result.push(item);
}
}
return result;
}
const columns = reactive<ColumnProps<any>[]>([ const columns = reactive<ColumnProps<any>[]>([
{ type: 'selection', fixed: 'left', width: 70 }, { type: 'selection', fixed: 'left', width: 70 },
{ type: 'index', fixed: 'left', width: 70, label: '序号' }, { type: 'index', fixed: 'left', width: 70, label: '序号' },
@@ -107,10 +125,24 @@ const batchDelete = async (id: string[]) => {
// 删除设备 // 删除设备
const handleDelete = async (params: TestSource.ResTestSource) => { const handleDelete = async (params: TestSource.ResTestSource) => {
console.log(tableData.value ) let parentIds = originalParameterArr.map(item => item.pId)
tableData.value = tableData.value.filter(item => item.id !== params.id); if (parentIds.includes(params.id)) {
console.log(tableData.value ) ElMessage.error('不能删除父节点');
return;
} }
originalParameterArr = originalParameterArr.filter(item => item.id !== params.id);
tableData.value = getTreeData(originalParameterArr)
}
const copyRow = (row) => {
let parentIds = originalParameterArr.map(item => item.pId)
// if (parentIds.includes(row.id)) {
// originalParameterArr.push({
//
// })
// } else {
//
// }
};
</script> </script>

View File

@@ -36,7 +36,7 @@
</el-form> </el-form>
</div> </div>
<ParameterTable :data="formContent"/> <ParameterTable :parameterStr="formContent.parameter"/>
<template #footer> <template #footer>
<div > <div >
<el-button @click='close()'> </el-button> <el-button @click='close()'> </el-button>