You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
import router from './router'
|
|
import Performance from '@/tools/performance'
|
|
import { usePermissionStore } from "@/store/permission"
|
|
import { useUserStore } from "@/store/user"
|
|
import { ipcRenderer } from "electron"
|
|
export function usePermission() {
|
|
let end = null
|
|
const whiteList = ['/login','/remind'] // 不重定向白名单
|
|
router.beforeEach(async (to, from, next) => {
|
|
if (to.path === '/login') {
|
|
await ipcRenderer.invoke("toggle-main-window-resizable",false)
|
|
await ipcRenderer.invoke("main-window-resize",{
|
|
width: 320,
|
|
height: 504
|
|
})
|
|
} else {
|
|
if (to.meta.toUrl) {
|
|
ipcRenderer.invoke("exec-admin-view-js",`window.routerTo['${to.meta.toUrl}']()`)
|
|
}
|
|
}
|
|
const { GenerateRoutes, routers } = usePermissionStore()
|
|
const { getUserInfo, token, roles, logOut } = useUserStore()
|
|
end = Performance.startExecute(`${from.path} => ${to.path} 路由耗时`) /// 路由性能监控
|
|
if (token) {
|
|
if (to.path === '/login') {
|
|
next({ path: '/' })
|
|
} else {
|
|
next()
|
|
}
|
|
} else {
|
|
if (whiteList.includes(to.path)) {
|
|
next()
|
|
} else {
|
|
next('/login')
|
|
}
|
|
}
|
|
|
|
setTimeout(() => {
|
|
end()
|
|
}, 0)
|
|
})
|
|
|
|
router.afterEach(() => { })
|
|
}
|