提交 3cdb3639 编写于 作者: 刘英杰's avatar 刘英杰

值班管理pc

上级 1dde1b52
......@@ -14,6 +14,16 @@ import Cookies from 'js-cookie';
Vue.use(VueRouter);
function getUrlKey(name) {
return (
decodeURIComponent(
(new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(
location.href
) || [, ""])[1].replace(/\+/g, "%20")
) || null
);
}
// 导出路由 在 main.js 里使用
const router = new VueRouter({
routes,
......@@ -25,6 +35,15 @@ const router = new VueRouter({
* 路由拦截
* 权限验证
*/
function getUrlKey(name) {
return (
decodeURIComponent(
(new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(
location.href
) || [, ""])[1].replace(/\+/g, "%20")
) || null
);
}
router.beforeEach(async (to, from, next) => {
console.log(to)
......@@ -33,22 +52,16 @@ router.beforeEach(async (to, from, next) => {
if (to.matched.some(_ => _.meta.auth)) {
// 这里依据 token 判断是否登录,可视情况修改
const token = util.cookies.get('token');
if (token && token !== 'undefined') {
next();
} else {
const token = Cookies.get('token');
const urlKey = getUrlKey('token');
if (urlKey) {
await store.dispatch('admin/account/ascLogin', {
"token": token
"token": urlKey
}, {root: true});
next();
// 没有登录的时候跳转到登录界面
// 携带上登陆成功之后需要跳转的页面完整路径
// next({
// name: 'login',
// query: {
// redirect: to.fullPath
// }
// });
} else if (token) {
next();
} else {
next({name: '403'});
}
} else {
// 不需要身份校验 直接通过
......
Markdown 格式
0% or
您添加了 0 人 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册 或