From e46e9e1d3ac352d10694af906c0373dbdb3a6c3c Mon Sep 17 00:00:00 2001 From: sjl <1716605279@qq.com> Date: Tue, 11 Feb 2025 10:32:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=B1=BB=E5=9E=8BCRUD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/device/device/index.ts | 2 +- frontend/src/views/home/components/table.vue | 6 +-- frontend/src/views/home/components/tree.vue | 56 +++++++++++--------- frontend/src/views/home/tabs/dashboard.vue | 1 - 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/frontend/src/api/device/device/index.ts b/frontend/src/api/device/device/index.ts index 2140ee9..fe584ad 100644 --- a/frontend/src/api/device/device/index.ts +++ b/frontend/src/api/device/device/index.ts @@ -54,7 +54,7 @@ export const importCNDev = (params: Device.ReqPqDevParams) => { } //根据设备类型决定(电源、icd、模板、通道数、额定电压、额定电流); export const getPqDev = () => { - return http.post(`/devType/listAll`) + return http.get(`/devType/listAll`) } //被检设备归档 diff --git a/frontend/src/views/home/components/table.vue b/frontend/src/views/home/components/table.vue index 5543bb6..3a49786 100644 --- a/frontend/src/views/home/components/table.vue +++ b/frontend/src/views/home/components/table.vue @@ -482,7 +482,7 @@ const getTableList = async (params: any) => { } else { checkStateList.value = checkStateTable.value } - console.log('table,getBoundPqDevList') + //console.log('table,getBoundPqDevList') return getBoundPqDevList({ 'planId': props.id, 'checkStateList': checkStateList.value, @@ -667,12 +667,12 @@ const handleSelectionChange = (selection: any[]) => { //查询 const handleSearch = () => { - console.log('handleSearch,getBoundPqDevList') + //console.log('handleSearch,getBoundPqDevList') proTable.value?.getTableList() } //重置 const handleRefresh = () => { - console.log('handleRefresh,getBoundPqDevList') + //console.log('handleRefresh,getBoundPqDevList') form.value.search = null form.value.checkStatus = null form.value.checkResult = null diff --git a/frontend/src/views/home/components/tree.vue b/frontend/src/views/home/components/tree.vue index 1131684..6ba2dcc 100644 --- a/frontend/src/views/home/components/tree.vue +++ b/frontend/src/views/home/components/tree.vue @@ -55,30 +55,34 @@ const searchForm = ref({ planName: '', }) const defaultChecked = ref([]) // 明确类型为 number[] +const tree = ref(false)//确保左侧树高凉只执行一次 const getTreeData = (val: any) => { - - defaultChecked.value = [] - data.value = val - if (data.value.length > 0 && data.value[0].children.length > 0) { - let node = data.value[0].children[0] - defaultChecked.value.push(node.id) - checkStore.setPlanId(node.id) - checkStore.setPlanCode(node.code) - checkStore.setScriptId(node.scriptId) - checkStore.setErrorSysId(node.errorSysId) - // 高亮显示第一个节点 - // 使用 nextTick 确保在 DOM 更新后调用 setCurrentKey - nextTick(() => { - treeRef.value?.setCurrentKey(node.id); - idd.value = node.id - }); - //console.log(checkStore.planId,checkStore.planCode,checkStore.scriptId,checkStore.errorSysId) - } + defaultChecked.value = []; + data.value = val; + for (let item of data.value) { + if (item.children.length > 0) { + let node = item.children[0]; + defaultChecked.value.push(node.id); + checkStore.setPlanId(node.id); + checkStore.setPlanCode(node.code); + checkStore.setScriptId(node.scriptId); + checkStore.setErrorSysId(node.errorSysId); + // 高亮显示第一个节点 + // 使用 nextTick 确保在 DOM 更新后调用 setCurrentKey + nextTick(() => { + treeRef.value?.setCurrentKey(node.id); + idd.value = node.id; + }); + // 找到第一个符合条件的 children 后跳出循环 + break; + } + } } //点击表格后左侧树刷新,高亮显示对应节点 const clickTableToTree = (val: any,id:any) => { + defaultChecked.value = [] data.value = val let node = ref('') @@ -116,14 +120,14 @@ watch( const idd = ref('') const handleNodeClick = (data: Plan.ResPlan) => { - - if (data.name === '未检' || data.name === '检测中' || data.name === '检测完成') { - // 如果是父节点,不执行任何操作 - //console.log('父节点不执行任何操作'); - // 设置当前高亮节点 - nextTick(() => { - treeRef.value?.setCurrentKey(idd.value); - }); + + if (data.name === '未检' || data.name === '检测中' || data.name === '检测完成') { + // 如果是父节点,不执行任何操作 + //console.log('父节点不执行任何操作'); + // 设置当前高亮节点 + nextTick(() => { + treeRef.value?.setCurrentKey(idd.value); + }); return; } diff --git a/frontend/src/views/home/tabs/dashboard.vue b/frontend/src/views/home/tabs/dashboard.vue index 0b99821..45035e4 100644 --- a/frontend/src/views/home/tabs/dashboard.vue +++ b/frontend/src/views/home/tabs/dashboard.vue @@ -399,7 +399,6 @@ const getPieData = async (id: string) => { pieRef3.value.init() } const getTree = (data?: any) => { - treeRef.value.getTreeData(data) } //前往检测