This commit is contained in:
zhangds 2022-07-28 13:45:58 +08:00
parent 46c2c20629
commit 7ecec8ffde
1 changed files with 32 additions and 13 deletions

View File

@ -1,6 +1,6 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { Button, Icon, BlockLoading, Notify, Grid } from "zent"; import { Button, Icon, BlockLoading, Notify, Grid } from "zent";
import { bachUploadQuery, handelResponse } from "../../assets/api.js"; import { bachUploadQuery } from "../../assets/api.js";
import "./style.less"; import "./style.less";
const columns = [ const columns = [
@ -32,27 +32,45 @@ const UseUploadExcel = (props) => {
const [fileState, setFilesState] = useState(null); // const [fileState, setFilesState] = useState(null); //
const [filesName, setFilesName] = useState(""); // const [filesName, setFilesName] = useState(""); //
const [filesTip, setFilesTip] = useState(2); // tip 0 1 2 const [filesTip, setFilesTip] = useState(2); // tip 0 1 200
const [loading, setLoading] = useState(false); // loading const [loading, setLoading] = useState(false); // loading
const [sha1, setSha1] = useState(""); // const [sha1, setSha1] = useState(""); //
const [disabledSureBtn, setDisabledSureBtn] = useState(true); // const [disabledSureBtn, setDisabledSureBtn] = useState(true); //
const [partSuccessTag, setPartSuccessTag] = useState(false); // const [partSuccessTag, setPartSuccessTag] = useState(false); //
const [showUpType, setShowUpType] = useState(false); // false true const [showUpType, setShowUpType] = useState(false); // false true
/**
* 状态操作
* @param {0失败 1部分成功 200全部成功} type
* @returns
*/
const resCurr = (type) => {
switch (type.code) {
case 200:
setFilesTip(200);
return;
case 0:
setFilesTip(0);
return;
case 1:
setFilesTip(1);
return;
default:
return;
}
};
/** /**
* 文件后端解析 * 文件后端解析
*/ */
const excelParseFun = () => { const excelParseFun = (file) => {
setLoading(true); setLoading(true);
let formdata = new FormData(); let formdata = new FormData();
formdata.append("file", fileState); console.log("files =>", file);
formdata.append("file", file);
bachUploadQuery(formdata).then((res) => { bachUploadQuery(formdata).then((res) => {
handelResponse(
res,
(req, msg) => {
console.log("res file =>", res); console.log("res file =>", res);
}, resCurr(res);
(err) => {}
);
}); });
}; };
@ -65,7 +83,7 @@ const UseUploadExcel = (props) => {
setFilesState(my_file); setFilesState(my_file);
setFilesName(my_file.name); setFilesName(my_file.name);
setShowUpType(true); setShowUpType(true);
excelParseFun(); // excelParseFun(my_file); //
console.log("file =>", my_file); console.log("file =>", my_file);
}; };
@ -197,9 +215,10 @@ const UseUploadExcel = (props) => {
switch (filesTip) { switch (filesTip) {
case 0: case 0:
return tipErr(); return tipErr();
case 1: case 200:
return tipSuccess(); return tipSuccess();
default: default:
return;
} }
})()} })()}
</div> </div>