2022年5月29日从svn移到git

This commit is contained in:
daihh
2022-05-29 18:56:34 +08:00
commit b050613020
488 changed files with 68444 additions and 0 deletions

69
src/security.js Normal file
View File

@@ -0,0 +1,69 @@
import router from './router'
import store from './store'
import { Message } from 'element-ui'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { getToken } from '@/utils/token'
import { routers } from "@/data/pages"
import watermark from './utils/warterMark.js'
NProgress.configure({ showSpinner: false })
const whiteList = ['/login','/logout','/loading','/pc/loading','/500','/auth-redirect','/forget','/reset/password']
router.beforeEach((to, from, next) => {
watermark.set("");
NProgress.start();
if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,直接进入
next()
}else{
if(getToken()){
if(to.path === '/login'){
next({ path: '/pc/index' })
NProgress.done();
} else {
//后续这里需要增加一定的控制
if (!store.getters.init) {
// 判断当前控制台是否已拉取完数据
store.dispatch('InitData').then(res => {
//加载信息资源归属,系统分类信息
store.dispatch('resOwner/loadResOwners');
store.dispatch('sysType/loadSysTypes');
store.commit('app/SET_INITDATA',true);
//routers数据先使用固定的以后在初始化接口中返回
let myRouters=routers();
store.dispatch('GenerateRoutes',{routers:myRouters}).then(accessRoutes=>{
router.addRoutes(accessRoutes) // 动态添加可访问路由表
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
});
}).catch(err => {
console.log(err);
store.commit('app/SET_INITDATA',false);
//如果初始化错误,就不再执行了,不然会一直循环下去
next({ path: '/500' })
//NProgress.done();
})
} else {
next();
}
}
//next();
}else{
//next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
location.href=process.env.VUE_APP_LOGIN_URL;
NProgress.done()
}
}
})
router.afterEach(() => {
NProgress.done()
})