From 5ef482edd8648688cde6e9175710e3b233841d47 Mon Sep 17 00:00:00 2001 From: xiaohu <448627663@qq.com> Date: Sat, 7 Jul 2018 14:42:20 +0800 Subject: [PATCH] 1.add step-form layout 2.add routes redirect --- config/config.js | 4 ++ src/common/menu.js | 29 ++++++++++--- src/models/form.js | 2 +- src/pages/Forms/StepForm/Step1.js | 2 +- src/pages/Forms/StepForm/Step2.js | 2 +- src/pages/Forms/StepForm/Step3.js | 2 +- .../Forms/StepForm/{index.js => _layout.js} | 18 ++++---- src/pages/_routes.json | 42 +++++++++++++++++++ 8 files changed, 83 insertions(+), 18 deletions(-) rename src/pages/Forms/StepForm/{index.js => _layout.js} (84%) create mode 100644 src/pages/_routes.json diff --git a/config/config.js b/config/config.js index a6300dcc..9fed9972 100644 --- a/config/config.js +++ b/config/config.js @@ -3,6 +3,7 @@ // https://umijs.org/config/ const path = require('path'); +const pageRoutes = require('../src/pages/_routes'); export default { // add for transfer to umi @@ -13,6 +14,9 @@ export default { 'umi-plugin-routes', { exclude: [/\.test\.js/], + update(routes) { + return [...pageRoutes, ...routes]; + }, }, ], ], diff --git a/src/common/menu.js b/src/common/menu.js index abcbe9eb..6c78a950 100644 --- a/src/common/menu.js +++ b/src/common/menu.js @@ -194,6 +194,7 @@ import { isUrl } from '../utils/utils'; +// TODO: authority const menuData = [ { name: 'dashboard', @@ -211,6 +212,7 @@ const menuData = [ { name: '工作台', path: 'Workplace', + // hideInBreadcrumb: true, // hideInMenu: true, }, ], @@ -226,11 +228,11 @@ const menuData = [ }, { name: '分步表单', - path: 'StepForm/Step1', + path: 'StepForm', }, { name: '高级表单', - authority: 'admin', + // authority: 'admin', path: 'AdvancedForm', }, ], @@ -246,7 +248,7 @@ const menuData = [ }, { name: '标准列表', - path: 'BasicList', + path: 'basicList', }, { name: '卡片列表', @@ -279,11 +281,11 @@ const menuData = [ children: [ { name: '基础详情页', - path: 'BasicProfile', + path: 'Basic', }, { name: '高级详情页', - path: 'AdvancedProfile', + path: 'Advanced', authority: 'admin', }, ], @@ -299,7 +301,7 @@ const menuData = [ }, { name: '失败', - path: 'Error', + path: 'Fail', }, ], }, @@ -347,6 +349,21 @@ const menuData = [ }, ], }, + { + name: '个人页', + icon: 'user', + path: 'Account', + children: [ + { + name: '个人中心', + path: 'Center', + }, + { + name: '个人设置', + path: 'Settings', + }, + ], + }, ]; function formatter(data, parentPath = '/', parentAuthority) { diff --git a/src/models/form.js b/src/models/form.js index 64a1d497..d849f802 100644 --- a/src/models/form.js +++ b/src/models/form.js @@ -25,7 +25,7 @@ export default { type: 'saveStepFormData', payload, }); - yield put(routerRedux.push('/form/step-form/result')); + yield put(routerRedux.push('/Forms/StepForm/Step3')); }, *submitAdvancedForm({ payload }, { call }) { yield call(fakeSubmitForm, payload); diff --git a/src/pages/Forms/StepForm/Step1.js b/src/pages/Forms/StepForm/Step1.js index 5082c1a3..0f572396 100644 --- a/src/pages/Forms/StepForm/Step1.js +++ b/src/pages/Forms/StepForm/Step1.js @@ -27,7 +27,7 @@ class Step1 extends React.PureComponent { type: 'form/saveStepFormData', payload: values, }); - dispatch(routerRedux.push('/form/step-form/confirm')); + dispatch(routerRedux.push('/Forms/StepForm/Step2')); } }); }; diff --git a/src/pages/Forms/StepForm/Step2.js b/src/pages/Forms/StepForm/Step2.js index 9b142007..9daa3fe0 100644 --- a/src/pages/Forms/StepForm/Step2.js +++ b/src/pages/Forms/StepForm/Step2.js @@ -20,7 +20,7 @@ class Step2 extends React.PureComponent { const { form, data, dispatch, submitting } = this.props; const { getFieldDecorator, validateFields } = form; const onPrev = () => { - dispatch(routerRedux.push('/form/step-form')); + dispatch(routerRedux.push('/Forms/StepForm')); }; const onValidateForm = e => { e.preventDefault(); diff --git a/src/pages/Forms/StepForm/Step3.js b/src/pages/Forms/StepForm/Step3.js index 9a8d6d46..eb8afeac 100644 --- a/src/pages/Forms/StepForm/Step3.js +++ b/src/pages/Forms/StepForm/Step3.js @@ -9,7 +9,7 @@ class Step3 extends React.PureComponent { render() { const { dispatch, data } = this.props; const onFinish = () => { - dispatch(routerRedux.push('/form/step-form')); + dispatch(routerRedux.push('/Forms/StepForm')); }; const information = (
diff --git a/src/pages/Forms/StepForm/index.js b/src/pages/Forms/StepForm/_layout.js similarity index 84% rename from src/pages/Forms/StepForm/index.js rename to src/pages/Forms/StepForm/_layout.js index 51983dac..e71e0e96 100644 --- a/src/pages/Forms/StepForm/index.js +++ b/src/pages/Forms/StepForm/_layout.js @@ -1,10 +1,11 @@ import React, { PureComponent, Fragment } from 'react'; -import { Route, Redirect, Switch } from 'dva/router'; import { Card, Steps } from 'antd'; import PageHeaderLayout from '../../../layouts/PageHeaderLayout'; -import { getRoutes } from '../../../utils/utils'; import styles from '../style.less'; +// import { Route, Redirect, Switch } from 'dva/router'; +// import { getRoutes } from '../../../utils/utils'; + const { Step } = Steps; export default class StepForm extends PureComponent { @@ -13,11 +14,11 @@ export default class StepForm extends PureComponent { const { pathname } = location; const pathList = pathname.split('/'); switch (pathList[pathList.length - 1]) { - case 'info': + case 'Step1': return 0; - case 'confirm': + case 'Step2': return 1; - case 'result': + case 'Step3': return 2; default: return 0; @@ -25,7 +26,7 @@ export default class StepForm extends PureComponent { } render() { - const { match, routerData, location } = this.props; + const { location, children } = this.props; return ( - + {children} + {/* {getRoutes(match.path, routerData).map(item => ( - + */} diff --git a/src/pages/_routes.json b/src/pages/_routes.json new file mode 100644 index 00000000..3ac872b2 --- /dev/null +++ b/src/pages/_routes.json @@ -0,0 +1,42 @@ +[ + { + "path": "/Dashboard", + "exact": true, + "redirect": "/Dashboard/Analysis" + }, + { + "path": "/Forms", + "exact": true, + "redirect": "/Forms/BasicForm" + }, + { + "path": "/Forms/StepForm", + "exact": true, + "redirect": "/Forms/StepForm/Step1" + }, + { + "path": "/List", + "exact": true, + "redirect": "/List/TableList" + }, + { + "path": "/List/Search", + "exact": true, + "redirect": "/List/Search/Articles" + }, + { + "path": "/Profile", + "exact": true, + "redirect": "/Profile/BasicProfile" + }, + { + "path": "/Result", + "exact": true, + "redirect": "/Result/Success" + }, + { + "path": "/Exception", + "exact": true, + "redirect": "/Exception/403" + } +] -- GitLab