Authored by zhangwenxue

style: apply eslint

... ... @@ -17,5 +17,5 @@ Vue.use(yohoPluginCache);
Vue.render({
el: '#app',
template: '<App/>',
components: {App}
components: { App },
});
... ...
... ... @@ -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;
};
}
},
};
... ...
... ... @@ -38,24 +38,26 @@ export default {
}
},
install(Vue) {
let childRouters = _.flattenDeep(this.loadRouters(pageRoutes));
const childRouters = _.flattenDeep(this.loadRouters(pageRoutes));
if (Vue.$config.homePage) {
let homePage = _.find(childRouters, router => router.name === Vue.$config.homePage);
const homePage = _.find(childRouters, router => router.name === Vue.$config.homePage);
homePage && (homePage.path = '/');
}
let routes = [{
let routes = [
{
path: '/',
component: layout,
children: childRouters
}];
children: childRouters,
},
];
routes = routes.concat(common);
Vue.$router = new Router({
routes: routes,
mode: Vue.$config.historyMode
routes,
mode: Vue.$config.historyMode,
});
}
},
};
... ...
... ... @@ -6,7 +6,7 @@ class UserService extends Service {
return this.post('/login', {
username,
password,
captcha
captcha,
});
}
update(params) {
... ... @@ -14,9 +14,9 @@ class UserService extends Service {
}
purviews() {
return this.post('/erp/getPurview', {
platform_id: 4
platform_id: 4,
}).then(res => {
return {ori: res.data, deep: this.deepList(res.data)};
return { ori: res.data, deep: this.deepList(res.data) };
});
}
config() {
... ... @@ -26,11 +26,11 @@ class UserService extends Service {
let purs = [];
_.each(purviews, pur => {
let sub = pur.sub;
const sub = pur.sub;
purs.push(pur);
if (sub && sub.length) {
let subs = this.deepList(sub);
const subs = this.deepList(sub);
_.each(subs, s => {
s.pMenu = pur;
... ... @@ -42,7 +42,7 @@ class UserService extends Service {
}
switchShop(shopId) {
return this.post('/switchShop', {
shopId
shopId,
});
}
geeCaptcha() {
... ...