Skip to content

Commit

Permalink
feat(demo): 更新demo
Browse files Browse the repository at this point in the history
  • Loading branch information
stbui committed Jan 2, 2020
1 parent 5f09c6f commit 8692b79
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 124 deletions.
83 changes: 52 additions & 31 deletions examples/demo/src/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,63 @@ import { routes } from './routes';

const CustomMenu = props => {
const { hasDashboard, location } = props;
const renderMenu = () => {
const loop = data => {
return data.map(item => {
if (item.children) {
return (
<Menu.SubMenu
key={item.id}
title={
<span>
<Icon type={item.icon} />
{item.name}
</span>
}
>
{item.children.map(chid => {
if (chid.children) {
return (
<Menu.SubMenu
key={chid.id}
title={
<span>
<Icon type={chid.icon} />
<span>{chid.name}</span>
</span>
}
>
{loop(chid.children)}
</Menu.SubMenu>
);
}

return (
<Menu.Item key={chid.path}>
<Link to={chid.path}>{chid.name}</Link>
</Menu.Item>
);
})}
</Menu.SubMenu>
);
}

return (
<Menu.Item key={item.path}>
<Link to={item.path}>{item.name}</Link>
</Menu.Item>
);
});
};

return loop(routes);
};
return (
<Menu
theme="dark"
mode="inline"
selectedKeys={[location.pathname]}
defaultOpenKeys={[location.pathname.split('/')[1]]}
defaultSelectedKeys={[location.pathname]}
>
{hasDashboard && (
<Menu.Item>
Expand All @@ -21,36 +71,7 @@ const CustomMenu = props => {
</Link>
</Menu.Item>
)}
{routes.map(route => {
if (route.children) {
return (
<Menu.SubMenu
key={route.id}
title={
<span>
<Icon type={route.icon} />
{route.title}
</span>
}
>
{route.children.map(r => {
return (
<Menu.Item key={r.id}>
<Link to={r.url}>{r.title}</Link>
</Menu.Item>
);
})}
</Menu.SubMenu>
);
} else {
return (
<Menu.Item key={route.id}>
<Icon type={route.icon} />
<span>{route.title}</span>
</Menu.Item>
);
}
})}
{renderMenu()}
</Menu>
);
};
Expand Down
140 changes: 51 additions & 89 deletions examples/demo/src/Menu/routes.js
Original file line number Diff line number Diff line change
@@ -1,189 +1,151 @@
export const routes = [
{
id: 'goods',
title: '商品管理',
type: 'collapse',
name: '商品管理',
icon: 'alert',
children: [
{
id: 'list',
title: '商品列表',
type: 'item',
url: '/store',
name: '商品列表',
path: '/store',
},
{
id: 'category',
title: '商品分类',
type: 'item',
url: '/goods/category',
name: '商品分类',
path: '/goods/category',
},
{
id: 'comment',
title: '商品评价',
type: 'item',
url: '/goods/comment',
name: '商品评价',
path: '/goods/comment',
},
],
},
{
id: 'order',
title: '订单管理',
type: 'collapse',
name: '订单管理',
icon: 'appstore',
badge: {
title: '7',
bg: '#ff4081',
fg: '#fff',
},
children: [
{
id: 'orderlist',
title: '全部订单',
type: 'item',
url: '/order/list',
name: '全部订单',
path: '/order/list',
},
{
id: 'delivery',
title: '待发货',
type: 'item',
url: '/order/delivery',
name: '待发货',
path: '/order/delivery',
},
{
id: 'receipt',
title: '待收货',
type: 'item',
url: '/order/receipt',
name: '待收货',
path: '/order/receipt',
},
{
id: 'pay',
title: '待付款',
type: 'item',
url: '/order/pay',
name: '待付款',
path: '/order/pay',
},
{
id: 'complete',
title: '已完成',
type: 'item',
url: '/order/complete',
name: '已完成',
path: '/order/complete',
},
{
id: 'cancel',
title: 'cancel',
type: 'item',
url: '/order/cancel',
name: 'cancel',
path: '/order/cancel',
},
{
id: 'refund',
title: '售后管理',
type: 'item',
url: '/order/refund',
name: '售后管理',
path: '/order/refund',
},
],
},
{
id: 'user',
title: '用户管理',
type: 'collapse',
name: '用户管理',
icon: 'build',
badge: {
title: '2',
bg: '#ff6f00',
fg: '#fff',
},
children: [
{
id: 'list',
title: '用户列表',
type: 'item',
url: '/user/list',
name: '用户列表',
path: '/user/list',
},
{
id: 'grade',
title: '会员等级',
type: 'item',
url: '/user/grade',
name: '会员等级',
path: '/user/grade',
},
{
id: 'recharge',
title: '充值记录',
type: 'item',
url: '/user/recharge',
name: '充值记录',
path: '/user/recharge',
},
{
id: 'balance',
title: '余额明细',
type: 'item',
url: '/user/balance',
name: '余额明细',
path: '/user/balance',
},
],
},
{
id: 'market',
title: '营销管理',
type: 'collapse',
name: '营销管理',
icon: 'database',
children: [
{
id: 'coupon',
title: '优惠券列表',
type: 'item',
url: '/market/coupon',
name: '优惠券列表',
path: '/market/coupon',
},
],
},
{
id: 'setting',
title: '设置',
type: 'collapse',
name: '设置',
icon: 'eye',
children: [
{
id: 'store',
title: '商城设置',
type: 'item',
url: '/setting/store',
name: '商城设置',
path: '/setting/store',
},
{
id: 'trade',
title: '交易设置',
type: 'item',
url: '/setting/trade',
name: '交易设置',
path: '/setting/trade',
},
{
id: 'delivery',
title: '运费模板',
type: 'item',
url: '/setting/delivery',
name: '运费模板',
path: '/setting/delivery',
},
{
id: 'express',
title: '物流公司',
type: 'item',
url: '/setting/express',
name: '物流公司',
path: '/setting/express',
},
{
id: 'sms',
title: '短信通知',
type: 'item',
url: '/setting/sms',
name: '短信通知',
path: '/setting/sms',
},
{
id: 'tplmsg',
title: '模板消息',
type: 'item',
url: '/setting/tplmsg',
name: '模板消息',
path: '/setting/tplmsg',
},
{
id: 'address',
title: '退货地址',
type: 'item',
url: '/setting/address',
name: '退货地址',
path: '/setting/address',
},
{
id: 'storage',
title: '上传设置',
type: 'item',
url: '/setting/storage',
name: '上传设置',
path: '/setting/storage',
},
],
},
Expand Down
4 changes: 4 additions & 0 deletions examples/demo/src/authProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default {
},

checkAuth: () => {
// return localStorage.getItem('username')
// ? Promise.resolve()
// : Promise.reject({redirectTo: '/configuration'});

return localStorage.getItem('username')
? Promise.resolve()
: Promise.reject();
Expand Down
11 changes: 9 additions & 2 deletions examples/demo/src/dataProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@

// export default dataProvider;

import { GET_LIST, GET_ONE, CREATE, UPDATE, DELETE } from '@stbui/prophet';
import {
GET_LIST,
GET_ONE,
CREATE,
UPDATE,
DELETE,
fetchUtils,
} from '@stbui/prophet';

const list = {
data: Array.from(Array(200).keys()).map(id => {
Expand All @@ -20,7 +27,7 @@ const list = {
total: 200,
};

const dataProvider = (apiUrl = './api', httpClient = fetch) => {
const dataProvider = (apiUrl = './api', httpClient = fetchUtils.fetchJson) => {
return (type, resource, params) => {
switch (type) {
case GET_LIST:
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { Route } from 'react-router-dom';
import Configuration from './configuration/Configuration';

export default [
<Route exact path="/configuration" render={() => <Configuration />} />,
<Route exact path="/configuration" noLayout render={() => <Configuration />} />,
];
3 changes: 2 additions & 1 deletion packages/core/src/core/CoreRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ const CoreRouter: FunctionComponent<CoreRouterProps> = ({
})
)}
<Route
render={() =>
render={routeProps =>
createElement<any>(
layout,
{
...routeProps,
dashboard,
menu,
title,
Expand Down

0 comments on commit 8692b79

Please sign in to comment.