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.

67 lines
1.6 KiB

/*
* @Author: 1036896656@qq.com 1036896656@qq.com
* @Date: 2023-08-04 11:13:12
* @LastEditors: 1036896656@qq.com 1036896656@qq.com
* @LastEditTime: 2023-08-28 16:39:13
* @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",
"DataProducts",
"DataServiceGuide",
"ApiList",
"DataLaboratory",
"SuccessCase",
"Login",
"ResetPwd",
"FindPwd",
"NewsCenter",
"NewsDetail",
"introduce"
]; // no redirect whitelist
router.beforeEach(async (to, from, next) => {
// start progress bar
NProgress.start();
if (whiteList.indexOf(to.name) === -1) {
if (store.getters.userName == '') {
// 判断当前用户是否已拉取完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: '/' })
})
})
} else {
next();
NProgress.done();
}
} else {
next();
NProgress.done();
}
});
router.afterEach(() => {
// finish progress bar
NProgress.done();
});