...
|
...
|
@@ -27,12 +27,12 @@ export default { |
|
|
// return Promise.reject();
|
|
|
},
|
|
|
initPurview(Vue, user) {
|
|
|
return this.userService.purviews().then((purviews) => {
|
|
|
return this.userService.purviews().then(purviews => {
|
|
|
this.updateUser(Vue, user, purviews);
|
|
|
});
|
|
|
},
|
|
|
initConfig(Vue) {
|
|
|
return this.userService.config().then((data) => {
|
|
|
return this.userService.config().then(data => {
|
|
|
Object.assign(Vue.$config, data);
|
|
|
Vue.prop('config', Vue.$config);
|
|
|
});
|
...
|
...
|
@@ -40,21 +40,21 @@ export default { |
|
|
install(Vue) {
|
|
|
this.userService = new UserService();
|
|
|
|
|
|
Vue.beforeRender((next) => {
|
|
|
Vue.beforeRender(next => {
|
|
|
let user = Vue.$store.get(Vue.$config.storeKeys.user);
|
|
|
let isLogin = Vue.$cookie.get('_isLogin');
|
|
|
const isLogin = Vue.$cookie.get('_isLogin');
|
|
|
|
|
|
if (isLogin && user) {
|
|
|
try {
|
|
|
user = crypto.aesDecrypt(user, Object);
|
|
|
return Promise.all([
|
|
|
this.initPurview(Vue, user),
|
|
|
this.initConfig(Vue)
|
|
|
]).then(() => {
|
|
|
return Promise.all([this.initPurview(Vue, user), this.initConfig(Vue)]).then(
|
|
|
() => {
|
|
|
next();
|
|
|
}, () => {
|
|
|
},
|
|
|
() => {
|
|
|
next();
|
|
|
});
|
|
|
}
|
|
|
);
|
|
|
} catch (e) {
|
|
|
Vue.logout();
|
|
|
}
|
...
|
...
|
@@ -64,14 +64,13 @@ export default { |
|
|
|
|
|
// 路由权限控制
|
|
|
Vue.$router.beforeEach((to, from, next) => {
|
|
|
|
|
|
// 需要修改密码去修改密码
|
|
|
if (Vue.$store.get('needUpdate') && to.name !== 'login' && to.name !== 'user.password') {
|
|
|
return next('/user/password.html');
|
|
|
}
|
|
|
|
|
|
// 无权限控制理由直接pass
|
|
|
let authPass = _.get(_.last(to.matched), 'meta.authPass', false);
|
|
|
const authPass = _.get(_.last(to.matched), 'meta.authPass', false);
|
|
|
|
|
|
if (authPass) {
|
|
|
// 已登录跳转到首页
|
...
|
...
|
@@ -85,23 +84,21 @@ export default { |
|
|
if (!Vue.$isLogin) {
|
|
|
return next('/login.html');
|
|
|
}
|
|
|
|
|
|
|
|
|
return this.checkPurview(Vue, to).then(() => {
|
|
|
return this.checkPurview(Vue, to).then(
|
|
|
() => {
|
|
|
return next();
|
|
|
}, () => {
|
|
|
},
|
|
|
() => {
|
|
|
return next('/401.html');
|
|
|
});
|
|
|
}
|
|
|
);
|
|
|
});
|
|
|
|
|
|
Vue.passport = {
|
|
|
local: (username, password, captcha) => {
|
|
|
return this.userService.login(username, password, captcha).then((res) => {
|
|
|
return this.userService.login(username, password, captcha).then(res => {
|
|
|
if (res.code === 200) {
|
|
|
return Promise.all([
|
|
|
this.initPurview(Vue, res.data),
|
|
|
this.initConfig(Vue)
|
|
|
]).then(() => {
|
|
|
return Promise.all([this.initPurview(Vue, res.data), this.initConfig(Vue)]).then(() => {
|
|
|
if (res.data.needUpdate) {
|
|
|
Vue.$store.set('needUpdate', true);
|
|
|
}
|
...
|
...
|
@@ -110,12 +107,12 @@ export default { |
|
|
}
|
|
|
return Promise.reject(res);
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
};
|
|
|
Vue.switchShop = shopsId => {
|
|
|
Vue.$store.set(Vue.$config.storeKeys.user, crypto.aesEncrypt(Vue.$user));
|
|
|
Vue.$cookie.set('_sign', shopsId, {
|
|
|
path: '/'
|
|
|
path: '/',
|
|
|
});
|
|
|
};
|
|
|
Vue.logout = () => {
|
...
|
...
|
@@ -127,7 +124,7 @@ export default { |
|
|
axios.post('/logout');
|
|
|
Vue.$router.push('/login.html');
|
|
|
};
|
|
|
axios.defaults.validateStatus = (status) => {
|
|
|
axios.defaults.validateStatus = status => {
|
|
|
if (status === 401) {
|
|
|
Vue.logout();
|
|
|
return false;
|
...
|
...
|
@@ -138,5 +135,5 @@ export default { |
|
|
}
|
|
|
return true;
|
|
|
};
|
|
|
}
|
|
|
},
|
|
|
}; |
...
|
...
|
|