feat: BMS 项目初始化(前端+后端)
- 前端 bms-front:基于 RuoYi-Vue3,封装 BasicForm/BasicTable 公共组件,替换 18 个业务页面表格 - 后端 bms-back:基于 RuoYi-Vue,包含 system/quartz/generator 等模块 - 项目标题由若依管理系统改为 BMS
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import router from './router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import NProgress from 'nprogress'
|
||||
import 'nprogress/nprogress.css'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import { isHttp, isPathMatch } from '@/utils/validate'
|
||||
import { isRelogin } from '@/utils/request'
|
||||
import useUserStore from '@/store/modules/user'
|
||||
import useLockStore from '@/store/modules/lock'
|
||||
import useSettingsStore from '@/store/modules/settings'
|
||||
import usePermissionStore from '@/store/modules/permission'
|
||||
|
||||
NProgress.configure({ showSpinner: false })
|
||||
|
||||
const whiteList = ['/login', '/register']
|
||||
|
||||
const isWhiteList = (path) => {
|
||||
return whiteList.some(pattern => isPathMatch(pattern, path))
|
||||
}
|
||||
|
||||
router.beforeEach(async (to, from) => {
|
||||
NProgress.start()
|
||||
if (getToken()) {
|
||||
to.meta.title && useSettingsStore().setTitle(to.meta.title)
|
||||
const isLock = useLockStore().isLock
|
||||
if (to.path === '/login') {
|
||||
NProgress.done()
|
||||
return { path: '/' }
|
||||
}
|
||||
if (isWhiteList(to.path)) {
|
||||
return true
|
||||
}
|
||||
if (isLock && to.path !== '/lock') {
|
||||
NProgress.done()
|
||||
return { path: '/lock' }
|
||||
}
|
||||
if (!isLock && to.path === '/lock') {
|
||||
NProgress.done()
|
||||
return { path: '/' }
|
||||
}
|
||||
if (useUserStore().roles.length === 0) {
|
||||
isRelogin.show = true
|
||||
try {
|
||||
// 拉取user_info信息
|
||||
await useUserStore().getInfo()
|
||||
isRelogin.show = false
|
||||
// 根据roles权限生成可访问的路由
|
||||
const accessRoutes = await usePermissionStore().generateRoutes()
|
||||
accessRoutes.forEach(route => {
|
||||
if (!isHttp(route.path)) {
|
||||
router.addRoute(route)
|
||||
}
|
||||
})
|
||||
// 重新导航到目标路由,确保动态路由已注册
|
||||
return { ...to, replace: true }
|
||||
} catch (err) {
|
||||
await useUserStore().logOut()
|
||||
ElMessage.error(err)
|
||||
return { path: '/' }
|
||||
}
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
// 没有token
|
||||
if (isWhiteList(to.path)) {
|
||||
// 在免登录白名单,直接进入
|
||||
return true
|
||||
}
|
||||
NProgress.done()
|
||||
return `/login?redirect=${to.fullPath}` // 否则全部重定向到登录页
|
||||
}
|
||||
})
|
||||
|
||||
router.afterEach(() => {
|
||||
NProgress.done()
|
||||
})
|
||||
Reference in New Issue
Block a user