Authored by htoooth

Merge remote-tracking branch 'origin/master'

<template>
<Row class="layout-header">
<Col :span="12" class="brand-title">{{userInfo.currentShop.shopName}}</Col>
<Col :span="12" class="brand-title">{{userInfo.name}}</Col>
<Col :span="12" class="shop-info">
<span class="name">{{userInfo.name}}</span>
<a href="javascript:;" @click="logout">[退出]</a>
<span class="name">{{userInfo.currentShop.shopName}}</span>
<span>|</span>
<Dropdown @on-click="switchShop">
<a class="swtich-shop" href="javascript:void(0)">
[切换店铺]
</a>
<Dropdown-menu slot="list">
<Dropdown-item v-for="shop in userInfo.shops" :key="shop.id" :name="shop.id">{{shop.shopName}}</Dropdown-item>
</Dropdown-menu>
</Dropdown>
<a class="logout" href="javascript:;" @click="logout">[退出]</a>
</Col>
</Row>
</template>
... ... @@ -23,11 +32,42 @@ export default {
methods: {
logout() {
Vue.logout();
},
switchShop(shop) {
console.log(shop)
}
}
};
</script>
<style lang="scss">
.layout-header {
height: 60px !important;
background: #fff;
box-shadow: 0 1px 1px rgba(0, 0, 0, .1);
font-size: 14px;
line-height: 20px;
padding: 20px;
.shop-info {
text-align: right;
padding-right: 20px;
.name {
margin-right: 5px;
}
.swtich-shop {
margin-left: 5px;
font-size: 12px;
color: #444;
}
.logout {
color: #F44545;
font-size: 12px;
margin-left: 5px;
}
}
}
</style>
... ...
... ... @@ -82,25 +82,7 @@ export default {
color: #9ea7b4;
}
.layout-header {
height: 60px !important;
background: #fff;
box-shadow: 0 1px 1px rgba(0, 0, 0, .1);
font-size: 14px;
line-height: 20px;
padding: 20px;
.shop-info {
text-align: right;
padding-right: 20px;
a {
color: #F44545;
font-size: 12px;
margin-left: 10px;
}
}
}
.layout-logo-left {
width: 90%;
... ...
... ... @@ -8,7 +8,8 @@
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const Express = require('express');
const session = require('express-session');
// const session = require('express-session');
const cookieSession = require('cookie-session');
const favicon = require('serve-favicon');
const path = require('path');
... ... @@ -28,9 +29,12 @@ global.yoho = {
co: global.Promise.coroutine
};
app.use(session({
app.use(cookieSession({
name: 'yoho-shop',
secret: 'yoho!shop@manage'
secret: 'yoho!shop@manage',
cookie: {
maxAge: 24 * 60 * 60 * 1000
}
}));
app.use(favicon(path.join(__dirname, '/favicon.ico')));
... ...
... ... @@ -14,6 +14,7 @@ let router = Express.Router(); // eslint-disable-line
router.post('/login', middleware(UserController, 'login'));
router.post('/logout', middleware(UserController, 'logout'));
router.post('/switchShop', middleware(UserController, 'switchShop'));
module.exports = router;
... ...
... ... @@ -29,6 +29,12 @@ class UserController extends Context {
name: user.account,
email: user.email,
createDate: user.create_date,
shops: _.map(result.data, shop => {
return {
id: shop.id,
shopName: shop.shopName
};
}),
currentShop: {
shopName: currentShop.shopName,
id: currentShop.id
... ... @@ -45,12 +51,39 @@ class UserController extends Context {
}
logout(req, res) {
delete req.session.USER;
delete req.session.LOGIN_UID;
delete req.session.CURRENT_SHOP;
return res.json({
code: 200,
data: '登出成功'
});
}
switchShop(req, res) {
let id = req.body.id;
if (!id) {
return res.json({
code: 400,
message: '参数错误'
});
}
let shop = _.get(req.user, 'shops', []).find(s => s.id === id);
if (shop.id === id) {
return res.json({
code: 200,
message: '已设置店铺'
});
}
req.session.CURRENT_SHOP = shop;
return res.json({
code: 200,
message: '切换成功'
});
}
syncSession(req, user) {
req.session.USER = user;
req.session.LOGIN_UID = user.pid; // pid 为用户名
... ...