mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-13 14:57:14 +08:00
refactor: 优化路由守卫代码(同步 GiDemo 更新)
This commit is contained in:
@@ -9,8 +9,6 @@ import ArcoVueIcon from '@arco-design/web-vue/es/icon'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
|
||||
import '@/router/guard'
|
||||
|
||||
// 使用动画库
|
||||
import 'animate.css/animate.min.css'
|
||||
|
||||
@@ -25,6 +23,8 @@ import 'virtual:svg-icons-register'
|
||||
|
||||
// 自定义指令
|
||||
import directives from './directives'
|
||||
|
||||
// 状态管理
|
||||
import pinia from '@/stores'
|
||||
|
||||
// 对特定组件进行默认配置
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { Button, Message, Notification, Space } from '@arco-design/web-vue'
|
||||
import NProgress from 'nprogress'
|
||||
import router from '@/router'
|
||||
import type { Router } from 'vue-router'
|
||||
import { useRouteStore, useUserStore } from '@/stores'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import { isHttp } from '@/utils/validate'
|
||||
@@ -36,7 +36,10 @@ const handleNotification = () => {
|
||||
closable: true,
|
||||
position: 'bottomRight',
|
||||
footer: () => {
|
||||
return h(Space, {}, () => [h(Button, { type: 'primary', onClick: () => onUpdateSystem(id) }, '更新'), h(Button, { type: 'secondary', onClick: () => onCloseUpdateSystem(id) }, '关闭')])
|
||||
return h(Space, {}, () => [h(Button, {
|
||||
type: 'primary',
|
||||
onClick: () => onUpdateSystem(id),
|
||||
}, '更新'), h(Button, { type: 'secondary', onClick: () => onCloseUpdateSystem(id) }, '关闭')])
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -75,6 +78,8 @@ export const resetHasRouteFlag = () => {
|
||||
hasRouteFlag = false
|
||||
}
|
||||
|
||||
/** 初始化路由守卫 */
|
||||
export const setupRouterGuard = (router: Router) => {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
NProgress.start()
|
||||
const userStore = useUserStore()
|
||||
@@ -136,3 +141,4 @@ router.onError(() => {
|
||||
router.afterEach(() => {
|
||||
NProgress.done()
|
||||
})
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { useRouteStore } from '@/stores'
|
||||
import { constantRoutes, systemRoutes } from '@/router/route'
|
||||
import { setupRouterGuard } from '@/router/guard'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
@@ -8,6 +9,8 @@ const router = createRouter({
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
})
|
||||
|
||||
setupRouterGuard(router)
|
||||
|
||||
/**
|
||||
* @description 重置路由
|
||||
* @description 注意:所有动态路由路由必须带有 name 属性,否则可能会不能完全重置干净
|
||||
|
Reference in New Issue
Block a user