From d835d1b51f832889929cdf69010034a30ef44d02 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期四, 17 十月 2024 13:57:29 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/App.jsx | 184 ++++++++++++++++++++++++++++++---------------
1 files changed, 123 insertions(+), 61 deletions(-)
diff --git a/zy-asrs-flow/src/App.jsx b/zy-asrs-flow/src/App.jsx
index 4aa6d96..84866e2 100644
--- a/zy-asrs-flow/src/App.jsx
+++ b/zy-asrs-flow/src/App.jsx
@@ -1,21 +1,25 @@
import React from 'react';
-import { Footer, Question, SelectLang, AvatarDropdown, AvatarName } from '@/components';
+import { Footer, Question, SelectLang, AvatarDropdown, AvatarName, Brightness, LayoutSwitch, FullScreen } 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 { currentUser as queryCurrentUser } from '@/services/ant-design-pro/api';
import { getRemoteMenu, getRoutersInfo, getUserInfo, setRemoteMenu, patchRouteWithRemoteMenus } from './services/route';
-import { getToken } from '@/utils/token-util'
+import { getToken, setToken } from '@/utils/token-util'
import { TOKEN_HEADER_NAME, TOKEN_STORE_NAME } from '@/config/setting';
+import { API_BASE_URL, API_TIMEOUT } from '@/config/setting'
+import { message } from 'antd';
+
+import logo from '../public/img/logo.png'
+import logoDark from '../public/img/logo-dark.png'
const isDev = process.env.NODE_ENV === 'development';
const loginPath = '/user/login';
const defaultAvatar = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'
+// https://xflow.antv.vision/zh-CN/docs/tutorial/solutions/dag DAG 娴佺▼鍥�
export function render(oldRender) {
- console.log("1");
const token = getToken();
if (!token || token?.length === 0) {
oldRender();
@@ -28,31 +32,32 @@
}
export async function patchClientRoutes({ routes }) {
- console.log("2");
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() {
- console.log("3");
const fetchUserInfo = async () => {
try {
- // const userInfo = await getUserInfo({
- // skipErrorHandler: true,
- // });
- // if (userInfo?.user.avatar === '') {
- // response.user.avatar = defaultAvatar;
- // }
- // return {
- // ...userInfo
- // };
-
- const userInfo = await queryCurrentUser({
+ const { data: userInfo } = await getUserInfo({
skipErrorHandler: true,
});
- return userInfo.data;
+ if (userInfo?.avatar === '') {
+ userInfo.avatar = defaultAvatar;
+ }
+ userInfo.name = userInfo.nickname;
+ return {
+ ...userInfo
+ };
} catch (error) {
console.log(error);
history.push(loginPath);
@@ -70,16 +75,40 @@
};
}
return {
+ memo: 'create by vincent',
fetchUserInfo,
settings: defaultSettings,
};
}
// ProLayout 鏀寔鐨刟pi https://procomponents.ant.design/components/layout
+// 浼樺厛绾� layout > config > defaultSetting
export const layout = ({ initialState, setInitialState }) => {
- console.log("4");
+ const [darkMode, setDarkMode] = React.useState(() => {
+ const storedValue = localStorage.getItem('darkMode');
+ return storedValue !== null ? JSON.parse(storedValue) : false;
+ });
+
+ const [layoutMode, setLayoutMode] = React.useState(() => {
+ const storedValue = localStorage.getItem('layoutMode');
+ return storedValue !== null ? JSON.parse(storedValue) : true;
+ });
+
+ const [fullScreen, setFullScreen] = React.useState(false);
+
+ React.useEffect(() => {
+ localStorage.setItem('darkMode', JSON.stringify(darkMode));
+ localStorage.setItem('layoutMode', JSON.stringify(layoutMode));
+ }, [darkMode, layoutMode]);
+
return {
- actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />],
+ actionsRender: () => [
+ // <Question key="doc" />,
+ <SelectLang key="SelectLang" />,
+ <FullScreen fullScreen={fullScreen} setFullScreen={setFullScreen} />,
+ <LayoutSwitch layoutMode={layoutMode} setLayoutMode={setLayoutMode} />,
+ <Brightness darkMode={darkMode} setDarkMode={setDarkMode} />,
+ ],
avatarProps: {
src: initialState?.currentUser?.avatar,
title: <AvatarName />,
@@ -91,18 +120,14 @@
locale: false,
// 姣忓綋 initialState?.currentUser?.userid 鍙戠敓淇敼鏃堕噸鏂版墽琛� request
params: {
- userId: initialState?.currentUser?.userId,
+ userId: initialState?.currentUser?.id,
},
request: async () => {
- // console.log(initialState?.currentUser?.userId);
- // if (!initialState?.currentUser?.userId) {
- // return [];
- // }
+ if (!initialState?.currentUser?.id) {
+ return [];
+ }
return getRemoteMenu();
},
- },
- waterMarkProps: {
- content: initialState?.currentUser?.name,
},
footerRender: () => <Footer />,
onPageChange: () => {
@@ -112,34 +137,40 @@
history.push(loginPath);
}
},
+ // token: {
+ // bgLayout: '#fff',
+ // header: {
+ // colorBgHeader: '#fff',
+ // },
+ // sider: {
+ // colorMenuBackground: '#fff',
+ // },
+ // pageContainer: {
+ // colorBgPageContainer: '#fff',
+ // },
+ // },
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',
- },
+ // {
+ // 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>,
- ]
- : [],
+ // 鏄剧ず鍦ㄨ彍鍗曞彸涓嬭鐨勫揩鎹锋搷浣�
+ links: [],
menuHeaderRender: undefined,
// 鑷畾涔� 403 椤甸潰
// unAccessible: <div>unAccessible</div>,
@@ -149,23 +180,45 @@
return (
<>
{children}
- {isDev && (
+ {/* {isDev && (
<SettingDrawer
disableUrlParams
enableDarkTheme
settings={initialState?.settings}
onSettingChange={(settings) => {
+ console.log(settings);
setInitialState((preInitialState) => ({
...preInitialState,
settings,
}));
}}
/>
- )}
+ )} */}
</>
);
},
...initialState?.settings,
+ layout: layoutMode ? 'top' : 'mix', // layout 鐨勮彍鍗曟ā寮忥紝side锛氬彸渚у鑸紝top锛氶《閮ㄥ鑸�
+ // contentStyle: () => { // layout 鐨勫唴瀹瑰尯 style
+ // return
+ // },
+ contentWidth: 'Fluid', // layout 鐨勫唴瀹规ā寮忥紝Fluid锛氳嚜閫傚簲锛堝叏灞忥級锛孎ixed锛氬畾瀹� 锛堝皬锛� 1200px
+ fixedHeader: true, // 鍥哄畾 header
+ fixSiderbar: true, // 鍥哄畾瀵艰埅
+ // settings: defaultSettings, // layout 鐨勮缃�
+ // waterMarkProps: { content: initialState?.currentUser?.nickname }, //姘村嵃
+ // navTheme: 'realDark', // 榛樿涓婚棰滆壊 "realDark" | "light" | undef...
+ navTheme: darkMode ? 'realDark' : 'light',
+ footerRender: false, // 椤佃剼 鍚敤璇锋敞閲婏紝涓嶆槸璁剧疆涓簍rue
+ logo: darkMode
+ ? <img src={logo} className='header-logo' />
+ : <img src={logoDark} className='header-logo' />
+ ,
+ title: (
+ <div className='header-title'>
+ </div>
+ ),
+ colorWeak: true,
};
};
@@ -176,13 +229,12 @@
* @doc https://umijs.org/docs/max/request#閰嶇疆
*/
export const request = {
- // baseURL: 'http://localhost:9999',
+ baseURL: API_BASE_URL,
...errorConfig,
- timeout: 10000,
+ timeout: API_TIMEOUT * 1000,
// 鍓嶇疆瀹堝崼
requestInterceptors: [
(url, options) => {
- console.log('request ====>:', url);
const token = getToken();
if (token && options.headers) {
options.headers[TOKEN_HEADER_NAME] = token;
@@ -193,7 +245,17 @@
// 鍚庣疆瀹堝崼
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);
+ }
return response;
}
]
--
Gitblit v1.9.1