思考题

This commit is contained in:
@fawn-nine
2024-08-30 10:42:24 +08:00
parent 0e54268b83
commit 40af077306
2 changed files with 122 additions and 23 deletions

View File

@@ -41,19 +41,17 @@
>新增考题</el-button >新增考题</el-button
> >
<el-upload <el-upload
style="display: inline-block;margin-left: 10px;"
:limit="1"
class="upload-demo" class="upload-demo"
:action="baseUrl + '/oss/fileoss'"
:show-file-list="false" :show-file-list="false"
multiple ref="files"
:on-exceed="handleExceed" action="#"
:on-success="handleSuccess"
:before-upload="beforeUploadHandle"
accept=".xlsx,.xls" accept=".xlsx,.xls"
:on-remove="handleRemoveNovel" :http-request="handleRequest"
>
<!-- accept=".xlsx,.xls" -->
<el-button size="small" type="primary" plain :loading="showLoadIcon" :disabled="showLoadIcon"
>导入考题 {{ loadText }}</el-button
> >
<el-button size="small" type="primary" plain :loading="showLoadIcon">导入考题 {{loadText}}</el-button>
</el-upload> </el-upload>
<!-- </el-form-item> --> <!-- </el-form-item> -->
<!-- <div :loading="showLoadIcon">{{loadText}}</div> --> <!-- <div :loading="showLoadIcon">{{loadText}}</div> -->
@@ -188,13 +186,13 @@
import global from "@/views/common/common.vue"; //引入共用组间 import global from "@/views/common/common.vue"; //引入共用组间
import commonShopTable from "./questionBank/shopproductTable.vue"; import commonShopTable from "./questionBank/shopproductTable.vue";
import Add from "./questionBank/add.vue"; import Add from "./questionBank/add.vue";
import axios from "axios";
export default { export default {
props: ["course"], props: ["course"],
data() { data() {
return { return {
showLoadIcon: false, showLoadIcon: false,
loadText:'', loadText: "",
baseUrl: global.baseUrl, baseUrl: global.baseUrl,
selectType: [], selectType: [],
shopTableVisible: false, shopTableVisible: false,
@@ -246,7 +244,8 @@ export default {
}, },
resList: [], resList: [],
resListVisible: false, resListVisible: false,
optCourse: {} optCourse: {},
currentFile:{}
}; };
}, },
components: { components: {
@@ -298,17 +297,54 @@ export default {
}, },
beforeUploadHandle() { beforeUploadHandle() {
// this.$message.info('正在上传中') // this.$message.info('正在上传中')
this.showLoadIcon = true this.showLoadIcon = true;
this.loadText = '正在上传中' this.loadText = "正在上传中";
}, },
handleSuccess(file, fileList) { handleSuccess(file, fileList) {
this.showLoadIcon = false this.showLoadIcon = false;
this.loadText = '' this.loadText = "";
console.log('fileurl', file.url) console.log("fileurl", this.course.id, file.url);
this.getQuestList(file.url, this.course.id);
// this.form.imageList.push('file.url',file.url); // this.form.imageList.push('file.url',file.url);
}, },
// 请求自动生成接口
getQuestList(url, courseId) {
// this.$http
// .request({
// url: this.$http.adornUrl('/common/classExam/importSubject'),
// method: "POST",
// data: {
// courseId: courseId,
// file:url
// },
// header: {
// //默认 无 说明:请求头
// "Content-Type": "application/json"
// }
// })
this.$http({
url: this.$http.adornUrl("/common/classExam/importSubject"),
method: "post",
data: this.$http.adornData({
courseId: courseId,
file: url
})
})
.then(res => {
console.log("reschenggong", res);
// if (res.data.code == 0) {
// this.$message.success("操作成功!");
// }
})
.catch(e => {
this.$message.error("获取课程信息失败");
_info = null;
});
},
handleRemoveNovel() { handleRemoveNovel() {
console.log('删除文件') console.log("删除文件");
}, },
handleExceed(files, fileList) { handleExceed(files, fileList) {
this.$message.warning(`当前限制选择 3 个文件`); this.$message.warning(`当前限制选择 3 个文件`);
@@ -422,6 +458,63 @@ export default {
} }
this.directorShow = true; this.directorShow = true;
}, },
handleRequest(option) {
console.log("jinlailema");
var that = this;
const { onProgress, onSuccess, onError } = option;
// this.progressPercent = 0;
this.currentFile = option.file;
let formdata = new FormData();
formdata.append("file", option.file);
// formdata.append("fileName", option.file.fileNamee);
formdata.append("courseId", this.course.id);
console.log("🚀 ~ handleRequest ~ formdata:", formdata);
this.showLoadIcon = true;
this.loadText = '正在上传文件'
// onProgress()
axios
.post(this.baseUrl + "/common/classExam/importSubject", formdata, {
headers: { token: this.$cookie.get("token") },
onUploadProgress: function(progressEvent) {
const percentCompleted = Math.round(
(progressEvent.loaded * 100) / progressEvent.total
);
if(percentCompleted == 100){
that.$message.success('文件上传成功,正在写入数据')
that.loadText = '文件上传成功,正在写入数据'
}
console.log(`Upload Progress: ${percentCompleted}%`);
}
})
.then(res => {
// console.log("上传成功", res);
if (res.data.code == 0) {
this.$message.success("导入成功!");
// that.fileList[that.fileList.length - 1].status = "done";
// clearInterval(that.uploadTimer);
that.showLoadIcon = false;
that.loadText = ''
that.currentFile = {};
onSuccess();
that.getDataList()
} else {
// that.fileList[that.fileList.length - 1].ststus = "error";
that.$message.error(res.data.msg);
onError();
that.showLoadIcon = false;
that.loadText = ''
}
})
.catch(e => {
that.$message.error(e.data.msg);
that.loadText = ''
});
// var prom = new Promise((resolve, reject) => {});
// prom.abort = () => {};
// return prom;
},
// 检索教务信息 // 检索教务信息
getDirectorInfo(id) { getDirectorInfo(id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -730,6 +823,9 @@ export default {
color: #149f97; color: #149f97;
} }
} }
.upload-demo {
display: contents;
}
.flexbox { .flexbox {
display: flex; display: flex;
} }

View File

@@ -586,6 +586,7 @@ export default {
duration: 1500, duration: 1500,
onClose: () => { onClose: () => {
this.visible = false; this.visible = false;
this.tableData = []
this.relationProductIds = []; this.relationProductIds = [];
this.relationProducts = []; this.relationProducts = [];
this.$emit("refreshDataList"); this.$emit("refreshDataList");
@@ -627,9 +628,11 @@ export default {
handlereset() { handlereset() {
// (this.fileList = []), (this.fileListNovel = []), (this.visible = false); // (this.fileList = []), (this.fileListNovel = []), (this.visible = false);
this.$emit("pclose"); this.$emit("pclose");
// this.relationProducts = []; // this.relationProducts = [];
// this.courseId = undefined; // this.courseId = undefined;
this.visible = false; this.visible = false;
this.tableData = []
}, },
handlePreview(file) { handlePreview(file) {
console.log(file); console.log(file);