Browse Source

fix:上传文件

chenzhen2 1 year ago
parent
commit
8d0c474498
1 changed files with 13 additions and 6 deletions
  1. 13 6
      src/pages/Member/components/StartImport/Uploader/index.jsx

+ 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>