update
This commit is contained in:
parent
46c2c20629
commit
7ecec8ffde
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue