|
1 | | -// The Vue build version to load with the `import` command |
2 | | -// (runtime-only or standalone) has been set in webpack.base.conf with an alias. |
3 | | -import Vue from 'vue'; |
4 | | -import App from './App'; |
5 | | -import router from './router'; |
6 | | -import store from './store'; |
7 | | -import ElementUI from 'element-ui'; |
8 | | -import 'element-ui/lib/theme-default/index.css'; |
9 | | -import 'assets/custom-theme/index.css'; // 换肤版本element-ui css |
10 | | -import NProgress from 'nprogress'; // Progress 进度条 |
11 | | -import 'nprogress/nprogress.css';// Progress 进度条 样式 |
12 | | -import 'normalize.css/normalize.css';// normalize.css 样式格式化 |
13 | | -import 'assets/iconfont/iconfont'; // iconfont 具体图标见https://github.com/PanJiaChen/vue-element-admin/wiki |
14 | | -import * as filters from './filters'; // 全局vue filter |
15 | | -import Multiselect from 'vue-multiselect';// 使用的一个多选框组件,element-ui的select不能满足所有需求 |
16 | | -import 'vue-multiselect/dist/vue-multiselect.min.css';// 多选框组件css |
17 | | -import Sticky from 'components/Sticky'; // 粘性header组件 |
18 | | -import IconSvg from 'components/Icon-svg';// svg 组件 |
19 | | -import vueWaves from './directive/waves';// 水波纹指令 |
20 | | -import errLog from 'store/errLog';// error log组件 |
21 | | -import './mock/index.js'; // 该项目所有请求使用mockjs模拟 |
22 | | -import { getToken } from 'utils/auth'; |
| 1 | +import Vue from 'vue' |
| 2 | +import App from './App' |
| 3 | +import router from './router' |
| 4 | +import store from './store' |
| 5 | +import 'normalize.css/normalize.css'// normalize.css 样式格式化 |
| 6 | +import ElementUI from 'element-ui' |
| 7 | +import 'element-ui/lib/theme-default/index.css' |
| 8 | +import '@/assets/iconfont/iconfont' // iconfont 具体图标见https://github.com/PanJiaChen/vue-element-admin/wiki |
| 9 | +import IconSvg from '@/components/Icon-svg'// svg组件 |
| 10 | +import * as filters from '@/filters' // 全局filter |
| 11 | +import '@/errorLog'// error log |
| 12 | +import '@/permission' // 权限 |
| 13 | +import '@/mock/index.js' // 该项目所有请求使用mockjs模拟 |
23 | 14 |
|
24 | 15 | // register globally |
25 | | -Vue.component('multiselect', Multiselect); |
26 | | -Vue.component('Sticky', Sticky); |
27 | 16 | Vue.component('icon-svg', IconSvg) |
28 | | -Vue.use(ElementUI); |
29 | | -Vue.use(vueWaves); |
| 17 | +Vue.use(ElementUI) |
30 | 18 |
|
31 | 19 | // register global utility filters. |
32 | 20 | Object.keys(filters).forEach(key => { |
33 | 21 | Vue.filter(key, filters[key]) |
34 | | -}); |
35 | | - |
36 | | -// permissiom judge |
37 | | -function hasPermission(roles, permissionRoles) { |
38 | | - if (roles.indexOf('admin') >= 0) return true; // admin权限 直接通过 |
39 | | - if (!permissionRoles) return true; |
40 | | - return roles.some(role => permissionRoles.indexOf(role) >= 0) |
41 | | -} |
42 | | - |
43 | | -// register global progress. |
44 | | -const whiteList = ['/login', '/authredirect', '/reset', '/sendpwd'];// 不重定向白名单 |
45 | | -router.beforeEach((to, from, next) => { |
46 | | - NProgress.start(); // 开启Progress |
47 | | - if (getToken()) { // 判断是否有token |
48 | | - if (to.path === '/login') { |
49 | | - next({ path: '/' }); |
50 | | - } else { |
51 | | - if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息 |
52 | | - store.dispatch('GetInfo').then(res => { // 拉取user_info |
53 | | - const roles = res.data.role; |
54 | | - store.dispatch('GenerateRoutes', { roles }).then(() => { // 生成可访问的路由表 |
55 | | - router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 |
56 | | - next({ ...to }); // hack方法 确保addRoutes已完成 |
57 | | - }) |
58 | | - }).catch(() => { |
59 | | - store.dispatch('FedLogOut').then(() => { |
60 | | - next({ path: '/login' }); |
61 | | - }) |
62 | | - }) |
63 | | - } else { |
64 | | - // 没有动态改变权限的需求可直接next() 删除下方权限判断 ↓ |
65 | | - if (hasPermission(store.getters.roles, to.meta.role)) { |
66 | | - next();// |
67 | | - } else { |
68 | | - next({ path: '/401', query: { noGoBack: true } }); |
69 | | - } |
70 | | - // 可删 ↑ |
71 | | - } |
72 | | - } |
73 | | - } else { |
74 | | - if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入 |
75 | | - next() |
76 | | - } else { |
77 | | - next('/login'); // 否则全部重定向到登录页 |
78 | | - NProgress.done(); // 在hash模式下 改变手动改变hash 重定向回来 不会触发afterEach 暂时hack方案 ps:history模式下无问题,可删除该行! |
79 | | - } |
80 | | - } |
81 | | -}); |
82 | | - |
83 | | -router.afterEach(() => { |
84 | | - NProgress.done(); // 结束Progress |
85 | | -}); |
86 | | - |
87 | | -Vue.config.productionTip = false; |
| 22 | +}) |
88 | 23 |
|
89 | | -// 生产环境错误日志 |
90 | | -if (process.env.NODE_ENV === 'production') { |
91 | | - Vue.config.errorHandler = function(err, vm) { |
92 | | - console.log(err, window.location.href); |
93 | | - errLog.pushLog({ |
94 | | - err, |
95 | | - url: window.location.href, |
96 | | - vm |
97 | | - }) |
98 | | - }; |
99 | | -} |
| 24 | +Vue.config.productionTip = false |
100 | 25 |
|
101 | 26 | new Vue({ |
102 | 27 | el: '#app', |
|
0 commit comments