更改开发目录
This commit is contained in:
@@ -25,6 +25,14 @@ const router = createRouter({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 标记动态路由是否已经注册
|
||||||
|
let dynamicRoutesRegistered = false;
|
||||||
|
|
||||||
|
// 重置动态路由注册状态的函数
|
||||||
|
export function resetDynamicRoutes() {
|
||||||
|
dynamicRoutesRegistered = false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 路由守卫
|
* 路由守卫
|
||||||
*/
|
*/
|
||||||
@@ -48,10 +56,20 @@ router.beforeEach(async (to, from) => {
|
|||||||
|
|
||||||
// 注册动态路由
|
// 注册动态路由
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
if (!userStore.menus) {
|
if (!userStore.menus && !dynamicRoutesRegistered) {
|
||||||
const { menus, homePath } = await userStore.fetchUserInfo();
|
const { menus, homePath } = await userStore.fetchUserInfo();
|
||||||
if (menus) {
|
if (menus) {
|
||||||
router.addRoute(getMenuRoutes(menus, homePath));
|
const menuRoute = getMenuRoutes(menus, homePath);
|
||||||
|
router.addRoute(menuRoute);
|
||||||
|
dynamicRoutesRegistered = true;
|
||||||
|
|
||||||
|
// 只有当访问根路径时才跳转到首页
|
||||||
|
if (to.path === LAYOUT_PATH) {
|
||||||
|
return { path: homePath || '/dashboard', replace: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 对于其他路径,只有在路由确实不存在时才跳转
|
||||||
|
// 这避免了已存在页面的不必要跳转
|
||||||
return { ...to, replace: true };
|
return { ...to, replace: true };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,15 @@ export const useUserStore = defineStore({
|
|||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 重置用户状态(退出登录时调用)
|
||||||
|
*/
|
||||||
|
resetUserState() {
|
||||||
|
this.info = null;
|
||||||
|
this.menus = null;
|
||||||
|
this.authorities = [];
|
||||||
|
this.roles = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import { unref } from 'vue';
|
|||||||
import type { RouteLocationNormalizedLoaded } from 'vue-router';
|
import type { RouteLocationNormalizedLoaded } from 'vue-router';
|
||||||
import type { TabItem, TabRemoveOption } from 'ele-admin-pro/es';
|
import type { TabItem, TabRemoveOption } from 'ele-admin-pro/es';
|
||||||
import { message } from 'ant-design-vue/es';
|
import { message } from 'ant-design-vue/es';
|
||||||
import router from '@/router';
|
import router, { resetDynamicRoutes } from '@/router';
|
||||||
import { useThemeStore } from '@/store/modules/theme';
|
import { useThemeStore } from '@/store/modules/theme';
|
||||||
import type { RouteReloadOption } from '@/store/modules/theme';
|
import type { RouteReloadOption } from '@/store/modules/theme';
|
||||||
|
import { useUserStore } from '@/store/modules/user';
|
||||||
import { removeToken } from '@/utils/token-util';
|
import { removeToken } from '@/utils/token-util';
|
||||||
import { setDocumentTitle } from '@/utils/document-title-util';
|
import { setDocumentTitle } from '@/utils/document-title-util';
|
||||||
import {
|
import {
|
||||||
@@ -242,6 +243,12 @@ export function goHomeRoute(from?: string) {
|
|||||||
*/
|
*/
|
||||||
export function logout(route?: boolean, from?: string) {
|
export function logout(route?: boolean, from?: string) {
|
||||||
removeToken();
|
removeToken();
|
||||||
|
// 重置动态路由注册状态
|
||||||
|
resetDynamicRoutes();
|
||||||
|
// 重置用户状态
|
||||||
|
const userStore = useUserStore();
|
||||||
|
userStore.resetUserState();
|
||||||
|
|
||||||
if (route) {
|
if (route) {
|
||||||
router.push({
|
router.push({
|
||||||
path: '/login',
|
path: '/login',
|
||||||
|
|||||||
@@ -244,11 +244,7 @@
|
|||||||
</a-card>
|
</a-card>
|
||||||
<a-card title="收货信息" style="margin-bottom: 20px" :bordered="false">
|
<a-card title="收货信息" style="margin-bottom: 20px" :bordered="false">
|
||||||
<a-spin :spinning="loading">
|
<a-spin :spinning="loading">
|
||||||
<a-table
|
|
||||||
:data-source="orderGoods"
|
|
||||||
:columns="columns"
|
|
||||||
:pagination="false"
|
|
||||||
/>
|
|
||||||
</a-spin>
|
</a-spin>
|
||||||
</a-card>
|
</a-card>
|
||||||
</a-drawer>
|
</a-drawer>
|
||||||
|
|||||||
Reference in New Issue
Block a user