mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 代码优化
This commit is contained in:
@ -14,7 +14,6 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { RouterView } from 'vue-router';
|
||||
import { useAppStore, useThemeStore, useRouteStore } from '@/store';
|
||||
|
||||
interface Props {
|
||||
|
@ -8,7 +8,6 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { RouterLink } from 'vue-router';
|
||||
import { routePath } from '@/router';
|
||||
import { useAppInfo } from '@/composables';
|
||||
|
||||
|
@ -67,7 +67,8 @@ export const useAuthStore = defineStore('auth-store', {
|
||||
setUserInfo(data);
|
||||
|
||||
// 更新状态
|
||||
Object.assign(this, { userInfo: data, token });
|
||||
this.userInfo = data;
|
||||
this.token = token;
|
||||
|
||||
// 跳转登录后的地址
|
||||
toLoginRedirect();
|
||||
|
@ -69,7 +69,8 @@ export const useTabStore = defineStore('tab-store', {
|
||||
*/
|
||||
addTab(route: RouteLocationNormalizedLoaded) {
|
||||
if (!isInTabRoutes(this.tabs, route.path)) {
|
||||
this.tabs.push(getTabRouteByVueRoute(route));
|
||||
const tab = getTabRouteByVueRoute(route);
|
||||
this.tabs.push(tab);
|
||||
}
|
||||
},
|
||||
/**
|
||||
|
10
src/typings/route.d.ts
vendored
10
src/typings/route.d.ts
vendored
@ -70,7 +70,7 @@ declare namespace AuthRoute {
|
||||
type RouteMeta = {
|
||||
/** 路由标题(可用来作document.title或者菜单的名称) */
|
||||
title: string;
|
||||
/** 路由的动态路径 */
|
||||
/** 路由的动态路径(需要动态路径的页面需要将path添加进范型参数) */
|
||||
dynamicPath?: PathToDynamicPath<'/login'>;
|
||||
/** 作为单级路由的父级路由布局组件 */
|
||||
singleLayout?: Extract<RouteComponent, 'basic' | 'blank'>;
|
||||
@ -85,7 +85,7 @@ declare namespace AuthRoute {
|
||||
keepAlive?: boolean;
|
||||
/** 菜单和面包屑对应的图标 */
|
||||
icon?: string;
|
||||
/** 是否在菜单中隐藏 */
|
||||
/** 是否在菜单中隐藏(一些列表、表格的详情页面需要通过参数跳转,所以不能显示在菜单中) */
|
||||
hide?: boolean;
|
||||
/** 外链链接 */
|
||||
href?: string;
|
||||
@ -140,9 +140,9 @@ declare namespace AuthRoute {
|
||||
|
||||
/** 路由path转换动态路径 */
|
||||
type PathToDynamicPath<Path extends RoutePath> =
|
||||
| `${Path}/:module`
|
||||
| `${Path}/:module(${string})`
|
||||
| `${Path}/:module(${string})?`;
|
||||
| `${Path}/:${string}`
|
||||
| `${Path}/:${string}(${string})`
|
||||
| `${Path}/:${string}(${string})?`;
|
||||
|
||||
/** 获取一级路由(包括有子路由的一级路由) */
|
||||
type GetSingleRouteKey<Key extends RouteKey> = Key extends `${infer _Left}${RouteSplitMark}${infer _Right}`
|
||||
|
@ -13,12 +13,13 @@ export function filterAuthRoutesByUserPermission(routes: AuthRoute.Route[], perm
|
||||
* @param permission - 权限
|
||||
*/
|
||||
function filterAuthRouteByUserPermission(route: AuthRoute.Route, permission: Auth.RoleType): AuthRoute.Route[] {
|
||||
const filterRoute = { ...route };
|
||||
const hasPermission =
|
||||
!route.meta.permissions || permission === 'super' || route.meta.permissions.includes(permission);
|
||||
|
||||
if (route.children) {
|
||||
const filterChildren = route.children.map(item => filterAuthRouteByUserPermission(item, permission)).flat(1);
|
||||
Object.assign(route, { children: filterChildren });
|
||||
if (filterRoute.children) {
|
||||
const filterChildren = filterRoute.children.map(item => filterAuthRouteByUserPermission(item, permission)).flat(1);
|
||||
Object.assign(filterRoute, { children: filterChildren });
|
||||
}
|
||||
return hasPermission ? [route] : [];
|
||||
return hasPermission ? [filterRoute] : [];
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { RouterLink } from 'vue-router';
|
||||
import { routeName } from '@/router';
|
||||
|
||||
type ExceptionType = '403' | '404' | '500';
|
||||
|
Reference in New Issue
Block a user