fix: 网元信息更新删除不刷新列表,进行单个更新并清除网元列表缓存

This commit is contained in:
TsMask
2024-06-12 10:16:35 +08:00
parent b67d591d0a
commit c9eb0240d8
2 changed files with 83 additions and 59 deletions

View File

@@ -3,7 +3,6 @@ import { reactive, onMounted, toRaw, watch } from 'vue';
import { message, Form, Modal } from 'ant-design-vue/lib';
import useI18n from '@/hooks/useI18n';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import useNeInfoStore from '@/store/modules/neinfo';
import { NE_TYPE_LIST } from '@/constants/ne-constants';
import { regExpIPv4, regExpIPv6 } from '@/utils/regular-utils';
import { getNeInfo, addNeInfo, updateNeInfo } from '@/api/ne/neInfo';
@@ -250,9 +249,8 @@ function fnModalOk() {
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success(t('common.operateOk'), 3);
// 刷新缓存的网元信息
useNeInfoStore().fnRefreshNelist();
emit('ok');
// 返回无引用信息
emit('ok', JSON.parse(JSON.stringify(from)));
fnModalCancel();
} else {
message.error({

View File

@@ -8,7 +8,7 @@ import { ColumnsType } from 'ant-design-vue/lib/table';
import useI18n from '@/hooks/useI18n';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import useNeInfoStore from '@/store/modules/neinfo';
import { listNeInfo, delNeInfo } from '@/api/ne/neInfo';
import { listNeInfo, delNeInfo, stateNeInfo } from '@/api/ne/neInfo';
import { NE_TYPE_LIST } from '@/constants/ne-constants';
import useDictStore from '@/store/modules/dict';
import useNeOptions from './hooks/useNeOptions';
@@ -70,7 +70,7 @@ type TabeStateType = {
/**搜索栏 */
seached: boolean;
/**记录数据 */
data: object[];
data: Record<string, any>[];
/**勾选记录 */
selectedRowKeys: (string | number)[];
};
@@ -219,8 +219,20 @@ function fnModalVisibleByEdit(row?: Record<string, any>) {
* 对话框弹出确认执行函数
* 进行表达规则校验
*/
function fnModalEditOk() {
fnGetList(1);
function fnModalEditOk(from: Record<string, any>) {
stateNeInfo(from.neType, from.neId)
.then(res => {
// 找到编辑更新的网元
const item = tableState.data.find(s => s.id === from.id);
if (item && res.code === RESULT_CODE_SUCCESS) {
Object.assign(item.serverState, res.data);
const resouresUsage = parseResouresUsage(item.serverState);
Reflect.set(item, 'resoures', resouresUsage);
}
})
.finally(() => {
useNeInfoStore().fnRefreshNelist();
});
}
/**
@@ -256,7 +268,16 @@ function fnRecordDelete(id: string) {
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success(t('common.operateOk'), 3);
fnGetList(1);
// 过滤掉删除的id
tableState.data = tableState.data.filter(item => {
if (id.indexOf(',')) {
return !tableState.selectedRowKeys.includes(item.id);
} else {
return item.id != id;
}
});
// 刷新缓存
useNeInfoStore().fnRefreshNelist();
} else {
message.error({
content: `${res.msg}`,
@@ -331,6 +352,17 @@ function fnGetList(pageNum?: number) {
// 遍历处理资源情况数值
tableState.data = res.rows.map(item => {
const neState = item.serverState;
const resouresUsage = parseResouresUsage(neState);
Reflect.set(item, 'resoures', resouresUsage);
return item;
});
}
tableState.loading = false;
});
}
/**解析网元状态携带的资源利用率 */
function parseResouresUsage(neState: Record<string, any>) {
let sysCpuUsage = 0;
let nfCpuUsage = 0;
if (neState.cpu) {
@@ -374,18 +406,12 @@ function fnGetList(pageNum?: number) {
}
}
Reflect.set(item, 'resoures', {
return {
sysDiskUsage,
sysMemUsage,
sysCpuUsage,
nfCpuUsage,
});
return item;
});
}
tableState.loading = false;
});
};
}
onMounted(() => {