From edfa49f201d3fc8fc6b51b700e91f80246660855 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 13 二月 2024 20:29:14 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/App.jsx | 217 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 210 insertions(+), 7 deletions(-)
diff --git a/zy-asrs-flow/src/App.jsx b/zy-asrs-flow/src/App.jsx
index ad00d3b..6892f48 100644
--- a/zy-asrs-flow/src/App.jsx
+++ b/zy-asrs-flow/src/App.jsx
@@ -1,11 +1,214 @@
+import React from 'react';
+import { Footer, Question, SelectLang, AvatarDropdown, AvatarName } from '@/components';
+import { LinkOutlined } from '@ant-design/icons';
+import { SettingDrawer } from '@ant-design/pro-components';
+import { history, Link } from '@umijs/max';
+import defaultSettings from '../config/defaultSettings';
+import { errorConfig } from './requestErrorConfig';
+import { getRemoteMenu, getRoutersInfo, getUserInfo, setRemoteMenu, patchRouteWithRemoteMenus } from './services/route';
+import { getToken, setToken } from '@/utils/token-util'
+import { TOKEN_HEADER_NAME, TOKEN_STORE_NAME } from '@/config/setting';
+import { API_BASE_URL } from '@/config/setting'
+import { message } from 'antd';
-function App() {
+const isDev = process.env.NODE_ENV === 'development';
+const loginPath = '/user/login';
+const defaultAvatar = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'
- return (
- <>
- <h1>Hello Flow</h1>
- </>
- )
+// https://xflow.antv.vision/zh-CN/docs/tutorial/solutions/dag DAG 娴佺▼鍥�
+// https://ant-design.antgroup.com/components/table-cn 琛ㄦ牸
+// https://procomponents.ant.design/components/form 琛ㄥ崟pro
+export function render(oldRender) {
+ const token = getToken();
+ if (!token || token?.length === 0) {
+ oldRender();
+ return;
+ }
+ getRoutersInfo().then(res => {
+ setRemoteMenu(res);
+ oldRender();
+ });
}
-export default App
+export async function patchClientRoutes({ routes }) {
+ patchRouteWithRemoteMenus(routes);
+}
+
+export async function onRouteChange({ clientRoutes, location }) {
+ const menus = getRemoteMenu();
+ if (menus === null && location.pathname !== loginPath) {
+ history.go(0);
+ }
+}
+
+/**
+ * @see https://umijs.org/zh-CN/plugins/plugin-initial-state
+ * */
+export async function getInitialState() {
+ const fetchUserInfo = async () => {
+ try {
+ const { data: userInfo } = await getUserInfo({
+ skipErrorHandler: true,
+ });
+ if (userInfo?.avatar === '') {
+ userInfo.avatar = defaultAvatar;
+ }
+ userInfo.name = userInfo.nickname;
+ return {
+ ...userInfo
+ };
+ } catch (error) {
+ console.log(error);
+ history.push(loginPath);
+ }
+ return undefined;
+ };
+ // 濡傛灉涓嶆槸鐧诲綍椤甸潰锛屾墽琛�
+ const { location } = history;
+ if (location.pathname !== loginPath) {
+ const currentUser = await fetchUserInfo();
+ return {
+ fetchUserInfo,
+ currentUser,
+ settings: defaultSettings,
+ };
+ }
+ return {
+ memo: 'create by vincent',
+ fetchUserInfo,
+ settings: defaultSettings,
+ };
+}
+
+// ProLayout 鏀寔鐨刟pi https://procomponents.ant.design/components/layout
+export const layout = ({ initialState, setInitialState }) => {
+ return {
+ actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />],
+ avatarProps: {
+ src: initialState?.currentUser?.avatar,
+ title: <AvatarName />,
+ render: (_, avatarChildren) => {
+ return <AvatarDropdown>{avatarChildren}</AvatarDropdown>;
+ },
+ },
+ menu: {
+ locale: false,
+ // 姣忓綋 initialState?.currentUser?.userid 鍙戠敓淇敼鏃堕噸鏂版墽琛� request
+ params: {
+ userId: initialState?.currentUser?.id,
+ },
+ request: async () => {
+ if (!initialState?.currentUser?.id) {
+ return [];
+ }
+ return getRemoteMenu();
+ },
+ },
+ waterMarkProps: {
+ // content: initialState?.currentUser?.nickname,
+ },
+ footerRender: () => <Footer />,
+ onPageChange: () => {
+ const { location } = history;
+ // 濡傛灉娌℃湁鐧诲綍锛岄噸瀹氬悜鍒� login
+ if (!initialState?.currentUser && location.pathname !== loginPath) {
+ history.push(loginPath);
+ }
+ },
+ bgLayoutImgList: [
+ {
+ src: 'https://mdn.alipayobjects.com/yuyan_qk0oxh/afts/img/D2LWSqNny4sAAAAAAAAAAAAAFl94AQBr',
+ left: 85,
+ bottom: 100,
+ height: '303px',
+ },
+ {
+ src: 'https://mdn.alipayobjects.com/yuyan_qk0oxh/afts/img/C2TWRpJpiC0AAAAAAAAAAAAAFl94AQBr',
+ bottom: -68,
+ right: -45,
+ height: '303px',
+ },
+ {
+ src: 'https://mdn.alipayobjects.com/yuyan_qk0oxh/afts/img/F6vSTbj8KpYAAAAAAAAAAAAAFl94AQBr',
+ bottom: 0,
+ left: 0,
+ width: '331px',
+ },
+ ],
+ links: isDev
+ ? [
+ <Link key="openapi" to="/umi/plugin/openapi" target="_blank">
+ <LinkOutlined />
+ <span>OpenAPI 鏂囨。</span>
+ </Link>,
+ ]
+ : [],
+ menuHeaderRender: undefined,
+ // 鑷畾涔� 403 椤甸潰
+ // unAccessible: <div>unAccessible</div>,
+ // 澧炲姞涓�涓� loading 鐨勭姸鎬�
+ childrenRender: (children) => {
+ // if (initialState?.loading) return <PageLoading />;
+ return (
+ <>
+ {children}
+ {isDev && (
+ <SettingDrawer
+ disableUrlParams
+ enableDarkTheme
+ settings={initialState?.settings}
+ onSettingChange={(settings) => {
+ setInitialState((preInitialState) => ({
+ ...preInitialState,
+ settings,
+ }));
+ }}
+ />
+ )}
+ </>
+ );
+ },
+ ...initialState?.settings,
+ };
+};
+
+
+/**
+ * @name request 閰嶇疆锛屽彲浠ラ厤缃敊璇鐞�
+ * 瀹冨熀浜� axios 鍜� ahooks 鐨� useRequest 鎻愪緵浜嗕竴濂楃粺涓�鐨勭綉缁滆姹傚拰閿欒澶勭悊鏂规銆�
+ * @doc https://umijs.org/docs/max/request#閰嶇疆
+ */
+export const request = {
+ baseURL: API_BASE_URL,
+ ...errorConfig,
+ timeout: 60000,
+ // 鍓嶇疆瀹堝崼
+ requestInterceptors: [
+ (url, options) => {
+ console.log('request ====>:', url);
+ const token = getToken();
+ if (token && options.headers) {
+ options.headers[TOKEN_HEADER_NAME] = token;
+ }
+ return { url, options };
+ }
+ ],
+ // 鍚庣疆瀹堝崼
+ responseInterceptors: [
+ (response) => {
+ if (response?.data?.code === 401) {
+ // message.error(intl.formatMessage({
+ // id: 'pages.login.failure',
+ // defaultMessage: '鐧诲綍澶辫触锛岃閲嶈瘯锛�',
+ // }));
+ history.push(loginPath)
+ }
+ const token = response.headers[TOKEN_HEADER_NAME];
+ if (token) {
+ setToken(token);
+ }
+ console.log(response?.data);
+ return response;
+ }
+ ]
+};
--
Gitblit v1.9.1