This commit is contained in:
仲么了
2024-02-19 13:44:32 +08:00
commit 361cbb713d
238 changed files with 202544 additions and 0 deletions

47
src/router/index.ts Normal file
View File

@@ -0,0 +1,47 @@
import { createRouter, createWebHashHistory } from 'vue-router'
import staticRoutes from '@/router/static'
import { useAdminInfo } from '@/stores/adminInfo'
import NProgress from 'nprogress'
import { loading } from '@/utils/loading'
import { ElMessage } from 'element-plus'
const router = createRouter({
history: createWebHashHistory(),
routes: staticRoutes
})
router.beforeEach((to, from, next) => {
NProgress.configure({ showSpinner: false })
NProgress.start()
if (!window.existLoading) {
loading.show()
window.existLoading = true
}
if (to.path == '/login' || to.path == '/404') {
// 登录或者注册才可以往下进行
next()
} else {
// 获取 token
const adminInfo = useAdminInfo()
const token = adminInfo.getToken()
// token 不存在
if (token === null || token === '') {
ElMessage.error('您还没有登录,请先登录')
next('/login')
} else {
next()
}
}
// next()
})
// 路由加载后
router.afterEach(() => {
if (window.existLoading) {
loading.hide()
}
NProgress.done()
})
export default router