Bladeren bron

something

code4eat 3 jaren geleden
bovenliggende
commit
a1e57ffe99
8 gewijzigde bestanden met toevoegingen van 161 en 52 verwijderingen
  1. 5 1
      .umirc.ts
  2. 18 7
      src/app.tsx
  3. 34 4
      src/global.tsx
  4. 66 0
      src/models/index.ts
  5. 10 14
      src/pages/index/components/iframePage/index.tsx
  6. 17 14
      src/pages/index/index.tsx
  7. 3 9
      src/pages/login/index.tsx
  8. 8 3
      src/typings.d.ts

+ 5 - 1
.umirc.ts

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-09 11:20:18
- * @LastEditTime: 2021-12-20 16:33:57
+ * @LastEditTime: 2021-12-22 09:41:36
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/.umirc.ts
@@ -12,6 +12,10 @@ export default defineConfig({
   nodeModulesTransform: {
     type: 'none',
   },
+  dva: {
+    immer: true,
+    hmr: true,
+  },
   theme: {},
   routes: [
     {

+ 18 - 7
src/app.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-09 13:57:41
- * @LastEditTime: 2021-12-20 17:45:12
+ * @LastEditTime: 2021-12-22 09:43:26
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/app.ts
@@ -10,17 +10,14 @@
 import React from 'react';
 import {
   PageLoading,
-  BasicLayoutProps,
-  Settings as LayoutSettings,
 } from '@ant-design/pro-layout';
-import { notification, ConfigProvider } from 'antd';
+import { notification, message } from 'antd';
 import { RequestConfig, history } from 'umi';
+// import { createLogger } from 'redux-logger';
 import type { RequestOptionsInit } from 'umi-request';
 
 import { getHospSubSystemList } from '@/service/login';
 
-import TopBar from '@/components/topBar/index';
-
 const loginPath = '/login';
 
 let hospSign: string = ''; //医院标识
@@ -61,7 +58,7 @@ export async function getInitialState(): Promise<InitialStateType> {
 
   //获取当前账号所有子应用列表
   const systemLists = await getHospSubSystemList();
-
+  
   const userData = await fetchUserInfo();
 
   return {
@@ -73,6 +70,20 @@ export async function getInitialState(): Promise<InitialStateType> {
   };
 }
 
+
+
+// export const dva = {
+//         config: {
+//           onAction: createLogger(),
+//           onError(e: Error) {
+//             message.error(e.message, 3);
+//           },
+//         },
+// };
+
+
+
+
 const requestInterceptorsHandle = (
   url: string,
   options: RequestOptionsInit,

+ 34 - 4
src/global.tsx

@@ -1,13 +1,15 @@
 /*
  * @Author: your name
  * @Date: 2021-12-21 11:05:37
- * @LastEditTime: 2021-12-21 15:13:11
+ * @LastEditTime: 2021-12-22 09:02:37
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/global.tsx
  */
 
 
+import {history } from 'umi';
+
 
     window.stateFromTop = {   //挂载通信数据
     
@@ -22,6 +24,34 @@
     //         }
     // });
 
-    window.postMessageToChild = async (data)=>{   //添加全局监听事件
-          window.postMessage({...data},'http://localhost:8804')
-    }
+    window.postMessageToChild = async (data)=>{   //添加全局postMessageToChild函数
+          const iframes = document.getElementsByClassName('iframe');
+          Array.from(iframes).forEach((iframe) => {
+            const iframeWindow = iframe as HTMLIFrameElement;
+            if(iframeWindow&&iframeWindow.contentWindow){
+                iframeWindow.contentWindow.postMessage({...data},'http://localhost:8804')
+            } 
+          });
+        //   window.postMessage({...data},'http://localhost:8804')
+    }
+
+    window.removeListenner = async (handlerName:string)=>{   
+        console.log({handlerName});
+        window.removeEventListener('handlerName',()=>{
+            console.log('remove message listener');
+        });
+      //   window.postMessage({...data},'http://localhost:8804')
+    }  
+    
+    
+
+    window.addEventListener('message',(event)=>{
+        if (event.origin === "http://localhost:8804"){
+                 console.log(event.data);
+                 if(event.data.type == 'LOGOUT'){
+                    window.removeListenner('message');
+                    history.replace('/login');
+                 }
+        }
+        
+      }, false);

+ 66 - 0
src/models/index.ts

@@ -0,0 +1,66 @@
+/*
+ * @Author: your name
+ * @Date: 2021-12-22 09:36:53
+ * @LastEditTime: 2021-12-22 09:48:30
+ * @LastEditors: Please set LastEditors
+ * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
+ * @FilePath: /KC-MiddlePlatform/src/models/model.ts
+ */
+
+
+import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';
+
+export interface IndexModelState {
+  name: string;
+}
+
+export interface IndexModelType {
+  namespace: 'index';
+  state: IndexModelState;
+  effects: {
+    query: Effect;
+  };
+  reducers: {
+    save: Reducer<IndexModelState>;
+    // 启用 immer 之后
+    // save: ImmerReducer<IndexModelState>;
+  };
+  subscriptions: { setup: Subscription };
+}
+
+const IndexModel: IndexModelType = {
+  namespace: 'index',
+
+  state: {
+    name: '',
+  },
+
+  effects: {
+    *query({ payload }, { call, put }) {},
+  },
+  reducers: {
+    save(state, action) {
+      return {
+        ...state,
+        ...action.payload,
+      };
+    },
+    // 启用 immer 之后
+    // save(state, action) {
+    //   state.name = action.payload;
+    // },
+  },
+  subscriptions: {
+    setup({ dispatch, history }) {
+      return history.listen(({ pathname }) => {
+        if (pathname === '/') {
+          dispatch({
+            type: 'query',
+          });
+        }
+      });
+    },
+  },
+};
+
+export default IndexModel;

+ 10 - 14
src/pages/index/components/iframePage/index.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-19 15:20:40
- * @LastEditTime: 2021-12-20 11:23:06
+ * @LastEditTime: 2021-12-21 16:29:08
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/pages/index/components/iframePage/index.tsx
@@ -17,13 +17,19 @@ import './style.less';
 export interface IframePage {
   activedItem?: SystemListItem;
   list: SystemListItem[];
+  onload?:()=>void,
 }
 //http://118.31.245.65:8804/user/login/?redirect=%2FDataManagement%2FpublicData&hospSign=tYAoFaa20yCAgaiy
 
-const Iframe = ({ id, url }: SystemListItem) => {
+interface A extends SystemListItem {
+      onload?:()=>void
+}
+
+const Iframe = ({ id, url,onload }:A ) => {
   const [loading, setLoading] = useState(true);
 
   const onLoadHandle = () => {
+      onload&&onload();
     setLoading(false);
   };
 
@@ -38,20 +44,10 @@ const Iframe = ({ id, url }: SystemListItem) => {
 };
 
 const IframePage: React.FC<IframePage> = (props) => {
-  const { list, activedItem } = props;
+  const { list, activedItem,onload } = props;
 
   return (
     <div className="iframeContainer">
-      {/* {
-            loading && (
-                  <div className='content'>
-                        <div className='spin'>
-                              <LoadingOutlined style={{ fontSize: 24 }} spin />
-                              <span>努力加载中...</span>
-                        </div>
-                  </div>
-            )
-        } */}
       {list.map((item) => (
         <div
           key={item.id}
@@ -62,7 +58,7 @@ const IframePage: React.FC<IframePage> = (props) => {
             zIndex: activedItem && activedItem.id == item.id ? 9 : 1,
           }}
         >
-          <Iframe {...item} />
+          <Iframe {...item} onload={onload} />
         </div>
       ))}
     </div>

+ 17 - 14
src/pages/index/index.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-10 09:33:30
- * @LastEditTime: 2021-12-21 11:04:18
+ * @LastEditTime: 2021-12-22 08:59:34
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/pages/index.tsx
@@ -63,6 +63,18 @@ const IndexPage = () => {
     }
   };
 
+  const onIframePageLoad = ()=>{
+        console.log('onload');
+        window.postMessageToChild({
+            type:'LOGIN',
+            data:{
+               name: "管理员",
+               token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjEwMjgwMDU2MjAyLCJ1c2VySWQiOjMwNTd9.6nCb_0c4ZW4bgN1ogq6SRGeEhFXw_p2Rf22FLFEHtXc",
+               userId: 3057
+            }
+       });
+  }
+
   const userPannelTabClick = async (tag: string) => {
     if (tag == 'LOGOUT') {
       if (logout) {
@@ -88,19 +100,10 @@ const IndexPage = () => {
     if (systemLists) setSelectableSysList(systemLists);
     if (openedSysLists) setOpenTabs(openedSysLists);
 
-
-    window.addEventListener('message', function(event){
-      if (event.origin === "http://localhost:8804"){
-               console.log(event.data);
-               if(event.data.type == 'LOGOUT'){
-                     history.replace('/login') 
-               }
-      }
-      
-    }, false);
-
     return ()=>{
-      window.removeEventListener('message',()=>{}); 
+      window.removeEventListener('message',()=>{
+              console.log('remove message listener');
+      }); 
     }
   }, []);
 
@@ -123,7 +126,7 @@ const IndexPage = () => {
       {/* <MicroApp name='MedicalWisdomCheckSys' /> */}
 
       {openedTabs && (
-        <IframePage activedItem={currentOpenedTab} list={openedTabs} />
+        <IframePage activedItem={currentOpenedTab} list={openedTabs} onload={onIframePageLoad} />
       )}
     </div>
   );

+ 3 - 9
src/pages/login/index.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-09 14:58:08
- * @LastEditTime: 2021-12-21 15:51:11
+ * @LastEditTime: 2021-12-21 17:05:36
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/pages/login/index.tsx
@@ -86,14 +86,7 @@ const LoginPage: React.FC<any> = () => {
         userData:{},
         systemLists: data,
       }));
-      await window.postMessageToChild({
-             type:'DATA',
-             data:{
-                name: "管理员",
-                token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjEwMjgwMDU2MjAyLCJ1c2VySWQiOjMwNTd9.6nCb_0c4ZW4bgN1ogq6SRGeEhFXw_p2Rf22FLFEHtXc",
-                userId: 3057
-             }
-      });
+
       localStorage.setItem('KC-MiddlePlatformUserData', JSON.stringify(resp));
 
       if (data.length > 1) {
@@ -118,6 +111,7 @@ const LoginPage: React.FC<any> = () => {
     }));
     const { query } = history.location;
     const { redirect } = query as { redirect: string };
+    
     history.push(redirect || '/');
   };
 

+ 8 - 3
src/typings.d.ts

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-19 16:31:19
- * @LastEditTime: 2021-12-21 11:16:16
+ * @LastEditTime: 2021-12-21 17:50:45
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/typings.d.ts
@@ -17,10 +17,15 @@ type SystemListItem = {
 
 
 declare interface PostMessageData {
-    type:'LOGOUT'|'REFRESH'|'DATA',
+    type:'LOGOUT'|'REFRESH'|'DATA'|'LOGIN',
     data?:any
 }
 declare interface Window  {
   stateFromTop: any,
-  postMessageToChild:(data:PostMessageData)=>Promise<any>
+  postMessageToChild:(data:PostMessageData)=>Promise<any>,
+  removeListenner:(name:string)=>Promise<any>,
 }
+
+declare interface Iframe  {
+    contentWindow:any
+}