fix: 修复页面刷新顶部菜单不展示

This commit is contained in:
xinxin.wu 2024-04-08 15:04:05 +08:00 committed by Craftsman
parent 4994f78dfe
commit 625d832310
5 changed files with 30 additions and 17 deletions

View File

@ -22,11 +22,12 @@ function getInsertCommonScript() {
}
export const SCRIPT_MENU: CommonScriptMenu[] = [
{
title: t('project.code_segment.importApiTest'),
value: 'api_definition',
command: 'api_definition',
},
// TODO 这个版本不上
// {
// title: t('project.code_segment.importApiTest'),
// value: 'api_definition',
// command: 'api_definition',
// },
{
title: t('project.code_segment.newApiTest'),
value: 'new_api_request',

View File

@ -95,15 +95,7 @@
}
const filterMenuTopRouter =
currentParent?.children?.filter((item: any) => {
if (permission.accessRouter(item) && item.meta?.isTopMenu) {
// if (item.name === RouteEnum.SETTING_SYSTEM_AUTHORIZED_MANAGEMENT) {
// return appStore.packageType === 'enterprise';
// }
return true;
}
return false;
}) || [];
currentParent?.children?.filter((item: any) => permission.accessRouter(item) && item.meta?.isTopMenu) || [];
appStore.setTopMenus(filterMenuTopRouter);
setCurrentTopMenu(name as string);

View File

@ -16,7 +16,7 @@ export default function usePermission() {
* @returns
*/
accessRouter(route: RouteLocationNormalized | RouteRecordRaw) {
if (includes(firstLevelMenu, route.name)) {
if (firstLevelMenu.includes(route.name as string)) {
// 一级菜单: 创建项目时 被勾选的模块
return topLevelMenuHasPermission(route);
}

View File

@ -272,6 +272,22 @@ const useAppStore = defineStore('app', {
return false;
}
},
async getProjectInfos() {
try {
const res = await getProjectInfo(this.currentProjectId);
if (!res || res.deleted) {
const router = useRouter();
router.push({
name: NO_PROJECT_ROUTE_NAME,
});
}
if (res) {
this.setCurrentMenuConfig(res?.moduleIds || []);
}
} catch (error) {
console.log(error);
}
},
/**
*
*/

View File

@ -82,11 +82,15 @@ export function composePermissions(userRoleRelations: UserRoleRelation[], type:
}
// 判断当前一级菜单是否有权限
export function topLevelMenuHasPermission(route: RouteLocationNormalized | RouteRecordRaw) {
export async function topLevelMenuHasPermission(route: RouteLocationNormalized | RouteRecordRaw) {
const userStore = useUserStore();
const appStore = useAppStore();
const { currentMenuConfig } = appStore;
if (!currentMenuConfig.includes(route.name as string)) {
if (!currentMenuConfig.length) {
await appStore.getProjectInfos();
}
if (currentMenuConfig.length && !currentMenuConfig.includes(route.name as string)) {
// 没有配置的菜单不显示
return false;
}