|
|
|
@ -4,7 +4,7 @@
|
|
|
|
|
* @Author: JC9527
|
|
|
|
|
* @Date: 2024-01-09 23:08:15
|
|
|
|
|
* @LastEditors: JC9527
|
|
|
|
|
* @LastEditTime: 2024-05-16 11:20:06
|
|
|
|
|
* @LastEditTime: 2024-09-03 20:23:09
|
|
|
|
|
*/
|
|
|
|
|
import router from './router'
|
|
|
|
|
import store from './store'
|
|
|
|
@ -22,74 +22,53 @@ const whiteList = ['/login', '/register', '/bigScreen']
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
NProgress.start()
|
|
|
|
|
// console.log('tototo',to.path);
|
|
|
|
|
if(localStorage.getItem('accessToken')) {
|
|
|
|
|
if(localStorage.getItem('accessToken') && localStorage.getItem('account')) {
|
|
|
|
|
next()
|
|
|
|
|
NProgress.done()
|
|
|
|
|
} else {
|
|
|
|
|
if (window.location.href.includes("code=")) {
|
|
|
|
|
var reg = new RegExp(/[?&]code=([^&#]+)/);
|
|
|
|
|
var c = window.location.href.match(reg);
|
|
|
|
|
const code = c && c[1];
|
|
|
|
|
getAccesstoken({code:code}).then(res=>{
|
|
|
|
|
// console.log(res,"res")
|
|
|
|
|
// setAccessToken(res.data.accessToken)
|
|
|
|
|
localStorage.setItem('accessToken',res.data.accessToken)
|
|
|
|
|
let url = window.location.href;
|
|
|
|
|
var modifiedUrl = url.replace(/[\?&](code)=.*?(#\/|$)/g, '');
|
|
|
|
|
// console.log(modifiedUrl,'modifiedUrl');
|
|
|
|
|
window.location.href = modifiedUrl;
|
|
|
|
|
// next()
|
|
|
|
|
NProgress.done()
|
|
|
|
|
// return getUserinfo({accessToken:res.data.accessToken})
|
|
|
|
|
})
|
|
|
|
|
// .then(res=>{
|
|
|
|
|
// localStorage.setItem('AuserInfo', JSON.stringify(el.data))
|
|
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
} else {
|
|
|
|
|
location.href = "http://10.236.2.28:54567/bjh-admin/"
|
|
|
|
|
}
|
|
|
|
|
} else if (window.location.href.includes("code=")) {
|
|
|
|
|
var reg = new RegExp(/[?&]code=([^&#]+)/);
|
|
|
|
|
var c = window.location.href.match(reg);
|
|
|
|
|
const code = c && c[1];
|
|
|
|
|
getAccesstoken({code:code}).then(res=>{
|
|
|
|
|
// console.log(res,"res")
|
|
|
|
|
// setAccessToken(res.data.accessToken)
|
|
|
|
|
localStorage.setItem('accessToken',res.data.accessToken)
|
|
|
|
|
return getUserinfo({ accessToken: res.data.accessToken })
|
|
|
|
|
}).then(el=>{
|
|
|
|
|
// setToken(el.data.token)
|
|
|
|
|
localStorage.setItem('account',el.data.account)
|
|
|
|
|
let url = window.location.href;
|
|
|
|
|
var modifiedUrl = url.replace(/[\?&](code)=.*?(#\/|$)/g, '');
|
|
|
|
|
// console.log(modifiedUrl,'modifiedUrl');
|
|
|
|
|
window.location.href = modifiedUrl;
|
|
|
|
|
// next()
|
|
|
|
|
NProgress.done()
|
|
|
|
|
})
|
|
|
|
|
// .then(res=>{
|
|
|
|
|
// localStorage.setItem('AuserInfo', JSON.stringify(el.data))
|
|
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
}
|
|
|
|
|
// next()
|
|
|
|
|
|
|
|
|
|
// if (getToken()) {
|
|
|
|
|
// else if(getToken()) {
|
|
|
|
|
// to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
|
|
|
|
|
// /* has token*/
|
|
|
|
|
// if (to.path === '/login') {
|
|
|
|
|
// next({ path: '/' })
|
|
|
|
|
// NProgress.done()
|
|
|
|
|
// } else {
|
|
|
|
|
// console.log('store.getters.roles',store.getters.roles)
|
|
|
|
|
// if (store.getters.roles.length === 0) {
|
|
|
|
|
// isRelogin.show = true
|
|
|
|
|
// // 判断当前用户是否已拉取完user_info信息
|
|
|
|
|
// store.dispatch('GetInfo').then(() => {
|
|
|
|
|
// isRelogin.show = false
|
|
|
|
|
// store.dispatch('GenerateRoutes').then(accessRoutes => {
|
|
|
|
|
// // 根据roles权限生成可访问的路由表
|
|
|
|
|
// router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
|
|
|
|
// next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
|
|
|
|
// })
|
|
|
|
|
// }).catch(err => {
|
|
|
|
|
// store.dispatch('LogOut').then(() => {
|
|
|
|
|
// Message.error(err)
|
|
|
|
|
// next({ path: '/' })
|
|
|
|
|
// })
|
|
|
|
|
// })
|
|
|
|
|
// } else {
|
|
|
|
|
// if (store.getters.roles.length === 0) {
|
|
|
|
|
// // isRelogin.show = true
|
|
|
|
|
// // 判断当前用户是否已拉取完user_info信息
|
|
|
|
|
// store.dispatch('GetInfo').then(() => {
|
|
|
|
|
// isRelogin.show = false
|
|
|
|
|
// next()
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// // 没有token
|
|
|
|
|
// if (whiteList.indexOf(to.path) !== -1) {
|
|
|
|
|
// // 在免登录白名单,直接进入
|
|
|
|
|
// next()
|
|
|
|
|
// NProgress.done()
|
|
|
|
|
// }).catch(err => {
|
|
|
|
|
// })
|
|
|
|
|
// } else {
|
|
|
|
|
// next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
|
|
|
|
|
// next()
|
|
|
|
|
// NProgress.done()
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
else {
|
|
|
|
|
location.href = "http://10.236.2.28:54567/bjh-admin/"
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.afterEach(() => {
|
|
|
|
|