MarkParamUploadAnswer.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div class="mark-param-upload-answer">
  3. <div class="box-justify part-box part-box-pad">
  4. <div>
  5. <p class="tips-info">1.主观题标答请上传PDF文档;</p>
  6. <p class="tips-info">
  7. 2.主观题标答文档上传后,在评卷界面小助手里可以打开进行查看,作为评卷参考;
  8. </p>
  9. <p class="tips-info">3.支持重复提交,以最后一次提交标答文件为准。</p>
  10. </div>
  11. <div>
  12. <mark-status field="answerFile"></mark-status>
  13. </div>
  14. </div>
  15. <div class="part-box part-box-pad">
  16. <el-form ref="modalFormComp" :model="infos" label-width="50px">
  17. <div class="part-box">
  18. <h3 class="mb-2">
  19. 卷型{{ markParamInfos.basicPaperInfo.paperType }}
  20. </h3>
  21. <el-form-item prop="file" label="标答:">
  22. <select-file
  23. :format="fileFormat"
  24. :disabled="loading"
  25. @file-change="fileChange"
  26. ></select-file>
  27. <p v-if="infos.errorMsg" class="tips-info tips-error">
  28. {{ infos.errorMsg }}
  29. </p>
  30. </el-form-item>
  31. <el-form-item v-if="answerFileUrl">
  32. <span
  33. class="cont-link"
  34. title="点击查看已上传标答文件"
  35. @click="toViewAnswer"
  36. >
  37. <i class="el-icon-document mr-1"></i>{{ answerFileName }}
  38. </span>
  39. </el-form-item>
  40. </div>
  41. </el-form>
  42. </div>
  43. <div class="text-center">
  44. <el-button type="primary" :disabled="loading" @click="submit"
  45. >确认</el-button
  46. >
  47. <el-button @click="cancel">取消</el-button>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. import { mapState, mapMutations } from "vuex";
  53. import { examStructureUploadAnswer } from "../../api";
  54. import SelectFile from "@/components/SelectFile.vue";
  55. import MarkStatus from "./MarkStatus.vue";
  56. export default {
  57. name: "mark-param-upload-answer",
  58. components: { SelectFile, MarkStatus },
  59. data() {
  60. return {
  61. modalIsShow: false,
  62. loading: false,
  63. infos: { file: null, md5: null, errorMsg: null },
  64. fileFormat: ["pdf"],
  65. };
  66. },
  67. computed: {
  68. ...mapState("markParam", ["markParamInfos"]),
  69. answerFileName() {
  70. return `${this.markParamInfos.basicPaperInfo.courseName}-标答文件`;
  71. },
  72. answerFileUrl() {
  73. const { paperType, paperAnswer } = this.markParamInfos.basicPaperInfo;
  74. if (!paperAnswer) return;
  75. const paperAnswerInfo = JSON.parse(paperAnswer);
  76. const paper = paperAnswerInfo.find(
  77. (item) => item.paperType === paperType
  78. );
  79. return paper ? paper.answerUrl : "";
  80. },
  81. },
  82. methods: {
  83. ...mapMutations("markParam", ["setMarkParamInfos"]),
  84. toViewAnswer() {
  85. window.open(this.answerFileUrl);
  86. },
  87. fileChange(data) {
  88. if (data.errorMsg) {
  89. this.infos.file = null;
  90. this.infos.md5 = null;
  91. this.infos.errorMsg = data.errorMsg;
  92. } else {
  93. this.infos.file = data.file;
  94. this.infos.md5 = data.md5;
  95. this.infos.errorMsg = null;
  96. }
  97. },
  98. async submit() {
  99. if (!this.infos.file) {
  100. this.$message.error("请选择标答文件");
  101. return;
  102. }
  103. if (this.loading) return;
  104. this.loading = true;
  105. let formData = new FormData();
  106. formData.append("id", this.markParamInfos.basicPaperInfo.id);
  107. formData.append(`file`, this.infos.file);
  108. formData.append(`md5`, this.infos.md5);
  109. const data = await examStructureUploadAnswer(formData).catch(() => {});
  110. this.loading = false;
  111. if (!data) return;
  112. this.$message.success("上传成功!");
  113. this.$emit("confirm");
  114. },
  115. cancel() {
  116. this.$emit("cancel");
  117. },
  118. },
  119. };
  120. </script>