chore: format code
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { ExRouteRecordRaw, MenuRecordRaw } from '@vben-core/typings';
|
||||
import type { RouteRecordRaw, Router } from 'vue-router';
|
||||
|
||||
import { mapTree } from '@vben-core/toolkit';
|
||||
import type { RouteRecordRaw, Router } from 'vue-router';
|
||||
|
||||
/**
|
||||
* 根据 routes 生成菜单列表
|
||||
|
@@ -1,16 +1,30 @@
|
||||
import { filterTree } from '@vben-core/toolkit';
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import { filterTree, mapTree } from '@vben-core/toolkit';
|
||||
/**
|
||||
* 动态生成路由
|
||||
*/
|
||||
async function generatorRoutes(
|
||||
routes: RouteRecordRaw[],
|
||||
roles: string[],
|
||||
forbiddenPage?: RouteRecordRaw['component'],
|
||||
): Promise<RouteRecordRaw[]> {
|
||||
// 根据角色标识过滤路由表,判断当前用户是否拥有指定权限
|
||||
return filterTree(routes, (route) => {
|
||||
const finalRoutes = filterTree(routes, (route) => {
|
||||
return hasVisible(route) && hasAuthority(route, roles);
|
||||
});
|
||||
|
||||
if (!forbiddenPage) {
|
||||
return finalRoutes;
|
||||
}
|
||||
|
||||
// 如果有禁止访问的页面,将禁止访问的页面替换为403页面
|
||||
return mapTree(finalRoutes, (route) => {
|
||||
if (menuHasVisibleWithForbidden(route)) {
|
||||
route.component = forbiddenPage;
|
||||
}
|
||||
return route;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,9 +38,10 @@ function hasAuthority(route: RouteRecordRaw, access: string[]) {
|
||||
if (!authority) {
|
||||
return true;
|
||||
}
|
||||
return access.some((value) => {
|
||||
return authority.includes(value);
|
||||
});
|
||||
return (
|
||||
access.some((value) => authority.includes(value)) ||
|
||||
menuHasVisibleWithForbidden(route)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,4 +52,12 @@ function hasVisible(route?: RouteRecordRaw) {
|
||||
return !route?.meta?.hideInMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断路由是否在菜单中显示,但是访问会被重定向到403
|
||||
* @param route
|
||||
*/
|
||||
function menuHasVisibleWithForbidden(route: RouteRecordRaw) {
|
||||
return !!route.meta?.menuVisibleWithForbidden;
|
||||
}
|
||||
|
||||
export { generatorRoutes, hasAuthority, hasVisible };
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import type { RouteModuleType } from './merge-route-modules';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { mergeRouteModules } from './merge-route-modules';
|
||||
|
||||
import type { RouteModuleType } from './merge-route-modules';
|
||||
|
||||
describe('mergeRouteModules', () => {
|
||||
it('should merge route modules correctly', () => {
|
||||
const routeModules: Record<string, RouteModuleType> = {
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import type { Flatten } from '@vben-core/typings';
|
||||
|
||||
import { preferencesManager } from './preferences';
|
||||
|
||||
import type { Preferences } from './types';
|
||||
|
||||
import { preferencesManager } from './preferences';
|
||||
|
||||
// 偏好设置(带有层级关系)
|
||||
const preferences: Preferences = preferencesManager.getPreferences();
|
||||
|
||||
|
@@ -4,6 +4,10 @@ import type {
|
||||
FlattenObjectKeys,
|
||||
} from '@vben-core/typings';
|
||||
|
||||
import type { Preferences } from './types';
|
||||
|
||||
import { markRaw, reactive, watch } from 'vue';
|
||||
|
||||
import { StorageManager } from '@vben-core/cache';
|
||||
import { flattenObject, nestedObject } from '@vben-core/helpers';
|
||||
import { convertToHslCssVar, merge } from '@vben-core/toolkit';
|
||||
@@ -14,12 +18,9 @@ import {
|
||||
useCssVar,
|
||||
useDebounceFn,
|
||||
} from '@vueuse/core';
|
||||
import { markRaw, reactive, watch } from 'vue';
|
||||
|
||||
import { defaultPreferences } from './config';
|
||||
|
||||
import type { Preferences } from './types';
|
||||
|
||||
const STORAGE_KEY = 'preferences';
|
||||
const STORAGE_KEY_LOCALE = `${STORAGE_KEY}-locale`;
|
||||
const STORAGE_KEY_THEME = `${STORAGE_KEY}-theme`;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { diff } from '@vben-core/toolkit';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { diff } from '@vben-core/toolkit';
|
||||
|
||||
import { isDarkTheme, preferencesManager } from './preferences';
|
||||
|
||||
function usePreferences() {
|
||||
|
@@ -6,6 +6,8 @@ import type {
|
||||
InternalAxiosRequestConfig,
|
||||
} from 'axios';
|
||||
|
||||
import type { MakeAuthorizationFn, RequestClientOptions } from './types';
|
||||
|
||||
import { merge } from '@vben-core/toolkit';
|
||||
|
||||
import axios from 'axios';
|
||||
@@ -15,8 +17,6 @@ import { FileDownloader } from './modules/downloader';
|
||||
import { InterceptorManager } from './modules/interceptor';
|
||||
import { FileUploader } from './modules/uploader';
|
||||
|
||||
import type { MakeAuthorizationFn, RequestClientOptions } from './types';
|
||||
|
||||
class RequestClient {
|
||||
private instance: AxiosInstance;
|
||||
private makeAuthorization: MakeAuthorizationFn | undefined;
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import type { MenuRecordRaw } from '@vben-core/typings';
|
||||
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import { acceptHMRUpdate, defineStore } from 'pinia';
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
|
||||
import { createPinia, setActivePinia } from 'pinia';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
|
||||
import { useTabsStore } from './tabs';
|
||||
|
||||
|
@@ -1,10 +1,12 @@
|
||||
import { startProgress, stopProgress } from '@vben-core/toolkit';
|
||||
import { TabItem } from '@vben-core/typings';
|
||||
import type { RouteRecordNormalized, Router } from 'vue-router';
|
||||
|
||||
import { acceptHMRUpdate, defineStore } from 'pinia';
|
||||
import { toRaw } from 'vue';
|
||||
|
||||
import { startProgress, stopProgress } from '@vben-core/toolkit';
|
||||
import { TabItem } from '@vben-core/typings';
|
||||
|
||||
import { acceptHMRUpdate, defineStore } from 'pinia';
|
||||
|
||||
/**
|
||||
* @zh_CN 克隆路由,防止路由被修改
|
||||
* @param route
|
||||
|
Reference in New Issue
Block a user