Authored by zhangwenxue

style: apply eslint

@@ -15,7 +15,7 @@ Vue.use(yohoPluginAuth); @@ -15,7 +15,7 @@ Vue.use(yohoPluginAuth);
15 Vue.use(yohoPluginCache); 15 Vue.use(yohoPluginCache);
16 16
17 Vue.render({ 17 Vue.render({
18 - el: '#app',  
19 - template: '<App/>',  
20 - components: {App} 18 + el: '#app',
  19 + template: '<App/>',
  20 + components: { App },
21 }); 21 });
@@ -7,136 +7,133 @@ import UserService from 'services/user/user-service'; @@ -7,136 +7,133 @@ import UserService from 'services/user/user-service';
7 import crypto from 'util/crypto'; 7 import crypto from 'util/crypto';
8 8
9 export default { 9 export default {
10 - updateUser(Vue, user, purviews) {  
11 - Vue.$store.set(Vue.$config.storeKeys.user, crypto.aesEncrypt(user));  
12 - Vue.prop('purviews', purviews.deep);  
13 - Vue.prop('oriPurviews', purviews.ori);  
14 - Vue.prop('user', user);  
15 - Vue.prop('isLogin', true);  
16 - }, 10 + updateUser(Vue, user, purviews) {
  11 + Vue.$store.set(Vue.$config.storeKeys.user, crypto.aesEncrypt(user));
  12 + Vue.prop('purviews', purviews.deep);
  13 + Vue.prop('oriPurviews', purviews.ori);
  14 + Vue.prop('user', user);
  15 + Vue.prop('isLogin', true);
  16 + },
17 17
18 - // 权限验证  
19 - checkPurview() {  
20 - return Promise.resolve(); 18 + // 权限验证
  19 + checkPurview() {
  20 + return Promise.resolve();
21 21
22 - // let pur = _.find(Vue.$purviews, p => p.menu_url === to.path); 22 + // let pur = _.find(Vue.$purviews, p => p.menu_url === to.path);
23 23
24 - // if (pur) {  
25 - // return Promise.resolve();  
26 - // }  
27 - // return Promise.reject();  
28 - },  
29 - initPurview(Vue, user) {  
30 - return this.userService.purviews().then((purviews) => {  
31 - this.updateUser(Vue, user, purviews);  
32 - });  
33 - },  
34 - initConfig(Vue) {  
35 - return this.userService.config().then((data) => {  
36 - Object.assign(Vue.$config, data);  
37 - Vue.prop('config', Vue.$config);  
38 - });  
39 - },  
40 - install(Vue) {  
41 - this.userService = new UserService();  
42 -  
43 - Vue.beforeRender((next) => {  
44 - let user = Vue.$store.get(Vue.$config.storeKeys.user);  
45 - let isLogin = Vue.$cookie.get('_isLogin');  
46 -  
47 - if (isLogin && user) {  
48 - try {  
49 - user = crypto.aesDecrypt(user, Object);  
50 - return Promise.all([  
51 - this.initPurview(Vue, user),  
52 - this.initConfig(Vue)  
53 - ]).then(() => {  
54 - next();  
55 - }, () => {  
56 - next();  
57 - });  
58 - } catch (e) {  
59 - Vue.logout();  
60 - }  
61 - }  
62 - next();  
63 - }); 24 + // if (pur) {
  25 + // return Promise.resolve();
  26 + // }
  27 + // return Promise.reject();
  28 + },
  29 + initPurview(Vue, user) {
  30 + return this.userService.purviews().then(purviews => {
  31 + this.updateUser(Vue, user, purviews);
  32 + });
  33 + },
  34 + initConfig(Vue) {
  35 + return this.userService.config().then(data => {
  36 + Object.assign(Vue.$config, data);
  37 + Vue.prop('config', Vue.$config);
  38 + });
  39 + },
  40 + install(Vue) {
  41 + this.userService = new UserService();
64 42
65 - // 路由权限控制  
66 - Vue.$router.beforeEach((to, from, next) => { 43 + Vue.beforeRender(next => {
  44 + let user = Vue.$store.get(Vue.$config.storeKeys.user);
  45 + const isLogin = Vue.$cookie.get('_isLogin');
67 46
68 - // 需要修改密码去修改密码  
69 - if (Vue.$store.get('needUpdate') && to.name !== 'login' && to.name !== 'user.password') {  
70 - return next('/user/password.html'); 47 + if (isLogin && user) {
  48 + try {
  49 + user = crypto.aesDecrypt(user, Object);
  50 + return Promise.all([this.initPurview(Vue, user), this.initConfig(Vue)]).then(
  51 + () => {
  52 + next();
  53 + },
  54 + () => {
  55 + next();
71 } 56 }
  57 + );
  58 + } catch (e) {
  59 + Vue.logout();
  60 + }
  61 + }
  62 + next();
  63 + });
72 64
73 - // 无权限控制理由直接pass  
74 - let authPass = _.get(_.last(to.matched), 'meta.authPass', false); 65 + // 路由权限控制
  66 + Vue.$router.beforeEach((to, from, next) => {
  67 + // 需要修改密码去修改密码
  68 + if (Vue.$store.get('needUpdate') && to.name !== 'login' && to.name !== 'user.password') {
  69 + return next('/user/password.html');
  70 + }
75 71
76 - if (authPass) {  
77 - // 已登录跳转到首页  
78 - if (to.name === 'login' && Vue.$isLogin) {  
79 - return next('/');  
80 - }  
81 - return next();  
82 - } 72 + // 无权限控制理由直接pass
  73 + const authPass = _.get(_.last(to.matched), 'meta.authPass', false);
83 74
84 - // 未登录去登录  
85 - if (!Vue.$isLogin) {  
86 - return next('/login.html');  
87 - } 75 + if (authPass) {
  76 + // 已登录跳转到首页
  77 + if (to.name === 'login' && Vue.$isLogin) {
  78 + return next('/');
  79 + }
  80 + return next();
  81 + }
88 82
  83 + // 未登录去登录
  84 + if (!Vue.$isLogin) {
  85 + return next('/login.html');
  86 + }
  87 + return this.checkPurview(Vue, to).then(
  88 + () => {
  89 + return next();
  90 + },
  91 + () => {
  92 + return next('/401.html');
  93 + }
  94 + );
  95 + });
89 96
90 - return this.checkPurview(Vue, to).then(() => {  
91 - return next();  
92 - }, () => {  
93 - return next('/401.html'); 97 + Vue.passport = {
  98 + local: (username, password, captcha) => {
  99 + return this.userService.login(username, password, captcha).then(res => {
  100 + if (res.code === 200) {
  101 + return Promise.all([this.initPurview(Vue, res.data), this.initConfig(Vue)]).then(() => {
  102 + if (res.data.needUpdate) {
  103 + Vue.$store.set('needUpdate', true);
  104 + }
  105 + return res.data;
94 }); 106 });
  107 + }
  108 + return Promise.reject(res);
95 }); 109 });
96 -  
97 - Vue.passport = {  
98 - local: (username, password, captcha) => {  
99 - return this.userService.login(username, password, captcha).then((res) => {  
100 - if (res.code === 200) {  
101 - return Promise.all([  
102 - this.initPurview(Vue, res.data),  
103 - this.initConfig(Vue)  
104 - ]).then(() => {  
105 - if (res.data.needUpdate) {  
106 - Vue.$store.set('needUpdate', true);  
107 - }  
108 - return res.data;  
109 - });  
110 - }  
111 - return Promise.reject(res);  
112 - });  
113 - }  
114 - };  
115 - Vue.switchShop = shopsId => {  
116 - Vue.$store.set(Vue.$config.storeKeys.user, crypto.aesEncrypt(Vue.$user));  
117 - Vue.$cookie.set('_sign', shopsId, {  
118 - path: '/'  
119 - });  
120 - };  
121 - Vue.logout = () => {  
122 - _.each(Vue.$config.storeKeys, Vue.$store.remove);  
123 - Vue.prop('user', void 0);  
124 - Vue.prop('isLogin', void 0);  
125 - Vue.prop('purviews', void 0);  
126 - Vue.$store.remove('needUpdate');  
127 - axios.post('/logout');  
128 - Vue.$router.push('/login.html');  
129 - };  
130 - axios.defaults.validateStatus = (status) => {  
131 - if (status === 401) {  
132 - Vue.logout();  
133 - return false;  
134 - }  
135 - if (status === 403) {  
136 - Vue.$store.set('needUpdate', true);  
137 - return false;  
138 - }  
139 - return true;  
140 - };  
141 - } 110 + },
  111 + };
  112 + Vue.switchShop = shopsId => {
  113 + Vue.$store.set(Vue.$config.storeKeys.user, crypto.aesEncrypt(Vue.$user));
  114 + Vue.$cookie.set('_sign', shopsId, {
  115 + path: '/',
  116 + });
  117 + };
  118 + Vue.logout = () => {
  119 + _.each(Vue.$config.storeKeys, Vue.$store.remove);
  120 + Vue.prop('user', void 0);
  121 + Vue.prop('isLogin', void 0);
  122 + Vue.prop('purviews', void 0);
  123 + Vue.$store.remove('needUpdate');
  124 + axios.post('/logout');
  125 + Vue.$router.push('/login.html');
  126 + };
  127 + axios.defaults.validateStatus = status => {
  128 + if (status === 401) {
  129 + Vue.logout();
  130 + return false;
  131 + }
  132 + if (status === 403) {
  133 + Vue.$store.set('needUpdate', true);
  134 + return false;
  135 + }
  136 + return true;
  137 + };
  138 + },
142 }; 139 };
@@ -5,57 +5,59 @@ import common from '../pages/common'; @@ -5,57 +5,59 @@ import common from '../pages/common';
5 import _ from 'lodash'; 5 import _ from 'lodash';
6 6
7 export default { 7 export default {
8 - loadRouters(rous, paths, children) {  
9 - if (_.has(rous, 'path')) {  
10 - let ps = _.flattenDeep(paths).filter(p => p); 8 + loadRouters(rous, paths, children) {
  9 + if (_.has(rous, 'path')) {
  10 + let ps = _.flattenDeep(paths).filter(p => p);
11 11
12 - if (_.last(ps) === rous.name) {  
13 - ps = _.dropRight(ps);  
14 - }  
15 - if (!children) {  
16 - if (rous.path) {  
17 - rous.path = _.join(ps, '/') + (rous.path[0] === '/' ? '' : '/') + rous.path;  
18 - } else {  
19 - rous.path = _.join(ps, '/') + '.html';  
20 - }  
21 - }  
22 - rous.name = _.join(_.concat(ps, [rous.name]), '.');  
23 -  
24 - if (rous.children) {  
25 - _.each(rous.children, child => this.loadRouters(child, [paths, child.name], true));  
26 - return [rous];  
27 - }  
28 - return [rous];  
29 - }  
30 - if (rous.length) {  
31 - return _.map(rous, r => {  
32 - return this.loadRouters(r, [paths]);  
33 - }); 12 + if (_.last(ps) === rous.name) {
  13 + ps = _.dropRight(ps);
  14 + }
  15 + if (!children) {
  16 + if (rous.path) {
  17 + rous.path = _.join(ps, '/') + (rous.path[0] === '/' ? '' : '/') + rous.path;
34 } else { 18 } else {
35 - return _.map(rous, (rou, k) => {  
36 - return this.loadRouters(rou, [paths, k]);  
37 - }); 19 + rous.path = _.join(ps, '/') + '.html';
38 } 20 }
39 - },  
40 - install(Vue) {  
41 - let childRouters = _.flattenDeep(this.loadRouters(pageRoutes)); 21 + }
  22 + rous.name = _.join(_.concat(ps, [rous.name]), '.');
42 23
43 - if (Vue.$config.homePage) {  
44 - let homePage = _.find(childRouters, router => router.name === Vue.$config.homePage);  
45 -  
46 - homePage && (homePage.path = '/');  
47 - } 24 + if (rous.children) {
  25 + _.each(rous.children, child => this.loadRouters(child, [paths, child.name], true));
  26 + return [rous];
  27 + }
  28 + return [rous];
  29 + }
  30 + if (rous.length) {
  31 + return _.map(rous, r => {
  32 + return this.loadRouters(r, [paths]);
  33 + });
  34 + } else {
  35 + return _.map(rous, (rou, k) => {
  36 + return this.loadRouters(rou, [paths, k]);
  37 + });
  38 + }
  39 + },
  40 + install(Vue) {
  41 + const childRouters = _.flattenDeep(this.loadRouters(pageRoutes));
48 42
49 - let routes = [{  
50 - path: '/',  
51 - component: layout,  
52 - children: childRouters  
53 - }]; 43 + if (Vue.$config.homePage) {
  44 + const homePage = _.find(childRouters, router => router.name === Vue.$config.homePage);
54 45
55 - routes = routes.concat(common);  
56 - Vue.$router = new Router({  
57 - routes: routes,  
58 - mode: Vue.$config.historyMode  
59 - }); 46 + homePage && (homePage.path = '/');
60 } 47 }
  48 +
  49 + let routes = [
  50 + {
  51 + path: '/',
  52 + component: layout,
  53 + children: childRouters,
  54 + },
  55 + ];
  56 +
  57 + routes = routes.concat(common);
  58 + Vue.$router = new Router({
  59 + routes,
  60 + mode: Vue.$config.historyMode,
  61 + });
  62 + },
61 }; 63 };
@@ -2,51 +2,51 @@ import _ from 'lodash'; @@ -2,51 +2,51 @@ import _ from 'lodash';
2 import Service from '../service'; 2 import Service from '../service';
3 3
4 class UserService extends Service { 4 class UserService extends Service {
5 - login(username, password, captcha) {  
6 - return this.post('/login', {  
7 - username,  
8 - password,  
9 - captcha  
10 - });  
11 - }  
12 - update(params) {  
13 - return this.post('/updatePwd', params);  
14 - }  
15 - purviews() {  
16 - return this.post('/erp/getPurview', {  
17 - platform_id: 4  
18 - }).then(res => {  
19 - return {ori: res.data, deep: this.deepList(res.data)};  
20 - });  
21 - }  
22 - config() {  
23 - return this.post('/config');  
24 - }  
25 - deepList(purviews) {  
26 - let purs = []; 5 + login(username, password, captcha) {
  6 + return this.post('/login', {
  7 + username,
  8 + password,
  9 + captcha,
  10 + });
  11 + }
  12 + update(params) {
  13 + return this.post('/updatePwd', params);
  14 + }
  15 + purviews() {
  16 + return this.post('/erp/getPurview', {
  17 + platform_id: 4,
  18 + }).then(res => {
  19 + return { ori: res.data, deep: this.deepList(res.data) };
  20 + });
  21 + }
  22 + config() {
  23 + return this.post('/config');
  24 + }
  25 + deepList(purviews) {
  26 + let purs = [];
27 27
28 - _.each(purviews, pur => {  
29 - let sub = pur.sub; 28 + _.each(purviews, pur => {
  29 + const sub = pur.sub;
30 30
31 - purs.push(pur);  
32 - if (sub && sub.length) {  
33 - let subs = this.deepList(sub); 31 + purs.push(pur);
  32 + if (sub && sub.length) {
  33 + const subs = this.deepList(sub);
34 34
35 - _.each(subs, s => {  
36 - s.pMenu = pur;  
37 - });  
38 - purs = purs.concat(...subs);  
39 - }  
40 - });  
41 - return purs;  
42 - }  
43 - switchShop(shopId) {  
44 - return this.post('/switchShop', {  
45 - shopId 35 + _.each(subs, s => {
  36 + s.pMenu = pur;
46 }); 37 });
47 - }  
48 - geeCaptcha() {  
49 - return this.get('/geeCaptcha?r=' + Math.random());  
50 - } 38 + purs = purs.concat(...subs);
  39 + }
  40 + });
  41 + return purs;
  42 + }
  43 + switchShop(shopId) {
  44 + return this.post('/switchShop', {
  45 + shopId,
  46 + });
  47 + }
  48 + geeCaptcha() {
  49 + return this.get('/geeCaptcha?r=' + Math.random());
  50 + }
51 } 51 }
52 export default UserService; 52 export default UserService;