Browse Source

fix:修改租户信息

zhaojing 1 year ago
parent
commit
e818a03f95

+ 10 - 19
src/app.tsx

@@ -1,6 +1,6 @@
 import { PageLoading } from '@ant-design/pro-layout';
 import { history, useModel } from 'umi';
-import UserStorage from '@/config/sagacare/sagacare_user';
+import { queryTenantData } from '@/services/sagacare_service/member';
 
 /** 获取用户信息比较慢的时候会展示一个 loading */
 export const initialStateConfig = {
@@ -13,7 +13,7 @@ export const initialStateConfig = {
 export async function getInitialState(): Promise<{
   projectId: String;
   currentUser?: API.CurrentUser;
-  fetchUser?: () => Promise<API.CurrentUser | undefined>;
+  companyConfig?: any;
   //fetchUserInfo?: () => Promise<API.CurrentUser | undefined>;
 }> {
   const { location } = history;
@@ -27,40 +27,31 @@ export async function getInitialState(): Promise<{
   //debugger;
   let currentUser = {
     appId: 'wxda2ef261ac3cca32',
-    companyId: '17fe48afcdde4d6797583c6d6270a035', // 'ff80c708fe72446eb790b764c3a7b66b',
+    companyId: '17fe48afcdde4d6797583c6d6270a035', // ff80c708fe72446eb790b764c3a7b66b,
     loginType: 'app',
     manageUserType: 3,
     name: '赵静',
     openId: 'oDcGY5Qq3Vk-7WKTNsn-lLGNT118',
     phone: '13810794283',
-    projectId: 'Pj1101080259', //'Pj1101099999',
+    projectId: 'Pj1101080259', //  Pj1101099999
     userId: 'db445a9cd7be4341a14448928014605c',
   };
-  let projectId = 'Pj1101080259'; // 'Pj1101099999';
+  let projectId = 'Pj1101080259'; //  Pj1101099999
   if (location.pathname.indexOf('login') == -1 && token) {
     var localUser = localStorage.getItem('user') || '';
     currentUser = JSON.parse(localUser);
     projectId = currentUser?.projectId;
   }
-
-  if (projectId == 'Pj3301100002') {
-    //之江项目 验证token
-    // currentUser = await fetchUser();
-  } else {
-    //非之江项目
-    let tempUser = {
-      name: '行政测试',
-      phone: '17611228068',
-      id: '9a1ecfbacb6b4f249bf2dd3ec7793ead',
-    };
-
-    var userObj = UserStorage.getInstance();
-    userObj.setUser(tempUser);
+  let companyConfig = {};
+  if (currentUser.userId) {
+    const res = await queryTenantData(currentUser);
+    companyConfig = res.data;
   }
 
   return {
     projectId,
     currentUser,
+    companyConfig,
   };
 }
 

+ 20 - 20
src/hooks/useMenuList.ts

@@ -26,26 +26,26 @@ export default function () {
         ],
       },
 
-      {
-        title: '运营服务',
-        menus: [
-          {
-            id: 'environment',
-            title: '环境信息',
-            icon: homeImgMap.environment,
-          },
-          {
-            id: 'equipment',
-            title: '设备管理',
-            icon: homeImgMap.equipment,
-          },
-          {
-            id: 'runtime',
-            title: '运行时间',
-            icon: homeImgMap.runtime,
-          },
-        ],
-      },
+      // {
+      //   title: '运营服务',
+      //   menus: [
+      //     // {
+      //     //   id: 'environment',
+      //     //   title: '环境信息',
+      //     //   icon: homeImgMap.environment,
+      //     // },
+      //     {
+      //       id: 'equipment',
+      //       title: '设备管理',
+      //       icon: homeImgMap.equipment,
+      //     },
+      //     // {
+      //     //   id: 'runtime',
+      //     //   title: '运行时间',
+      //     //   icon: homeImgMap.runtime,
+      //     // },
+      //   ],
+      // },
     ]);
     // setMenuList([
     //   // { name: '环境信息', id: 'environment' },

+ 2 - 1
src/layouts/index.jsx

@@ -103,7 +103,8 @@ export default (props) => {
               history.push('/home');
             }}
           >
-            之江项目
+            <span className={styles.projectName}>{initialState?.companyConfig?.projectName}</span>
+            <span>{initialState?.companyConfig?.companyName}</span>
           </span>
           <Head></Head>
         </div>

+ 6 - 0
src/layouts/index.less

@@ -34,10 +34,16 @@
     display: flex;
     align-items: baseline;
     .project {
+      display: flex;
+      flex-direction: column;
       color: #000;
       font-weight: 600;
       font-size: 24px;
       cursor: pointer;
+      .projectName {
+        color: #c4c4c4;
+        font-size: 14px;
+      }
     }
   }
   .right {

+ 4 - 0
src/pages/Home/index.less

@@ -3,6 +3,10 @@
   justify-content: space-between;
   .left {
     width: 500px;
+    .userName {
+      color: #000000;
+      font-size: 20px;
+    }
   }
   .right {
     width: 400px;

+ 5 - 1
src/pages/Home/index.tsx

@@ -7,9 +7,13 @@ import cx from 'classnames';
 import NavMenu from '@/sagacare_components/navMenu';
 
 const Runtime: React.FC = () => {
+  const { initialState } = useModel('@@initialState');
+
   return (
     <div className={styles.homewrap}>
-      <div className={styles.left}></div>
+      <div className={styles.left}>
+        <span className={styles.userName}>你好,{initialState?.companyConfig?.name}</span>
+      </div>
       <div className={styles.right}>
         <NavMenu></NavMenu>
       </div>

+ 13 - 6
src/pages/Member/components/StartImport/Uploader/index.jsx

@@ -1,6 +1,6 @@
 import React, { useState, useCallback, useRef } from 'react';
 import cx from 'classnames';
-import { Button, Checkbox } from 'antd';
+import { Button, Checkbox, message } from 'antd';
 import { importUsers } from './service';
 import { useModel, history } from 'umi';
 import iconExcel from './icon-excel.svg';
@@ -37,13 +37,16 @@ export default ({ onUploadDone }) => {
   const handleFileSelected = useCallback((e) => {
     const file = e.target.files[0];
 
+    if (!file) {
+      setUploadState(3);
+    }
     setFileInfo({
       file,
       name: file.name,
       size: `${Math.ceil(file.size / 1024)}K`,
     });
     if (!isExcel(file.type)) {
-      setErrorInfo('文件格式不正确');
+      setErrorInfo('不支持此类文件格式');
       setUploadState(2);
     } else if (file.size > 1024 * 1024 * 10) {
       setErrorInfo('文件大小不能超过 10MB');
@@ -62,13 +65,17 @@ export default ({ onUploadDone }) => {
     importUsers(fileInfo.file, params)
       .then((res) => {
         setUploading(false);
-        onUploadDone(res);
+        if (res.key) {
+          onUploadDone(res);
+        } else {
+          message.error(res.message);
+          setUploadState(0);
+        }
       })
       .catch(() => {
         // 文件上传失败
         setUploading(false);
-        // setErrorInfo('导入失败');
-        setUploadState(1);
+        setUploadState(3);
       });
   }, [fileInfo, autoSendActiveMsg, onUploadDone]);
 
@@ -161,7 +168,7 @@ export default ({ onUploadDone }) => {
             {fileInfo.name} ({fileInfo.size})
           </div>
           <div>
-            文件上传失败,请<span onClick={beginUpload}>再次上传</span>或
+            文件导入失败,请<span onClick={beginUpload}>再次上传</span>或
             <span onClick={() => fileInputRef.current.click()}>重新选择文件</span>
           </div>
         </div>

+ 18 - 0
src/sagacare_components/navMenu/index.less

@@ -5,6 +5,20 @@
   padding: 0 24px;
   background-color: #fff;
   border-radius: 10px;
+  .tenantNum {
+    display: flex;
+    flex-direction: column;
+    // padding-top: 20px;
+    padding-bottom: 30px;
+    .memberNum {
+      color: #656872;
+      font-size: 30px;
+    }
+    .memberName {
+      color: #c4c4c4;
+      font-size: 14px;
+    }
+  }
   .title {
     display: flex;
     align-items: center;
@@ -15,6 +29,10 @@
     position: absolute;
     top: 42px;
     right: 36px;
+    cursor: pointer;
+  }
+  .exit {
+    cursor: pointer;
   }
   .groupTitle {
     margin: 0 0 13px 10px;

+ 26 - 2
src/sagacare_components/navMenu/index.tsx

@@ -1,5 +1,5 @@
 import React, { useEffect } from 'react';
-import { Row, Col, Image } from 'antd';
+import { Row, Col, Image, Popover } from 'antd';
 import styles from './index.less';
 import Icon from '@/tenants-ui/SgIcon';
 import useMenuList, { menutype } from '@/hooks/useMenuList';
@@ -11,6 +11,8 @@ const NavMenu: React.FC = () => {
   const location = useLocation();
   const { closeMenu } = useModel('controller');
   const { menuList } = useMenuList();
+  const { initialState } = useModel('@@initialState');
+
   //debugger;
   const menuClick = (item: menutype) => {
     closeMenu();
@@ -20,13 +22,35 @@ const NavMenu: React.FC = () => {
   useEffect(() => {
     console.log('location', location);
   }, [location]);
+  const exitClick = () => {
+    localStorage.removeItem('token');
+    history.replace('/login');
+  };
   return (
     <div className={styles.drawerDiv}>
       <div className={styles.title}>
         <img src={logo} style={{ height: 70 }}></img>
       </div>
       <div className={styles.setOut}>
-        <img src={homeImgMap.set} />
+        <Popover
+          placement="leftTop"
+          content={
+            <div
+              style={{ cursor: 'pointer' }}
+              onClick={() => {
+                exitClick();
+              }}
+            >
+              退出
+            </div>
+          }
+        >
+          <img src={homeImgMap.set} />
+        </Popover>
+      </div>
+      <div className={styles.tenantNum}>
+        <span className={styles.memberNum}>{initialState?.companyConfig?.userTotal}</span>
+        <span className={styles.memberName}>员工总数</span>
       </div>
       {menuList?.map((group, fidx) => {
         return (

+ 16 - 0
src/services/sagacare_service/member.js

@@ -119,3 +119,19 @@ export async function qrCodeInfo(params, options) {
     ...(options || {}),
   });
 }
+
+//获取租户信息
+export async function queryTenantData(params, options) {
+  // /sgadmin/duoduo-service/duoduoenv-service/userNew/qrCodeInfo
+  return request(
+    `/xiaojing/user/queryData?userId=${params.userId}&projectId=${params.projectId}&companyId=${params.companyId}`,
+    {
+      method: 'GET',
+      from: 'sagacare',
+      headers: {
+        'Content-Type': 'application/json',
+      },
+      ...(options || {}),
+    },
+  );
+}