Authored by 陈峰

history模式

... ... @@ -8,10 +8,12 @@ import yohoPluginUser from './plugins/yoho-plugin-user';
import './filters';
import './directives';
import 'iview/dist/styles/iview.css';
import 'common.scss';
import 'font-awesome/css/font-awesome.css';
let router = new Router({routes: Routers});
let router = new Router({
routes: Routers,
mode: 'history'
});
Vue.use(yohoPluginCore, {router});
Vue.use(yohoPluginPurview);
... ...
... ... @@ -11,9 +11,10 @@ module.exports = {
app: ['./app.js']
},
output: {
path: util.resolve('../server/public'),
path: util.resolve('./build/bundle'),
filename: '[name].[hash:7].js',
chunkFilename: '[name].[hash:7].js'
chunkFilename: '[name].[hash:7].js',
publicPath: '/'
},
resolve: {
extensions: ['.js', '.vue', '.json'],
... ... @@ -40,11 +41,21 @@ module.exports = {
chunks: false,
assetsSort: 'size',
},
historyApiFallback: {
rewrites: [
{ from: /\.html$/, to: '/index.html' },
{ from: /.*?\.(js)|(css)$/,
to: (context) => {
return context.parsedUrl.pathname;
}
}
]
},
headers: {
'Access-Control-Allow-Origin': '*'
},
proxy: {
'**': 'http://localhost:6007'
'/Api': 'http://localhost:6007'
}
},
module: {
... ... @@ -110,7 +121,7 @@ module.exports = {
name: ['view', 'libs'],
}),
new CleanWebpackPlugin(['*'], {
root: util.resolve('../server/public'),
root: util.resolve('./build/bundle'),
verbose: true,
dry: false
})
... ...
... ... @@ -9,7 +9,7 @@ const component = function editor(resolve) {
image: {
sizeLimit: 512 * 1024,
upload: {
url: '/upload/image',
url: '/Api/upload/image',
headers: {},
params: {
bucket: 'goodsimg'
... ...
... ... @@ -19,7 +19,7 @@ export default {
props: {
action: {
type: String,
default: '/upload/image'
default: '/Api/upload/image'
},
data: {
type: Object,
... ...
... ... @@ -5,7 +5,7 @@ let purviews = {
subPurviews: {
create: {
name: '发布新商品',
path: '/product/create/step1',
path: '/product/create/step1.html',
menu: true,
own: true,
subPurviews: {
... ... @@ -25,20 +25,20 @@ let purviews = {
},
onsale: {
name: '在售商品',
path: '/product/onsale',
path: '/product/onsale.html',
menu: true,
own: true
},
offsale: {
name: '未上架商品',
path: '/product/offsale',
path: '/product/offsale.html',
menu: true,
own: true
},
vips: {
name: 'VIP价格商品',
menu: true,
path: '/product/vips'
path: '/product/vips.html'
}
}
}
... ...
const home = r => require.ensure([], () => r(require('./login')), 'auth.login');
export default {
path: '/login',
path: '/login.html',
name: 'login',
component: home,
meta: {
... ...
const page = r => require.ensure([], () => r(require('./error')), 'error');
const router = [{
path: '/401',
path: '/401.html',
name: 'error.401',
component: page,
meta: {
authPass: true
}
}, {
path: '/404',
path: '/404.html',
name: 'error.404',
component: page,
meta: {
authPass: true
}
}, {
path: '/500',
path: '/500.html',
name: 'error.500',
component: page,
meta: {
... ...
... ... @@ -2,14 +2,14 @@
<div>
默认页
<div style="display:none;">
<Table ref="table" :data="data" :columns="columns"></Table>
<!--<Table ref="table" :data="data" :columns="columns"></Table>
<Button @click="getTable">获得数据</Button>
<Button @click="addRow">增加一列</Button>
{{data}}
<br />
<editor :content="content" @change="updateData"></editor>
{{content}}
<yoho-upload id="123" @on-success="uploadSuccess" @on-error="uploadError"></yoho-upload>
<yoho-upload id="123" @on-success="uploadSuccess" @on-error="uploadError"></yoho-upload>-->
</div>
</div>
</template>
... ...
... ... @@ -25,7 +25,10 @@ export default {
</script>
<style lang="scss">
body {
color: #444;
}
.layout {
position: absolute;
width: 100%;
... ...
... ... @@ -7,15 +7,15 @@ const step3 = r => require.ensure([], () => r(require('./step3')), 'product.crea
export default [{
path: 'step1',
path: 'step1.html',
name: 'product.create.step1',
component: step1
}, {
path: 'step2',
path: 'step2.html',
name: 'product.create.step2',
component: step2
}, {
path: 'step3',
path: 'step3.html',
name: 'product.create.step3',
component: step3
}];
... ...
... ... @@ -8,49 +8,43 @@
</div>
</Row>
<Form :model="product" :label-width="70">
<Row>
<Col span="8">
<Form :model="product" :label-width="70">
<Form-item label="品 牌*">
<Select v-model="product.brandId" placeholder="请选择" :label-in-value="true" @on-change="selectBrand">
<Option v-for="brand in brands" :value="brand.brandId" :key="brand">{{ brand.brandName }}</Option>
</Select>
</Form-item>
</Form>
</Col>
</Row>
<Row>
<Col span="8" v-if="show[1]">
<Form :model="product" :label-width="70">
<Form-item label="类目*">
<Select v-model="pickedSortId[1]" placeholder="一级类目" @on-change="selectSort1" :label-in-value="true">
<Option v-for="sort in sorts[1]" :value="sort.sortId" :key="sort">{{ sort.sortName }}</Option>
</Select>
</Form-item>
</Form>
</Col>
<Col span="6" offset="1" v-if="show[2]">
<Form :model="product">
<Form-item>
<Select v-model="pickedSortId[2]" placeholder="二级类目" @on-change="selectSort2" :label-in-value="true">
<Option v-for="sort in sorts[2]" :value="sort.sortId" :key="sort">{{ sort.sortName }}</Option>
</Select>
</Form-item>
</Form>
</Col>
<Col span="6" offset="1" v-if="show[3]">
<Form :model="product">
<Form-item>
<Select v-model="pickedSortId[3]" placeholder="三级类目" @on-change="selectSort3" :label-in-value="true">
<Option v-for="sort in sorts[3]" :value="sort.sortId" :key="sort">{{ sort.sortName }}</Option>
</Select>
</Form-item>
</Form>
</Col>
</Row>
</Form>
<Row>
<Col span="2" offset="12">
... ...
const page = r => require.ensure([], () => r(require('./offsale')), 'product.offsale');
export default {
path: '/offsale',
path: '/offsale.html',
name: 'offsale',
component: page
};
... ...
const page = r => require.ensure([], () => r(require('./onsale')), 'product.onsale');
export default {
path: '/onsale',
path: '/onsale.html',
name: 'onsale',
component: page
};
... ...
const page = r => require.ensure([], () => r(require('./vips')), 'product.vips');
export default {
path: '/vips',
path: '/vips.html',
name: 'vips',
component: page
};
... ...
... ... @@ -23,7 +23,7 @@ const plugin = {
Vue.$router = options.router;
options.router.beforeEach((to, from, next) => {
if (to.matched.length === 0) {
return next('/404');
return next('/404.html');
}
return next();
});
... ... @@ -38,7 +38,7 @@ const plugin = {
});
// 设置axios默认参数
// axios.defaults.baseURL = '';
axios.defaults.baseURL = '/Api';
axios.defaults.responseType = 'json';
}
};
... ...
... ... @@ -24,7 +24,7 @@ const plugin = {
if (purview.own) {
return next();
} else {
return next('/401');
return next('/401.html');
}
}
});
... ...
... ... @@ -31,10 +31,10 @@ const plugin = {
}
return next();
} else {
return next('/login');
return next('/login.html');
}
}
return next('/login');
return next('/login.html');
}
});
Vue.passport = {
... ... @@ -52,11 +52,10 @@ const plugin = {
};
Vue.logout = () => {
Vue.$store.remove(config.userKey);
Vue.$router.push('/login');
Vue.$router.push('/login.html');
axios.post('/logout');
};
Vue.updateUser = (user) => {
console.log('upda')
Vue.$store.set(config.userKey, user);
Vue.prototype.isLogin = Vue.isLogin = true;
Vue.prototype.$user = user;
... ...
body {
color: #444;
}
import axios from 'axios';
const purviewService = {
getPurviews() {
return axios.post('')
}
};
export default purviewService;
... ...
... ... @@ -40,7 +40,6 @@ app.use(cookieSession({
app.use(compression());
app.use(favicon(path.join(__dirname, '/favicon.ico')));
app.use(Express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
... ... @@ -53,7 +52,7 @@ try {
app.use(middleware.before);
// controller
app.use(controllers);
app.use('/Api', controllers);
// // 鉴权中间件
app.use(middleware.auth);
... ...
... ... @@ -14,8 +14,15 @@ module.exports = (err, req, res, next) => { // eslint-disable-line
redirect: '/signin.html'
});
}
return res.status(err.code || 500).json({
code: err.code || 500,
if (err.code === 404) {
return res.status(404).json({
code: 404,
message: 'Not Found'
});
}
return res.status(500).json({
code: 500,
message: '服务器错误!'
});
};
... ...
... ... @@ -8,6 +8,7 @@ const _ = require('lodash');
const blacklist = require('../common/api-blacklist');
const apiDomain = global.yoho.apiDomain;
const logger = global.yoho.logger;
const apiReg = /^\/Api/;
module.exports = (req, res, next) => {
let api = new Api();
... ... @@ -16,7 +17,12 @@ module.exports = (req, res, next) => {
req,
res
});
let apiMap = req.path.split('/').filter(n => n).join('.');
if (!apiReg.test(req.path)) {
return next({
code: 404
});
}
let apiMap = req.path.replace(apiReg, '').split('/').filter(n => n).join('.');
if (_.some(blacklist, n => n.toLowerCase() === apiMap.toLowerCase())) {
logger.error(`proxy [${req.method}] fail`, `${req.path} can't blacklist`);
... ...