123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- import React from 'react';
- import dynamic from 'dva/dynamic';
- import { getMenuData } from './menu';
- // wrapper of dynamic
- const dynamicWrapper = (app, models, component) => dynamic({
- app,
- // eslint-disable-next-line no-underscore-dangle
- models: () => models.filter(m => !app._models.some(({ namespace }) => namespace === m)).map(m => import(`../models/${m}.js`)),
- // add routerData prop
- component: () => {
- const p = component();
- return new Promise((resolve, reject) => {
- p.then((Comp) => {
- resolve(props => <Comp {...props} routerData={getRouterData(app)} />);
- }).catch(err => reject(err));
- });
- },
- });
- function getFlatMenuData(menus) {
- let keys = {};
- menus.forEach((item) => {
- if (item.children) {
- keys[item.path] = item.name;
- keys = { ...keys, ...getFlatMenuData(item.children) };
- } else {
- keys[item.path] = item.name;
- }
- });
- return keys;
- }
- export const getRouterData = (app) => {
- const routerData = {
- '/': {
- component: dynamicWrapper(app, ['user', 'login'], () => import('../layouts/BasicLayout')),
- },
- // '/help': {
- // component: dynamicWrapper(app, [], () => import('../routes/About')),
- // },
- '/dashboard': {
- component: dynamicWrapper(app, [], () => import('../routes/Dashboard')),
- },
- '/resource/gallery': {
- component: dynamicWrapper(app, ['resource'], () => import('../routes/Resource/gallery')),
- },
- '/resource/video': {
- component: dynamicWrapper(app, ['resource'], () => import('../routes/Resource/video')),
- },
- '/terminal/campus': {
- component: dynamicWrapper(app, ['campus', 'merchant/merchant'], () => import('../routes/Campus')),
- },
- '/terminal/user': {
- component: dynamicWrapper(app, ['terminal/terminal'], () => import('../routes/Terminal/List')),
- },
- '/terminal/user/add': {
- component: dynamicWrapper(app, ['terminal/detail', 'campus'], () => import('../routes/Terminal/Edit')),
- name: '添加终端',
- },
- '/terminal/user/edit/:id': {
- component: dynamicWrapper(app, ['terminal/detail', 'campus'], () => import('../routes/Terminal/Edit')),
- name: '编辑终端',
- },
- '/merchant': {
- component: dynamicWrapper(app, ['merchant/merchant'], () => import('../routes/Merchant/List')),
- },
- '/merchant/add': {
- component: dynamicWrapper(app, ['merchant/detail', 'mproduct/mproduct'], () => import('../routes/Merchant/Edit')),
- name: '添加厂商',
- },
- '/merchant/edit/:id': {
- component: dynamicWrapper(app, ['merchant/detail', 'mproduct/mproduct'], () => import('../routes/Merchant/Edit')),
- name: '编辑厂商',
- },
- '/tag/tagGroup': {
- component: dynamicWrapper(app, ['group/group', 'merchant/merchant'], () => import('../routes/TagGroup/List')),
- },
- '/tag/tagGroup/add': {
- component: dynamicWrapper(app, ['group/detail', 'merchant/merchant'], () => import('../routes/TagGroup/Edit')),
- name: '创建标签组',
- },
- '/tag/tagGroup/edit/:id': {
- component: dynamicWrapper(app, ['group/detail', 'merchant/merchant'], () => import('../routes/TagGroup/Edit')),
- name: '修改标签组',
- },
- '/tag/tagItem': {
- component: dynamicWrapper(app, ['tag/tag', 'merchant/merchant'], () => import('../routes/Tag/List')),
- },
- '/tag/tagItem/add': {
- component: dynamicWrapper(app, ['tag/detail', 'group/group'], () => import('../routes/Tag/Edit')),
- name: '创建标签',
- },
- '/tag/tagItem/edit/:id': {
- component: dynamicWrapper(app, ['tag/detail', 'group/group'], () => import('../routes/Tag/Edit')),
- name: '修改标签',
- },
- '/basic-product/ware': {
- component: dynamicWrapper(app, ['ware/ware'], () => import('../routes/Ware/List')),
- },
- '/basic-product/ware/add': {
- component: dynamicWrapper(app, ['ware/detail', 'resource'], () => import('../routes/Ware/Edit')),
- name: '创建课件',
- },
- '/basic-product/ware/edit/:id': {
- component: dynamicWrapper(app, ['ware/detail', 'resource'], () => import('../routes/Ware/Edit')),
- name: '修改课件',
- },
- '/basic-product/lesson': {
- component: dynamicWrapper(app, ['lesson/lesson'], () => import('../routes/Lesson/List')),
- },
- '/basic-product/lesson/add': {
- component: dynamicWrapper(app, ['lesson/detail', 'ware/ware'], () => import('../routes/Lesson/Edit')),
- name: '创建课',
- },
- '/basic-product/lesson/edit/:id': {
- component: dynamicWrapper(app, ['lesson/detail', 'ware/ware'], () => import('../routes/Lesson/Edit')),
- name: '修改课',
- },
- '/product/course': {
- component: dynamicWrapper(app, ['course/course'], () => import('../routes/Course/List')),
- },
- '/product/course/add': {
- component: dynamicWrapper(app, ['course/detail', 'resource', 'lesson/lesson', 'support/support', 'merchant/merchant'], () => import('../routes/Course/Edit')),
- name: '创建课程',
- },
- '/product/course/edit/:id': {
- component: dynamicWrapper(app, ['course/detail', 'resource', 'lesson/lesson', 'support/support', 'merchant/merchant'], () => import('../routes/Course/Edit')),
- name: '修改课程',
- },
- '/product/support': {
- component: dynamicWrapper(app, ['support/support'], () => import('../routes/Support/List')),
- },
- '/product/support/add': {
- component: dynamicWrapper(app, ['support/detail', 'resource', 'support/support', 'merchant/merchant'], () => import('../routes/Support/Edit')),
- name: '创建配套',
- },
- '/product/support/edit/:id': {
- component: dynamicWrapper(app, ['support/detail', 'resource', 'support/support', 'merchant/merchant'], () => import('../routes/Support/Edit')),
- name: '修改配套',
- },
- '/product/package': {
- component: dynamicWrapper(app, ['combo/combo'], () => import('../routes/Combo/List')),
- },
- '/product/package/add': {
- component: dynamicWrapper(app, ['combo/detail', 'product'], () => import('../routes/Combo/Edit')),
- name: '创建课程包',
- },
- '/product/package/edit/:id': {
- component: dynamicWrapper(app, ['combo/detail', 'product'], () => import('../routes/Combo/Edit')),
- name: '修改课程包',
- },
- '/goods': {
- component: dynamicWrapper(app, ['mproduct/mproduct', 'merchant/merchant'], () => import('../routes/MProduct/List')),
- },
- '/goods/add': {
- component: dynamicWrapper(app, ['course/course', 'support/support', 'combo/combo', 'merchant/merchant', 'mproduct/detail'], () => import('../routes/MProduct/Add')),
- name: '创建商品',
- },
- '/goods/edit': {
- component: dynamicWrapper(app, ['mproduct/detail', 'goods', 'tag/tag'], () => import('../routes/MProduct/Edit')),
- name: '修改商品',
- },
- '/order': {
- component: dynamicWrapper(app, ['order/order'], () => import('../routes/Order/List')),
- },
- '/order/add': {
- component: dynamicWrapper(app, ['order/detail', 'terminal/terminal', 'mproduct/mproduct'], () => import('../routes/Order/Add')),
- name: '新建订单',
- },
- // '/order/edit/:id': {
- // component: dynamicWrapper(app, ['order/detail'], () => import('../routes/Order/detail')),
- // name: '修改订单',
- // },
- // '/order/profile/:id': {
- // component: dynamicWrapper(app, ['order/detail'], () => import('../routes/Order/detail/orderProfile')),
- // name: '订单详情',
- // },
- '/sold': {
- component: dynamicWrapper(app, [], () => import('../routes/SoldProduct')),
- },
- '/user': {
- component: dynamicWrapper(app, [], () => import('../layouts/UserLayout')),
- },
- '/user/login': {
- component: dynamicWrapper(app, ['login'], () => import('../routes/Login')),
- },
- '/cms/user': {
- component: dynamicWrapper(app, ['cmsUser', 'merchant/merchant'], () => import('../routes/CmsUser')),
- },
- };
- // Get name from ./menu.js or just set it in the router data.
- const menuData = getFlatMenuData(getMenuData());
- const routerDataWithName = {};
- Object.keys(routerData).forEach((item) => {
- routerDataWithName[item] = {
- ...routerData[item],
- name: routerData[item].name || menuData[item.replace(/^\//, '')],
- };
- });
- return routerDataWithName;
- };
|