yoho-plugin-purview.js
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* 权限插件
*/
import _ from 'lodash';
import axios from 'axios';
import purviews from 'purview';
const plugin = {
install(Vue) {
// 路由权限
Vue.mixin({
beforeRouteEnter(to, from, next) {
// TODO 获取权限
if (to.matched && to.matched.length > 0) {
let authPass = _.get(_.last(to.matched), 'meta.authPass', false);
if (authPass) {
return next();
}
}
let purview = _.get(purviews, to.name.replace(/\./g, '.subPurviews.'));
if (purview.own) {
return next();
} else {
return next('/401');
}
}
});
// 接口权限
axios.defaults.validateStatus = (status) => {
if (status >= 200 && status < 300) {
return true;
}
if (status === 401) {
Vue.logout();
return false;
}
Vue.$Message.error('接口异常');
return false;
};
}
};
export default plugin;