From 67e2fa57d049324dc5d3602769393c21aae3f44e Mon Sep 17 00:00:00 2001 From: sjl <1716605279@qq.com> Date: Wed, 17 Dec 2025 16:47:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E8=AE=BE=E5=A4=87=E5=BD=95?= =?UTF-8?q?=E5=85=A5=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/govern/cloudDeviceEntry/index.vue | 1036 ++++++++++--------- 1 file changed, 545 insertions(+), 491 deletions(-) diff --git a/src/views/govern/cloudDeviceEntry/index.vue b/src/views/govern/cloudDeviceEntry/index.vue index 52c38f1..bb394e3 100644 --- a/src/views/govern/cloudDeviceEntry/index.vue +++ b/src/views/govern/cloudDeviceEntry/index.vue @@ -80,6 +80,7 @@ label-width="120px" :inline="true" ref="mainForm" + :model="formData" > 0 || pageStatus == 2" > --> - + - +
@@ -636,6 +652,7 @@
@@ -679,7 +696,7 @@
- + @@ -1016,6 +1041,20 @@ const devTypeOptions2: any = ref([]) const treeClickCount = ref(0) const areaTree: any = tree +const formData = ref({ + lineInfoList: [] as LineInfo[], + projectInfoList:[] as ProjectInfo[], + deviceInfoList :[] as DeviceInfo[], + engineeringParam: { + city: '', + description: '', + name: '', + province: '' + } +}) + + + const project = ref([ { name: '治理设备', value: '治理设备' }, { name: '便携式设备', value: '便携式设备' }, @@ -1043,12 +1082,12 @@ const lineSpaceArr = ref([ { name: '10分钟', value: 10 } ]) //工程 -const engineeringParam = ref({ - city: '', - description: '', - name: '', - province: '' -}) +// const engineeringParam = ref({ +// city: '', +// description: '', +// name: '', +// province: '' +// }) interface ProjectInfo { name: string @@ -1056,7 +1095,7 @@ interface ProjectInfo { description: string } // 项目信息列表 -const projectInfoList = ref([]) +//const projectInfoList = ref([]) interface DeviceInfo { name: string devModel: string @@ -1070,7 +1109,7 @@ interface DeviceInfo { nodeProcess: string } // 设备信息列表 -const deviceInfoList = ref([]) +//const deviceInfoList = ref([]) interface LineInfo { name: string lineNo: number @@ -1092,7 +1131,7 @@ interface LineInfo { protocolCapacity: number } // 监测点信息列表 -const lineInfoList = ref([]) +//const lineInfoList = ref([]) const arrdess: any = ref((rule: any, value: any, callback: any) => { let reg1 = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/ @@ -1116,8 +1155,8 @@ const arrdess: any = ref((rule: any, value: any, callback: any) => { // 省市选择相关数据 const provinceOptions = computed(() => areaTree) const cityOptions = computed(() => { - if (engineeringParam.value.province) { - const province = areaTree.find((item: any) => item.value === engineeringParam.value.province) + if (formData.value.engineeringParam.province) { + const province = areaTree.find((item: any) => item.value === formData.value.engineeringParam.province) return province ? province.children : [] } return [] @@ -1144,7 +1183,7 @@ const voltageLevelOptions = computed(() => { // 省改变时清空市的选择 const provinceChange = () => { - engineeringParam.value.city = '' + formData.value.engineeringParam.city = '' } // 临时存储所有层级的数据 const tempAllLevelData = ref({ @@ -1204,13 +1243,13 @@ const nodeClick = (e: anyObj, data: any) => { // 关键修改:确保tabs展开 setTimeout(() => { // 设置默认选中的tab索引 - if (nodeLevel.value >= 2 && projectInfoList.value.length > 0) { + if (nodeLevel.value >= 2 && formData.value.projectInfoList.length > 0) { deviceIndex.value = '0' } - if (nodeLevel.value >= 3 && deviceInfoList.value.length > 0) { + if (nodeLevel.value >= 3 && formData.value.deviceInfoList.length > 0) { busBarIndex.value = '0' } - if (nodeLevel.value >= 4 && lineInfoList.value.length > 0) { + if (nodeLevel.value >= 4 && formData.value.lineInfoList.length > 0) { lineIndex.value = '0' } }, 100) @@ -1318,18 +1357,18 @@ const cleanUnnecessaryData = () => { switch (nodeLevel.value) { case 0: // 根节点 // 清理所有数据 - projectInfoList.value = [] - deviceInfoList.value = [] - lineInfoList.value = [] + formData.value.projectInfoList = [] + formData.value.deviceInfoList = [] + formData.value.lineInfoList = [] break case 1: // 工程节点 // 清理设备和监测点数据 - deviceInfoList.value = [] - lineInfoList.value = [] + formData.value.deviceInfoList = [] + formData.value.lineInfoList = [] break case 2: // 项目节点 // 清理监测点数据 - lineInfoList.value = [] + formData.value.lineInfoList = [] break case 3: // 设备节点 // 不清理任何数据 @@ -1377,17 +1416,17 @@ const queryNodeContent = () => { } getInfoById(nodeData.value.id).then((res: any) => { - Object.assign(engineeringParam.value, res.data) - engineeringParam.value.name = res.data.engineeringName - engineeringParam.value.description = res.data.engineeringDescription - projectInfoList.value = res.data.projectInfoList || [] + Object.assign(formData.value.engineeringParam, res.data) + formData.value.engineeringParam.name = res.data.engineeringName + formData.value.engineeringParam.description = res.data.engineeringDescription + formData.value.projectInfoList = res.data.projectInfoList || [] if (nodeLevel.value >= 2) { - deviceInfoList.value = res.data.deviceInfoList || [] + formData.value.deviceInfoList = res.data.deviceInfoList || [] } if (nodeLevel.value >= 3) { - lineInfoList.value = res.data.lineInfoList || [] - lineInfoList.value.map((item: any) => { + formData.value.lineInfoList = res.data.lineInfoList || [] + formData.value.lineInfoList.map((item: any) => { item.volGrade = item.volGrade + 'kV' }) } @@ -1409,30 +1448,30 @@ const add = () => { switch (nodeLevel.value) { case 0: // 新增工程,不需要添加tab // 初始化工程参数 - engineeringParam.value.city = '' - engineeringParam.value.description = '' - engineeringParam.value.name = '' - engineeringParam.value.province = '' + formData.value.engineeringParam.city = '' + formData.value.engineeringParam.description = '' + formData.value.engineeringParam.name = '' + formData.value.engineeringParam.province = '' // 清理其他层级数据 - projectInfoList.value = [] - deviceInfoList.value = [] - lineInfoList.value = [] + formData.value.projectInfoList = [] + formData.value.deviceInfoList = [] + formData.value.lineInfoList = [] break case 1: // 新增项目,添加一个新的项目tab // 添加一个新的空项目到projectInfoList - projectInfoList.value.push({ + formData.value.projectInfoList.push({ name: '', area: '', description: '' }) - deviceIndex.value = (projectInfoList.value.length - 1).toString() + deviceIndex.value = (formData.value.projectInfoList.length - 1).toString() // 清理设备和监测点数据 - deviceInfoList.value = [] - lineInfoList.value = [] + formData.value.deviceInfoList = [] + formData.value.lineInfoList = [] break case 2: // 新增设备,添加一个新的设备tab // 添加一个新的空设备到deviceInfoList - deviceInfoList.value.push({ + formData.value.deviceInfoList.push({ name: '', devModel: '', devType: '', @@ -1444,13 +1483,13 @@ const add = () => { sort: 0, nodeProcess: '' }) - busBarIndex.value = (deviceInfoList.value.length - 1).toString() + busBarIndex.value = (formData.value.deviceInfoList.length - 1).toString() // 清理监测点数据 - lineInfoList.value = [] + formData.value.lineInfoList = [] break case 3: // 新增监测点,添加一个新的监测点tab // 添加一个新的空监测点到lineInfoList - lineInfoList.value.push({ + formData.value.lineInfoList.push({ name: '', lineNo: 1, conType: 0, @@ -1470,7 +1509,7 @@ const add = () => { devCapacity: 0, protocolCapacity: 0 }) - lineIndex.value = (lineInfoList.value.length - 1).toString() + lineIndex.value = (formData.value.lineInfoList.length - 1).toString() break } } @@ -1514,7 +1553,7 @@ const update = () => { */ const updateEngineering = (id: any) => { // 获取工程信息 - const engData = engineeringParam.value + const engData = formData.value.engineeringParam // 构建工程修改数据结构 const engineeringData = { @@ -1539,7 +1578,7 @@ const updateEngineering = (id: any) => { */ const updateProjectFunc = (id: any) => { // 获取当前选中的项目信息 - const currentProject = projectInfoList.value[deviceIndex.value] + const currentProject = formData.value.projectInfoList[deviceIndex.value] if (!currentProject) { ElMessage({ type: 'error', @@ -1562,7 +1601,7 @@ const updateProjectFunc = (id: any) => { */ const updateEquipmentFunc = (id: any) => { // 获取当前选中的设备信息 - const currentDevice = deviceInfoList.value[busBarIndex.value] + const currentDevice = formData.value.deviceInfoList[busBarIndex.value] if (!currentDevice) { ElMessage({ type: 'error', @@ -1600,7 +1639,7 @@ const updateEquipmentFunc = (id: any) => { */ const updateLineFunc = (id: any) => { // 获取当前选中的监测点信息 - const currentLine = lineInfoList.value[lineIndex.value] + const currentLine = formData.value.lineInfoList[lineIndex.value] if (!currentLine) { ElMessage({ type: 'error', @@ -1618,11 +1657,11 @@ const updateLineFunc = (id: any) => { // 获取设备MAC地址和设备ID let devMac = '' let devId = '' - if (deviceInfoList.value && deviceInfoList.value[busBarIndex.value]) { - devMac = deviceInfoList.value[busBarIndex.value].mac || '' + if (formData.value.deviceInfoList && formData.value.deviceInfoList[busBarIndex.value]) { + devMac = formData.value.deviceInfoList[busBarIndex.value].mac || '' // 如果有设备ID,也获取它 - if (deviceInfoList.value[busBarIndex.value].id) { - devId = deviceInfoList.value[busBarIndex.value].id || '' + if (formData.value.deviceInfoList[busBarIndex.value].id) { + devId = formData.value.deviceInfoList[busBarIndex.value].id || '' } } @@ -1776,83 +1815,88 @@ const remove = () => { } // 下一步 const next = async () => { - // 在新增模式下(pageStatus == 2)保存当前数据并创建下一个层级的Tab - switch (nodeLevel.value) { - case 0: // 工程层级,下一步创建项目Tab - // 保存当前工程信息到临时存储 - tempAllLevelData.value.engineering = { ...engineeringParam.value } + await mainForm.value.validate((valid: any) => { + if (valid) { + // 在新增模式下(pageStatus == 2)保存当前数据并创建下一个层级的Tab + switch (nodeLevel.value) { + case 0: // 工程层级,下一步创建项目Tab + // 保存当前工程信息到临时存储 + tempAllLevelData.value.engineering = { ...formData.value.engineeringParam } - // 创建新的项目Tab - projectInfoList.value.push({ - name: '', - area: '', - description: '' - }) - deviceIndex.value = (projectInfoList.value.length - 1).toString() - nextfalg.value = false - nodeLevel.value = 1 - break - case 1: // 项目层级,下一步创建设备Tab - // 保存当前项目信息到临时存储 - const currentProject = { ...projectInfoList.value[deviceIndex.value] } - tempAllLevelData.value.projects[deviceIndex.value] = currentProject + // 创建新的项目Tab + formData.value.projectInfoList.push({ + name: '', + area: '', + description: '' + }) + deviceIndex.value = (formData.value.projectInfoList.length - 1).toString() + nextfalg.value = false + nodeLevel.value = 1 + break + case 1: // 项目层级,下一步创建设备Tab + // 保存当前项目信息到临时存储 + const currentProject = { ...formData.value.projectInfoList[deviceIndex.value] } + tempAllLevelData.value.projects[deviceIndex.value] = currentProject - // 创建新的设备Tab - deviceInfoList.value.push({ - name: '', - devModel: '', - devType: '', - devAccessMethod: 'CLD', - mac: '', - ndid: '', - nodeId: '', - cntractNo: '', - sort: 0, - nodeProcess: '' - }) - busBarIndex.value = (deviceInfoList.value.length - 1).toString() - nextfalg.value = false - nodeLevel.value = 2 - break - case 2: // 设备层级,下一步创建监测点Tab - // 保存当前设备信息到临时存储 - const currentDevice = { ...deviceInfoList.value[busBarIndex.value] } - tempAllLevelData.value.devices[busBarIndex.value] = currentDevice + // 创建新的设备Tab + formData.value.deviceInfoList.push({ + name: '', + devModel: '', + devType: '', + devAccessMethod: 'CLD', + mac: '', + ndid: '', + nodeId: '', + cntractNo: '', + sort: 0, + nodeProcess: '' + }) + busBarIndex.value = (formData.value.deviceInfoList.length - 1).toString() + nextfalg.value = false + nodeLevel.value = 2 + break + case 2: // 设备层级,下一步创建监测点Tab + // 保存当前设备信息到临时存储 + const currentDevice = { ...formData.value.deviceInfoList[busBarIndex.value] } + tempAllLevelData.value.devices[busBarIndex.value] = currentDevice - // 创建新的监测点Tab - lineInfoList.value.push({ - name: '', - lineNo: 1, - conType: 0, - lineInterval: 1, - ptRatio: 1, - pt2Ratio: 1, - ctRatio: 1, - ct2Ratio: 1, - volGrade: '', - monitorUser: '', - devMac: '', - monitorObj: '', - govern: 0, - runStatus: 0, - basicCapacity: 0, - shortCircuitCapacity: 0, - devCapacity: 0, - protocolCapacity: 0 - }) - lineIndex.value = (lineInfoList.value.length - 1).toString() - nextfalg.value = true - nodeLevel.value = 3 - break - case 3: // 监测点层级 - // 保存当前监测点信息到临时存储 - const currentLine = { ...lineInfoList.value[lineIndex.value] } - tempAllLevelData.value.lines[lineIndex.value] = currentLine + // 创建新的监测点Tab + formData.value.lineInfoList.push({ + name: '', + lineNo: 1, + conType: 0, + lineInterval: 1, + ptRatio: 1, + pt2Ratio: 1, + ctRatio: 1, + ct2Ratio: 1, + volGrade: '', + monitorUser: '', + devMac: '', + monitorObj: '', + govern: 0, + runStatus: 0, + basicCapacity: 0, + shortCircuitCapacity: 0, + devCapacity: 0, + protocolCapacity: 0 + }) + lineIndex.value = (formData.value.lineInfoList.length - 1).toString() + nextfalg.value = true + nodeLevel.value = 3 + break + case 3: // 监测点层级 + // 保存当前监测点信息到临时存储 + const currentLine = { ...formData.value.lineInfoList[lineIndex.value] } + tempAllLevelData.value.lines[lineIndex.value] = currentLine - nextfalg.value = true - nodeLevel.value = 4 - break - } + nextfalg.value = true + nodeLevel.value = 4 + break + } + } + }) + } // 撤销 @@ -1874,353 +1918,363 @@ const black = () => { } // 确认提交 -const onsubmit = () => { - if (pageStatus.value == 2) { - // 新增 - // 检查是否是多层级新增还是单层级新增 - if ( - tempAllLevelData.value.engineering !== null || - tempAllLevelData.value.projects.length > 0 || - tempAllLevelData.value.devices.length > 0 || - tempAllLevelData.value.lines.length > 0 - ) { - // 多层级新增,一次性提交所有数据 - submitAllLevelData() - } else { - // 单层级新增,使用原有的提交方式 - submitData() +const onsubmit = async () => { + await mainForm.value.validate((valid: any) => { + if (valid) { + if (pageStatus.value == 2) { + // 新增 + // 检查是否是多层级新增还是单层级新增 + if ( + tempAllLevelData.value.engineering !== null || + tempAllLevelData.value.projects.length > 0 || + tempAllLevelData.value.devices.length > 0 || + tempAllLevelData.value.lines.length > 0 + ) { + // 多层级新增,一次性提交所有数据 + submitAllLevelData() + } else { + // 单层级新增,使用原有的提交方式 + submitData() + } + } else if (pageStatus.value == 3) { + // 修改 + switch (nodeLevel.value) { + case 1: // 修改工程 + updateEngineering(nodeData.value.id) + break + case 2: // 修改项目 + updateProjectFunc(nodeData.value.id) + break + case 3: // 修改设备 + updateEquipmentFunc(nodeData.value.id) + break + case 4: // 修改监测点 + updateLineFunc(nodeData.value.id) + break + } + } } - } else if (pageStatus.value == 3) { - // 修改 - switch (nodeLevel.value) { - case 1: // 修改工程 - updateEngineering(nodeData.value.id) - break - case 2: // 修改项目 - updateProjectFunc(nodeData.value.id) - break - case 3: // 修改设备 - updateEquipmentFunc(nodeData.value.id) - break - case 4: // 修改监测点 - updateLineFunc(nodeData.value.id) - break - } - } + + }) } /** * 一次性提交所有层级数据 */ -const submitAllLevelData = () => { +const submitAllLevelData = async () => { let submitData: any = {} - - // 根据当前节点层级构建相应的数据结构 - switch (nodeLevel.value) { - case 0: // 只有工程 - submitData = { - engineering: tempAllLevelData.value.engineering || { ...engineeringParam.value } - } - break - - case 1: // 工程 + 项目 - // 工程信息 - const engineeringData = tempAllLevelData.value.engineering || { ...engineeringParam.value } - - // 项目信息 - const projectData = - tempAllLevelData.value.projects.length > 0 - ? tempAllLevelData.value.projects.find(project => project !== undefined) || {} - : projectInfoList.value[0] || {} - // 如果是从根节点开始新增工程和项目 - if (nodeData.value.level === 0) { - submitData = { - engineering: engineeringData, - project: projectData - } - } else { - // 如果是从工程节点开始新增项目 - submitData = { - engineeringIndex: nodeData.value?.id || '', - project: projectData - } - } - break - - case 2: // 工程 + 项目 + 设备 - // 工程信息 - const engineeringData2 = tempAllLevelData.value.engineering || { ...engineeringParam.value } - // 项目信息 - const projectData2 = - tempAllLevelData.value.projects.length > 0 - ? tempAllLevelData.value.projects.find(project => project !== undefined) || {} - : projectInfoList.value[0] || {} - - // 设备信息 - let devices = [] - if (tempAllLevelData.value.devices.length > 0) { - devices = tempAllLevelData.value.devices.filter((d: any) => d && d.name) - } else { - devices = deviceInfoList.value.filter((d: any) => d && d.name) - } - - // 如果是从根节点开始新增 - if (nodeData.value.level === 0) { - submitData = { - engineering: engineeringData2, - project: projectData2, - device: devices.map((device: any) => ({ - ...device, - ndid: device.mac ? device.mac.replace(/:/g, '') : '' - })) - } - } - // 如果是从工程节点开始新增 - else if (nodeData.value.level === 1) { - submitData = { - engineeringIndex: nodeData.value?.id || '', - project: projectData2, - device: devices.map((device: any) => ({ - ...device, - ndid: device.mac ? device.mac.replace(/:/g, '') : '' - })) - } - } - // 如果是从项目节点开始新增 - else if (nodeData.value.level === 2) { - const pidsArray = nodeData.value?.pids ? nodeData.value.pids.split(',') : [] - const engineeringId = pidsArray.length >= 2 ? pidsArray[1] : '' - - submitData = { - projectIndex: nodeData.value?.id || '', - engineeringIndex: engineeringId, - device: devices.map((device: any) => ({ - ...device, - ndid: device.mac ? device.mac.replace(/:/g, '') : '' - })) - } - } - break - - case 3: // 工程 + 项目 + 设备 + 监测点 - case 4: - // 工程信息 - const engineeringData3 = tempAllLevelData.value.engineering || { ...engineeringParam.value } - - // 项目信息 - const projectData3 = - tempAllLevelData.value.projects.length > 0 - ? tempAllLevelData.value.projects.find(project => project !== undefined) || {} - : projectInfoList.value[0] || {} - - // 设备信息 - let devices2: any[] = [] - if (tempAllLevelData.value.devices.length > 0) { - devices2 = tempAllLevelData.value.devices.filter((d: any) => d && d.name) - } else { - devices2 = deviceInfoList.value.filter((d: any) => d && d.name) - } - - // 监测点信息 - let lines = [] - if (tempAllLevelData.value.lines.length > 0) { - lines = tempAllLevelData.value.lines.filter((l: any) => l && l.name) - } else { - lines = lineInfoList.value.filter((l: any) => l && l.name) - } - - // 如果是从根节点开始新增 - if (nodeData.value.level === 0) { - submitData = { - engineering: engineeringData3, - project: projectData3, - device: devices2.map((device: any) => ({ - ...device, - ndid: device.mac ? device.mac.replace(/:/g, '') : '' - })), - line: lines.map((line: any) => { - // 处理电压等级,去除"kV"后缀 - let volGradeValue = line.volGrade - if (typeof volGradeValue === 'string' && volGradeValue.endsWith('kV')) { - volGradeValue = volGradeValue.slice(0, -2) - } - - // 获取设备MAC地址 - let devMac = '' - if (devices2.length > 0) { - devMac = devices2[0].mac || '' - } - - return { - ...line, - volGrade: volGradeValue, - devMac: devMac - } - }) - } - } - // 如果是从工程节点开始新增 - else if (nodeData.value.level === 1) { - submitData = { - engineeringIndex: nodeData.value?.id || '', - project: projectData3, - device: devices2.map((device: any) => ({ - ...device, - ndid: device.mac ? device.mac.replace(/:/g, '') : '' - })), - line: lines.map((line: any) => { - // 处理电压等级,去除"kV"后缀 - let volGradeValue = line.volGrade - if (typeof volGradeValue === 'string' && volGradeValue.endsWith('kV')) { - volGradeValue = volGradeValue.slice(0, -2) - } - - // 获取设备MAC地址 - let devMac = '' - if (devices2.length > 0) { - devMac = devices2[0].mac || '' - } - - return { - ...line, - volGrade: volGradeValue, - devMac: devMac - } - }) - } - } - // 如果是从项目节点开始新增 - else if (nodeData.value.level === 2) { - const pidsArray = nodeData.value?.pids ? nodeData.value.pids.split(',') : [] - const engineeringId = pidsArray.length >= 2 ? pidsArray[1] : '' - - submitData = { - device: devices2.map((device: any) => ({ - ...device, - ndid: device.mac ? device.mac.replace(/:/g, '') : '' - })), - projectIndex: nodeData.value?.id || '', - engineeringIndex: engineeringId, - line: lines.map((line: any) => { - // 处理电压等级,去除"kV"后缀 - let volGradeValue = line.volGrade - if (typeof volGradeValue === 'string' && volGradeValue.endsWith('kV')) { - volGradeValue = volGradeValue.slice(0, -2) - } - - // 获取设备MAC地址 - let devMac = '' - if (devices2.length > 0) { - devMac = devices2[0].mac || '' - } - - return { - ...line, - volGrade: volGradeValue, - devMac: devMac - } - }) - } - } - // 如果是从设备节点开始新增 - else if (nodeData.value.level === 3) { - const pidsArray2 = nodeData.value?.pids ? nodeData.value.pids.split(',') : [] - const engineeringId2 = pidsArray2.length >= 2 ? pidsArray2[1] : '' - const projectId = pidsArray2.length >= 3 ? pidsArray2[2] : '' - - submitData = { - devIndex: nodeData.value?.id || '', - projectIndex: projectId, - engineeringIndex: engineeringId2, - line: lines.map((line: any) => { - // 处理电压等级,去除"kV"后缀 - let volGradeValue = line.volGrade - if (typeof volGradeValue === 'string' && volGradeValue.endsWith('kV')) { - volGradeValue = volGradeValue.slice(0, -2) - } - - // 获取设备MAC地址 - let devMac = '' - if (devices2.length > 0) { - devMac = devices2[0].mac || '' - } - - return { - ...line, - volGrade: volGradeValue, - devMac: devMac - } - }) - } - } - break - } - - // 发送请求 - addLedger(submitData).then((res: any) => { - ElMessage({ - type: 'success', - message: '数据提交成功' - }) - pageStatus.value = 1 - // 清空所有表单 - resetAllForms() - // 刷新树并选中合适的节点 - TerminalRef.value.info() - // 等待树更新完成后,根据之前点击的节点层级选中合适的节点 - setTimeout(() => { - let nodeIdToSelect: string | null | undefined = null - - // 根据新增的层级选择要选中的节点 + await mainForm.value.validate((valid: any) => { + if (valid) { + // 根据当前节点层级构建相应的数据结构 switch (nodeLevel.value) { - case 0: // 新增了工程,选中根节点 - nodeIdToSelect = null // 根节点 + case 0: // 只有工程 + submitData = { + engineering: tempAllLevelData.value.engineering || { ...formData.value.engineeringParam } + } break - case 1: // 新增了项目,选中工程节点 - nodeIdToSelect = nodeData.value.id // 工程节点 + + case 1: // 工程 + 项目 + // 工程信息 + const engineeringData = tempAllLevelData.value.engineering || { ...formData.value.engineeringParam } + + // 项目信息 + const projectData = + tempAllLevelData.value.projects.length > 0 + ? tempAllLevelData.value.projects.find(project => project !== undefined) || {} + : formData.value.projectInfoList[0] || {} + // 如果是从根节点开始新增工程和项目 + if (nodeData.value.level === 0) { + submitData = { + engineering: engineeringData, + project: projectData + } + } else { + // 如果是从工程节点开始新增项目 + submitData = { + engineeringIndex: nodeData.value?.id || '', + project: projectData + } + } break - case 2: // 新增了设备,选中项目节点 - nodeIdToSelect = nodeData.value.id // 项目节点 + + case 2: // 工程 + 项目 + 设备 + // 工程信息 + const engineeringData2 = tempAllLevelData.value.engineering || { ...formData.value.engineeringParam } + // 项目信息 + const projectData2 = + tempAllLevelData.value.projects.length > 0 + ? tempAllLevelData.value.projects.find(project => project !== undefined) || {} + : formData.value.projectInfoList[0] || {} + + // 设备信息 + let devices = [] + if (tempAllLevelData.value.devices.length > 0) { + devices = tempAllLevelData.value.devices.filter((d: any) => d && d.name) + } else { + devices = formData.value.deviceInfoList.filter((d: any) => d && d.name) + } + + // 如果是从根节点开始新增 + if (nodeData.value.level === 0) { + submitData = { + engineering: engineeringData2, + project: projectData2, + device: devices.map((device: any) => ({ + ...device, + ndid: device.mac ? device.mac.replace(/:/g, '') : '' + })) + } + } + // 如果是从工程节点开始新增 + else if (nodeData.value.level === 1) { + submitData = { + engineeringIndex: nodeData.value?.id || '', + project: projectData2, + device: devices.map((device: any) => ({ + ...device, + ndid: device.mac ? device.mac.replace(/:/g, '') : '' + })) + } + } + // 如果是从项目节点开始新增 + else if (nodeData.value.level === 2) { + const pidsArray = nodeData.value?.pids ? nodeData.value.pids.split(',') : [] + const engineeringId = pidsArray.length >= 2 ? pidsArray[1] : '' + + submitData = { + projectIndex: nodeData.value?.id || '', + engineeringIndex: engineeringId, + device: devices.map((device: any) => ({ + ...device, + ndid: device.mac ? device.mac.replace(/:/g, '') : '' + })) + } + } break - case 3: // 新增了监测点,选中设备节点 + + case 3: // 工程 + 项目 + 设备 + 监测点 case 4: - nodeIdToSelect = nodeData.value.id // 设备节点 + // 工程信息 + const engineeringData3 = tempAllLevelData.value.engineering || { ...formData.value.engineeringParam } + + // 项目信息 + const projectData3 = + tempAllLevelData.value.projects.length > 0 + ? tempAllLevelData.value.projects.find(project => project !== undefined) || {} + : formData.value.projectInfoList[0] || {} + + // 设备信息 + let devices2: any[] = [] + if (tempAllLevelData.value.devices.length > 0) { + devices2 = tempAllLevelData.value.devices.filter((d: any) => d && d.name) + } else { + devices2 = formData.value.deviceInfoList.filter((d: any) => d && d.name) + } + + // 监测点信息 + let lines = [] + if (tempAllLevelData.value.lines.length > 0) { + lines = tempAllLevelData.value.lines.filter((l: any) => l && l.name) + } else { + lines = formData.value.lineInfoList.filter((l: any) => l && l.name) + } + + // 如果是从根节点开始新增 + if (nodeData.value.level === 0) { + submitData = { + engineering: engineeringData3, + project: projectData3, + device: devices2.map((device: any) => ({ + ...device, + ndid: device.mac ? device.mac.replace(/:/g, '') : '' + })), + line: lines.map((line: any) => { + // 处理电压等级,去除"kV"后缀 + let volGradeValue = line.volGrade + if (typeof volGradeValue === 'string' && volGradeValue.endsWith('kV')) { + volGradeValue = volGradeValue.slice(0, -2) + } + + // 获取设备MAC地址 + let devMac = '' + if (devices2.length > 0) { + devMac = devices2[0].mac || '' + } + + return { + ...line, + volGrade: volGradeValue, + devMac: devMac + } + }) + } + } + // 如果是从工程节点开始新增 + else if (nodeData.value.level === 1) { + submitData = { + engineeringIndex: nodeData.value?.id || '', + project: projectData3, + device: devices2.map((device: any) => ({ + ...device, + ndid: device.mac ? device.mac.replace(/:/g, '') : '' + })), + line: lines.map((line: any) => { + // 处理电压等级,去除"kV"后缀 + let volGradeValue = line.volGrade + if (typeof volGradeValue === 'string' && volGradeValue.endsWith('kV')) { + volGradeValue = volGradeValue.slice(0, -2) + } + + // 获取设备MAC地址 + let devMac = '' + if (devices2.length > 0) { + devMac = devices2[0].mac || '' + } + + return { + ...line, + volGrade: volGradeValue, + devMac: devMac + } + }) + } + } + // 如果是从项目节点开始新增 + else if (nodeData.value.level === 2) { + const pidsArray = nodeData.value?.pids ? nodeData.value.pids.split(',') : [] + const engineeringId = pidsArray.length >= 2 ? pidsArray[1] : '' + + submitData = { + device: devices2.map((device: any) => ({ + ...device, + ndid: device.mac ? device.mac.replace(/:/g, '') : '' + })), + projectIndex: nodeData.value?.id || '', + engineeringIndex: engineeringId, + line: lines.map((line: any) => { + // 处理电压等级,去除"kV"后缀 + let volGradeValue = line.volGrade + if (typeof volGradeValue === 'string' && volGradeValue.endsWith('kV')) { + volGradeValue = volGradeValue.slice(0, -2) + } + + // 获取设备MAC地址 + let devMac = '' + if (devices2.length > 0) { + devMac = devices2[0].mac || '' + } + + return { + ...line, + volGrade: volGradeValue, + devMac: devMac + } + }) + } + } + // 如果是从设备节点开始新增 + else if (nodeData.value.level === 3) { + const pidsArray2 = nodeData.value?.pids ? nodeData.value.pids.split(',') : [] + const engineeringId2 = pidsArray2.length >= 2 ? pidsArray2[1] : '' + const projectId = pidsArray2.length >= 3 ? pidsArray2[2] : '' + + submitData = { + devIndex: nodeData.value?.id || '', + projectIndex: projectId, + engineeringIndex: engineeringId2, + line: lines.map((line: any) => { + // 处理电压等级,去除"kV"后缀 + let volGradeValue = line.volGrade + if (typeof volGradeValue === 'string' && volGradeValue.endsWith('kV')) { + volGradeValue = volGradeValue.slice(0, -2) + } + + // 获取设备MAC地址 + let devMac = '' + if (devices2.length > 0) { + devMac = devices2[0].mac || '' + } + + return { + ...line, + volGrade: volGradeValue, + devMac: devMac + } + }) + } + } break } - if (nodeIdToSelect) { + // 发送请求 + addLedger(submitData).then((res: any) => { + ElMessage({ + type: 'success', + message: '数据提交成功' + }) + pageStatus.value = 1 + // 清空所有表单 + resetAllForms() + // 刷新树并选中合适的节点 + TerminalRef.value.info() + // 等待树更新完成后,根据之前点击的节点层级选中合适的节点 setTimeout(() => { - treedata(nodeIdToSelect !== null ? nodeIdToSelect : undefined) - // 重新加载节点内容以显示最新数据 - setTimeout(() => { - queryNodeContent() - }, 200) + let nodeIdToSelect: string | null | undefined = null + + // 根据新增的层级选择要选中的节点 + switch (nodeLevel.value) { + case 0: // 新增了工程,选中根节点 + nodeIdToSelect = null // 根节点 + break + case 1: // 新增了项目,选中工程节点 + nodeIdToSelect = nodeData.value.id // 工程节点 + break + case 2: // 新增了设备,选中项目节点 + nodeIdToSelect = nodeData.value.id // 项目节点 + break + case 3: // 新增了监测点,选中设备节点 + case 4: + nodeIdToSelect = nodeData.value.id // 设备节点 + break + } + + if (nodeIdToSelect) { + setTimeout(() => { + treedata(nodeIdToSelect !== null ? nodeIdToSelect : undefined) + // 重新加载节点内容以显示最新数据 + setTimeout(() => { + queryNodeContent() + }, 200) + }, 100) + } else { + treedata() // 选中根节点 + } }, 100) - } else { - treedata() // 选中根节点 - } - }, 100) + }) + + } }) + } /** * 重置所有表单 */ const resetAllForms = () => { // 清空工程表单 - engineeringParam.value.city = '' - engineeringParam.value.description = '' - engineeringParam.value.name = '' - engineeringParam.value.province = '' + formData.value.engineeringParam.city = '' + formData.value.engineeringParam.description = '' + formData.value.engineeringParam.name = '' + formData.value.engineeringParam.province = '' // 清空项目表单 - projectInfoList.value.forEach(project => { + formData.value.projectInfoList.forEach(project => { project.name = '' project.area = '' project.description = '' }) // 清空设备表单 - deviceInfoList.value.forEach(device => { + formData.value.deviceInfoList.forEach(device => { device.name = '' device.devModel = '' device.devType = '' @@ -2232,7 +2286,7 @@ const resetAllForms = () => { }) // 清空监测点表单 - lineInfoList.value.forEach(line => { + formData.value.lineInfoList.forEach(line => { line.name = '' line.lineNo = 1 line.conType = 0 @@ -2269,10 +2323,10 @@ const submitData = () => { case 0: // 新增工程 const engineering = { engineering: { - city: engineeringParam.value.city, - description: engineeringParam.value.description, - name: engineeringParam.value.name, - province: engineeringParam.value.province + city: formData.value.engineeringParam.city, + description: formData.value.engineeringParam.description, + name: formData.value.engineeringParam.name, + province: formData.value.engineeringParam.province } } @@ -2292,9 +2346,9 @@ const submitData = () => { const project = { engineeringIndex: nodeData.value?.id || '', project: { - area: projectInfoList.value[deviceIndex.value]?.area || '', - description: projectInfoList.value[deviceIndex.value]?.description || '', - name: projectInfoList.value[deviceIndex.value]?.name || '', + area: formData.value.projectInfoList[deviceIndex.value]?.area || '', + description: formData.value.projectInfoList[deviceIndex.value]?.description || '', + name: formData.value.projectInfoList[deviceIndex.value]?.name || '', engineeringId: nodeData.value?.id || '' } } @@ -2322,7 +2376,7 @@ const submitData = () => { break case 2: // 新增设备 // 获取当前选中的设备信息 - const currentDevice = deviceInfoList.value[busBarIndex.value] + const currentDevice = formData.value.deviceInfoList[busBarIndex.value] if (!currentDevice) { ElMessage({ type: 'error', @@ -2375,7 +2429,7 @@ const submitData = () => { break case 3: // 新增监测点 // 获取当前选中的监测点信息 - const currentLine = lineInfoList.value[lineIndex.value] + const currentLine = formData.value.lineInfoList[lineIndex.value] if (!currentLine) { ElMessage({ type: 'error', @@ -2418,7 +2472,7 @@ const submitData = () => { devCapacity: currentLine.devCapacity, protocolCapacity: currentLine.protocolCapacity, volGrade: volGradeValue, - devMac: deviceInfoList.value[busBarIndex.value].mac + devMac: formData.value.deviceInfoList[busBarIndex.value].mac } ] } @@ -2453,12 +2507,12 @@ const submitData = () => { const handleDeviceTabsEdit = (targetName: any, action: any) => { if (action === 'add') { // 新增项目 - projectInfoList.value.push({ + formData.value.projectInfoList.push({ name: '', area: '', description: '' }) - deviceIndex.value = (projectInfoList.value.length - 1).toString() + deviceIndex.value = (formData.value.projectInfoList.length - 1).toString() } else if (action === 'remove') { // 删除项目 ElMessageBox.confirm('此操作将永久删除, 是否继续?', '提示', { @@ -2468,12 +2522,12 @@ const handleDeviceTabsEdit = (targetName: any, action: any) => { }) .then(() => { // 删除项目 - if (projectInfoList.value[deviceIndex.value]?.id) { + if (formData.value.projectInfoList[deviceIndex.value]?.id) { deleteProject( - projectInfoList.value[deviceIndex.value].id, - projectInfoList.value[deviceIndex.value].name, - projectInfoList.value[deviceIndex.value].area, - projectInfoList.value[deviceIndex.value].description, + formData.value.projectInfoList[deviceIndex.value].id, + formData.value.projectInfoList[deviceIndex.value].name, + formData.value.projectInfoList[deviceIndex.value].area, + formData.value.projectInfoList[deviceIndex.value].description, 0 // 0表示删除 ).then((res: any) => { ElMessage({ @@ -2481,10 +2535,10 @@ const handleDeviceTabsEdit = (targetName: any, action: any) => { message: res.message }) // 从列表中移除 - projectInfoList.value.splice(deviceIndex.value, 1) + formData.value.projectInfoList.splice(deviceIndex.value, 1) // 重新设置当前选中的tab - deviceIndex.value = projectInfoList.value.length - ? (projectInfoList.value.length - 1).toString() + deviceIndex.value = formData.value.projectInfoList.length + ? (formData.value.projectInfoList.length - 1).toString() : '0' // 重置相关索引 busBarIndex.value = '0' @@ -2494,9 +2548,9 @@ const handleDeviceTabsEdit = (targetName: any, action: any) => { }) } else { // 如果是新增模式下删除未保存的项目 - projectInfoList.value.splice(deviceIndex.value, 1) - deviceIndex.value = projectInfoList.value.length - ? (projectInfoList.value.length - 1).toString() + formData.value.projectInfoList.splice(deviceIndex.value, 1) + deviceIndex.value = formData.value.projectInfoList.length + ? (formData.value.projectInfoList.length - 1).toString() : '0' busBarIndex.value = '0' lineIndex.value = '0' @@ -2521,7 +2575,7 @@ const handleDeviceTabsEdit = (targetName: any, action: any) => { const handleBusBarTabsEdit = (targetName: any, action: any) => { if (action === 'add') { // 新增设备 - deviceInfoList.value.push({ + formData.value.deviceInfoList.push({ name: '', devModel: '', devType: '', @@ -2533,7 +2587,7 @@ const handleBusBarTabsEdit = (targetName: any, action: any) => { sort: 0, nodeProcess: '' }) - busBarIndex.value = (deviceInfoList.value.length - 1).toString() + busBarIndex.value = (formData.value.deviceInfoList.length - 1).toString() } else if (action === 'remove') { // 删除设备 ElMessageBox.confirm('此操作将永久删除, 是否继续?', '提示', { @@ -2543,17 +2597,17 @@ const handleBusBarTabsEdit = (targetName: any, action: any) => { }) .then(() => { // 如果是编辑现有设备 - if (deviceInfoList.value[busBarIndex.value]?.id) { - deleteEquipment(deviceInfoList.value[busBarIndex.value].id).then((res: any) => { + if (formData.value.deviceInfoList[busBarIndex.value]?.id) { + deleteEquipment(formData.value.deviceInfoList[busBarIndex.value].id).then((res: any) => { ElMessage({ type: 'success', message: res.message }) // 从列表中移除 - deviceInfoList.value.splice(busBarIndex.value, 1) + formData.value.deviceInfoList.splice(busBarIndex.value, 1) // 重新设置当前选中的tab - busBarIndex.value = deviceInfoList.value.length - ? (deviceInfoList.value.length - 1).toString() + busBarIndex.value = formData.value.deviceInfoList.length + ? (formData.value.deviceInfoList.length - 1).toString() : '0' lineIndex.value = '0' pageStatus.value = 1 @@ -2561,8 +2615,8 @@ const handleBusBarTabsEdit = (targetName: any, action: any) => { }) } else { // 如果是新增模式下删除未保存的设备 - deviceInfoList.value.splice(busBarIndex.value, 1) - busBarIndex.value = deviceInfoList.value.length ? (deviceInfoList.value.length - 1).toString() : '0' + formData.value.deviceInfoList.splice(busBarIndex.value, 1) + busBarIndex.value = formData.value.deviceInfoList.length ? (formData.value.deviceInfoList.length - 1).toString() : '0' lineIndex.value = '0' ElMessage({ type: 'success', @@ -2585,7 +2639,7 @@ const handleBusBarTabsEdit = (targetName: any, action: any) => { const handleLineTabsEdit = (targetName: any, action: any) => { if (action === 'add') { // 新增监测点 - lineInfoList.value.push({ + formData.value.lineInfoList.push({ name: '', lineNo: 1, conType: 0, @@ -2605,7 +2659,7 @@ const handleLineTabsEdit = (targetName: any, action: any) => { devCapacity: 0, protocolCapacity: 0 }) - lineIndex.value = (lineInfoList.value.length - 1).toString() + lineIndex.value = (formData.value.lineInfoList.length - 1).toString() } else if (action === 'remove') { // 删除监测点 ElMessageBox.confirm('此操作将永久删除, 是否继续?', '提示', { @@ -2615,23 +2669,23 @@ const handleLineTabsEdit = (targetName: any, action: any) => { }) .then(() => { // 如果是编辑现有监测点 - if (lineInfoList.value[lineIndex.value]?.lineId) { - deleteLine(lineInfoList.value[lineIndex.value].lineId).then((res: any) => { + if (formData.value.lineInfoList[lineIndex.value]?.lineId) { + deleteLine(formData.value.lineInfoList[lineIndex.value].lineId).then((res: any) => { ElMessage({ type: 'success', message: res.message }) // 从列表中移除 - lineInfoList.value.splice(lineIndex.value, 1) + formData.value.lineInfoList.splice(lineIndex.value, 1) // 重新设置当前选中的tab - lineIndex.value = lineInfoList.value.length ? (lineInfoList.value.length - 1).toString() : '0' + lineIndex.value = formData.value.lineInfoList.length ? (formData.value.lineInfoList.length - 1).toString() : '0' pageStatus.value = 1 treedata() }) } else { // 如果是新增模式下删除未保存的监测点 - lineInfoList.value.splice(lineIndex.value, 1) - lineIndex.value = lineInfoList.value.length ? (lineInfoList.value.length - 1).toString() : '0' + formData.value.lineInfoList.splice(lineIndex.value, 1) + lineIndex.value = formData.value.lineInfoList.length ? (formData.value.lineInfoList.length - 1).toString() : '0' ElMessage({ type: 'success', message: '删除成功'