Skip to content

Commit

Permalink
feat: course14
Browse files Browse the repository at this point in the history
  • Loading branch information
aspirantzhang committed Mar 9, 2021
1 parent 3edea05 commit d2d707a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 39 deletions.
2 changes: 1 addition & 1 deletion config/defaultSettings.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Settings: LayoutSettings & {
title: 'Ant Design Pro', title: 'Ant Design Pro',
pwa: false, pwa: false,
logo: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg', logo: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg',
iconfontUrl: '', iconfontUrl: '//at.alicdn.com/t/font_2112134_uyx998l7ji.js',
}; };


export default Settings; export default Settings;
12 changes: 5 additions & 7 deletions config/routes.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@
component: './TableList', component: './TableList',
}, },
{ {
name: 'basic-list', path: '/basic-list/api/*/*',
icon: 'table', component: './BasicList/component/Page',
path: '/basic-list',
component: './BasicList',
}, },
{ {
name: 'single-page', name: 'basic-list',
icon: 'table', icon: 'table',
path: '/basic-list/api/admins/*', path: '/basic-list/*',
component: './BasicList/component/Page', component: './BasicList',
}, },
{ {
path: '/', path: '/',
Expand Down
47 changes: 19 additions & 28 deletions src/app.tsx
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { history } from 'umi';
import RightContent from '@/components/RightContent'; import RightContent from '@/components/RightContent';
import Footer from '@/components/Footer'; import Footer from '@/components/Footer';
import type { ResponseError } from 'umi-request'; import type { ResponseError } from 'umi-request';
import { currentUser as queryCurrentUser } from './services/ant-design-pro/api'; import {
import { BookOutlined, LinkOutlined } from '@ant-design/icons'; currentUser as queryCurrentUser,

currentMenu as queryCurrentMenu,
const isDev = process.env.NODE_ENV === 'development'; } from './services/ant-design-pro/api';


/** 获取用户信息比较慢的时候会展示一个 loading */ /** 获取用户信息比较慢的时候会展示一个 loading */
export const initialStateConfig = { export const initialStateConfig = {
Expand All @@ -23,6 +23,7 @@ export const initialStateConfig = {
export async function getInitialState(): Promise<{ export async function getInitialState(): Promise<{
settings?: Partial<LayoutSettings>; settings?: Partial<LayoutSettings>;
currentUser?: API.CurrentUser; currentUser?: API.CurrentUser;
currentMenu?: any;
fetchUserInfo?: () => Promise<API.CurrentUser | undefined>; fetchUserInfo?: () => Promise<API.CurrentUser | undefined>;
}> { }> {
const fetchUserInfo = async () => { const fetchUserInfo = async () => {
Expand All @@ -34,12 +35,23 @@ export async function getInitialState(): Promise<{
} }
return undefined; return undefined;
}; };
const fetchMenu = async () => {
try {
const currentMenu = await queryCurrentMenu();
return currentMenu;
} catch (error) {
message.error('Get menu data failed.', 10);
}
return undefined;
};
// 如果是登录页面,不执行 // 如果是登录页面,不执行
if (history.location.pathname !== '/user/login') { if (history.location.pathname !== '/user/login') {
const currentUser = await fetchUserInfo(); const currentUser = await fetchUserInfo();
const currentMenu = await fetchMenu();
return { return {
fetchUserInfo, fetchUserInfo,
currentUser, currentUser,
currentMenu,
settings: {}, settings: {},
}; };
} }
Expand All @@ -62,31 +74,10 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
history.push('/user/login'); history.push('/user/login');
} }
}, },
links: isDev
? [
<>
<LinkOutlined />
<span
onClick={() => {
window.open('/umi/plugin/openapi');
}}
>
openAPI 文档
</span>
</>,
<>
<BookOutlined />
<span
onClick={() => {
window.open('/~docs');
}}
>
业务组件文档
</span>
</>,
]
: [],
menuHeaderRender: undefined, menuHeaderRender: undefined,
menuDataRender: () => {
return initialState?.currentMenu;
},
// 自定义 403 页面 // 自定义 403 页面
// unAccessible: <div>unAccessible</div>, // unAccessible: <div>unAccessible</div>,
...initialState?.settings, ...initialState?.settings,
Expand Down
16 changes: 16 additions & 0 deletions src/locales/en-US/menu.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -50,4 +50,20 @@ export default {
'menu.editor.mind': 'Mind Editor', 'menu.editor.mind': 'Mind Editor',
'menu.editor.koni': 'Koni Editor', 'menu.editor.koni': 'Koni Editor',
'menu.basic-list': 'Admin List', 'menu.basic-list': 'Admin List',
'menu.admin-list': 'Admin List',
'menu.admin-list.edit': 'Admin Edit',
'menu.admin-list.add': 'Admin Add',
'menu.menu-list': 'Menu List',
'menu.menu-list.edit': 'Menu Edit',
'menu.menu-list.add': 'Menu Add',
'menu.group-list': 'Group List',
'menu.group-list.edit': 'Group Edit',
'menu.group-list.add': 'Group Add',
'menu.rule-list': 'Rule List',
'menu.rule-list.edit': 'Rule Edit',
'menu.rule-list.add': 'Rule Add',
'menu.model-list': 'Model List',
'menu.model-list.design': 'Model Design',
'menu.model-list.edit': 'Model Edit',
'menu.model-list.add': 'Model Add',
}; };
10 changes: 7 additions & 3 deletions src/pages/BasicList/index.tsx
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
Form, Form,
InputNumber, InputNumber,
} from 'antd'; } from 'antd';
import { useRequest, useIntl, history } from 'umi'; import { useRequest, useIntl, history, useLocation } from 'umi';
import { useSessionStorageState, useToggle } from 'ahooks'; import { useSessionStorageState, useToggle } from 'ahooks';
import { stringify } from 'query-string'; import { stringify } from 'query-string';
import { PageContainer, FooterToolbar } from '@ant-design/pro-layout'; import { PageContainer, FooterToolbar } from '@ant-design/pro-layout';
Expand Down Expand Up @@ -41,10 +41,14 @@ const Index = () => {
const { confirm } = AntdModal; const { confirm } = AntdModal;
const lang = useIntl(); const lang = useIntl();
const [searchForm] = Form.useForm(); const [searchForm] = Form.useForm();
const location = useLocation();


const init = useRequest<{ data: BasicListApi.ListData }>((values: any) => { const init = useRequest<{ data: BasicListApi.ListData }>((values: any) => {
return { return {
url: `https://public-api-v2.aspirantzhang.com/api/admins?X-API-KEY=antd${pageQuery}${sortQuery}`, url: `https://public-api-v2.aspirantzhang.com${location.pathname.replace(
'/basic-list',
'',
)}?X-API-KEY=antd${pageQuery}${sortQuery}`,
params: values, params: values,
paramsSerializer: (params: any) => { paramsSerializer: (params: any) => {
return stringify(params, { arrayFormat: 'comma', skipEmptyString: true, skipNull: true }); return stringify(params, { arrayFormat: 'comma', skipEmptyString: true, skipNull: true });
Expand Down Expand Up @@ -80,7 +84,7 @@ const Index = () => {


useEffect(() => { useEffect(() => {
init.run(); init.run();
}, [pageQuery, sortQuery]); }, [pageQuery, sortQuery, location.pathname]);


useEffect(() => { useEffect(() => {
if (init?.data?.layout?.tableColumn) { if (init?.data?.layout?.tableColumn) {
Expand Down
7 changes: 7 additions & 0 deletions src/services/ant-design-pro/api.ts
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export async function currentUser(options?: { [key: string]: any }) {
}); });
} }


export async function currentMenu(options?: { [key: string]: any }) {
return request('https://public-api-v2.aspirantzhang.com/api/menus/backend', {
method: 'GET',
...(options || {}),
});
}

/** 此处后端没有提供注释 GET /api/notices */ /** 此处后端没有提供注释 GET /api/notices */
export async function getNotices(options?: { [key: string]: any }) { export async function getNotices(options?: { [key: string]: any }) {
return request<API.NoticeIconList>('/api/notices', { return request<API.NoticeIconList>('/api/notices', {
Expand Down

0 comments on commit d2d707a

Please sign in to comment.