Authored by 陈峰

路由规则

import Vue from 'vue';
import Promise from 'promise-polyfill';
import App from './pages/app';
import yohoPluginCore from './plugins/yoho-plugin-core';
import yohoPluginRouter from './plugins/yoho-plugin-router';
... ... @@ -9,22 +8,7 @@ import './directives';
import 'iview/dist/styles/iview.css';
import 'font-awesome/css/font-awesome.css';
// 兼容IE的Function没有name属性为题,为了修复iView的bug
if (!(function f() {}).name) {
Object.defineProperty(Function.prototype, 'name', { //eslint-disable-line
get: function() {
let name = (this.toString().match(/^function\s*([^\s(]+)/) || [])[1];
Object.defineProperty(this, 'name', { value: name });
return name;
}
});
}
// 使用了webpack code spliting IE下需要promise ployfill
if (!window.Promise) {
window.Promise = Promise;
}
Vue.use(yohoPluginCore);
... ...
... ... @@ -26,6 +26,7 @@ module.exports = {
util.resolve('scss'),
util.resolve('config'),
util.resolve('services'),
util.resolve('util'),
'node_modules'
]
},
... ...
... ... @@ -30,16 +30,16 @@ export default {
userInfo: this.$user
};
},
created() {
},
methods: {
logout() {
Vue.logout();
},
switchShop(id) {
this.userInfo.currentShop = this.userInfo.shops.find(shop => shop.id === id);
Vue.switchShop(id);
this.$emit('shop-change', this.userInfo.currentShop);
if (this.userInfo.currentShop.id !== id) {
this.userInfo.currentShop = this.userInfo.shops.find(shop => shop.id === id);
Vue.switchShop(id);
this.$emit('shop-change', this.userInfo.currentShop);
}
}
}
};
... ...
... ... @@ -3,6 +3,7 @@ export default {
historyMode: 'history',
axiosBaseUrl: '/Api',
axiosResponseType: 'json',
homePage: 'home.overview',
storeKeys: {
user: '_user',
}
... ...
const page = r => require.ensure([], () => r(require('./overview')), 'home.overview');
export default {
path: '',
path: '/overview.html',
name: 'overview',
component: page
};
... ...
const decoration = r => require.ensure([], () => r(require('./decoration')), 'shop.decoration');
const shops = r => require.ensure([], () => r(require('./decoration')), 'shop.shops');
const shops = r => require.ensure([], () => r(require('./shops')), 'shop.shops');
export default [
... ... @@ -12,8 +12,8 @@ export default [
}
},
{
path: '/decoration.html',
name: 'decoration',
path: '/decor.html',
name: 'decor',
component: decoration,
meta: {
pageName: '店铺装修'
... ...
<template>
<LayoutBody>
<LayoutList>
<Table border :context="self" :data="data" :columns="columns"></Table>
</LayoutList>
</LayoutBody>
</template>
<script>
export default {
data() {
return {
self: this,
data: [],
columns: [{
title: '店铺ID',
key: 'shopName',
}, {
title: '店铺名称',
key: 'shopName',
}, {
title: '品牌',
key: 'shopName',
}, {
title: '发布时间',
key: 'shopName',
}, {
title: '状态',
key: 'shopName',
}, {
title: '操作',
render() {
return `
<i-button type="primary" size="small" >尺码维护</i-button>
<i-button type="primary" size="small">内容编辑</i-button>
`;
}
}]
};
}
}
</script>
... ...
... ... @@ -6,7 +6,7 @@ import config from 'config';
import axios from 'axios';
import userService from 'user-service';
import iView from 'iview';
import Rsa from './rsa';
import Rsa from 'rsa';
const plugin = {
updateUser(Vue, user, purviews) {
... ... @@ -35,7 +35,7 @@ const plugin = {
});
},
install(Vue) {
Vue.beforeRender.push((next) => {
Vue.beforeRender((next) => {
let user = Vue.$store.get(config.storeKeys.user);
let isLogin = Vue.$cookie.get('_isLogin');
... ...
... ... @@ -2,6 +2,7 @@
* 插件
*/
import Router from 'vue-router';
import Promise from 'promise-polyfill';
import iView from 'iview';
import store from 'yoho-store';
import cookie from 'yoho-cookie';
... ... @@ -20,15 +21,18 @@ const plugin = {
Vue.prop = (key, value) => {
Vue[`$${key}`] = Vue.prototype[`$${key}`] = value;
};
Vue.beforeRender = [];
Vue.beforeRenderHooks = [];
Vue.beforeRender = (fn) => {
Vue.beforeRenderHooks.push(fn);
};
Vue.render = opts => {
return new Promise(resolve => {
if (Vue.beforeRender.length) {
if (Vue.beforeRenderHooks.length) {
let step = index => {
if (index >= Vue.beforeRender.length) {
if (index >= Vue.beforeRenderHooks.length) {
resolve();
} else {
Vue.beforeRender[index](() => {
Vue.beforeRenderHooks[index](() => {
step(index + 1);
});
}
... ... @@ -45,6 +49,24 @@ const plugin = {
});
};
},
compatible() {
// 兼容IE的Function没有name属性为题,为了修复iView的bug
if (!(function f() {}).name) {
Object.defineProperty(Function.prototype, 'name', { //eslint-disable-line
get: function() {
let name = (this.toString().match(/^function\s*([^\s(]+)/) || [])[1];
Object.defineProperty(this, 'name', { value: name });
return name;
}
});
}
// 使用了webpack code spliting IE下需要promise ployfill
if (!window.Promise) {
window.Promise = Promise;
}
},
install(Vue) {
// 定义Vue全局属性
this.defineVueProp(Vue);
... ...
import Router from 'vue-router';
import config from 'config';
import pageRoutes from '../pages';
import layout from '../pages/layout';
import common from '../pages/common';
... ... @@ -27,7 +26,7 @@ const plugin = {
}
if (rous.length) {
return _.map(rous, r => {
return this.loadRouters(r, [paths]);
return this.loadRouters(r, [paths, r.name]);
});
} else {
return _.map(rous, (rou, k) => {
... ... @@ -36,18 +35,24 @@ const plugin = {
}
},
install(Vue) {
let childRouters = this.loadRouters(pageRoutes);
let childRouters = _.flattenDeep(this.loadRouters(pageRoutes));
if (Vue.$config.homePage) {
let homePage = _.find(childRouters, router => router.name === Vue.$config.homePage);
homePage && (homePage.path = '/');
}
let routes = [{
path: '/',
component: layout,
children: _.flattenDeep(childRouters)
children: childRouters
}];
routes = routes.concat(common);
Vue.$router = new Router({
routes: routes,
mode: config.historyMode
mode: Vue.$config.historyMode
});
}
};
... ...
... ... @@ -63,7 +63,7 @@ export default [
},
{
menu_name: '店铺装修',
menu_url: '/shop/decoration.html',
menu_url: '/shop/decoration/shops.html',
menu_id: 'shop.decoration',
status: 1,
id: 22
... ...
... ... @@ -29,7 +29,7 @@ class UserController extends Context {
shops: result.data,
currentShop: currentShop
}), sess);
console.log(result.data)
return res.json({
code: 200,
data: {
... ...