浏览代码

refactor: mock & routers

Sendya 5 年之前
父节点
当前提交
d822767675
共有 4 个文件被更改,包括 248 次插入56 次删除
  1. 0 7
      README.md
  2. 212 43
      src/mock/services/user.js
  3. 31 6
      src/router/generator-routers.js
  4. 5 0
      src/views/dashboard/TestWork.vue

+ 0 - 7
README.md

@@ -18,13 +18,6 @@ An out-of-box UI solution for enterprise applications as a Vue boilerplate. base
 - Documentation: https://pro.loacg.com/docs/getting-started
 - ChangeLog: https://pro.loacg.com/docs/changelog
 - FAQ: https://pro.loacg.com/docs/faq
-- Branches: 
-  - demo/router-view-table: CRUD view in router
-  - feature/demand_load: loaded on demand
-  - feature/lang: i18n support
-  - feature/dynamic-menu: dynamic menu demo
-  - lite: lite template (legacy)
-
 
 Overview
 ----

+ 212 - 43
src/mock/services/user.js

@@ -372,6 +372,7 @@ const info = (options) => {
 
 const userNav = (options) => {
   const nav = [
+    // dashboard
     {
       'name': 'dashboard',
       'parentId': -1,
@@ -385,34 +386,34 @@ const userNav = (options) => {
       'redirect': '/dashboard/workplace'
     },
     {
-      'name': 'analysis',
+      'name': 'workplace',
       'parentId': 1,
-      'id': 2,
+      'id': 7,
       'meta': {
-        'title': '分析页',
+        'title': '工作台',
         'show': true
       },
-      'component': 'Analysis'
+      'component': 'Workplace'
     },
     {
       'name': 'monitor',
+      'path': 'https://www.baidu.com/',
       'parentId': 1,
       'id': 3,
       'meta': {
-        'title': '监控页',
+        'title': '监控页(外部)',
         'show': true
-      },
-      'component': 'Monitor'
+      }
     },
     {
-      'name': 'workplace',
+      'name': 'analysis',
       'parentId': 1,
-      'id': 7,
+      'id': 2,
       'meta': {
-        'title': '工作台',
+        'title': '分析页',
         'show': true
       },
-      'component': 'Workplace'
+      'component': 'Analysis'
     },
     {
       'name': 'tests',
@@ -424,77 +425,245 @@ const userNav = (options) => {
       },
       'component': 'TestWork'
     },
+
+    // form
+    {
+      'name': 'form',
+      'parentId': -1,
+      'id': 10,
+      'meta': {
+        'icon': 'form',
+        'title': '表单页'
+      },
+      'redirect': '/form/base-form',
+      'component': 'PageView'
+    },
     {
-      'name': 'permission',
+      'name': 'basic-form',
       'parentId': 10,
-      'id': 4,
+      'id': 6,
       'meta': {
-        'title': '权限管理',
-        'show': true
+        'title': '基础表单'
       },
-      'component': 'PermissionList'
+      'component': 'BasicForm'
     },
     {
-      'name': 'role',
+      'name': 'step-form',
       'parentId': 10,
       'id': 5,
       'meta': {
-        'title': '角色管理',
-        'show': true
+        'title': '分步表单'
       },
-      'component': 'RoleList'
+      'component': 'StepForm'
     },
     {
-      'name': 'user',
+      'name': 'advanced-form',
       'parentId': 10,
-      'id': 6,
+      'id': 4,
       'meta': {
-        'title': '用户管理',
-        'show': true
+        'title': '高级表单'
       },
-      'component': 'UserList'
+      'component': 'AdvanceForm'
     },
+
+    // list
     {
-      'name': 'system',
+      'name': 'list',
       'parentId': -1,
-      'id': 10,
+      'id': 10010,
       'meta': {
-        'icon': 'setting',
-        'title': '系统管理',
+        'icon': 'table',
+        'title': '列表页',
         'show': true
       },
+      'redirect': '/list/table-list',
       'component': 'PageView'
     },
     {
-      'name': 'features',
+      'name': 'table-list',
+      'parentId': 10010,
+      'id': 10011,
+      'path': '/list/table-list/:pageNo([1-9]\\d*)?',
+      'meta': {
+        'title': '查询表格',
+        'show': true
+      },
+      'component': 'TableList'
+    },
+    {
+      'name': 'basic-list',
+      'parentId': 10010,
+      'id': 10012,
+      'meta': {
+        'title': '标准列表',
+        'show': true
+      },
+      'component': 'StandardList'
+    },
+    {
+      'name': 'card',
+      'parentId': 10010,
+      'id': 10013,
+      'meta': {
+        'title': '卡片列表',
+        'show': true
+      },
+      'component': 'CardList'
+    },
+    {
+      'name': 'search',
+      'parentId': 10010,
+      'id': 10014,
+      'meta': {
+        'title': '搜索列表',
+        'show': true
+      },
+      'redirect': '/list/search/article',
+      'component': 'SearchLayout'
+    },
+    {
+      'name': 'article',
+      'parentId': 10014,
+      'id': 10015,
+      'meta': {
+        'title': '搜索列表(文章)',
+        'show': true
+      },
+      'component': 'SearchArticles'
+    },
+    {
+      'name': 'project',
+      'parentId': 10014,
+      'id': 10016,
+      'meta': {
+        'title': '搜索列表(项目)',
+        'show': true
+      },
+      'component': 'SearchProjects'
+    },
+    {
+      'name': 'application',
+      'parentId': 10014,
+      'id': 10017,
+      'meta': {
+        'title': '搜索列表(应用)',
+        'show': true
+      },
+      'component': 'SearchApplications'
+    },
+
+    // profile
+    {
+      'name': 'profile',
+      'parentId': -1,
+      'id': 10018,
+      'meta': {
+        'title': '详情页',
+        'icon': 'profile',
+        'show': true
+      },
+      'redirect': '/profile/basic',
+      'component': 'RouteView'
+    },
+    {
+      'name': 'basic',
+      'parentId': 10018,
+      'id': 10019,
+      'meta': {
+        'title': '基础详情页',
+        'show': true
+      },
+      'component': 'ProfileBasic'
+    },
+    {
+      'name': 'advanced',
+      'parentId': 10018,
+      'id': 10020,
+      'meta': {
+        'title': '高级详情页',
+        'show': true
+      },
+      'component': 'ProfileAdvanced'
+    },
+
+    // result
+    {
+      'name': 'result',
       'parentId': -1,
-      'id': 11,
+      'id': 10021,
       'meta': {
-        'icon': 'ordered-list',
-        'title': '功能管理',
+        'title': '结果页',
+        'icon': 'check-circle-o',
         'show': true
       },
+      'redirect': '/result/success',
       'component': 'PageView'
     },
     {
-      'name': 'task',
-      'parentId': 11,
-      'id': 12,
+      'name': 'success',
+      'parentId': 10021,
+      'id': 10022,
+      'meta': {
+        'title': '成功',
+        'hiddenHeaderContent': true,
+        'show': true
+      },
+      'component': 'ResultSuccess'
+    },
+    {
+      'name': 'fail',
+      'parentId': 10021,
+      'id': 10023,
+      'meta': {
+        'title': '失败',
+        'hiddenHeaderContent': true,
+        'show': true
+      },
+      'component': 'ResultFail'
+    },
+
+    // Exception
+    {
+      'name': 'exception',
+      'parentId': -1,
+      'id': 10024,
+      'meta': {
+        'title': '异常页',
+        'icon': 'warning',
+        'show': true
+      },
+      'redirect': '/exception/403',
+      'component': 'RouteView'
+    },
+    {
+      'name': '403',
+      'parentId': 10024,
+      'id': 10025,
+      'meta': {
+        'title': '403',
+        'show': true
+      },
+      'component': 'Exception403'
+    },
+    {
+      'name': '404',
+      'parentId': 10024,
+      'id': 10026,
       'meta': {
-        'title': '任务列表',
+        'title': '404',
         'show': true
       },
-      'component': 'TaskList'
+      'component': 'Exception404'
     },
     {
-      'name': 'tag',
-      'parentId': 11,
-      'id': 13,
+      'name': '500',
+      'parentId': 10024,
+      'id': 10027,
       'meta': {
-        'title': '标签列表',
+        'title': '500',
         'show': true
       },
-      'component': 'TagList'
+      'component': 'Exception500'
     }
   ]
   return builder(nav)

+ 31 - 6
src/router/generator-routers.js

@@ -15,9 +15,32 @@ const constantRouterComponents = {
   '500': () => import(/* webpackChunkName: "error" */ '@/views/exception/500'),
 
   // 你需要动态引入的页面组件
-  'Analysis': () => import('@/views/dashboard/Analysis'),
   'Workplace': () => import('@/views/dashboard/Workplace'),
-  'TestWork': () => import('@/views/dashboard/TestWork')
+  'Analysis': () => import('@/views/dashboard/Analysis'),
+
+  // form
+  'BasicForm': () => import('@/views/form/BasicForm'),
+  'StepForm': () => import('@/views/form/stepForm/StepForm'),
+  'AdvanceForm': () => import('@/views/form/advancedForm/AdvancedForm'),
+
+  // list
+  'TableList': () => import('@/views/list/TableList'),
+  'BasicList': () => import('@/views/list/StandardList'),
+  'CardList': () => import('@/views/list/CardList'),
+  'SearchLayout': () => import('@/views/list/search/SearchLayout'),
+  'SearchArticles': () => import('@/views/list/search/Article'),
+  'SearchProjects': () => import('@/views/list/search/Projects'),
+  'SearchApplications': () => import('@/views/list/search/Applications'),
+  'ProfileBasic': () => import('@/views/profile/basic/Index'),
+  'ProfileAdvanced': () => import('@/views/profile/advanced/Advanced'),
+  'ResultSuccess': () => import(/* webpackChunkName: "result" */ '@/views/result/Success'),
+  'ResultFail': () => import(/* webpackChunkName: "result" */ '@/views/result/Error'),
+
+  'Exception403': () => import(/* webpackChunkName: "fail" */ '@/views/exception/403'),
+  'Exception404': () => import(/* webpackChunkName: "fail" */ '@/views/exception/404'),
+  'Exception500': () => import(/* webpackChunkName: "fail" */ '@/views/exception/500'),
+
+  'TestWork': () => import(/* webpackChunkName: "TestWork" */ '@/views/dashboard/TestWork')
 }
 
 // 前端未找到页面路由(固定不用改)
@@ -74,10 +97,10 @@ export const generatorDynamicRouter = (token) => {
  */
 export const generator = (routerMap, parent) => {
   return routerMap.map(item => {
-    const { title, show, hideChildren, icon } = item.meta || {}
+    const { title, show, hideChildren, hiddenHeaderContent, icon } = item.meta || {}
     const currentRouter = {
       // 路由地址 动态拼接生成如 /dashboard/workplace
-      path: `${parent && parent.path || ''}/${item.key}`,
+      path: item.path || `${parent && parent.path || ''}/${item.key}`,
       // 路由名称,建议唯一
       name: item.name || item.key || '',
       // 该路由对应页面的 组件 :方案1
@@ -86,7 +109,7 @@ export const generator = (routerMap, parent) => {
       // component: () => import(`@/views/${item.component}`),
 
       // meta: 页面标题, 菜单图标, 页面权限(供指令权限用,可去掉)
-      meta: { title: title, icon: icon || undefined, permission: item.name }
+      meta: { title: title, icon: icon || undefined, hiddenHeaderContent: hiddenHeaderContent, permission: item.name }
     }
     // 是否设置了隐藏菜单
     if (show === false) {
@@ -97,7 +120,9 @@ export const generator = (routerMap, parent) => {
       currentRouter.hideChildrenInMenu = true
     }
     // 为了防止出现后端返回结果不规范,处理有可能出现拼接出两个 反斜杠
-    currentRouter.path = currentRouter.path.replace('//', '/')
+    if (!currentRouter.path.startsWith('http')) {
+      currentRouter.path = currentRouter.path.replace('//', '/')
+    }
     // 重定向
     item.redirect && (currentRouter.redirect = item.redirect)
     // 是否有子菜单,并递归处理

+ 5 - 0
src/views/dashboard/TestWork.vue

@@ -6,6 +6,7 @@
       <h4>多标签组件测试功能</h4>
       <a-button @click="handleCloseCurrentTab" style="margin-right: 16px;">关闭当前页</a-button>
       <a-button @click="handleOpenTab">打开 任务列表</a-button>
+      <a-input ref="tInput" />
     </div>
     <a-divider />
     <div class="page-loading-test">
@@ -28,6 +29,10 @@ export default {
     },
 
     handleOpenLoading () {
+      this.$nextTick(function () {
+        console.log('this', this)
+        console.log('this.$refs.tInput', this.$refs.tInput)
+      })
       this.$loading.show()
       setTimeout(() => {
         this.$loading.hide()