Merge pull request #1 from PlayEdu/dev

优化批量导入
This commit is contained in:
Teng 2023-04-09 14:48:19 +08:00 committed by GitHub
commit 4093f84b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 25 deletions

View File

@ -8,7 +8,6 @@ import { getHost } from "../../utils/index";
const MemberImportPage = () => { const MemberImportPage = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const [tableData, setWageTableData] = useState<any>([]);
const [errorData, setErrorData] = useState<any>([]); const [errorData, setErrorData] = useState<any>([]);
const uploadProps = { const uploadProps = {
@ -30,41 +29,39 @@ const MemberImportPage = () => {
reader.readAsBinaryString(f); reader.readAsBinaryString(f);
return false; return false;
}, },
onRemove: () => {
setWageTableData([]);
},
}; };
const handleImpotedJson = (jsonArr: any, file: any) => { const handleImpotedJson = (jsonArr: any[], file: any) => {
//jsonArr返回的是你上传的excel表格的每一行的数据 是数组形式 jsonArr.splice(0, 2); // 去掉表头[第一行规则描述,第二行表头名]
jsonArr.splice(0, 1); // 去掉表头 let data: any[] = [];
const jsonArrData = jsonArr.map((item: any, index: number) => { for (let i = 0; i < jsonArr.length; i++) {
// console.log(item, index); let tmpItem = jsonArr[i];
let jsonObj = item; if (typeof tmpItem === undefined) {
//在这写你需要的处理逻辑 break;
// jsonObj.id = data.length + index + 1; }
// jsonObj.key = data.length + index + 1 + ''; if (tmpItem.length === 0) {
// jsonObj.name = item[0]; //空行
continue;
}
data.push({
deps: tmpItem[0],
email: tmpItem[1],
password: tmpItem[2],
name: tmpItem[3],
id_card: tmpItem[4],
});
}
// jsonObj.profession = item[1]; storeBatchTableData(data);
// jsonObj.pay = item[2];
// jsonObj.work = item[3];
return jsonObj;
});
// setData([...data, ...jsonArrData]);
setWageTableData(jsonArrData);
storeBatchTableData(jsonArrData);
}; };
const storeBatchTableData = (data: any) => { const storeBatchTableData = (data: any) => {
user user
.storeBatch(2, data) .storeBatch(2, data)
.then((res: any) => { .then(() => {
message.success("导入成功!"); message.success("导入成功!");
navigate(-1); navigate(-1);
}) })
.catch((e) => { .catch((e) => {
setWageTableData([]);
if (e.code === -1) { if (e.code === -1) {
setErrorData(e.data); setErrorData(e.data);
} }