Commit e2f62c6d authored by afc163's avatar afc163

refactor menu data

parent eb9881d6
......@@ -30,151 +30,140 @@ import Login from '../routes/User/Login';
import Register from '../routes/User/Register';
import RegisterResult from '../routes/User/RegisterResult';
function userAdapter(userData) {
userData.children.forEach((item) => {
if (item.children) {
userAdapter(item);
} else {
const userItem = item;
userItem.noRoute = true;
}
});
return userData;
}
export const user = [{
name: '帐户',
icon: 'user',
path: 'user',
children: [{
name: '登录',
path: 'login',
component: Login,
}, {
name: 'ζ³¨ε†Œ',
path: 'register',
component: Register,
}, {
name: 'ζ³¨ε†Œη»“ζžœ',
path: 'register-result',
component: RegisterResult,
}],
}];
export const menus = [{
name: 'Dashboard',
icon: 'dashboard',
path: 'dashboard',
children: [{
name: 'εˆ†ζžι‘΅',
path: 'analysis',
component: Analysis,
}, {
name: 'η›‘ζŽ§ι‘΅',
path: 'monitor',
component: Monitor,
}, {
name: 'ε·₯作台',
path: 'workplace',
component: Workplace,
}],
}, {
name: '葨单鑡',
path: 'form',
icon: 'form',
const data = [{
component: BasicLayout,
name: 'ι¦–ι‘΅', // for breadcrumb
path: '',
children: [{
name: 'εŸΊη‘€θ‘¨ε•',
path: 'basic-form',
component: BasicForm,
}, {
name: 'εˆ†ζ­₯葨单',
path: 'step-form',
component: StepForm,
name: 'Dashboard',
icon: 'dashboard',
path: 'dashboard',
children: [{
path: 'confirm',
component: Step2,
name: 'εˆ†ζžι‘΅',
path: 'analysis',
component: Analysis,
}, {
name: 'η›‘ζŽ§ι‘΅',
path: 'monitor',
component: Monitor,
}, {
path: 'result',
component: Step3,
name: 'ε·₯作台',
path: 'workplace',
component: Workplace,
}],
}, {
name: 'ι«˜ηΊ§θ‘¨ε•',
path: 'advanced-form',
component: AdvancedForm,
}],
}, {
name: 'εˆ—θ‘¨ι‘΅',
path: 'list',
icon: 'table',
children: [{
name: 'ζ ‡ε‡†θ‘¨ζ ΌοΌˆθ‘¨ζ ΌζŸ₯θ―’οΌ‰',
path: 'table-list',
component: TableList,
}, {
name: 'ζ ‡ε‡†εˆ—θ‘¨',
path: 'basic-list',
component: BasicList,
}, {
name: 'ε‘η‰‡εˆ—θ‘¨',
path: 'card-list',
component: CardList,
name: '葨单鑡',
path: 'form',
icon: 'form',
children: [{
name: 'εŸΊη‘€θ‘¨ε•',
path: 'basic-form',
component: BasicForm,
}, {
name: 'εˆ†ζ­₯葨单',
path: 'step-form',
component: StepForm,
children: [{
path: 'confirm',
component: Step2,
}, {
path: 'result',
component: Step3,
}],
}, {
name: 'ι«˜ηΊ§θ‘¨ε•',
path: 'advanced-form',
component: AdvancedForm,
}],
}, {
name: 'ε‘η‰‡εˆ—θ‘¨οΌˆε°ι’οΌ‰',
path: 'cover-card-list',
component: CoverCardList,
name: 'εˆ—θ‘¨ι‘΅',
path: 'list',
icon: 'table',
children: [{
name: 'ζ ‡ε‡†θ‘¨ζ ΌοΌˆθ‘¨ζ ΌζŸ₯θ―’οΌ‰',
path: 'table-list',
component: TableList,
}, {
name: 'ζ ‡ε‡†εˆ—θ‘¨',
path: 'basic-list',
component: BasicList,
}, {
name: 'ε‘η‰‡εˆ—θ‘¨',
path: 'card-list',
component: CardList,
}, {
name: 'ε‘η‰‡εˆ—θ‘¨οΌˆε°ι’οΌ‰',
path: 'cover-card-list',
component: CoverCardList,
}, {
name: 'εΈ¦η­›ι€‰ε‘η‰‡εˆ—θ‘¨',
path: 'filter-card-list',
component: FilterCardList,
}, {
name: 'ζœη΄’εˆ—θ‘¨',
path: 'search',
component: SearchList,
}],
}, {
name: 'εΈ¦η­›ι€‰ε‘η‰‡εˆ—θ‘¨',
path: 'filter-card-list',
component: FilterCardList,
name: 'θ―¦ζƒ…ι‘΅',
path: 'profile',
component: Profile,
icon: 'profile',
}, {
name: 'ζœη΄’εˆ—θ‘¨',
path: 'search',
component: SearchList,
}],
}, {
name: 'θ―¦ζƒ…ι‘΅',
path: 'profile',
component: Profile,
icon: 'profile',
}, {
name: 'η»“ζžœ',
path: 'result',
icon: 'check-circle-o',
children: [{
name: '成功',
path: 'success',
component: Success,
name: 'η»“ζžœ',
path: 'result',
icon: 'check-circle-o',
children: [{
name: '成功',
path: 'success',
component: Success,
}, {
name: 'ε€±θ΄₯',
path: 'fail',
component: Error,
}],
}, {
name: 'ε€±θ΄₯',
path: 'fail',
component: Error,
name: 'ι”™θ――',
path: 'error',
icon: 'warning',
children: [{
name: '403',
path: '403',
component: Exception403,
}, {
name: '404',
path: '404',
component: Exception404,
}, {
name: '500',
path: '500',
component: Exception500,
}],
}],
}, {
name: 'ι”™θ――',
path: 'error',
icon: 'warning',
component: UserLayout,
children: [{
name: '403',
path: '403',
component: Exception403,
}, {
name: '404',
path: '404',
component: Exception404,
}, {
name: '500',
path: '500',
component: Exception500,
name: '帐户',
icon: 'user',
path: 'user',
children: [{
name: '登录',
path: 'login',
component: Login,
}, {
name: 'ζ³¨ε†Œ',
path: 'register',
component: Register,
}, {
name: 'ζ³¨ε†Œη»“ζžœ',
path: 'register-result',
component: RegisterResult,
}],
}],
}, userAdapter(JSON.parse(JSON.stringify(user[0])))];
export default [{
component: BasicLayout,
name: 'ι¦–ι‘΅',
children: menus,
path: '',
}, {
component: UserLayout,
name: '账户',
children: user,
}];
export function getNavData() {
return data;
}
export default data;
......@@ -10,7 +10,7 @@ import styles from './BasicLayout.less';
import HeaderSearch from '../components/HeaderSearch';
import NoticeIcon from '../components/NoticeIcon';
import GlobalFooter from '../components/GlobalFooter';
import { menus } from '../common/nav';
import { getNavData } from '../common/nav';
const { Header, Sider, Content } = Layout;
const { SubMenu } = Menu;
......@@ -20,6 +20,11 @@ class BasicLayout extends React.PureComponent {
routes: PropTypes.array,
params: PropTypes.object,
}
constructor(props) {
super(props);
// ζŠŠδΈ€ηΊ§ Layout ηš„ children δ½œδΈΊθœε•ι‘Ή
this.menus = getNavData().reduce((arr, current) => arr.concat(current.children), []);
}
state = {
mode: 'inline',
};
......@@ -52,11 +57,14 @@ class BasicLayout extends React.PureComponent {
const { location: { pathname } } = this.props;
const keys = pathname.split('/').slice(1);
if (keys.length === 1 && keys[0] === '') {
return [menus[0].key];
return [this.menus[0].key];
}
return keys;
}
getNavMenuItems(menusData, parentPath = '') {
if (!menusData) {
return [];
}
return menusData.map((item) => {
if (!item.name) {
return null;
......@@ -186,7 +194,7 @@ class BasicLayout extends React.PureComponent {
style={{ margin: '24px 0', width: '100%' }}
inlineIndent={32}
>
{this.getNavMenuItems(menus)}
{this.getNavMenuItems(this.menus)}
</Menu>
</Sider>
<Layout>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment