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