Browse Source

代码优化

yuwenjun 3 years ago
parent
commit
a1c470399b

+ 1 - 0
src/api/message.js

@@ -1,5 +1,6 @@
 import request from '@/utils/request'
 import request from '@/utils/request'
 
 
+// 获取消息列表
 export function getMessage(data) {
 export function getMessage(data) {
   return request({
   return request({
     url: '/message/admin/list',
     url: '/message/admin/list',

+ 1 - 0
src/api/upload.js

@@ -1,5 +1,6 @@
 import request from '@/utils/request'
 import request from '@/utils/request'
 
 
+// 上传图片
 export function uploadImage(data) {
 export function uploadImage(data) {
   return request({
   return request({
     headers: {
     headers: {

+ 3 - 14
src/api/user.js

@@ -1,5 +1,6 @@
 import request from '@/utils/request'
 import request from '@/utils/request'
 
 
+// 用户登录
 export function login(data) {
 export function login(data) {
   return request({
   return request({
     url: '/user/login/password',
     url: '/user/login/password',
@@ -8,6 +9,7 @@ export function login(data) {
   })
   })
 }
 }
 
 
+// 修改密码
 export function modifyPassword(data) {
 export function modifyPassword(data) {
   return request({
   return request({
     url: '/user/update/password',
     url: '/user/update/password',
@@ -16,6 +18,7 @@ export function modifyPassword(data) {
   })
   })
 }
 }
 
 
+// 重置密码
 export function resetPassword(data) {
 export function resetPassword(data) {
   return request({
   return request({
     url: '/shop/reset/password',
     url: '/shop/reset/password',
@@ -24,17 +27,3 @@ export function resetPassword(data) {
   })
   })
 }
 }
 
 
-// export function getInfo(token) {
-//   return request({
-//     url: '/vue-element-admin/user/info',
-//     method: 'get',
-//     params: { token }
-//   })
-// }
-
-// export function logout() {
-//   return request({
-//     url: '/vue-element-admin/user/logout',
-//     method: 'post'
-//   })
-// }

+ 14 - 143
src/router/index.js

@@ -6,6 +6,11 @@ Vue.use(Router)
 /* Layout */
 /* Layout */
 import Layout from '@/layout'
 import Layout from '@/layout'
 
 
+import supplierRoutes from './modules/supplier'
+import authRoutes from './modules/auth'
+import productRoutes from './modules/product'
+import reviewRoutes from './modules/review'
+
 /**
 /**
  * Note: sub-menu only appear when route children.length >= 1
  * Note: sub-menu only appear when route children.length >= 1
  * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
@@ -28,24 +33,8 @@ import Layout from '@/layout'
   }
   }
  */
  */
 
 
-/**
- * 默认路由 全部用户都可以访问
- * constantRoutes
- * a base page that does not have permission requirements
- * all roles can be accessed
- */
+// 默认路由列表 全部用户都可以访问
 export const constantRoutes = [
 export const constantRoutes = [
-  {
-    path: '/redirect',
-    component: Layout,
-    hidden: true,
-    children: [
-      {
-        path: '/redirect/:path(.*)',
-        component: () => import('@/views/redirect/index')
-      }
-    ]
-  },
   // 登录
   // 登录
   {
   {
     path: '/login',
     path: '/login',
@@ -92,145 +81,27 @@ export const constantRoutes = [
   }
   }
 ]
 ]
 
 
-/**
- * 需要权限访问的路由
- * asyncRoutes
- * the routes that need to be dynamically loaded based on user roles
- */
+// 需要权限访问的路由列表
 export const asyncRoutes = [
 export const asyncRoutes = [
+  ...supplierRoutes,
+  ...authRoutes,
+  ...productRoutes,
+  ...reviewRoutes,
 
 
-  // 供应商管理页面
-  {
-    path: '/supplier',
-    component: Layout,
-    alwaysShow: true,
-    name: 'Supplier',
-    redirect: '/supplier/list',
-    meta: { title: '供应商管理', icon: 'el-icon-s-custom', roles: ['admin'], noCache: true },
-    children: [
-      {
-        path: 'list',
-        component: () => import('@/views/supplier/user/index'),
-        name: 'SupplierList',
-        meta: { title: '供应商列表', icon: 'el-icon-menu', affix: true, roles: ['admin'], noCache: true }
-      },
-      {
-        hidden: true,
-        path: 'add',
-        component: () => import('@/views/supplier/user/add'),
-        name: 'SupplierAdd',
-        meta: { title: '添加供应商', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
-      },
-      {
-        hidden: true,
-        path: 'edit',
-        component: () => import('@/views/supplier/user/edit'),
-        name: 'SupplierEdit',
-        meta: { title: '修改供应商', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
-      }
-    ]
-  },
-  // 授权管理页面
-  {
-    path: '/auth',
-    component: Layout,
-    alwaysShow: true,
-    redirect: '/auth/list',
-    name: 'Auth',
-    meta: { title: '授权管理', icon: 'el-icon-s-promotion', roles: ['admin', 'normal'], noCache: true, proxy: true },
-    children: [
-      {
-        path: 'list',
-        component: () => import('@/views/supplier/auth/index'),
-        name: 'AuthList',
-        meta: { title: '授权列表', icon: 'el-icon-menu', roles: ['admin', 'normal'], affix: true, noCache: true, proxy: true }
-      }
-    ]
-  },
-  // 商品管理
-  {
-    path: '/product',
-    component: Layout,
-    alwaysShow: true,
-    redirect: '/product/list',
-    hidden: true,
-    name: 'Product',
-    meta: { title: '商品管理', icon: 'el-icon-s-shop', roles: ['admin', 'normal'], noCache: true, proxy: true },
-    children: [
-      {
-        hidden: true,
-        path: 'list',
-        component: () => import('@/views/supplier/product/index'),
-        name: 'ProductList',
-        meta: { title: '商品列表', icon: 'el-icon-menu', roles: ['admin', 'normal'], noCache: true, proxy: true }
-      },
-      {
-        hidden: true,
-        path: 'add',
-        component: () => import('@/views/supplier/product/add'),
-        name: 'AddProduct',
-        meta: { title: '添加商品', icon: 'el-icon-menu', roles: ['admin', 'normal'], noCache: true, proxy: true }
-      },
-      {
-        hidden: true,
-        path: 'edit',
-        component: () => import('@/views/supplier/product/edit'),
-        name: 'EditProduct',
-        meta: { title: '修改商品', icon: 'el-icon-menu', roles: ['admin', 'normal'], noCache: true, proxy: true }
-      }
-    ]
-  },
-  // 审核页面
-  {
-    path: '/review',
-    component: Layout,
-    alwaysShow: true,
-    redirect: '/review/list',
-    name: 'Review',
-    meta: { title: '品牌授权审核', icon: 'el-icon-s-check', roles: ['admin'], noCache: true },
-    children: [
-      {
-        path: 'list',
-        component: () => import('@/views/supplier/review/index'),
-        name: 'ReviewList',
-        meta: { title: '审核列表', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
-      },
-      {
-        path: 'auth-list',
-        hidden: true,
-        component: () => import('@/views/supplier/review/authList'),
-        name: 'ReviewAuthList',
-        meta: { title: '授权机构审核列表', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
-      },
-      {
-        path: 'shop-list',
-        hidden: true,
-        component: () => import('@/views/supplier/review/shopList'),
-        name: 'ShopList',
-        meta: { title: '商品审核列表', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
-      },
-      {
-        path: 'shop-detail',
-        hidden: true,
-        component: () => import('@/views/supplier/review/shopDetail'),
-        name: 'ShopDetail',
-        meta: { title: '商品审核详情', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
-      }
-    ]
-  },
-  // 404页面
+  // 404页面 放在最后面
   { path: '*', redirect: '/404', hidden: true }
   { path: '*', redirect: '/404', hidden: true }
 ]
 ]
 
 
+// 创建路由对象
 const createRouter = () =>
 const createRouter = () =>
   new Router({
   new Router({
-    // mode: 'history', // require service support
     scrollBehavior: () => ({ y: 0 }),
     scrollBehavior: () => ({ y: 0 }),
     routes: constantRoutes
     routes: constantRoutes
   })
   })
 
 
 const router = createRouter()
 const router = createRouter()
 
 
+// 重置路由
 export function resetRouter() {
 export function resetRouter() {
   const newRouter = createRouter()
   const newRouter = createRouter()
   router.matcher = newRouter.matcher // reset router
   router.matcher = newRouter.matcher // reset router

+ 24 - 0
src/router/modules/auth.js

@@ -0,0 +1,24 @@
+/* Layout */
+import Layout from '@/layout'
+
+// 授权管理页面
+const authRoutes = [
+  {
+    path: '/auth',
+    component: Layout,
+    alwaysShow: true,
+    redirect: '/auth/list',
+    name: 'Auth',
+    meta: { title: '授权管理', icon: 'el-icon-s-promotion', roles: ['admin', 'normal'], noCache: true, proxy: true },
+    children: [
+      {
+        path: 'list',
+        component: () => import('@/views/supplier/auth/index'),
+        name: 'AuthList',
+        meta: { title: '授权列表', icon: 'el-icon-menu', roles: ['admin', 'normal'], affix: true, noCache: true, proxy: true }
+      }
+    ]
+  }
+]
+
+export default authRoutes

+ 0 - 36
src/router/modules/charts.js

@@ -1,36 +0,0 @@
-/** When your routing table is too long, you can split it into small modules**/
-
-import Layout from '@/layout'
-
-const chartsRouter = {
-  path: '/charts',
-  component: Layout,
-  redirect: 'noRedirect',
-  name: 'Charts',
-  meta: {
-    title: 'Charts',
-    icon: 'chart'
-  },
-  children: [
-    {
-      path: 'keyboard',
-      component: () => import('@/views/charts/keyboard'),
-      name: 'KeyboardChart',
-      meta: { title: 'Keyboard Chart', noCache: true }
-    },
-    {
-      path: 'line',
-      component: () => import('@/views/charts/line'),
-      name: 'LineChart',
-      meta: { title: 'Line Chart', noCache: true }
-    },
-    {
-      path: 'mix-chart',
-      component: () => import('@/views/charts/mix-chart'),
-      name: 'MixChart',
-      meta: { title: 'Mix Chart', noCache: true }
-    }
-  ]
-}
-
-export default chartsRouter

+ 0 - 102
src/router/modules/components.js

@@ -1,102 +0,0 @@
-/** When your routing table is too long, you can split it into small modules **/
-
-import Layout from '@/layout'
-
-const componentsRouter = {
-  path: '/components',
-  component: Layout,
-  redirect: 'noRedirect',
-  name: 'ComponentDemo',
-  meta: {
-    title: 'Components',
-    icon: 'component'
-  },
-  children: [
-    {
-      path: 'tinymce',
-      component: () => import('@/views/components-demo/tinymce'),
-      name: 'TinymceDemo',
-      meta: { title: 'Tinymce' }
-    },
-    {
-      path: 'markdown',
-      component: () => import('@/views/components-demo/markdown'),
-      name: 'MarkdownDemo',
-      meta: { title: 'Markdown' }
-    },
-    {
-      path: 'json-editor',
-      component: () => import('@/views/components-demo/json-editor'),
-      name: 'JsonEditorDemo',
-      meta: { title: 'JSON Editor' }
-    },
-    {
-      path: 'split-pane',
-      component: () => import('@/views/components-demo/split-pane'),
-      name: 'SplitpaneDemo',
-      meta: { title: 'SplitPane' }
-    },
-    {
-      path: 'avatar-upload',
-      component: () => import('@/views/components-demo/avatar-upload'),
-      name: 'AvatarUploadDemo',
-      meta: { title: 'Upload' }
-    },
-    {
-      path: 'dropzone',
-      component: () => import('@/views/components-demo/dropzone'),
-      name: 'DropzoneDemo',
-      meta: { title: 'Dropzone' }
-    },
-    {
-      path: 'sticky',
-      component: () => import('@/views/components-demo/sticky'),
-      name: 'StickyDemo',
-      meta: { title: 'Sticky' }
-    },
-    {
-      path: 'count-to',
-      component: () => import('@/views/components-demo/count-to'),
-      name: 'CountToDemo',
-      meta: { title: 'Count To' }
-    },
-    {
-      path: 'mixin',
-      component: () => import('@/views/components-demo/mixin'),
-      name: 'ComponentMixinDemo',
-      meta: { title: 'Component Mixin' }
-    },
-    {
-      path: 'back-to-top',
-      component: () => import('@/views/components-demo/back-to-top'),
-      name: 'BackToTopDemo',
-      meta: { title: 'Back To Top' }
-    },
-    {
-      path: 'drag-dialog',
-      component: () => import('@/views/components-demo/drag-dialog'),
-      name: 'DragDialogDemo',
-      meta: { title: 'Drag Dialog' }
-    },
-    {
-      path: 'drag-select',
-      component: () => import('@/views/components-demo/drag-select'),
-      name: 'DragSelectDemo',
-      meta: { title: 'Drag Select' }
-    },
-    {
-      path: 'dnd-list',
-      component: () => import('@/views/components-demo/dnd-list'),
-      name: 'DndListDemo',
-      meta: { title: 'Dnd List' }
-    },
-    {
-      path: 'drag-kanban',
-      component: () => import('@/views/components-demo/drag-kanban'),
-      name: 'DragKanbanDemo',
-      meta: { title: 'Drag Kanban' }
-    }
-  ]
-}
-
-export default componentsRouter

+ 0 - 66
src/router/modules/nested.js

@@ -1,66 +0,0 @@
-/** When your routing table is too long, you can split it into small modules **/
-
-import Layout from '@/layout'
-
-const nestedRouter = {
-  path: '/nested',
-  component: Layout,
-  redirect: '/nested/menu1/menu1-1',
-  name: 'Nested',
-  meta: {
-    title: 'Nested Routes',
-    icon: 'nested'
-  },
-  children: [
-    {
-      path: 'menu1',
-      component: () => import('@/views/nested/menu1/index'), // Parent router-view
-      name: 'Menu1',
-      meta: { title: 'Menu 1' },
-      redirect: '/nested/menu1/menu1-1',
-      children: [
-        {
-          path: 'menu1-1',
-          component: () => import('@/views/nested/menu1/menu1-1'),
-          name: 'Menu1-1',
-          meta: { title: 'Menu 1-1' }
-        },
-        {
-          path: 'menu1-2',
-          component: () => import('@/views/nested/menu1/menu1-2'),
-          name: 'Menu1-2',
-          redirect: '/nested/menu1/menu1-2/menu1-2-1',
-          meta: { title: 'Menu 1-2' },
-          children: [
-            {
-              path: 'menu1-2-1',
-              component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
-              name: 'Menu1-2-1',
-              meta: { title: 'Menu 1-2-1' }
-            },
-            {
-              path: 'menu1-2-2',
-              component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
-              name: 'Menu1-2-2',
-              meta: { title: 'Menu 1-2-2' }
-            }
-          ]
-        },
-        {
-          path: 'menu1-3',
-          component: () => import('@/views/nested/menu1/menu1-3'),
-          name: 'Menu1-3',
-          meta: { title: 'Menu 1-3' }
-        }
-      ]
-    },
-    {
-      path: 'menu2',
-      name: 'Menu2',
-      component: () => import('@/views/nested/menu2/index'),
-      meta: { title: 'Menu 2' }
-    }
-  ]
-}
-
-export default nestedRouter

+ 40 - 0
src/router/modules/product.js

@@ -0,0 +1,40 @@
+/* Layout */
+import Layout from '@/layout'
+
+// 商品管理
+const productRoutes = [
+  {
+    path: '/product',
+    component: Layout,
+    alwaysShow: true,
+    redirect: '/product/list',
+    hidden: true,
+    name: 'Product',
+    meta: { title: '商品管理', icon: 'el-icon-s-shop', roles: ['admin', 'normal'], noCache: true, proxy: true },
+    children: [
+      {
+        hidden: true,
+        path: 'list',
+        component: () => import('@/views/supplier/product/index'),
+        name: 'ProductList',
+        meta: { title: '商品列表', icon: 'el-icon-menu', roles: ['admin', 'normal'], noCache: true, proxy: true }
+      },
+      {
+        hidden: true,
+        path: 'add',
+        component: () => import('@/views/supplier/product/add'),
+        name: 'AddProduct',
+        meta: { title: '添加商品', icon: 'el-icon-menu', roles: ['admin', 'normal'], noCache: true, proxy: true }
+      },
+      {
+        hidden: true,
+        path: 'edit',
+        component: () => import('@/views/supplier/product/edit'),
+        name: 'EditProduct',
+        meta: { title: '修改商品', icon: 'el-icon-menu', roles: ['admin', 'normal'], noCache: true, proxy: true }
+      }
+    ]
+  }
+]
+
+export default productRoutes

+ 45 - 0
src/router/modules/review.js

@@ -0,0 +1,45 @@
+/* Layout */
+import Layout from '@/layout'
+
+// 审核页面路由
+const reviewRoutes = [
+  {
+    path: '/review',
+    component: Layout,
+    alwaysShow: true,
+    redirect: '/review/list',
+    name: 'Review',
+    meta: { title: '品牌授权审核', icon: 'el-icon-s-check', roles: ['admin'], noCache: true },
+    children: [
+      {
+        path: 'list',
+        component: () => import('@/views/supplier/review/index'),
+        name: 'ReviewList',
+        meta: { title: '审核列表', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
+      },
+      {
+        path: 'auth-list',
+        hidden: true,
+        component: () => import('@/views/supplier/review/authList'),
+        name: 'ReviewAuthList',
+        meta: { title: '授权机构审核列表', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
+      },
+      {
+        path: 'shop-list',
+        hidden: true,
+        component: () => import('@/views/supplier/review/shopList'),
+        name: 'ShopList',
+        meta: { title: '商品审核列表', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
+      },
+      {
+        path: 'shop-detail',
+        hidden: true,
+        component: () => import('@/views/supplier/review/shopDetail'),
+        name: 'ShopDetail',
+        meta: { title: '商品审核详情', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
+      }
+    ]
+  }
+]
+
+export default reviewRoutes

+ 38 - 0
src/router/modules/supplier.js

@@ -0,0 +1,38 @@
+/* Layout */
+import Layout from '@/layout'
+
+// 供应商管理页面
+const supplierRoutes = [
+  {
+    path: '/supplier',
+    component: Layout,
+    alwaysShow: true,
+    name: 'Supplier',
+    redirect: '/supplier/list',
+    meta: { title: '供应商管理', icon: 'el-icon-s-custom', roles: ['admin'], noCache: true },
+    children: [
+      {
+        path: 'list',
+        component: () => import('@/views/supplier/user/index'),
+        name: 'SupplierList',
+        meta: { title: '供应商列表', icon: 'el-icon-menu', affix: true, roles: ['admin'], noCache: true }
+      },
+      {
+        hidden: true,
+        path: 'add',
+        component: () => import('@/views/supplier/user/add'),
+        name: 'SupplierAdd',
+        meta: { title: '添加供应商', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
+      },
+      {
+        hidden: true,
+        path: 'edit',
+        component: () => import('@/views/supplier/user/edit'),
+        name: 'SupplierEdit',
+        meta: { title: '修改供应商', icon: 'el-icon-menu', roles: ['admin'], noCache: true }
+      }
+    ]
+  }
+]
+
+export default supplierRoutes

+ 0 - 41
src/router/modules/table.js

@@ -1,41 +0,0 @@
-/** When your routing table is too long, you can split it into small modules **/
-
-import Layout from '@/layout'
-
-const tableRouter = {
-  path: '/table',
-  component: Layout,
-  redirect: '/table/complex-table',
-  name: 'Table',
-  meta: {
-    title: 'Table',
-    icon: 'table'
-  },
-  children: [
-    {
-      path: 'dynamic-table',
-      component: () => import('@/views/table/dynamic-table/index'),
-      name: 'DynamicTable',
-      meta: { title: 'Dynamic Table' }
-    },
-    {
-      path: 'drag-table',
-      component: () => import('@/views/table/drag-table'),
-      name: 'DragTable',
-      meta: { title: 'Drag Table' }
-    },
-    {
-      path: 'inline-edit-table',
-      component: () => import('@/views/table/inline-edit-table'),
-      name: 'InlineEditTable',
-      meta: { title: 'Inline Edit' }
-    },
-    {
-      path: 'complex-table',
-      component: () => import('@/views/table/complex-table'),
-      name: 'ComplexTable',
-      meta: { title: 'Complex Table' }
-    }
-  ]
-}
-export default tableRouter

+ 11 - 9
src/store/index.js

@@ -6,15 +6,17 @@ import { closeWebSocket } from '@/utils/WebSocketUtil'
 Vue.use(Vuex)
 Vue.use(Vuex)
 
 
 // 动态加载modules
 // 动态加载modules
-const modulesFiles = require.context('./modules', true, /\.js$/)
-
-const modules = modulesFiles.keys().reduce((modules, modulePath) => {
-  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
-  const value = modulesFiles(modulePath)
-  modules[moduleName] = value.default
-  return modules
-}, {})
-
+const loadModules = () => {
+  const context = require.context('./modules', true, /\.js$/)
+  const modules = context.keys().reduce((modules, modulePath) => {
+    const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
+    const value = context(modulePath)
+    modules[moduleName] = value.default
+    return modules
+  }, {})
+  return { modules, context }
+}
+const { modules } = loadModules()
 // 创建store
 // 创建store
 const store = new Vuex.Store({
 const store = new Vuex.Store({
   modules,
   modules,