From ff8d7ada73c8ab0c842cef2ab348392e2d55d5dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BD=A9=E8=BE=95Rowboat?= Date: Tue, 20 Jun 2017 14:10:51 +0800 Subject: [PATCH 001/867] =?UTF-8?q?=E5=8D=83=E5=88=86=E7=AC=A6=E8=80=83?= =?UTF-8?q?=E8=99=91=E5=B0=8F=E6=95=B0=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/filters/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/filters/index.js b/src/filters/index.js index 36cb3e7cdbd..4943cde8490 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -104,5 +104,8 @@ export function html2Text(val) { export function toThousandslsFilter(num) { - return (+num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); + return (+num || 0).toString() + .replace(/^\-?\d+/g, function(m){ + return m.replace(/(?=(?!\b)(\d{3})+$)/g, ','); + }); } From aaa64a8ccf6c058ddcc555588c782d8f5e588e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BD=A9=E8=BE=95Rowboat?= Date: Tue, 20 Jun 2017 14:53:07 +0800 Subject: [PATCH 002/867] update format code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 没用编辑器,所以代码没格式化/(ㄒoㄒ)/~~ --- src/filters/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/filters/index.js b/src/filters/index.js index 4943cde8490..9524edccc2e 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -105,7 +105,7 @@ export function html2Text(val) { export function toThousandslsFilter(num) { return (+num || 0).toString() - .replace(/^\-?\d+/g, function(m){ - return m.replace(/(?=(?!\b)(\d{3})+$)/g, ','); - }); + .replace(/^\-?\d+/g, function (m) { + return m.replace(/(?=(?!\b)(\d{3})+$)/g, ','); + }); } From dbf96389228b875a69965b0f90bf5f89a1188574 Mon Sep 17 00:00:00 2001 From: Pan Date: Tue, 20 Jun 2017 23:02:36 +0800 Subject: [PATCH 003/867] refine dynamictable example --- src/views/example/table/dynamictable.vue | 37 +++-------- .../example/table/dynamictable/fixedThead.vue | 61 +++++++++++++++++++ .../table/dynamictable/unfixedThead.vue | 51 ++++++++++++++++ 3 files changed, 121 insertions(+), 28 deletions(-) create mode 100644 src/views/example/table/dynamictable/fixedThead.vue create mode 100644 src/views/example/table/dynamictable/unfixedThead.vue diff --git a/src/views/example/table/dynamictable.vue b/src/views/example/table/dynamictable.vue index 38ab0b33441..8e998f9e1e7 100644 --- a/src/views/example/table/dynamictable.vue +++ b/src/views/example/table/dynamictable.vue @@ -1,38 +1,19 @@ diff --git a/src/views/example/table/dynamictable/fixedThead.vue b/src/views/example/table/dynamictable/fixedThead.vue new file mode 100644 index 00000000000..9c3ea5a7e4c --- /dev/null +++ b/src/views/example/table/dynamictable/fixedThead.vue @@ -0,0 +1,61 @@ + + + + diff --git a/src/views/example/table/dynamictable/unfixedThead.vue b/src/views/example/table/dynamictable/unfixedThead.vue new file mode 100644 index 00000000000..5aa4a88b4d6 --- /dev/null +++ b/src/views/example/table/dynamictable/unfixedThead.vue @@ -0,0 +1,51 @@ + + + From 6de521d6717c9968d3f6cd975369a8e4f7bc0b87 Mon Sep 17 00:00:00 2001 From: Pan Date: Tue, 20 Jun 2017 23:14:50 +0800 Subject: [PATCH 004/867] refine css --- src/views/layout/Layout.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/layout/Layout.vue b/src/views/layout/Layout.vue index c59614dfcfb..2c50177290d 100644 --- a/src/views/layout/Layout.vue +++ b/src/views/layout/Layout.vue @@ -68,7 +68,7 @@ top: 0; bottom: 0; left: 0; - right: -17px; + width: 100%; overflow-y: scroll; } .main-container { From 657937c7a5565b1a45b00db655a2fe8c31ef4bad Mon Sep 17 00:00:00 2001 From: Pan Date: Wed, 21 Jun 2017 09:46:47 +0800 Subject: [PATCH 005/867] Revert "refine css" This reverts commit 6de521d6717c9968d3f6cd975369a8e4f7bc0b87. --- src/views/layout/Layout.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/layout/Layout.vue b/src/views/layout/Layout.vue index 2c50177290d..c59614dfcfb 100644 --- a/src/views/layout/Layout.vue +++ b/src/views/layout/Layout.vue @@ -68,7 +68,7 @@ top: 0; bottom: 0; left: 0; - width: 100%; + right: -17px; overflow-y: scroll; } .main-container { From 046d1369d2b45b1cae6d9b634d64f66ce7755db6 Mon Sep 17 00:00:00 2001 From: Pan Date: Wed, 21 Jun 2017 16:58:03 +0800 Subject: [PATCH 006/867] not use Lazy Loading In dev --- src/router/_import_development.js | 1 + src/router/_import_production.js | 1 + src/router/index.js | 73 ++++++++++++++++--------------- 3 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 src/router/_import_development.js create mode 100644 src/router/_import_production.js diff --git a/src/router/_import_development.js b/src/router/_import_development.js new file mode 100644 index 00000000000..f109b070509 --- /dev/null +++ b/src/router/_import_development.js @@ -0,0 +1 @@ +module.exports = file => require('../views/' + file + '.vue') diff --git a/src/router/_import_production.js b/src/router/_import_production.js new file mode 100644 index 00000000000..10d919de03d --- /dev/null +++ b/src/router/_import_production.js @@ -0,0 +1 @@ +module.exports = file => () => import('../views/' + file + '.vue') diff --git a/src/router/index.js b/src/router/index.js index 8ad7a4d0803..5b7ddc9a6de 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,67 +1,70 @@ import Vue from 'vue'; import Router from 'vue-router'; +const _import = require('./_import_' + process.env.NODE_ENV); +// in development env not use Lazy Loading,because Lazy Loading large page will cause webpack hot update too slow +// so only in production use Lazy Loading /* layout */ import Layout from '../views/layout/Layout'; /* login */ -import Login from '../views/login/'; -const authRedirect = () => import('../views/login/authredirect'); -const sendPWD = () => import('../views/login/sendpwd'); -const reset = () => import('../views/login/reset'); +const Login = _import('login/index'); +const authRedirect = _import('login/authredirect'); +const sendPWD = _import('login/sendpwd'); +const reset = _import('login/reset'); /* dashboard */ -const dashboard = () => import('../views/dashboard/index'); +const dashboard = _import('dashboard/index'); /* Introduction */ -const Introduction = () => import('../views/introduction/index'); +const Introduction = _import('introduction/index'); /* components */ -const componentsIndex = () => import('../views/components/index'); -const Tinymce = () => import('../views/components/tinymce'); -const Markdown = () => import('../views/components/markdown'); -const JsonEditor = () => import('../views/components/jsoneditor'); -const DndList = () => import('../views/components/dndlist'); -const AvatarUpload = () => import('../views/components/avatarUpload'); -const Dropzone = () => import('../views/components/dropzone'); -const Sticky = () => import('../views/components/sticky'); -const SplitPane = () => import('../views/components/splitpane'); -const CountTo = () => import('../views/components/countTo'); -const Mixin = () => import('../views/components/mixin'); +const componentsIndex = _import('components/index'); +const Tinymce = _import('components/tinymce'); +const Markdown = _import('components/markdown'); +const JsonEditor = _import('components/jsoneditor'); +const DndList = _import('components/dndlist'); +const AvatarUpload = _import('components/avatarUpload'); +const Dropzone = _import('components/dropzone'); +const Sticky = _import('components/sticky'); +const SplitPane = _import('components/splitpane'); +const CountTo = _import('components/countTo'); +const Mixin = _import('components/mixin'); /* charts */ -const chartIndex = () => import('../views/charts/index'); -const KeyboardChart = () => import('../views/charts/keyboard'); -const KeyboardChart2 = () => import('../views/charts/keyboard2'); -const LineMarker = () => import('../views/charts/line'); -const MixChart = () => import('../views/charts/mixchart'); +const chartIndex = _import('charts/index'); +const KeyboardChart = _import('charts/keyboard'); +const KeyboardChart2 = _import('charts/keyboard2'); +const LineMarker = _import('charts/line'); +const MixChart = _import('charts/mixchart'); /* error page */ -const Err404 = () => import('../views/error/404'); -const Err401 = () => import('../views/error/401'); +const Err404 = _import('error/404'); +const Err401 = _import('error/401'); /* error log */ -const ErrorLog = () => import('../views/errlog/index'); +const ErrorLog = _import('errlog/index'); /* excel */ -const ExcelDownload = () => import('../views/excel/index'); +const ExcelDownload = _import('excel/index'); /* theme */ -const Theme = () => import('../views/theme/index'); +const Theme = _import('theme/index'); /* example*/ -const TableLayout = () => import('../views/example/table/index'); -const DynamicTable = () => import('../views/example/table/dynamictable'); -const Table = () => import('../views/example/table/table'); -const DragTable = () => import('../views/example/table/dragTable'); -const InlineEditTable = () => import('../views/example/table/inlineEditTable'); +const TableLayout = _import('example/table/index'); +const DynamicTable = _import('example/table/dynamictable'); +const Table = _import('example/table/table'); +const DragTable = _import('example/table/dragTable'); +const InlineEditTable = _import('example/table/inlineEditTable'); -const Form = () => import('../views/example/form'); -const Tab = () => import('../views/example/tab/index'); +const Form = _import('example/form'); +const Tab = _import('example/tab/index'); /* permission */ -const Permission = () => import('../views/permission/index'); +const Permission = _import('permission/index'); Vue.use(Router); From 1072572ac6ebd149a3425a5e1a112c254d844936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=99=A8=E5=85=89?= <809200299@qq.com> Date: Fri, 23 Jun 2017 14:45:59 +0800 Subject: [PATCH 007/867] =?UTF-8?q?update:=20=E9=80=92=E5=BD=92=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E5=BC=82=E6=AD=A5=E8=B7=AF=E7=94=B1=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/permission.js | 43 ++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index 926c89b0fb2..93996741c30 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -8,6 +8,26 @@ function hasPermission(roles, route) { } } +/** + * 递归过滤异步路由表,返回符合用户角色权限的路由表 + * @param asyncRouterMap + * @param roles + * @returns {Array.|*} + */ +function filterAsyncRouter(asyncRouterMap, roles) { + let accessedRouters = asyncRouterMap.filter(route => { + if(hasPermission(roles, route)) { + if(route.children && route.children.length) { + route.children = filterAsyncRouter(route.children, roles) + } + return true + } + return false + }) + return accessedRouters +} + + const permission = { state: { routers: constantRouterMap, @@ -25,23 +45,12 @@ const permission = { GenerateRoutes({ commit }, data) { return new Promise(resolve => { const { roles } = data; - const accessedRouters = asyncRouterMap.filter(v => { - if (roles.indexOf('admin') >= 0) return true; - if (hasPermission(roles, v)) { - if (v.children && v.children.length > 0) { - v.children = v.children.filter(child => { - if (hasPermission(roles, child)) { - return child - } - return false; - }); - return v - } else { - return v - } - } - return false; - }); + let accessedRouters + if (roles.indexOf('admin') >= 0) { + accessedRouters = asyncRouterMap + } else { + accessedRouters = filterAsyncRouter(asyncRouterMap, roles) + } commit('SET_ROUTERS', accessedRouters); resolve(); }) From 7549eb8044cbd1f478bdf17b2408a822ffb9c479 Mon Sep 17 00:00:00 2001 From: Pan Date: Fri, 23 Jun 2017 15:39:13 +0800 Subject: [PATCH 008/867] fix eslint && refine code --- src/filters/index.js | 5 +---- src/store/modules/permission.js | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/filters/index.js b/src/filters/index.js index 9524edccc2e..682d5195c77 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -104,8 +104,5 @@ export function html2Text(val) { export function toThousandslsFilter(num) { - return (+num || 0).toString() - .replace(/^\-?\d+/g, function (m) { - return m.replace(/(?=(?!\b)(\d{3})+$)/g, ','); - }); + return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ',')); } diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index 93996741c30..c4cfa4f03ae 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -1,5 +1,10 @@ import { asyncRouterMap, constantRouterMap } from 'src/router'; +/** + * 通过meta.role判断是否与当前用户权限匹配 + * @param roles + * @param route + */ function hasPermission(roles, route) { if (route.meta && route.meta.role) { return roles.some(role => route.meta.role.indexOf(role) >= 0) @@ -12,39 +17,35 @@ function hasPermission(roles, route) { * 递归过滤异步路由表,返回符合用户角色权限的路由表 * @param asyncRouterMap * @param roles - * @returns {Array.|*} */ function filterAsyncRouter(asyncRouterMap, roles) { - let accessedRouters = asyncRouterMap.filter(route => { - if(hasPermission(roles, route)) { - if(route.children && route.children.length) { - route.children = filterAsyncRouter(route.children, roles) - } - return true - } - return false - }) - return accessedRouters + const accessedRouters = asyncRouterMap.filter(route => { + if (hasPermission(roles, route)) { + if (route.children && route.children.length) { + route.children = filterAsyncRouter(route.children, roles) + } + return true + } + return false + }) + return accessedRouters } - const permission = { state: { routers: constantRouterMap, addRouters: [] }, - mutations: { SET_ROUTERS: (state, routers) => { state.addRouters = routers; state.routers = constantRouterMap.concat(routers); } }, - actions: { GenerateRoutes({ commit }, data) { return new Promise(resolve => { - const { roles } = data; + const { roles } = data let accessedRouters if (roles.indexOf('admin') >= 0) { accessedRouters = asyncRouterMap @@ -58,5 +59,4 @@ const permission = { } }; - export default permission; From 91cb0ac5ca7a819f26eef1eb0ccf883bcfe76524 Mon Sep 17 00:00:00 2001 From: Pan Date: Fri, 23 Jun 2017 17:32:52 +0800 Subject: [PATCH 009/867] add view tabs --- src/store/getters.js | 1 + src/store/modules/app.js | 17 ++++++++++++++++- src/views/layout/Levelbar.vue | 22 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/store/getters.js b/src/store/getters.js index 4677e6d6179..4497ba44db5 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -1,5 +1,6 @@ const getters = { sidebar: state => state.app.sidebar, + visitedViews: state => state.app.visitedViews, token: state => state.user.token, avatar: state => state.user.avatar, name: state => state.user.name, diff --git a/src/store/modules/app.js b/src/store/modules/app.js index 83049ff589d..e30ae3bfd92 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -6,7 +6,8 @@ const app = { opened: !+Cookies.get('sidebarStatus') }, theme: 'default', - livenewsChannels: Cookies.get('livenewsChannels') || '[]' + livenewsChannels: Cookies.get('livenewsChannels') || '[]', + visitedViews: [] }, mutations: { TOGGLE_SIDEBAR: state => { @@ -16,11 +17,25 @@ const app = { Cookies.set('sidebarStatus', 0); } state.sidebar.opened = !state.sidebar.opened; + }, + ADD_VISITED_VIEWS: (state, view) => { + if (state.visitedViews.includes(view)) return + state.visitedViews.push(view) + }, + DEL_VISITED_VIEWS: (state, view) => { + const index = state.visitedViews.indexOf(view) + state.visitedViews.splice(index, 1) } }, actions: { ToggleSideBar: ({ commit }) => { commit('TOGGLE_SIDEBAR') + }, + addVisitedViews: ({ commit }, view) => { + commit('ADD_VISITED_VIEWS', view) + }, + delVisitedViews: ({ commit }, view) => { + commit('DEL_VISITED_VIEWS', view) } } }; diff --git a/src/views/layout/Levelbar.vue b/src/views/layout/Levelbar.vue index cb40084db89..af850ff8af0 100644 --- a/src/views/layout/Levelbar.vue +++ b/src/views/layout/Levelbar.vue @@ -4,14 +4,25 @@ {{item.name}} {{item.name}} + + + {{tag.name}} + + + + From f1aa01a233ddfb05aaaa7186ccec59eb43cfa621 Mon Sep 17 00:00:00 2001 From: Pan Date: Fri, 23 Jun 2017 21:19:30 +0800 Subject: [PATCH 012/867] fix theme example bug --- src/views/theme/index.vue | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/views/theme/index.vue b/src/views/theme/index.vue index 071f1c51441..f0655e2f4af 100644 --- a/src/views/theme/index.vue +++ b/src/views/theme/index.vue @@ -50,7 +50,7 @@ import { toggleClass } from 'utils'; export default { data() { return { - theme: '', + theme: false, tags: [ { name: '标签一', type: '' }, { name: '标签二', type: 'gray' }, @@ -68,9 +68,6 @@ export default { toggleClass(document.body, 'custom-theme') // this.$store.dispatch('setTheme', value); } - }, - methods: { - } }; From 80a281733a9e26562508e923ba36538e741e4006 Mon Sep 17 00:00:00 2001 From: Pan Date: Mon, 26 Jun 2017 09:57:24 +0800 Subject: [PATCH 013/867] refine assets path config --- config/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/index.js b/config/index.js index 9178385ba00..24fbf3792c6 100644 --- a/config/index.js +++ b/config/index.js @@ -7,9 +7,9 @@ module.exports = { prodEnv: require('./prod.env'), index: path.resolve(__dirname, '../dist/index.html'), assetsRoot: path.resolve(__dirname, '../dist'), - assetsSubDirectory: '', - assetsPublicPath: './', //生产环境assetsPublicPath: '/' - staticPath:'./', //生产环境 staticPath:'' + assetsSubDirectory: 'static', + assetsPublicPath: '/', + staticPath:'./', productionSourceMap: true, // Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. From 63ad0fc2f5ffb4edd0f2aa8074261b0171b5304e Mon Sep 17 00:00:00 2001 From: Pan Date: Mon, 26 Jun 2017 11:21:53 +0800 Subject: [PATCH 014/867] refine code --- src/main.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index aa81cb3b588..7656d8de18b 100644 --- a/src/main.js +++ b/src/main.js @@ -27,6 +27,8 @@ Vue.component('Sticky', Sticky); Vue.use(ElementUI); Vue.use(vueWaves); +Vue.config.productionTip = false; + // register global utility filters. Object.keys(filters).forEach(key => { Vue.filter(key, filters[key]) @@ -112,9 +114,11 @@ if (process.env === 'production') { // })(console.error); new Vue({ + el: '#app', router, store, - render: h => h(App) -}).$mount('#app'); + template: '', + components: { App } +}) From 33cf5ef16eae4eab923311c0a91582352f7e5749 Mon Sep 17 00:00:00 2001 From: Pan Date: Mon, 26 Jun 2017 13:35:43 +0800 Subject: [PATCH 015/867] refine code --- src/router/_import_development.js | 2 +- src/router/_import_production.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/router/_import_development.js b/src/router/_import_development.js index f109b070509..dfa4bb95f68 100644 --- a/src/router/_import_development.js +++ b/src/router/_import_development.js @@ -1 +1 @@ -module.exports = file => require('../views/' + file + '.vue') +module.exports = file => require('@/views/' + file + '.vue') diff --git a/src/router/_import_production.js b/src/router/_import_production.js index 10d919de03d..331acba4344 100644 --- a/src/router/_import_production.js +++ b/src/router/_import_production.js @@ -1 +1 @@ -module.exports = file => () => import('../views/' + file + '.vue') +module.exports = file => () => import('@/views/' + file + '.vue') From 805ab1d0acea8d89f85e3568d0a516b25e417743 Mon Sep 17 00:00:00 2001 From: Pan Date: Mon, 26 Jun 2017 16:50:34 +0800 Subject: [PATCH 016/867] add github link --- src/views/introduction/index.vue | 1 + src/views/layout/Navbar.vue | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/views/introduction/index.vue b/src/views/introduction/index.vue index ccdcb2c5cf1..6074897c9db 100644 --- a/src/views/introduction/index.vue +++ b/src/views/introduction/index.vue @@ -5,6 +5,7 @@ 这半年来一直在用vue写管理后台,目前后台已经有百来个个页面,十几种权限,但维护成本依然很低,所以准备开源分享一下后台开发的经验和成果。目前的技术栈主要的采用vue+element+axios由webpack2打包.由于是个人项目,所以数据请求都是用了mockjs模拟。注意:在次项目基础上改造开发时请移除mock文件。 写了一个系列的教程配套文章,如何从零构建后一个完整的后台项目: