From f6b8164aa786969e0b89fa5d000fc94af771c73c Mon Sep 17 00:00:00 2001 From: orangegzx Date: Mon, 24 Jul 2023 15:27:26 +0800 Subject: [PATCH] feat(monitoring): Node and group add memory function --- src/composables/data/useDataMonitoring.ts | 20 +++++++++++++++++--- src/store/index.ts | 8 +++----- src/utils/user.ts | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/composables/data/useDataMonitoring.ts b/src/composables/data/useDataMonitoring.ts index 6c385a05..4cae71d1 100644 --- a/src/composables/data/useDataMonitoring.ts +++ b/src/composables/data/useDataMonitoring.ts @@ -143,7 +143,10 @@ export default () => { } const groupIsDeleted = async () => { - currentGroup.value.groupName = '' + currentGroup.value = { + node: currentGroup.value.node, + groupName: '', + } totalData.value = [] await getGroupList(currentGroup.value.node) } @@ -279,7 +282,11 @@ export default () => { const selectedNodeChanged = async (nodeName: string) => { if (nodeName) { try { - currentGroup.value.node = nodeName + currentGroup.value = { + ...currentGroup.value, + node: nodeName, + } + selectedGroup = undefined totalData.value = [] @@ -290,7 +297,10 @@ export default () => { groupList.value = [] } } else { - currentGroup.value.groupName = '' + currentGroup.value = { + node: currentGroup.value.node, + groupName: '', + } resetKeywordSearch() groupList.value = [] totalData.value = [] @@ -301,6 +311,10 @@ export default () => { // change group const selectedGroupChanged = async (groupName: string) => { + currentGroup.value = { + node: currentGroup.value.node, + groupName, + } resetKeywordSearch() if (groupName) { diff --git a/src/store/index.ts b/src/store/index.ts index 8f7318ba..c10c257f 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,5 +1,5 @@ import { createStore } from 'vuex' -import { getToken, setToken, clearLocalStorage } from '@/utils/user' +import { getToken, setToken, clearLocalStorage, getNodeGroupData, setNodeGroupData } from '@/utils/user' import { DEFAULT_LANG } from '@/utils/constants' interface paginationInfo { @@ -43,10 +43,7 @@ export default createStore({ pageSize: 30, total: 0, }, - nodeGroupMemory: { - node: '', - groupName: '', - }, + nodeGroupMemory: getNodeGroupData(), axiosPromiseCancel: [], } }, @@ -78,6 +75,7 @@ export default createStore({ }, SET_NODE_GROUP(state, data: NodeGroup) { state.nodeGroupMemory = data + setNodeGroupData(data) }, ADD_AXIOS_PROMISE_CANCEL(state, data: any) { state.axiosPromiseCancel.push(data) diff --git a/src/utils/user.ts b/src/utils/user.ts index 2233292b..b23c1441 100644 --- a/src/utils/user.ts +++ b/src/utils/user.ts @@ -1,5 +1,6 @@ export const LOCAL_STORAGE_TOKEN_KEY = 'token' export const LOCAL_STORAGE_BREADCRUMB = 'breadcrumbs' +export const LOCAL_STORAGE_NODE_GROUP = 'nodeGroupData' export const getToken = (): string | null => window.localStorage.getItem(LOCAL_STORAGE_TOKEN_KEY) @@ -20,3 +21,16 @@ export const getBreadcrumbFullPaths = (): string => { const res: string = window.localStorage.getItem(LOCAL_STORAGE_BREADCRUMB) || '' return res } + +interface NodeGroup { + node: string + groupName: string +} +export const setNodeGroupData = (data: NodeGroup): void => { + window.localStorage.setItem(LOCAL_STORAGE_NODE_GROUP, JSON.stringify(data)) +} +export const getNodeGroupData = (): NodeGroup => { + const res: NodeGroup = + JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_NODE_GROUP) || '{"node":"","groupName":""}') || '' + return res +}