zhangjie 2 éve
szülő
commit
41d891c83a

+ 10 - 4
src/modules/question/api.js

@@ -272,11 +272,17 @@ export function updateSourceDetailApi(data) {
 }
 
 // question-import-edit
-export function questionImportParseRichText(richText) {
-  return $httpWithMsg.post(`${QUESTION_API}/question/import/parse`, {
-    richText,
+export function questionImportFileUpload(data, headData) {
+  return $httpWithMsg.post(`${QUESTION_API}/word/parse/struct`, data, {
+    headers: headData,
   });
 }
+export function questionImportParseRichText(richText) {
+  return $httpWithMsg.post(`${QUESTION_API}/word/parse/identify`, richText);
+}
 export function questionImportPaperSave(paperData) {
-  return $httpWithMsg.post(`${QUESTION_API}/question/import/paper`, paperData);
+  return $httpWithMsg.post(`${QUESTION_API}/word/parse/save`, paperData);
+}
+export function questionImportDownloadTemplate(datas) {
+  return $httpWithMsg.post(`${QUESTION_API}/word/parse/export`, datas);
 }

+ 6 - 3
src/modules/question/components/QuestionImportDialog.vue

@@ -72,7 +72,7 @@
       <el-form-item prop="file">
         <import-file
           ref="ImportFile"
-          :format="[importType]"
+          :format="importFileTypes"
           :template-url="templateUrl"
           only-fetch-file
           @file-change="fileChange"
@@ -87,7 +87,7 @@
 
 <script>
 import ImportFile from "@/components/ImportFile.vue";
-import { importQuestionApi } from "../api";
+import { questionImportFileUpload } from "../api";
 import { QUESTION_API } from "@/constants/constants";
 import { mapState } from "vuex";
 
@@ -150,6 +150,9 @@ export default {
   },
   computed: {
     ...mapState({ user: (state) => state.user }),
+    importFileTypes() {
+      return this.importType === "docx" ? ["docx", "doc"] : [this.importType];
+    },
   },
   watch: {
     "modalForm.useOriginalPaper": {
@@ -207,7 +210,7 @@ export default {
       });
       formData.append("file", this.fileData.file);
 
-      const res = await importQuestionApi(formData, {
+      const res = await questionImportFileUpload(formData, {
         md5: this.fileData.md5,
       }).catch(() => {});
       this.loading = false;

+ 78 - 55
src/modules/question/components/QuestionImportEdit.vue

@@ -53,15 +53,7 @@
                   plain
                   icon="icon icon-export-answer"
                   @click="toImportAnswer"
-                  >导入答案</el-button
-                >
-                <el-button
-                  size="small"
-                  type="primary"
-                  plain
-                  icon="icon icon-export-prop"
-                  @click="toImportProp"
-                  >导入属性</el-button
+                  >导入答案属性</el-button
                 >
                 <el-button
                   size="small"
@@ -101,32 +93,29 @@
       dialog-title="导入答案"
       :template-download-handle="answerTemplateDownload"
       :upload-url="uploadAnswerUrl"
+      :upload-data="uploadAnswerData"
       add-file-param="dataFile"
       @uploaded="answerUploaded"
     ></import-file-dialog>
-    <!-- 上传属性文件 -->
-    <import-file-dialog
-      ref="ImportPropDialog"
-      dialog-title="导入属性"
-      :template-download-handle="propTemplateDownload"
-      :upload-url="uploadPropUrl"
-      add-file-param="dataFile"
-      @uploaded="propUploaded"
-    ></import-file-dialog>
   </div>
 </template>
 
 <script>
-import paperRichTextJson from "../datas/paperRichText.json";
-import paperParseData from "../datas/paperParseData.json";
+// import paperRichTextJson from "../datas/paperRichText.json";
+// import paperParseData from "../datas/paperParseData.json";
 
-import { deepCopy, randomCode } from "@/plugins/utils";
+import { calcSum, deepCopy, randomCode } from "@/plugins/utils";
 import QuestionImportPaperEdit from "./QuestionImportPaperEdit.vue";
 import { isAnEmptyRichText } from "@/utils/utils";
-import { questionImportPaperSave, questionImportParseRichText } from "../api";
+import {
+  questionImportPaperSave,
+  questionImportParseRichText,
+  questionImportDownloadTemplate,
+} from "../api";
 import ImportFileDialog from "@/components/ImportFileDialog.vue";
 import { QUESTION_API } from "@/constants/constants";
 import { propertyNameQueryApi } from "@/modules/question/api";
+import { downloadByApi } from "@/plugins/download";
 
 const questionInfoField = [
   "courseId",
@@ -135,6 +124,7 @@ const questionInfoField = [
   "score",
   "publicity",
   "control",
+  "answerAnalysis",
   "quesAnswer",
 ];
 
@@ -146,8 +136,8 @@ export default {
       type: Object,
       default() {
         return {
-          paperRichText: { sections: [] },
-          paperData: [],
+          richText: { sections: [] },
+          detailInfo: [],
           importData: {
             courseId: "",
             name: "",
@@ -161,15 +151,14 @@ export default {
   },
   data() {
     return {
-      modalIsShow: true,
+      modalIsShow: false,
       loading: false,
       questionKey: "",
       paperData: [],
       paperRichJson: { sections: [] },
       // upload answer
-      uploadAnswerUrl: `${QUESTION_API}/paper/answer/import/`,
-      // upload prop
-      uploadPropUrl: `${QUESTION_API}/paper/answer/import/`,
+      uploadAnswerUrl: `${QUESTION_API}/word/parse/import`,
+      uploadAnswerData: {},
     };
   },
   beforeDestroy() {
@@ -178,14 +167,14 @@ export default {
   methods: {
     async visibleChange() {
       await this.getCourseProperty();
-      this.paperData = deepCopy(paperParseData);
-      this.paperRichJson = deepCopy(paperRichTextJson);
-      // this.paperRichJson = deepCopy(this.data.paperRichText);
-      // this.paperData = deepCopy(this.data.paperData);
+      // this.paperData = deepCopy(paperParseData);
+      // this.paperRichJson = deepCopy(paperRichTextJson);
+      this.paperRichJson = deepCopy(this.data.richText);
+      this.paperData = deepCopy(this.data.detailInfo);
       this.questionKey = randomCode();
     },
     async getCourseProperty() {
-      const res = await propertyNameQueryApi(this.courseId, "");
+      const res = await propertyNameQueryApi(this.data.importData.courseId, "");
       const optionList = res.data || [];
       window.sessionStorage.setItem(
         "coursePropertys",
@@ -258,16 +247,32 @@ export default {
       const paperData = this.$refs.QuestionImportPaperEdit.getData();
       const transformFieldMap = { body: "quesBody", options: "quesOptions" };
       const fields = Object.keys(transformFieldMap);
-      paperData.forEach((detail) => {
-        detail.questions.forEach((question) => {
+      const detailInfo = paperData.map((detail) => {
+        const questionInfo = detail.questions.map((question) => {
           fields.forEach((field) => {
             question[transformFieldMap[field]] = question[field];
             delete question[field];
           });
+
+          if (question.subQuestions && question.subQuestions.length) {
+            question.score = calcSum(
+              question.subQuestions.map((q) => q.score || 0)
+            );
+          }
+          return question;
         });
+
+        return {
+          name: detail.name,
+          number: detail.number,
+          questionCount: questionInfo.length,
+          questionInfo,
+          questionScore: detail.questionScore,
+          totalScore: calcSum(questionInfo.map((q) => q.score || 0)),
+        };
       });
-      console.log(paperData);
-      return paperData;
+      console.log(detailInfo);
+      return detailInfo;
     },
     checkImportPaperData(paperData) {
       // 题目内容校验
@@ -284,7 +289,7 @@ export default {
       ];
       let errInfos = [];
       paperData.forEach((detail) => {
-        detail.questions.forEach((question) => {
+        detail.questionInfo.forEach((question) => {
           const { questionType, quesBody } = question;
           const questionTitle = `第${detail.number}大题第${question.number}小题`;
           let qErrInfo = [];
@@ -359,14 +364,26 @@ export default {
 
       if (!this.data.importData.useOriginalPaper) return true;
       // 答案、分数校验
-      let totalScore = 0;
+      let totalScore = calcSum(paperData.map((d) => d.totalScore));
       let errQuestions = [];
       paperData.forEach((detail) => {
-        detail.questions.forEach((question) => {
-          if (!question.score) {
-            errQuestions.push(`第${detail.number}大题第${question.number}小题`);
+        detail.questionInfo.forEach((question) => {
+          if (question.subQuestions && question.subQuestions.length) {
+            let subIndexs = [];
+            question.subQuestions.forEach((subq, sind) => {
+              if (!subq.score)
+                subIndexs.push(question.number + "-" + (sind + 1));
+            });
+            if (subIndexs.length)
+              errQuestions.push(
+                `第${detail.number}大题第${subIndexs.join}小题`
+              );
           } else {
-            totalScore += question.score;
+            if (!question.score) {
+              errQuestions.push(
+                `第${detail.number}大题第${question.number}小题`
+              );
+            }
           }
         });
       });
@@ -413,21 +430,27 @@ export default {
     },
     // 导入答案
     toImportAnswer() {
+      const detailInfo = this.getImportPaperData();
+      this.uploadAnswerData = { detailInfo, ...this.data.importData };
       this.$refs.ImportAnswerDialog.open();
     },
-    answerTemplateDownload() {},
-    answerUploaded(answerData) {
-      const cacheData = this.getCachePaperInfo(answerData, ["quesAnswer"]);
-      this.paperData = this.assignCachePaperData(this.paperData, cacheData);
-      this.questionKey = randomCode();
-    },
-    // 导入属性
-    toImportProp() {
-      this.$refs.ImportPropDialog.open();
+    async answerTemplateDownload() {
+      const detailInfo = this.getImportPaperData();
+
+      const res = await downloadByApi(() => {
+        return questionImportDownloadTemplate({
+          detailInfo,
+          ...this.data.importData,
+        });
+      }).catch((e) => {
+        this.$message.error(e || "下载失败,请重新尝试!");
+      });
+
+      if (!res) return;
+      this.$message.success("下载成功!");
     },
-    propTemplateDownload() {},
-    propUploaded(propData) {
-      const cacheData = this.getCachePaperInfo(propData, ["quesProperties"]);
+    answerUploaded(answerData) {
+      const cacheData = this.getCachePaperInfo(answerData, questionInfoField);
       this.paperData = this.assignCachePaperData(this.paperData, cacheData);
       this.questionKey = randomCode();
     },

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 450 - 142
src/modules/question/datas/paperRichText.json


Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott