فهرست منبع

添加只有一个应用的情况

code4eat 3 سال پیش
والد
کامیت
935d471552
8فایلهای تغییر یافته به همراه85 افزوده شده و 111 حذف شده
  1. 3 3
      config/proxy.ts
  2. 0 9
      src/app.tsx
  3. 33 25
      src/components/topBar/index.tsx
  4. 2 1
      src/global.tsx
  5. 5 24
      src/layouts/index.tsx
  6. 2 1
      src/pages/index/index.tsx
  7. 29 46
      src/pages/login/index.tsx
  8. 11 2
      src/pages/platform/_layout.tsx

+ 3 - 3
config/proxy.ts

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2022-01-07 10:00:52
- * @LastEditTime: 2022-03-03 18:50:54
+ * @LastEditTime: 2022-03-29 16:10:58
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/config/proxy.ts
@@ -15,12 +15,12 @@
 const proxy: { [key: string]: any } = {
   dev: {
     '/master': {
-      target: 'http://112.124.59.133:7001/',
+      target: 'http://118.31.245.65:7001/',
       changeOrigin: true,
       pathRewrite: { '^/master': '' },
     },
     '/api': {
-      target: 'http://112.124.59.133:8083/',
+      target: 'http://118.31.245.65:8083/',
       changeOrigin: true,
       pathRewrite: { '^/api': '' },
     },

+ 0 - 9
src/app.tsx

@@ -1,12 +1,3 @@
-/*
- * @Author: your name
- * @Date: 2021-11-09 13:57:41
- * @LastEditTime: 2022-03-08 17:12:17
- * @LastEditors: Please set LastEditors
- * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- * @FilePath: /KC-MiddlePlatform/src/app.ts
- */
-
 import { useState } from 'react';
 import { PageLoading } from '@ant-design/pro-layout';
 import { notification, Modal } from 'antd';

+ 33 - 25
src/components/topBar/index.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-16 09:12:37
- * @LastEditTime: 2022-03-10 09:45:59
+ * @LastEditTime: 2022-03-29 16:10:09
  * @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/topBar/index.tsx
@@ -97,7 +97,6 @@ const TopBar: React.FC<TopBarType> = (props) => {
   };
 
   useEffect(() => {
-    console.log({ openedTabs });
     if (openedTabs.length == 1) {
       //当有且仅当只有一个的时候,默认激活
       setCurrentSelectedTab(openedTabs[0]);
@@ -106,7 +105,11 @@ const TopBar: React.FC<TopBarType> = (props) => {
     if (openedTabs.length == 0) {
       //当所有tab都关闭时
       setCurrentSelectedTab(undefined);
-      history.replace('/index');
+
+      if (sysList.length > 1) {
+        //有多个应用时
+        history.replace('/index');
+      }
     }
   }, [openedTabs]);
 
@@ -126,30 +129,35 @@ const TopBar: React.FC<TopBarType> = (props) => {
       <div className={styles.logoWrap}>
         <img className={styles.logo} src={logo} />
       </div>
-      <div className={ifOpenPannel ? `${styles.platformMenu} ${styles.on}` : `${styles.platformMenu}`} onClick={() => setIfOpenPannel(!ifOpenPannel)}>
-        <img src={platFormMenuIcon} />
-        <div className={styles.systemPannel}>
-          {sysList.map((item) => (
-            <div key={item.id} className={styles.systemList} onClick={() => _systemListClickHandle(item)}>
-              <img src={item.icon} alt="" />
-              <div className={styles.systemListName}>{item.name}</div>
-            </div>
-          ))}
-        </div>
-      </div>
-      {/**
-       * 已打开的tab
-       */}
-      <div className={styles.tabWrap}>
-        {systemTabs.map((item) => (
-          <div key={item.id} className={currentSelectedTab?.id == item.id ? `${styles.tab} ${styles.on}` : `${styles.tab}`} onClick={() => _systemTabClickHandle(item)}>
-            <div className={styles.tabText}>{item.name} </div>
-            <div className={styles.closeIconWrap}>
-              <img src={tabCloseIcon} onClick={(e) => closeTabHandle(item, e)} alt="close" />
+      {sysList.length > 1 && (
+        <>
+          <div className={ifOpenPannel ? `${styles.platformMenu} ${styles.on}` : `${styles.platformMenu}`} onClick={() => setIfOpenPannel(!ifOpenPannel)}>
+            <img src={platFormMenuIcon} />
+            <div className={styles.systemPannel}>
+              {sysList.map((item) => (
+                <div key={item.id} className={styles.systemList} onClick={() => _systemListClickHandle(item)}>
+                  <img src={item.icon} alt="" />
+                  <div className={styles.systemListName}>{item.name}</div>
+                </div>
+              ))}
             </div>
           </div>
-        ))}
-      </div>
+          {/**
+           * 已打开的tab
+           */}
+          <div className={styles.tabWrap}>
+            {systemTabs.map((item) => (
+              <div key={item.id} className={currentSelectedTab?.id == item.id ? `${styles.tab} ${styles.on}` : `${styles.tab}`} onClick={() => _systemTabClickHandle(item)}>
+                <div className={styles.tabText}>{item.name} </div>
+                <div className={styles.closeIconWrap}>
+                  <img src={tabCloseIcon} onClick={(e) => closeTabHandle(item, e)} alt="close" />
+                </div>
+              </div>
+            ))}
+          </div>
+        </>
+      )}
+
       <div className={styles.userRelaInfoWrap}>
         <div className={styles.notification}>
           <img className={styles.notificationIcon} src={require('../../../public/images/notificationIcon.png')} />

+ 2 - 1
src/global.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-12-21 11:05:37
- * @LastEditTime: 2022-03-04 09:42:15
+ * @LastEditTime: 2022-03-29 15:17:32
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/global.tsx
@@ -19,6 +19,7 @@ const loginPath = '/login';
 export const logoutHandle = async () => {
   // await logout();
   localStorage.removeItem('userData');
+  localStorage.removeItem('initialState');
 };
 
 (function () {

+ 5 - 24
src/layouts/index.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-09 13:56:33
- * @LastEditTime: 2022-03-09 14:54:50
+ * @LastEditTime: 2022-03-29 15:41:39
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/layouts/index.tsx
@@ -9,23 +9,12 @@
 
 import { IRouteComponentProps, useModel, history } from 'umi';
 import ProLayout from '@ant-design/pro-layout';
-import ProForm, { ProFormInstance, ProFormText } from '@ant-design/pro-form';
-import { useRef } from 'react';
-import { editUsers } from '@/service/user';
+
 import TopBar from '@/components/topBar';
 
 import { Modal } from 'antd';
 
-const TopHoc = ({
-  systemLists,
-  openedSysLists,
-  currentSelectedSys,
-}: {
-  systemLists: TopBar.Tab[];
-  openedSysLists: TopBar.Tab[];
-  currentSelectedSys: TopBar.Tab | undefined;
-}) => {
-  const formRef = useRef<ProFormInstance>();
+const TopHoc = ({ systemLists, openedSysLists, currentSelectedSys }: { systemLists: TopBar.Tab[]; openedSysLists: TopBar.Tab[]; currentSelectedSys: TopBar.Tab | undefined }) => {
   const { initialState, setInitialState } = useModel('@@initialState');
 
   localStorage.setItem('initialState', JSON.stringify(initialState)); //缓存tab状态,防止刷新丢失
@@ -75,13 +64,7 @@ const TopHoc = ({
   );
 };
 
-export default function Layout({
-  children,
-  location,
-  route,
-  history,
-  match,
-}: IRouteComponentProps) {
+export default function Layout({ children, location, route, history, match }: IRouteComponentProps) {
   const { initialState, setInitialState } = useModel('@@initialState');
   const viewportH = window.innerHeight;
   // console.log({children, location, route, history, match});
@@ -101,9 +84,7 @@ export default function Layout({
           <TopHoc
             systemLists={initialState.systemLists ? initialState.systemLists : []}
             openedSysLists={initialState.openedSysLists ? initialState.openedSysLists : []}
-            currentSelectedSys={
-              initialState.currentSelectedSys ? initialState.currentSelectedSys : undefined
-            }
+            currentSelectedSys={initialState.currentSelectedSys ? initialState.currentSelectedSys : undefined}
           />
         )
       }

+ 2 - 1
src/pages/index/index.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-10 09:33:30
- * @LastEditTime: 2022-03-04 14:17:22
+ * @LastEditTime: 2022-03-28 18:57:53
  * @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
@@ -27,6 +27,7 @@ const IndexPage: React.FC<IndexPageType> = ({ location }) => {
   });
 
   const selectSysHandle = async (systemInfo: userRelationInfo.OwnAppsItem) => {
+    console.log({ systemInfo });
     await setInitialState((s) => ({
       ...s,
       currentSelectedSys: systemInfo,

+ 29 - 46
src/pages/login/index.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2021-11-09 14:58:08
- * @LastEditTime: 2022-02-14 14:29:52
+ * @LastEditTime: 2022-03-29 15:49:50
  * @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
@@ -32,9 +32,8 @@ const LoginPage: React.FC<LoginPageType> = ({ location, children }) => {
   const [transformObj, setTransformObj] = useState<string>();
   const loginPageRef = useRef<HTMLDivElement>(null);
   const [subHospList, setSubHospList] = useState<{ name: string; value: string | number }[]>([]); //分院列表
-  const [ifSelectSystem, setIfSelectSystem] = useState(false); //是否跳转到选择系统界面
   const [ifLoading, setIfLoading] = useState(false);
-  const [systemList, setSystemList] = useState<userRelationInfo.OwnAppsItem[]>([]); //可选平台列表
+  // const [systemList, setSystemList] = useState<userRelationInfo.OwnAppsItem[]>([]); //可选平台列表
   const [currentHospName, setCurrentHospName] = useState('欢迎进入医务管理系统');
   const { initialState, setInitialState } = useModel('@@initialState');
 
@@ -100,25 +99,37 @@ const LoginPage: React.FC<LoginPageType> = ({ location, children }) => {
 
       if (initialState && initialState.getHospSubSystemListFunc) {
         const data = await initialState.getHospSubSystemListFunc();
+
+        console.log({ initialState });
+
         await setInitialState((s) => ({
           ...s,
           systemLists: data,
           userData: resp,
         }));
 
-        setSystemList(data);
-
         if (data.length > 1) {
           //当前医院拥有多个子平台时,进入选择
-          setIfSelectSystem(true);
           history.replace('/index');
-        } else {
-          //否则直接进入首页
-          const { query } = history.location;
-          const { redirect } = query as { redirect: string };
-          history.replace(redirect || '/index');
           return;
         }
+
+        if (data.length == 1) {
+          //直接进入该应用
+          history.replace(data[0].path);
+          await setInitialState((s) => ({
+            ...s,
+            currentSelectedSys: data[0],
+            openedSysLists: [data[0]],
+            systemLists: data,
+            userData: resp,
+          }));
+          return;
+        }
+
+        if (data.length == 0) {
+          history.replace('/login');
+        }
       }
 
       setIfLoading(false);
@@ -128,13 +139,7 @@ const LoginPage: React.FC<LoginPageType> = ({ location, children }) => {
   useEffect(() => {
     //根据hospSign获取分院信息
     location.pathname == '/login' && getSubHospFunc();
-
-    // window.addEventListener('message',(e)=>{
-    //      console.log(e.origin)
-    //      if(e.origin == 'http://192.168.50.76:8902'){
-    //       console.log({e})
-    //      }
-    // }, false);
+    setInitialState((s) => ({ ...s, currentSelectedSys: undefined, openedSysLists: [] }));
   }, []);
 
   // return (
@@ -144,21 +149,10 @@ const LoginPage: React.FC<LoginPageType> = ({ location, children }) => {
   // )
 
   return (
-    <div
-      className="loginPage"
-      onMouseMove={onMouseMoveHandle}
-      onMouseLeave={onMouseLeaveHandle}
-      ref={loginPageRef}
-    >
-      <div
-        className="circleBigOne"
-        style={{ transform: transformObj, transition: transitionObj }}
-      ></div>
+    <div className="loginPage" onMouseMove={onMouseMoveHandle} onMouseLeave={onMouseLeaveHandle} ref={loginPageRef}>
+      <div className="circleBigOne" style={{ transform: transformObj, transition: transitionObj }}></div>
       <div className="circleBigerOne"></div>
-      <div
-        className="circleLittleOne"
-        style={{ transform: transformObj, transition: transitionObj }}
-      ></div>
+      <div className="circleLittleOne" style={{ transform: transformObj, transition: transitionObj }}></div>
       {location.pathname == '/login' ? (
         <div className="loginBlock">
           <div className="left">
@@ -171,12 +165,7 @@ const LoginPage: React.FC<LoginPageType> = ({ location, children }) => {
                   allowClear={false}
                   style={{ width: 150 }}
                   defaultValue={subHospList[0].value}
-                  suffixIcon={
-                    <img
-                      style={{ width: '10px', height: '6px' }}
-                      src={require('../../../public/images/arrow.png')}
-                    />
-                  }
+                  suffixIcon={<img style={{ width: '10px', height: '6px' }} src={require('../../../public/images/arrow.png')} />}
                 >
                   {subHospList.map((item) => {
                     return (
@@ -190,17 +179,11 @@ const LoginPage: React.FC<LoginPageType> = ({ location, children }) => {
             </div>
             <div className="systemName">{currentHospName}</div>
             <Form onFinish={onFinish}>
-              <Form.Item
-                name="account"
-                rules={[{ required: true, message: 'Please input your username!' }]}
-              >
+              <Form.Item name="account" rules={[{ required: true, message: 'Please input your username!' }]}>
                 <Input className="input" placeholder="请输入用户名" />
               </Form.Item>
 
-              <Form.Item
-                name="password"
-                rules={[{ required: true, message: 'Please input your password!' }]}
-              >
+              <Form.Item name="password" rules={[{ required: true, message: 'Please input your password!' }]}>
                 <Input.Password className="input" placeholder="请输入密码" />
               </Form.Item>
 

+ 11 - 2
src/pages/platform/_layout.tsx

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2022-01-06 15:25:39
- * @LastEditTime: 2022-03-10 16:53:56
+ * @LastEditTime: 2022-03-29 16:31:14
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: /KC-MiddlePlatform/src/pages/platform/_layout.tsx
@@ -14,9 +14,11 @@ import { getPlatformMenu } from '@/service/menu';
 import './index.less';
 import { TreeItemType } from '@/utils';
 import { SpacicalPageParamsType } from '@/typings';
+import { useState } from 'react';
 
 export default function Layout({ children, location, route, history, match, ...rest }: IRouteComponentProps) {
   const { initialState, setInitialState } = useModel('@@initialState');
+  const [openKeys, set_openKeys] = useState<string[]>([]);
 
   return (
     <ProLayout
@@ -40,7 +42,10 @@ export default function Layout({ children, location, route, history, match, ...r
         </a>
       )}
       menuProps={{
-        openKeys: ['1476445565880504320'],
+        openKeys: [...openKeys],
+        onOpenChange: (openKeys: string[]) => {
+          set_openKeys([...openKeys]);
+        },
       }}
       menu={{
         autoClose: false,
@@ -51,6 +56,10 @@ export default function Layout({ children, location, route, history, match, ...r
             if (systemId) {
               const menuData = await getPlatformMenu(systemId);
 
+              if (menuData.length > 0) {
+                set_openKeys([menuData[0].key]);
+              }
+
               const getVFromTree = (data: TreeItemType[], key: string) => {
                 let result: SpacicalPageParamsType[] = [];
                 function looper(data: TreeItemType[], key: string) {