修改缓存查询逻辑.
This commit is contained in:
@@ -104,7 +104,7 @@
|
|||||||
// 加载所有展开的key
|
// 加载所有展开的key
|
||||||
eachAllExpandKeys(treeData.value);
|
eachAllExpandKeys(treeData.value);
|
||||||
};
|
};
|
||||||
init();
|
init([]);
|
||||||
|
|
||||||
// 获取值
|
// 获取值
|
||||||
const getValue = () => {
|
const getValue = () => {
|
||||||
|
|||||||
34
orion-ops-ui/src/store/modules/cache/index.ts
vendored
34
orion-ops-ui/src/store/modules/cache/index.ts
vendored
@@ -1,44 +1,24 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { CacheState } from './types';
|
import { CacheState } from './types';
|
||||||
import { MenuQueryResponse } from '@/api/system/menu';
|
|
||||||
import { RoleQueryResponse } from '@/api/user/role';
|
export type CacheType = 'menus' | 'roles' | 'tags'
|
||||||
|
|
||||||
const useCacheStore = defineStore('cache', {
|
const useCacheStore = defineStore('cache', {
|
||||||
state: (): CacheState => ({
|
state: (): CacheState => ({
|
||||||
menus: [],
|
menus: [],
|
||||||
roles: [],
|
roles: [],
|
||||||
|
tags: []
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {},
|
getters: {},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
/**
|
/**
|
||||||
* 更新菜单
|
* 设置
|
||||||
*/
|
*/
|
||||||
updateMenus(menus: MenuQueryResponse[]) {
|
set(name: CacheType, value: any) {
|
||||||
this.menus = menus;
|
this[name] = value;
|
||||||
},
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空菜单
|
|
||||||
*/
|
|
||||||
resetMenus() {
|
|
||||||
this.menus = [];
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新角色
|
|
||||||
*/
|
|
||||||
updateRoles(roles: RoleQueryResponse[]) {
|
|
||||||
this.roles = roles;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空角色
|
|
||||||
*/
|
|
||||||
resetRoles() {
|
|
||||||
this.roles = [];
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { MenuQueryResponse } from '@/api/system/menu';
|
import { MenuQueryResponse } from '@/api/system/menu';
|
||||||
import { RoleQueryResponse } from '@/api/user/role';
|
import { RoleQueryResponse } from '@/api/user/role';
|
||||||
|
import { TagResponse } from '@/api/meta/tag';
|
||||||
|
|
||||||
export interface CacheState {
|
export interface CacheState {
|
||||||
menus: MenuQueryResponse[],
|
menus: MenuQueryResponse[];
|
||||||
roles: RoleQueryResponse[],
|
roles: RoleQueryResponse[];
|
||||||
|
tags: TagResponse[];
|
||||||
[key: string]: unknown;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,7 +260,7 @@
|
|||||||
setFetchLoading(true);
|
setFetchLoading(true);
|
||||||
const { data } = await getMenuList(formModel);
|
const { data } = await getMenuList(formModel);
|
||||||
tableRenderData.value = data as MenuQueryResponse[];
|
tableRenderData.value = data as MenuQueryResponse[];
|
||||||
cacheStore.updateMenus(tableRenderData.value);
|
cacheStore.set('menus', tableRenderData.value);
|
||||||
} finally {
|
} finally {
|
||||||
setFetchLoading(false);
|
setFetchLoading(false);
|
||||||
}
|
}
|
||||||
@@ -301,11 +301,6 @@
|
|||||||
await loadMenuData();
|
await loadMenuData();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 卸载时清除 menu cache
|
|
||||||
onUnmounted(() => {
|
|
||||||
cacheStore.resetMenus();
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
|||||||
@@ -21,9 +21,16 @@
|
|||||||
import MenuTable from '@/views/system/menu/components/menu-table.vue';
|
import MenuTable from '@/views/system/menu/components/menu-table.vue';
|
||||||
import MenuFormModal from '@/views/system/menu/components/menu-form-modal.vue';
|
import MenuFormModal from '@/views/system/menu/components/menu-form-modal.vue';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
import { onUnmounted, ref } from 'vue';
|
||||||
|
import { useCacheStore } from '@/store';
|
||||||
|
|
||||||
const table = ref<any>();
|
const table = ref<any>();
|
||||||
const modal = ref<any>();
|
const modal = ref<any>();
|
||||||
|
|
||||||
|
// 卸载时清除 menu cache
|
||||||
|
onUnmounted(() => {
|
||||||
|
const cacheStore = useCacheStore();
|
||||||
|
cacheStore.set('menus', []);
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -74,7 +74,7 @@
|
|||||||
if (!cacheStore.menus?.length) {
|
if (!cacheStore.menus?.length) {
|
||||||
// 加载菜单
|
// 加载菜单
|
||||||
const { data: menuData } = await getMenuList({});
|
const { data: menuData } = await getMenuList({});
|
||||||
cacheStore.updateMenus(menuData);
|
cacheStore.set('menus', menuData);
|
||||||
}
|
}
|
||||||
// 获取角色菜单
|
// 获取角色菜单
|
||||||
const { data: roleMenuIdList } = await getRoleMenuId(record.id);
|
const { data: roleMenuIdList } = await getRoleMenuId(record.id);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
// 卸载时清除 menu cache
|
// 卸载时清除 menu cache
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
const cacheStore = useCacheStore();
|
const cacheStore = useCacheStore();
|
||||||
cacheStore.resetMenus();
|
cacheStore.set('menus', []);
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
// 获取全部角色
|
// 获取全部角色
|
||||||
if (!cacheStore.roles?.length) {
|
if (!cacheStore.roles?.length) {
|
||||||
const { data } = await getRoleList();
|
const { data } = await getRoleList();
|
||||||
cacheStore.updateRoles(data);
|
cacheStore.set('roles', data);
|
||||||
}
|
}
|
||||||
// 加载用户角色
|
// 加载用户角色
|
||||||
const { data: roleIdList } = await getUserRoleIdList(formModel.id);
|
const { data: roleIdList } = await getUserRoleIdList(formModel.id);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
// 卸载时清除 role cache
|
// 卸载时清除 role cache
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
const cacheStore = useCacheStore();
|
const cacheStore = useCacheStore();
|
||||||
cacheStore.resetRoles();
|
cacheStore.set('roles', []);
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user