|
@@ -0,0 +1,184 @@
|
|
|
|
+<template>
|
|
|
|
+ <el-dialog
|
|
|
|
+ class="upload-paper-answer-dialog"
|
|
|
|
+ :visible.sync="modalIsShow"
|
|
|
|
+ title="上传试卷结构文档/标答PDF文档"
|
|
|
|
+ top="10vh"
|
|
|
|
+ width="700px"
|
|
|
|
+ :close-on-click-modal="false"
|
|
|
|
+ :close-on-press-escape="false"
|
|
|
|
+ append-to-body
|
|
|
|
+ @open="visibleChange"
|
|
|
|
+ >
|
|
|
|
+ <el-form ref="modalFormComp" :model="infos" label-width="80px">
|
|
|
|
+ <div v-for="paperType in paperTypes" :key="paperType" class="part-box">
|
|
|
|
+ <h3 class="part-box-title">{{ paperType }}</h3>
|
|
|
|
+ <el-form-item
|
|
|
|
+ v-for="(val, key) in fileTypes"
|
|
|
|
+ :key="key"
|
|
|
|
+ :prop="`${paperType}.${key}`"
|
|
|
|
+ :label="`${val.name}:`"
|
|
|
|
+ :rules="{
|
|
|
|
+ required: true,
|
|
|
|
+ validator: fileValidator,
|
|
|
|
+ trigger: 'change'
|
|
|
|
+ }"
|
|
|
|
+ >
|
|
|
|
+ <select-file
|
|
|
|
+ :format="val.format"
|
|
|
|
+ :disabled="isSubmit"
|
|
|
|
+ @file-change="data => fileChange(paperType, key, data)"
|
|
|
|
+ ></select-file>
|
|
|
|
+ <el-button
|
|
|
|
+ v-if="val.downloadUrl"
|
|
|
|
+ type="success"
|
|
|
|
+ icon="el-icon-download"
|
|
|
|
+ >
|
|
|
|
+ <a :href="val.downloadUrl" :download="val.downloadName">模板下载</a>
|
|
|
|
+ </el-button>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ </div>
|
|
|
|
+ </el-form>
|
|
|
|
+ <div slot="footer">
|
|
|
|
+ <el-button type="primary" :disabled="isSubmit" @click="submit"
|
|
|
|
+ >确认</el-button
|
|
|
|
+ >
|
|
|
|
+ <el-button @click="cancel">取消</el-button>
|
|
|
|
+ </div>
|
|
|
|
+ </el-dialog>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script>
|
|
|
|
+import { uploadPaperAndAnswer } from "../api";
|
|
|
|
+import SelectFile from "./SelectFile.vue";
|
|
|
|
+
|
|
|
|
+// const files = {
|
|
|
|
+// files: [
|
|
|
|
+// {
|
|
|
|
+// paperType: "A",
|
|
|
|
+// subjectiveQuestionFile: "File",
|
|
|
|
+// subjectiveQuestionMd5: "string",
|
|
|
|
+// objectiveQuestionFile: "File",
|
|
|
|
+// objectiveQuestionMd5: "string",
|
|
|
|
+// standardAnswerFile: "File",
|
|
|
|
+// standardAnswerMd5: "string"
|
|
|
|
+// }
|
|
|
|
+// ]
|
|
|
|
+// };
|
|
|
|
+
|
|
|
|
+export default {
|
|
|
|
+ name: "upload-paper-answer-dialog",
|
|
|
|
+ components: { SelectFile },
|
|
|
|
+ props: {
|
|
|
|
+ instance: {
|
|
|
|
+ type: Object,
|
|
|
|
+ default() {
|
|
|
|
+ return {};
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ data() {
|
|
|
|
+ return {
|
|
|
|
+ modalIsShow: false,
|
|
|
|
+ isSubmit: false,
|
|
|
|
+ infos: {},
|
|
|
|
+ paperTypes: [],
|
|
|
|
+ fileTypes: {
|
|
|
|
+ subjectiveQuestion: {
|
|
|
|
+ name: "客观题",
|
|
|
|
+ downloadUrl: "111",
|
|
|
|
+ downloadName: "客观题结构.xlsx",
|
|
|
|
+ format: ["xlsx", "xls"]
|
|
|
|
+ },
|
|
|
|
+ objectiveQuestion: {
|
|
|
|
+ name: "主观题",
|
|
|
|
+ downloadUrl: "111",
|
|
|
|
+ downloadName: "主观题答案.xlsx",
|
|
|
|
+ format: ["xlsx", "xls"]
|
|
|
|
+ },
|
|
|
|
+ standardAnswer: {
|
|
|
|
+ name: "标答",
|
|
|
|
+ format: ["pdf"]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ initData() {
|
|
|
|
+ this.paperTypes = this.instance.paperType.split(",");
|
|
|
|
+ let infos = {};
|
|
|
|
+ this.paperTypes.forEach(paperType => {
|
|
|
|
+ let item = {};
|
|
|
|
+ Object.keys(this.fileTypes).map(typeKey => {
|
|
|
|
+ item[typeKey] = {
|
|
|
|
+ file: null,
|
|
|
|
+ md5: null,
|
|
|
|
+ errorMsg: null
|
|
|
|
+ };
|
|
|
|
+ });
|
|
|
|
+ infos[paperType] = item;
|
|
|
|
+ });
|
|
|
|
+ this.infos = infos;
|
|
|
|
+ },
|
|
|
|
+ visibleChange() {
|
|
|
|
+ this.initData();
|
|
|
|
+ },
|
|
|
|
+ cancel() {
|
|
|
|
+ this.modalIsShow = false;
|
|
|
|
+ },
|
|
|
|
+ open() {
|
|
|
|
+ this.modalIsShow = true;
|
|
|
|
+ },
|
|
|
|
+ fileChange(paperType, typeKey, data) {
|
|
|
|
+ if (data.errorMsg) {
|
|
|
|
+ this.infos[paperType][typeKey].file = null;
|
|
|
|
+ this.infos[paperType][typeKey].md5 = null;
|
|
|
|
+ this.infos[paperType][typeKey].errorMsg = data.errorMsg;
|
|
|
|
+ } else {
|
|
|
|
+ this.infos[paperType][typeKey].file = data.file;
|
|
|
|
+ this.infos[paperType][typeKey].md5 = data.md5;
|
|
|
|
+ this.infos[paperType][typeKey].errorMsg = null;
|
|
|
|
+ }
|
|
|
|
+ this.$refs.modalFormComp.validateField(`${paperType}.${typeKey}`);
|
|
|
|
+ },
|
|
|
|
+ fileValidator(rule, value, callback) {
|
|
|
|
+ const [paperType, typeKey] = rule.field.split(".");
|
|
|
|
+ const val = this.infos[paperType][typeKey];
|
|
|
|
+
|
|
|
|
+ if (val.errorMsg) {
|
|
|
|
+ return callback(new Error(val.errorMsg));
|
|
|
|
+ } else {
|
|
|
|
+ if (!val.file) {
|
|
|
|
+ return callback(new Error("请选择文件"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ callback();
|
|
|
|
+ },
|
|
|
|
+ async submit() {
|
|
|
|
+ const valid = await this.$refs.modalFormComp.validate().catch(() => {});
|
|
|
|
+ if (!valid) return;
|
|
|
|
+
|
|
|
|
+ if (this.isSubmit) return;
|
|
|
|
+ this.isSubmit = true;
|
|
|
|
+
|
|
|
|
+ let formData = new FormData();
|
|
|
|
+ formData.append("id", this.instance.id);
|
|
|
|
+ Object.entries(this.infos).forEach(([paperType, vals], index) => {
|
|
|
|
+ const indexName = `files[${index}]`;
|
|
|
|
+ formData.append(`${indexName}.paperType`, paperType);
|
|
|
|
+ Object.keys(vals).forEach(typeKey => {
|
|
|
|
+ formData.append(`${indexName}.${typeKey}File`, vals[typeKey].file);
|
|
|
|
+ formData.append(`${indexName}.${typeKey}Md5`, vals[typeKey].md5);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ const data = await uploadPaperAndAnswer(formData).catch(() => {});
|
|
|
|
+ this.isSubmit = false;
|
|
|
|
+ if (!data) return;
|
|
|
|
+
|
|
|
|
+ this.$message.success("上传成功!");
|
|
|
|
+ this.$emit("modified");
|
|
|
|
+ this.cancel();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+</script>
|