diff --git a/examples/ant-design-pro/src/app.tsx b/examples/ant-design-pro/src/app.tsx index 0848c9e0d5f7..55b9a051990d 100644 --- a/examples/ant-design-pro/src/app.tsx +++ b/examples/ant-design-pro/src/app.tsx @@ -1,109 +1,137 @@ -import Footer from '@/components/Footer'; -import RightContent from '@/components/RightContent'; -import { BookOutlined, LinkOutlined } from '@ant-design/icons'; -import type { Settings as LayoutSettings } from '@ant-design/pro-components'; -import { SettingDrawer } from '@ant-design/pro-components'; -import type { RunTimeLayoutConfig } from 'umi'; -import { history, Link } from 'umi'; -import { currentUser as queryCurrentUser } from './services/ant-design-pro/api'; +// @ts-ignore +import type { RequestConfig } from '@@/plugin-request'; +import { message } from 'antd'; +import { notification } from 'antd/es'; -const isDev = process.env.NODE_ENV === 'development'; -const loginPath = '/user/login'; - -// TODO: 不知道这是啥? -/** 获取用户信息比较慢的时候会展示一个 loading */ -// export const initialStateConfig = { -// loading: , -// }; +async function delay(ms: number) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} -/** - * @see https://umijs.org/zh-CN/plugins/plugin-initial-state - * */ -export async function getInitialState(): Promise<{ - settings?: Partial; - currentUser?: API.CurrentUser; - loading?: boolean; - fetchUserInfo?: () => Promise; -}> { - const fetchUserInfo = async () => { - try { - const msg = await queryCurrentUser(); - return msg.data; - } catch (error) { - history.push(loginPath); - } - return undefined; - }; - // 如果是登录页面,不执行 - if (history.location.pathname !== loginPath) { - const currentUser = await fetchUserInfo(); - return { - fetchUserInfo, - currentUser, - settings: { layout: 'mix' }, - }; - } +export async function getInitialState() { + await delay(500); return { - fetchUserInfo, - settings: { layout: 'mix' }, + name: 'Big Fish', + size: 'big', + color: 'blue', + mood: 'happy', + food: 'fish', + location: 'sea', }; } -// ProLayout 支持的api https://procomponents.ant.design/components/layout -export const layout: RunTimeLayoutConfig = ({ - initialState, - setInitialState, -}) => { - return { - rightContentRender: () => , - disableContentMargin: false, - waterMarkProps: { - content: initialState?.currentUser?.name, +export const locale = { + textComponent: 'h1', + onError: () => { + console.log('error handler...'); + }, + // locale: string + // formats: CustomFormats + // messages: Record | Record + // defaultLocale: string + // defaultFormats: CustomFormats + // timeZone?: string + // textComponent?: React.ComponentType | keyof React.ReactHTML + // wrapRichTextChunksInFragment?: boolean + // defaultRichTextElements?: Record> + // onError(err: string): void +}; + +export const layout = { + logout() { + alert('logout'); + }, +}; + +export function onRouteChange(opts: any) { + console.log('route changed', opts.location.pathname); +} + +enum ErrorShowType { + SILENT = 0, + WARN_MESSAGE = 1, + ERROR_MESSAGE = 2, + NOTIFICATION = 3, + REDIRECT = 9, +} + +interface ResponseStructure { + success: boolean; + data: any; + errorCode?: number; + errorMessage?: string; + showType?: number; +} + +export const request: RequestConfig = { + requestInterceptors: [ + (config) => { + console.log('Interceptor:', config); + return config; }, - footerRender: () =>