* refactor: fields/views/pages... * update * update * update * updates * updates * add yarn.lock * updates * updates * updates * updates * updates * updates * updates * updates * updates * developerMode * 一大波更新 * bugfix * fix: hide the sorting settings * fix: reload menu when menu is updated * 页面重构 * modify text * 补充细节 * system settings * 继续更新补充 * fix: 多级菜单支持 * 无限嵌套 * fix: icon * 省市区参数调整 * 表单描述、文案调整 * 支持草稿 * 邮箱登录 * 细节补充 * 菜单页面权限初步 * 详情页打开方式 * 菜单父级、草稿问题 * 描述文字 * 详情分组显示 * 状态改为 radio * 菜单权限 * 跳过省市区 api * 修复权限数据范围 * onDraft * 页面跳转 * 修改文案 * 注册、登录 * fix: 权限过滤问题 * 微调上传组件样式 * 0.4.0-alpha.0 * father-build * remove father-build * 细节调整
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import React from 'react';
|
|
import api from '@/api-client';
|
|
import { useRequest, useLocation, useHistory, Redirect } from 'umi';
|
|
import get from 'lodash/get';
|
|
import { TopMenuLayout } from './TopMenuLayout';
|
|
import { SideMenuLayout } from './SideMenuLayout';
|
|
import Page from './Page';
|
|
import pathToRegexp from 'path-to-regexp'
|
|
import { Spin } from '@nocobase/client';
|
|
|
|
export function AdminLoader(props: any) {
|
|
const { data = [], error, loading, run } = useRequest(() => api.resource('menus').getTree());
|
|
(window as any).reloadMenu = async () => {
|
|
await run();
|
|
};
|
|
const { lastPage: { path } } = props;
|
|
const location = useLocation();
|
|
const match = pathToRegexp(`${path}/:path?/:rowId?/:tabId?`).exec(location.pathname);
|
|
const pageName = match[1]||null;
|
|
const history = useHistory();
|
|
|
|
const currentRowId = match[2]||null;
|
|
const items = data
|
|
// .filter(item => item.type !== 'group' || (item.children && item.children.length))
|
|
;
|
|
const sideMenu = items.find(item => {
|
|
if (item.paths && item.paths.includes(pageName)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
});
|
|
console.log({pageName, sideMenu})
|
|
|
|
if (loading) {
|
|
return <Spin/>
|
|
}
|
|
|
|
if (!pageName) {
|
|
return <Redirect to={`/admin/${get(items, [0, 'path'])}`}/>;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<TopMenuLayout currentPageName={pageName} {...props} menu={items}>
|
|
{sideMenu ? (
|
|
<SideMenuLayout currentPageName={pageName} {...props} menuId={sideMenu.id} menu={sideMenu.children}>
|
|
<Page currentRowId={currentRowId} pageName={pageName}></Page>
|
|
</SideMenuLayout>
|
|
) : (
|
|
<Page pageName={pageName}></Page>
|
|
)}
|
|
</TopMenuLayout>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default AdminLoader;
|