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 |   70 +++++++++++++++++++++--------------
 1 files changed, 42 insertions(+), 28 deletions(-)

diff --git a/zy-asrs-flow/src/App.jsx b/zy-asrs-flow/src/App.jsx
index 4aa6d96..6892f48 100644
--- a/zy-asrs-flow/src/App.jsx
+++ b/zy-asrs-flow/src/App.jsx
@@ -5,17 +5,20 @@
 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 } from '@/config/setting'
+import { message } from 'antd';
 
 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 娴佺▼鍥�
+// https://ant-design.antgroup.com/components/table-cn 琛ㄦ牸
+// https://procomponents.ant.design/components/form 琛ㄥ崟pro
 export function render(oldRender) {
-  console.log("1");
   const token = getToken();
   if (!token || token?.length === 0) {
     oldRender();
@@ -28,31 +31,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,6 +74,7 @@
     };
   }
   return {
+    memo: 'create by vincent',
     fetchUserInfo,
     settings: defaultSettings,
   };
@@ -77,7 +82,6 @@
 
 // ProLayout 鏀寔鐨刟pi https://procomponents.ant.design/components/layout
 export const layout = ({ initialState, setInitialState }) => {
-  console.log("4");
   return {
     actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />],
     avatarProps: {
@@ -91,18 +95,17 @@
       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,
+      // content: initialState?.currentUser?.nickname,
     },
     footerRender: () => <Footer />,
     onPageChange: () => {
@@ -176,9 +179,9 @@
  * @doc https://umijs.org/docs/max/request#閰嶇疆
  */
 export const request = {
-  // baseURL: 'http://localhost:9999',
+  baseURL: API_BASE_URL,
   ...errorConfig,
-  timeout: 10000,
+  timeout: 60000,
   // 鍓嶇疆瀹堝崼
   requestInterceptors: [
     (url, options) => {
@@ -193,7 +196,18 @@
   // 鍚庣疆瀹堝崼
   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