Authored by 陈峰

config api

... ... @@ -31,6 +31,12 @@ export default {
this.updateUser(Vue, user, purviews);
});
},
initConfig(Vue) {
return this.userService.config().then((data) => {
Object.assign(Vue.$config, data);
Vue.prop('config', Vue.$config);
});
},
install(Vue) {
this.userService = new UserService();
... ... @@ -41,7 +47,10 @@ export default {
if (isLogin && user) {
try {
user = crypto.aesDecrypt(user, Object);
return this.initPurview(Vue, user).then(() => {
return Promise.all([
this.initPurview(Vue, user),
this.initConfig(Vue)
]).then(() => {
next();
}, () => {
next();
... ... @@ -82,7 +91,10 @@ export default {
local: (username, password) => {
return this.userService.login(username, password).then((res) => {
if (res.code === 200) {
return this.initPurview(Vue, res.data).then(() => {
return Promise.all([
this.initPurview(Vue, res.data),
this.initConfig(Vue)
]).then(() => {
return res.data;
});
}
... ...
... ... @@ -12,6 +12,9 @@ class UserService extends Service {
return {ori: res.data, deep: this.deepList(res.data)};
});
}
config() {
return this.post('/config');
}
deepList(purviews) {
let purs = [];
... ...
... ... @@ -20,6 +20,7 @@ const path = require('path');
global.env = {
version: pkg.version,
Production: process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'gray',
Gray: process.env.NODE_ENV === 'gray',
Test: (process.env.NODE_ENV || '').indexOf('test') >= 0
};
... ...
... ... @@ -104,7 +104,7 @@ if (global.env.Test) {
if (global.env.Production) {
domains.erp = 'http://gw.api.yohobuy.com';
domains.platform = 'http://api.platform.yohoops.org/platform';
domains.shop = 'http://shops.yohobuy.com';
domains.shop = 'http://127.0.0.1:30012';
}
_.each(domainApis, (apis, domainName) => {
... ...
... ... @@ -23,5 +23,6 @@ router.post('/switchShop', before, auth, middleware(UserController, 'switchShop'
router.post('/upload/image', before, auth, multipartMiddleware, middleware(FileController, 'uploadImage'));
router.post('/upload/xlsx', before, auth, multipartMiddleware, middleware(FileController, 'uploadXlsx'));
router.post('/importSeller', before, auth, multipartMiddleware, middleware(FileController, 'importSeller'));
router.post('/config', middleware(UserController, 'config'));
module.exports = router;
... ...
... ... @@ -72,6 +72,22 @@ class UserController extends Context {
data: '登出成功'
});
}
config(req, res) {
let config = {
shopsFeDomain: 'http://shops.yohobuy.com'
};
if (global.env.Production) {
Object.assign(config, {
shopsFeDomain: 'http://shops.yohobuy.com'
});
} else if (global.env.Gray) {
Object.assign(config, {
shopsFeDomain: 'http://shops.yohops.com'
});
}
res.json(config);
}
switchShop(req, res) {
let shopId = req.body.shopId;
... ...