|
|
|
/*
|
|
|
|
* @Author: 1036896656@qq.com 1036896656@qq.com
|
|
|
|
* @Date: 2023-08-04 11:13:12
|
|
|
|
* @LastEditors: 1036896656@qq.com 1036896656@qq.com
|
|
|
|
* @LastEditTime: 2023-09-26 09:41:22
|
|
|
|
* @FilePath: \agile-portal-ui\src\permission.js
|
|
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
|
|
*/
|
|
|
|
import router from "./router";
|
|
|
|
import store from "./store";
|
|
|
|
import {Message} from "element-ui";
|
|
|
|
import NProgress from "nprogress"; // progress bar
|
|
|
|
import "nprogress/nprogress.css"; // progress bar style
|
|
|
|
import {isRelogin} from '@/utils/request'
|
|
|
|
|
|
|
|
NProgress.configure({ showSpinner: false }); // NProgress Configuration
|
|
|
|
|
|
|
|
const whiteList = [
|
|
|
|
"Index",
|
|
|
|
"productsList",
|
|
|
|
"ProductsDetail",
|
|
|
|
"DataServiceGuide",
|
|
|
|
"ApiList",
|
|
|
|
"DataLaboratory",
|
|
|
|
"SuccessCase",
|
|
|
|
"Login",
|
|
|
|
"ResetPwd",
|
|
|
|
"FindPwd",
|
|
|
|
"NewsCenter",
|
|
|
|
"NewsDetail",
|
|
|
|
"introduce",
|
|
|
|
"AccountIssues",
|
|
|
|
"LegalNotice",
|
|
|
|
"privacyStatement",
|
|
|
|
"CompanyProfile"
|
|
|
|
]; // no redirect whitelist
|
|
|
|
|
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
|
|
|
|
|
|
// start progress bar
|
|
|
|
NProgress.start();
|
|
|
|
|
|
|
|
const storedData = localStorage.getItem('myData');
|
|
|
|
if (storedData) {
|
|
|
|
// 判断当前用户是否已拉取完user_info信息
|
|
|
|
isRelogin.show = true
|
|
|
|
store.dispatch('GetInfo').then(() => {
|
|
|
|
isRelogin.show = false
|
|
|
|
next();
|
|
|
|
NProgress.done();
|
|
|
|
}).catch(err => {
|
|
|
|
store.dispatch('LogOut').then(() => {
|
|
|
|
if (whiteList.indexOf(to.name) === -1) {
|
|
|
|
Message.error(err)
|
|
|
|
next({ path: '/login' })
|
|
|
|
} else {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
if (whiteList.indexOf(to.name) === -1) {
|
|
|
|
// 判断当前用户是否已拉取完user_info信息
|
|
|
|
isRelogin.show = true
|
|
|
|
store.dispatch('GetInfo').then(() => {
|
|
|
|
isRelogin.show = false
|
|
|
|
next();
|
|
|
|
NProgress.done();
|
|
|
|
}).catch(err => {
|
|
|
|
store.dispatch('LogOut').then(() => {
|
|
|
|
Message.error(err)
|
|
|
|
next({ path: '/login' })
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
|
|
|
|
next();
|
|
|
|
NProgress.done();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
router.afterEach(() => {
|
|
|
|
// finish progress bar
|
|
|
|
NProgress.done();
|
|
|
|
});
|