diff --git a/src/components/drawers/ImportStu.vue b/src/components/drawers/ImportStu.vue index fbd15382..2c030565 100644 --- a/src/components/drawers/ImportStu.vue +++ b/src/components/drawers/ImportStu.vue @@ -24,12 +24,28 @@
上传:
-
+
+ +

+ +

+

点击或将文件拖拽到此处上传

+

支持扩展名:.xls/.xlsx

+
+
+ + + +
+
+
+
+
+
+
{{ fileName }}
+
正在上传
+
+ + +
+
+ + +
+
+
+
+
+
+
+
+
{{ fileName }}
+
上传失败
+
+ + +
+ +
+ +
+ 下载失败数据 +
+ +
+
+
+ {{ succNum }}条数据导入成功,{{ errNum }}条数据导入失败 +
+
+
+
+ +
+
+
+
+
+
{{ fileName }}
+
上传成功
+
+ + +
+
+ +
+ 删除 +
+
+
+
+
+ 下载失败数据 +
+
+
+
+ +
+ {{ succNum }}条数据导入成功,{{ errNum }}条数据导入失败 +
+
- - + +
@@ -120,19 +258,176 @@ export default { }, }, setup(props, ctx) { - const state = reactive({}); + console.log(1222) + const state = reactive({ + fileType: ["xls", "xlsx"], + importLeader: + process.env.VUE_APP_BASE_API + + `/admin/studentGroup/importGroup/${props.projectId}`, + uploadpercent: -1, + uploadErr: false, //上传失败 + addLoading: false, + fileList: [], + succNum: 0, //成功数据数 + errNum: 0, //失败数据数 + downloadErrUrl: null, //下载失败数据 + fileName: "", + locationHref: + location.href.indexOf("http://") !== -1 + ? "http://43.143.139.204:12016/" + : location.href.slice(0, location.href.indexOf("/m")) + "/upload/", + template: process.env.VUE_APP_UP_LOAD_STUDENT_SCORE_TEMPLATE, + }); const closeDrawer = () => { - ctx.emit("update:Importvisible", false); + + ctx.emit("closeDraw", true); + ctx.emit("update:TaskFaceImpStuvisible", false); + state.fileList = []; + state.uploadpercent = -1; + state.uploadErr = false; //上传失败 }; const afterVisibleChange = (bool) => { console.log("state", bool); + if (bool) { + console.log("当前是 1 项目 2 路径图", props.type); + } }; + //上传文件 + const handleChange = (info) => { + if (info) { + var FileExt = info.file.name.replace(/.+\./, ""); + if (["xls", "xlsx"].indexOf(FileExt.toLowerCase()) === -1) { + state.fileList = []; + state.uploadpercent = -1; + message.destroy(); + message.error("请上传正确的文件格式"); + return; + } + } + + state.addLoading = true; + state.uploadpercent = parseInt(info.file.percent); + console.log("我是文件上传的进度---------->", info.file.percent); + const status = info.file.status; + if (status !== "uploading") { + // console.log(info.file, info.fileList); + } + if (status === "done") { + state.fileName = info.file.name; + let i = 0; + let timeouts = setTimeout(() => { + clearInterval(timer); + state.addLoading = false; + message.destroy(); + message.error(`文件导入超时`); + }, 30000); + + let timer = setInterval(() => { + let uid = info.file.response.data; + api + .getImportStatus(uid) + .then((res) => { + console.log("查询导入状态", res); + if (res.data.code === 200) { + if (res.data.data.status !== "START") { + i++; + if (i === 1) { + message.destroy(); + message.success(`${info.file.name}上传成功`); + state.addLoading = false; + props.searchTaskList && props.searchTaskList(); + } + state.succNum = res.data.data.successNum; + state.errNum = res.data.data.failedNum; + state.downloadErrUrl = res.data.data.url; + console.log("props.getStudent", props.getStudent); + clearInterval(timer); + clearTimeout(timeouts); + } + } + }) + .catch((err) => { + state.addLoading = false; + clearInterval(timer); + clearTimeout(timeouts); + console.log("查询导入状态失败", err); + }); + }, 500); + } else if (status === "error") { + state.uploadErr = true; + message.error(`${info.file.name}上传失败`); + } + }; + const beforeUpload = (file) => { + return new Promise((resolve, reject) => { + // const isJpgOrPng = + // file.name.indexOf(".xlsx") !== "-1" || + // file.name.indexOf(".xls") !== "-1"; + + // if (!isJpgOrPng) { + // message.destroy(); + // message.error("仅支持xls、xlsx格式!"); + // return reject(false); + // } + const formData = new FormData(); + formData.append("uploadFile", file); + // let progress = { percent: 1 }; + + // const intervalId = setInterval(() => { + // if (progress.percent < 100) { + // progress.percent++; + // file.onProgress(progress); + // } else { + // clearInterval(intervalId); + // } + // }, 100); + api.batchImportScore(formData).then((res) => { + if (res.data.code === 200) { + console.log("上传成功", res); + return reject(true); + } + }); + return reject(false); + }); + }; + const handleUpload = (e) => { + console.log("handleUpload", e); + }; + + //删除 + const removeUpload = () => { + state.fileList = []; + state.uploadpercent = -1; + state.uploadErr = false; //上传失败 + state.succNum = 0; + state.errNum = 0; + state.downloadErrUrl = null; + state.addLoading = false; + }; + // 下载失败数据 + const downloadEeeorData = () => { + if (state.downloadErrUrl !== "") { + window.open(process.env.VUE_APP_FILE_PATH + state.downloadErrUrl); + } + }; + function downTemplate() { + // console.log(state.locationHref + state.template); + // window.open(state.locationHref + state.template); + } + return { ...toRefs(state), afterVisibleChange, closeDrawer, + handleChange, + downTemplate, + BATCH_IMPORT_SCORE, + beforeUpload, + handleUpload, + removeUpload, + downloadEeeorData, // change, }; }, diff --git a/src/components/drawers/TaskFaceIn.vue b/src/components/drawers/TaskFaceIn.vue index 78f29d53..8fac83bc 100644 --- a/src/components/drawers/TaskFaceIn.vue +++ b/src/components/drawers/TaskFaceIn.vue @@ -8,14 +8,14 @@ >
- +
请下载
@@ -25,18 +25,154 @@
上传:
-
+
+ +

+ +

+

点击或将文件拖拽到此处上传

+

支持扩展名:.xls/.xlsx

+
+
+ +
+
+
+
+
+
+
{{ fileName }}
+
正在上传
+
+ + +
+
+ + +
+
+
+
+
+
+
+
+
{{ fileName }}
+
上传失败
+
+ + +
+
+ +
+ 下载失败数据 +
+ +
+
+
+ {{ succNum }}条数据导入成功,{{ errNum }}条数据导入失败 +
+
+
+
+ +
+
+
+
+
+
{{ fileName }}
+
上传成功
+
+ + +
+
+ +
+ 删除 +
+
+
+
+
+ 下载失败数据 +
+
+
+
+ +
+ {{ succNum }}条数据导入成功,{{ errNum }}条数据导入失败 +
+
+
- - + +
@@ -44,6 +180,9 @@