-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add bug-breadcrumb-link folder
- Loading branch information
Showing
105 changed files
with
8,027 additions
and
1,011 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: <PageLoading />, | ||
// }; | ||
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<LayoutSettings>; | ||
currentUser?: API.CurrentUser; | ||
loading?: boolean; | ||
fetchUserInfo?: () => Promise<API.CurrentUser | undefined>; | ||
}> { | ||
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: () => <RightContent />, | ||
disableContentMargin: false, | ||
waterMarkProps: { | ||
content: initialState?.currentUser?.name, | ||
export const locale = { | ||
textComponent: 'h1', | ||
onError: () => { | ||
console.log('error handler...'); | ||
}, | ||
// locale: string | ||
// formats: CustomFormats | ||
// messages: Record<string, string> | Record<string, MessageFormatElement[]> | ||
// defaultLocale: string | ||
// defaultFormats: CustomFormats | ||
// timeZone?: string | ||
// textComponent?: React.ComponentType | keyof React.ReactHTML | ||
// wrapRichTextChunksInFragment?: boolean | ||
// defaultRichTextElements?: Record<string, FormatXMLElementFn<React.ReactNode>> | ||
// 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: () => <Footer />, | ||
onPageChange: () => { | ||
const { location } = history; | ||
// 如果没有登录,重定向到 login | ||
// if (!initialState?.currentUser && location.pathname !== loginPath) { | ||
// history.push(loginPath); | ||
// } | ||
(url, options) => { | ||
console.log(url, options); | ||
return { url, options }; | ||
}, | ||
links: isDev | ||
? [ | ||
<Link to="/umi/plugin/openapi" target="_blank"> | ||
<LinkOutlined /> | ||
<span>OpenAPI 文档</span> | ||
</Link>, | ||
<Link to="/~docs"> | ||
<BookOutlined /> | ||
<span>业务组件文档</span> | ||
</Link>, | ||
] | ||
: [], | ||
menuHeaderRender: undefined, | ||
// 自定义 403 页面 | ||
// unAccessible: <div>unAccessible</div>, | ||
// 增加一个 loading 的状态 | ||
childrenRender: (children, props) => { | ||
// if (initialState?.loading) return <PageLoading />; | ||
return ( | ||
<> | ||
{children} | ||
{!props.location?.pathname?.includes('/login') && ( | ||
<SettingDrawer | ||
enableDarkTheme | ||
settings={initialState?.settings} | ||
onSettingChange={(settings) => { | ||
setInitialState((preInitialState) => ({ | ||
...preInitialState, | ||
settings, | ||
})); | ||
}} | ||
/> | ||
)} | ||
</> | ||
); | ||
], | ||
responseInterceptors: [ | ||
(res) => { | ||
console.log('responseInterceptor', res); | ||
return res; | ||
}, | ||
...initialState?.settings, | ||
}; | ||
], | ||
errorConfig: { | ||
errorHandler: (error: any, opts: any) => { | ||
if (opts?.skipErrorHandler) throw error; | ||
// 我们的 errorThrow 抛出的错误。 | ||
if (error.name === 'BizError') { | ||
const errorInfo: ResponseStructure | undefined = error.info; | ||
if (errorInfo) { | ||
const { errorMessage, errorCode } = errorInfo; | ||
switch (errorInfo.showType) { | ||
case ErrorShowType.SILENT: | ||
// do nothong | ||
break; | ||
case ErrorShowType.WARN_MESSAGE: | ||
message.warn(errorMessage); | ||
break; | ||
case ErrorShowType.ERROR_MESSAGE: | ||
message.error(errorMessage); | ||
break; | ||
case ErrorShowType.NOTIFICATION: | ||
notification.open({ | ||
description: errorMessage, | ||
message: errorCode, | ||
}); | ||
break; | ||
case ErrorShowType.REDIRECT: | ||
// TODO: redirect | ||
break; | ||
default: | ||
message.error(errorMessage); | ||
} | ||
} | ||
} else if (error.response) { | ||
// Axios 的错误 | ||
// 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围 | ||
message.error('Response status:', error.response.status); | ||
} else if (error.request) { | ||
// 请求已经成功发起,但没有收到响应 | ||
// \`error.request\` 在浏览器中是 XMLHttpRequest 的实例, | ||
// 而在node.js中是 http.ClientRequest 的实例 | ||
message.error('None response! Please retry.'); | ||
} else { | ||
// 发送请求时出了点问题 | ||
message.error('Request error, please retry.'); | ||
} | ||
}, | ||
errorThrower: (res: ResponseStructure) => { | ||
const { success, data, errorCode, errorMessage, showType } = res; | ||
if (!success) { | ||
const error: any = new Error(errorMessage); | ||
error.name = 'BizError'; | ||
error.info = { errorCode, errorMessage, showType, data }; | ||
throw error; | ||
} | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// https://umijs.org/config/ | ||
// import { defineConfig } from 'umi'; | ||
|
||
export default { | ||
// plugins: [ | ||
// // https://github.com/zthxxx/react-dev-inspector | ||
// 'react-dev-inspector/plugins/umi/react-inspector', | ||
// ], | ||
// // https://github.com/zthxxx/react-dev-inspector#inspector-loader-props | ||
// inspectorConfig: { | ||
// exclude: [], | ||
// babelPlugins: [], | ||
// babelOptions: {}, | ||
// }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// https://umijs.org/config/ | ||
import MonacoEditorWebpackPlugin from 'monaco-editor-webpack-plugin'; | ||
import { defineConfig } from 'umi'; | ||
import defaultSettings from './defaultSettings'; | ||
import proxy from './proxy'; | ||
const { REACT_APP_ENV } = process.env; | ||
|
||
export default defineConfig({ | ||
hash: true, | ||
model: {}, | ||
antd: {}, | ||
request: {}, | ||
initialState: {}, | ||
mock: { | ||
include: ['src/pages/**/_mock.ts'], | ||
}, | ||
dva: { | ||
// hmr: true, | ||
}, | ||
srcTranspiler: 'esbuild', | ||
layout: { | ||
// https://umijs.org/zh-CN/plugins/plugin-layout | ||
locale: true, | ||
siderWidth: 208, | ||
...defaultSettings, | ||
}, | ||
// https://umijs.org/zh-CN/plugins/plugin-locale | ||
locale: { | ||
// default zh-CN | ||
default: 'zh-CN', | ||
antd: true, | ||
// default true, when it is true, will use `navigator.language` overwrite default | ||
baseNavigator: true, | ||
}, | ||
// dynamicImport: { | ||
// loading: '@ant-design/pro-components/es/PageLoading', | ||
// }, | ||
targets: { | ||
// TODO: vite mode don't support ie 11 | ||
// ie: 11, | ||
}, | ||
// umi routes: https://umijs.org/docs/routing | ||
routes: [ | ||
{ | ||
name: '首页', | ||
path: '/home', | ||
routes: [ | ||
{ | ||
name: 'c', | ||
path: '/home/c', | ||
component: './Home/c', | ||
}, | ||
{ | ||
name: 'd', | ||
path: '/home/d', | ||
component: './Home/d', | ||
}, | ||
], | ||
}, | ||
], | ||
// Theme for antd: https://ant.design/docs/react/customize-theme-cn | ||
theme: { | ||
'root-entry-name': 'variable', | ||
}, | ||
// esbuild is father build tools | ||
// https://umijs.org/plugins/plugin-esbuild | ||
// esbuild: {}, | ||
// title: false, | ||
ignoreMomentLocale: true, | ||
// @ts-ignore | ||
proxy: proxy[REACT_APP_ENV || 'dev'], | ||
manifest: { | ||
basePath: '/', | ||
}, | ||
// Fast Refresh 热更新 | ||
fastRefresh: true, | ||
mfsu: { | ||
// esbuild: true, | ||
}, | ||
chainWebpack(memo: any) { | ||
memo.plugin('monaco-editor').use(MonacoEditorWebpackPlugin, []); | ||
return memo; | ||
}, | ||
// openAPI: [ | ||
// { | ||
// requestLibPath: "import { request } from 'umi'", | ||
// // 或者使用在线的版本 | ||
// // schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json" | ||
// schemaPath: join(__dirname, 'oneapi.json'), | ||
// mock: false, | ||
// }, | ||
// { | ||
// requestLibPath: "import { request } from 'umi'", | ||
// schemaPath: 'https://gw.alipayobjects.com/os/antfincdn/CA1dOm%2631B/openapi.json', | ||
// projectName: 'swagger', | ||
// }, | ||
// ], | ||
// nodeModulesTransform: { | ||
// type: 'none', | ||
// }, | ||
// exportStatic: {}, | ||
codeSplitting: { | ||
jsStrategy: 'granularChunks', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Settings as LayoutSettings } from '@ant-design/pro-components'; | ||
|
||
const Settings: LayoutSettings & { | ||
pwa?: boolean; | ||
logo?: string; | ||
} = { | ||
navTheme: 'light', | ||
// 拂晓蓝 | ||
colorPrimary: '#1890ff', | ||
layout: 'mix', | ||
contentWidth: 'Fluid', | ||
fixedHeader: false, | ||
fixSiderbar: true, | ||
colorWeak: false, | ||
title: 'Ant Design Pro', | ||
pwa: false, | ||
logo: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg', | ||
iconfontUrl: '', | ||
}; | ||
|
||
export default Settings; |
Oops, something went wrong.