Browse Source

feat 企业信息

anxiaoxia 1 year ago
parent
commit
fa6319f615
2 changed files with 36 additions and 34 deletions
  1. 17 32
      src/pages/Information/index.jsx
  2. 19 2
      src/services/sagacare_service/infomation.js

+ 17 - 32
src/pages/Information/index.jsx

@@ -1,9 +1,13 @@
 import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
 import styles from './index.less';
 import { Input, message } from 'antd';
-import { companyInfo, companyUpdate } from '@/services/sagacare_service/infomation';
+import {
+  companyInfo,
+  companyUpdate,
+  importUsers,
+  getFileUrl,
+} from '@/services/sagacare_service/infomation';
 export default () => {
-  let showImgUrl = `/image-service/common/file_get?systemId=dataPlatform&key`;
   const fileInputRef = useRef();
   const [englishAbbreviation, setEnglishAbbreviation] = useState('');
   const [abbreviation, setAbbreviation] = useState('');
@@ -11,37 +15,14 @@ export default () => {
   const [companyName, setCompanyName] = useState('');
   const [englishName, setEnglishName] = useState('');
   const [logoUrl, setLogoUrl] = useState('');
+  const [imgUrl, setImgUrl] = useState('');
   const handleFileSelected = useCallback(
     (e) => {
       const file = e.target.files[0];
-      console.log(file, '-----文件11');
-
       let fileName = file.name;
-      let url = `/yongqi/oss/uploadOssFile`;
-      //   let url = `/image-service/duoduo-service/custom-service/oss/uploadOssFile`;
-      let formData = new FormData();
-      formData.append('file', file);
-      //   const reader = new FileReader();
-      //   //   reader.readAsArrayBuffer(file);
-      //   reader.onload = () => {
-      var xhr = new XMLHttpRequest();
-      xhr.open('POST', url);
-      xhr.setRequestHeader('Content-Type', 'application/form-data');
-      xhr.send(formData);
-
-      xhr.onreadystatechange = function () {
-        if (xhr.readyState == 4) {
-          if (xhr.status == 200) {
-            message.success('文件上传成功');
-            send('logoUrl', fileName);
-          } else {
-            message.error('文件上传失败');
-            return;
-          }
-        }
-      };
-      console.log(xhr, '-------xhr-----');
-      //   };
+      importUsers(file).then((res) => {
+        send('logUrl', res.data.fileKey);
+      });
     },
     [abbreviation, englishAbbreviation, intro, logoUrl],
   );
@@ -59,8 +40,7 @@ export default () => {
       setIntro(resData.intro || '');
       setCompanyName(resData.companyName || '');
       setEnglishName(resData.englishName || '');
-      //   const logUrl = resData.logoUrl && `${showImgUrl}=${resData.logoUrl}`;
-      //   setLogoUrl(logUrl || '');
+      setLogoUrl(resData.logoUrl || '');
     });
   }
 
@@ -82,12 +62,17 @@ export default () => {
     if (companyName == '') {
       getData();
     }
+    if (logoUrl) {
+      getFileUrl(logoUrl).then((res) => {
+        setImgUrl(res.data);
+      });
+    }
   }, [englishAbbreviation, abbreviation, intro, logoUrl, companyName]);
   return (
     <div className={styles.information}>
       <div className={styles.left}>
         <div className={styles.imgBox}>
-          {logoUrl && <img className={styles.imgSt} src={logoUrl}></img>}
+          {imgUrl && <img className={styles.imgSt} src={imgUrl}></img>}
         </div>
         <input
           type="file"

+ 19 - 2
src/services/sagacare_service/infomation.js

@@ -25,7 +25,7 @@ export const companyInfo = () => {
       companyId: '751329b106254ac58c2bd3ae9eaefaa7',
     },
   };
-  return request(`/yongqi/company/info`, {
+  return request(`/sgadmin/duoduo-service/custom-service/company/info`, {
     method: 'POST',
     from: 'sagacare',
     isNotShowErrorToast: true,
@@ -39,7 +39,7 @@ export const companyInfo = () => {
 // 修改企业 信息
 export const companyUpdate = (params) => {
   params.companyId = '751329b106254ac58c2bd3ae9eaefaa7';
-  return request(`/yongqi/company/update`, {
+  return request(`/sgadmin/duoduo-service/custom-service/company/update`, {
     method: 'POST',
     from: 'sagacare',
     isNotShowErrorToast: true,
@@ -51,3 +51,20 @@ export const companyUpdate = (params) => {
   });
 };
 
+// 上传 图片
+export const importUsers = (file, param) => {
+  const data = new FormData();
+  data.append('file', file);
+  return request('/sgadmin/duoduo-service/custom-service/oss/uploadOssFile', {
+    data,
+    method: 'post',
+    parseResponse: true,
+  });
+};
+// 查看 图片
+export const getFileUrl = (param) => {
+  return request(`/sgadmin/duoduo-service/custom-service/oss/getFileUrl?fileKey=${param}`, {
+    method: 'post',
+    parseResponse: true,
+  });
+};