From 81f287e9ff180623f05edd7fe7cf95e357cf7fbc Mon Sep 17 00:00:00 2001 From: zhongzm Date: Sat, 18 Oct 2025 15:23:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=86=97=E4=BD=99=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/ne/neInfo/index.vue | 183 +--------------------------------- 1 file changed, 1 insertion(+), 182 deletions(-) diff --git a/src/views/ne/neInfo/index.vue b/src/views/ne/neInfo/index.vue index b39c9092..03b61197 100644 --- a/src/views/ne/neInfo/index.vue +++ b/src/views/ne/neInfo/index.vue @@ -304,10 +304,7 @@ function fnModalEditOk(from: Record) { * @param formData 表单数据 */ function updateFormDataToTable(foundItem: any, foundItemParent: any, formData: any) { - console.log('更新表单数据到表格:', { foundItem, foundItemParent, formData }); - if (!foundItem) { - console.error('未找到要更新的项目'); return; } @@ -334,8 +331,6 @@ function updateFormDataToTable(foundItem: any, foundItemParent: any, formData: a } } }); - - console.log('表单数据更新完成'); } /** @@ -346,13 +341,9 @@ function updateFormDataToTable(foundItem: any, foundItemParent: any, formData: a * @param neId 网元ID */ function updateStatusFromApi(foundItem: any, foundItemParent: any, neType: string, neId: string) { - console.log('从API获取状态信息:', { neType, neId }); - stateNeInfo(neType, neId) .then(res => { if (res.code === RESULT_CODE_SUCCESS) { - console.log('状态API返回:', res.data); - // 智能状态映射:根据字典数据动态确定状态值 const getStatusValue = (onlineValue: boolean): string => { if (!dict.neInfoStatus || dict.neInfoStatus.length === 0) { @@ -395,13 +386,7 @@ function updateStatusFromApi(foundItem: any, foundItemParent: any, neType: strin } else { // 如果是单行,直接更新 foundItem.status = newStatusValue; - } - - console.log('状态更新完成:', { - original: res.data.online, - mapped: newStatusValue, - dictData: dict.neInfoStatus - }); + }; // 强制触发Vue响应式更新 nextTick(() => { @@ -413,177 +398,12 @@ function updateStatusFromApi(foundItem: any, foundItemParent: any, neType: strin useNeInfoStore().fnRefreshNelist(); } else { - console.error('获取状态信息失败:', res.msg); } }) .catch(error => { - console.error('获取状态信息失败:', error); }); } -/** - * 更新单个网元信息 - * @param foundItem 找到的网元项目 - * @param foundItemParent 父级项目(如果是子项) - * @param newData 新的网元数据 - */ -function updateSingleNeInfo(foundItem: any, foundItemParent: any, newData: any) { - console.log('更新单个网元信息:', { foundItem, foundItemParent, newData }); - - if (!foundItem) { - console.error('未找到要更新的项目'); - return; - } - - // 调试:查看原本的状态值 - console.log('原本的状态值:', foundItem.status); - console.log('字典数据:', dict.neInfoStatus); - - // 字段映射:将接口返回的字段映射到表格使用的字段 - const fieldMapping: Record = { - 'neIP': 'ip', // neIP -> ip - 'online': 'status', // online -> status - 'neId': 'neId', - 'neName': 'neName', - 'neType': 'neType' - }; - - // 智能状态映射:根据字典数据动态确定状态值 - const getStatusValue = (onlineValue: boolean): string => { - if (!dict.neInfoStatus || dict.neInfoStatus.length === 0) { - // 如果字典数据未加载,使用默认值 - return onlineValue ? '1' : '0'; - } - - // 查找字典中的在线和离线状态 - const onlineStatus = dict.neInfoStatus.find(item => - item.label?.toLowerCase().includes('online') || - item.label?.toLowerCase().includes('在线') || - item.label?.toLowerCase().includes('正常') - ); - - const offlineStatus = dict.neInfoStatus.find(item => - item.label?.toLowerCase().includes('offline') || - item.label?.toLowerCase().includes('离线') || - item.label?.toLowerCase().includes('异常') - ); - - if (onlineValue) { - return onlineStatus?.value || '1'; - } else { - return offlineStatus?.value || '0'; - } - }; - - // 更新字段 - 使用Vue.set确保响应式更新 - Object.keys(fieldMapping).forEach(apiField => { - const tableField = fieldMapping[apiField]; - if (newData[apiField] !== undefined) { - if (apiField === 'online') { - // 特殊处理状态字段,使用智能映射 - const newStatusValue = getStatusValue(newData[apiField]); - - // 使用Vue的响应式更新方式 - if (foundItemParent) { - // 如果是子项,需要更新父级引用 - const childIndex = foundItemParent.children.findIndex((child: any) => child.id === foundItem.id); - if (childIndex !== -1) { - foundItemParent.children[childIndex] = { - ...foundItemParent.children[childIndex], - [tableField]: newStatusValue - }; - } - } else { - // 如果是单行,直接更新 - foundItem[tableField] = newStatusValue; - } - - console.log('状态映射:', { - original: newData[apiField], - mapped: newStatusValue, - dictData: dict.neInfoStatus - }); - } else { - // 其他字段的更新 - if (foundItemParent) { - const childIndex = foundItemParent.children.findIndex((child: any) => child.id === foundItem.id); - if (childIndex !== -1) { - foundItemParent.children[childIndex] = { - ...foundItemParent.children[childIndex], - [tableField]: newData[apiField] - }; - } - } else { - foundItem[tableField] = newData[apiField]; - } - } - } - }); - - // 更新其他可能存在的字段(保持原有值) - const preserveFields = ['rmUid', 'port', 'serverState']; - preserveFields.forEach(field => { - if (foundItem[field] !== undefined && newData[field] === undefined) { - // 保持原有值 - } else if (newData[field] !== undefined) { - foundItem[field] = newData[field]; - } - }); - - console.log('字段映射完成:', { - original: newData, - mapped: { - ip: foundItem.ip, - status: foundItem.status, - neId: foundItem.neId, - neName: foundItem.neName, - neType: foundItem.neType - } - }); - - // 如果是子项,处理分组逻辑 - if (foundItemParent) { - console.log('处理分组更新:', foundItemParent); - - const children = foundItemParent.children; - if (children && children.length > 1) { - // 按 neId 重新排序 - children.sort((a: any, b: any) => a.neId.localeCompare(b.neId)); - - // 更新分组行的ID - const sortedIds = children.map((child: any) => child.id).join('_'); - foundItemParent.id = `group_${foundItemParent.neType}_${sortedIds}`; - - console.log('分组排序完成:', { sortedIds, newGroupId: foundItemParent.id }); - } - } - - // 强制触发Vue响应式更新,确保显示效果一致 - // 使用Vue的响应式系统确保DictTag组件正确更新 - - // 方法1: 使用Vue的响应式更新机制 - nextTick(() => { - // 创建一个新的对象引用来触发响应式更新 - const updatedItem = { ...foundItem }; - Object.assign(foundItem, updatedItem); - - // 方法2: 如果foundItem在children中,也需要更新父级引用 - if (foundItemParent) { - const updatedParent = { ...foundItemParent }; - Object.assign(foundItemParent, updatedParent); - } - - // 方法3: 强制更新整个表格数据数组 - const newData = [...tableState.data]; - tableState.data = newData; - }); - - // 刷新缓存的网元信息 - useNeInfoStore().fnRefreshNelist(); - - console.log('网元信息更新完成'); -} - /** * 对话框弹出关闭执行函数 * 进行表达规则校验 @@ -1282,4 +1102,3 @@ onBeforeUnmount(() => { } } -··········