From bfb035821793e08b77ca7cf75b853dd3cdf14ecc Mon Sep 17 00:00:00 2001 From: iczer <1126263215@qq.com> Date: Wed, 29 Jul 2020 11:08:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20function=20of=20async=20router=20?= =?UTF-8?q?and=20async=20menu;=20:star2:=20=E6=96=B0=E5=A2=9E=EF=BC=9A?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E8=B7=AF=E7=94=B1=E5=92=8C=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 5 + .env.development | 5 + package.json | 1 - src/bootstrap.js | 18 ++ src/components/exception/ExceptionPage.vue | 12 +- src/config/default/setting.config.js | 1 + src/layouts/AdminLayout.vue | 9 +- src/layouts/header/HeaderlAvatar.vue | 4 +- src/layouts/tabs/index.js | 2 + src/main.js | 9 +- src/mock/index.js | 1 + src/mock/user/login.js | 2 + src/mock/user/routes.js | 26 ++ src/pages/dashboard/analysis/index.js | 2 + src/pages/dashboard/workplace/index.js | 2 + src/pages/exception/403.vue | 7 +- src/pages/exception/404.vue | 2 +- src/pages/exception/500.vue | 7 +- src/pages/form/advance/index.js | 2 + src/pages/form/basic/index.js | 2 + src/pages/form/step/index.js | 2 + src/pages/login/Login.vue | 30 +- src/pages/login/index.js | 2 + src/router/config.async.js | 24 ++ src/router/config.js | 48 +-- src/router/index.js | 34 +- src/router/router.map.js | 154 ++++++++++ src/services/api.js | 3 +- src/services/index.js | 5 +- src/services/user.js | 11 +- src/store/index.js | 8 - src/store/modules/account.js | 87 ++++-- src/store/modules/setting.js | 7 + src/utils/i18n.js | 32 +- src/utils/routerUtil.js | 157 ++++++++++ yarn.lock | 341 +-------------------- 36 files changed, 614 insertions(+), 450 deletions(-) create mode 100644 .env create mode 100644 .env.development create mode 100644 src/bootstrap.js create mode 100644 src/layouts/tabs/index.js create mode 100644 src/mock/user/routes.js create mode 100644 src/pages/dashboard/analysis/index.js create mode 100644 src/pages/dashboard/workplace/index.js create mode 100644 src/pages/form/advance/index.js create mode 100644 src/pages/form/basic/index.js create mode 100644 src/pages/form/step/index.js create mode 100644 src/pages/login/index.js create mode 100644 src/router/config.async.js create mode 100644 src/router/router.map.js create mode 100644 src/utils/routerUtil.js diff --git a/.env b/.env new file mode 100644 index 0000000..a776eb8 --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +VUE_APP_NAME=admin +VUE_APP_ROUTES_KEY=admin.routes +VUE_APP_PERMISSIONS_KEY=admin.permissions +VUE_APP_ROLES_KEY=admin.roles +VUE_APP_USER_KEY=admin.user diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..a776eb8 --- /dev/null +++ b/.env.development @@ -0,0 +1,5 @@ +VUE_APP_NAME=admin +VUE_APP_ROUTES_KEY=admin.routes +VUE_APP_PERMISSIONS_KEY=admin.permissions +VUE_APP_ROLES_KEY=admin.roles +VUE_APP_USER_KEY=admin.user diff --git a/package.json b/package.json index cae6313..13150ea 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "enquire.js": "^2.1.6", "js-cookie": "^2.2.1", "mockjs": "^1.1.0", - "pouchdb": "^7.2.1", "viser-vue": "^2.4.8", "vue": "^2.6.11", "vue-i18n": "^8.18.2", diff --git a/src/bootstrap.js b/src/bootstrap.js new file mode 100644 index 0000000..b3f0226 --- /dev/null +++ b/src/bootstrap.js @@ -0,0 +1,18 @@ +import {loadRoutes, loginGuard, authorityGuard} from '@/utils/routerUtil' + +/** + * 启动引导方法 + * 应用启动时需要执行的操作放在这里 + * @param router 应用的路由实例 + * @param store 应用的 vuex.store 实例 + * @param i18n 应用的 vue-i18n 实例 + */ +function bootstrap({router, store, i18n}) { + // 加载路由 + loadRoutes({router, store, i18n}) + // 添加路由守卫 + loginGuard(router) + authorityGuard(router, store) +} + +export default bootstrap diff --git a/src/components/exception/ExceptionPage.vue b/src/components/exception/ExceptionPage.vue index 5c5316b..f9fb84a 100644 --- a/src/components/exception/ExceptionPage.vue +++ b/src/components/exception/ExceptionPage.vue @@ -7,7 +7,7 @@

{{config[type].title}}

{{config[type].desc}}
- 返回首页 + 返回首页
@@ -18,11 +18,19 @@ import Config from './typeConfig' export default { name: 'ExceptionPage', - props: ['type'], + props: ['type', 'homeRoute'], data () { return { config: Config } + }, + methods: { + backHome() { + if (this.homeRoute) { + this.$router.push(this.homeRoute) + } + this.$emit('backHome', this.type) + } } } diff --git a/src/config/default/setting.config.js b/src/config/default/setting.config.js index 64f381c..58a24a6 100644 --- a/src/config/default/setting.config.js +++ b/src/config/default/setting.config.js @@ -16,6 +16,7 @@ module.exports = { hideSetting: false, //隐藏设置抽屉,true:隐藏,false:不隐藏 systemName: 'Vue Antd Admin', //系统名称 copyright: '2018 ICZER 工作室出品', //copyright + asyncRoutes: false, //异步加载路由,true:开启,false:不开启 animate: { //动画设置 disabled: false, //禁用动画,true:禁用,false:启用 name: 'bounce', //动画效果,支持的动画效果可参考 ./animate.config.js diff --git a/src/layouts/AdminLayout.vue b/src/layouts/AdminLayout.vue index 932483b..80c364e 100644 --- a/src/layouts/AdminLayout.vue +++ b/src/layouts/AdminLayout.vue @@ -35,8 +35,6 @@ import {mapState, mapMutations} from 'vuex' const minHeight = window.innerHeight - 64 - 24 - 122 -let menuData = [] - export default { name: 'AdminLayout', components: {Setting, SideMenu, Drawer, PageFooter, AdminHeader}, @@ -44,12 +42,12 @@ export default { return { minHeight: minHeight, collapsed: false, - menuData: menuData, showSetting: false } }, computed: { - ...mapState('setting', ['isMobile', 'theme', 'layout', 'footerLinks', 'copyright', 'fixedHeader', 'fixedSideBar', 'hideSetting', 'pageMinHeight']), + ...mapState('setting', ['isMobile', 'theme', 'layout', 'footerLinks', 'copyright', 'fixedHeader', 'fixedSideBar', + 'hideSetting', 'menuData']), sideMenuWidth() { return this.collapsed ? '80px' : '256px' }, @@ -74,9 +72,6 @@ export default { }, beforeDestroy() { this.correctPageMinHeight(-minHeight + 1) - }, - beforeCreate () { - menuData = this.$router.options.routes.find((item) => item.path === '/').children } } diff --git a/src/layouts/header/HeaderlAvatar.vue b/src/layouts/header/HeaderlAvatar.vue index 256580a..5884727 100644 --- a/src/layouts/header/HeaderlAvatar.vue +++ b/src/layouts/header/HeaderlAvatar.vue @@ -25,13 +25,13 @@ diff --git a/src/pages/exception/404.vue b/src/pages/exception/404.vue index fa4edfa..d424216 100644 --- a/src/pages/exception/404.vue +++ b/src/pages/exception/404.vue @@ -1,5 +1,5 @@ diff --git a/src/pages/form/advance/index.js b/src/pages/form/advance/index.js new file mode 100644 index 0000000..22fb509 --- /dev/null +++ b/src/pages/form/advance/index.js @@ -0,0 +1,2 @@ +import AdvancedForm from '@/pages/form/advance/AdvancedForm' +export default AdvancedForm diff --git a/src/pages/form/basic/index.js b/src/pages/form/basic/index.js new file mode 100644 index 0000000..b046177 --- /dev/null +++ b/src/pages/form/basic/index.js @@ -0,0 +1,2 @@ +import BasicForm from './BasicForm' +export default BasicForm diff --git a/src/pages/form/step/index.js b/src/pages/form/step/index.js new file mode 100644 index 0000000..4b75f8f --- /dev/null +++ b/src/pages/form/step/index.js @@ -0,0 +1,2 @@ +import StepForm from './StepForm' +export default StepForm diff --git a/src/pages/login/Login.vue b/src/pages/login/Login.vue index f9f42e5..16d371b 100644 --- a/src/pages/login/Login.vue +++ b/src/pages/login/Login.vue @@ -75,8 +75,10 @@