瀏覽代碼

编辑试卷题卡

zhangjie 3 年之前
父節點
當前提交
4012dd97d4

+ 3 - 0
src/modules/card/api.js

@@ -80,3 +80,6 @@ export const saveCard = (datas) => {
   Vue.ls.set("cardData", datas);
   return Promise.resolve("11");
 };
+export const paperDetailApi = (paperId) => {
+  return $httpWithMsg.get(`${QUESTION_API}/paper/${paperId}`, {});
+};

+ 1 - 1
src/modules/card/autoBuild/paperCard.js

@@ -152,7 +152,7 @@ function parseCommonTypeQuestions(structType, dataList) {
   return questions;
 }
 
-function getFillBackClozeCount(questionBodyContent) {
+export function getFillBackClozeCount(questionBodyContent) {
   // TODO:
   let questionBody = null;
   let num = 0;

+ 53 - 0
src/modules/card/autoBuild/paperStruct.js

@@ -0,0 +1,53 @@
+import { getFillBackClozeCount } from "./paperCard";
+
+const COMMON_QUESTION_TYPES = [
+  "SINGLE_ANSWER_QUESTION",
+  "MULTIPLE_ANSWER_QUESTION",
+  "BOOL_ANSWER_QUESTION",
+  "FILL_BLANK_QUESTION",
+  "TEXT_ANSWER_QUESTION",
+];
+
+export function getPaperJsonSimpleStructInfo(paperJson) {
+  let struct = [];
+  paperJson.paperDetails.forEach((detail) => {
+    struct.push(`${detail.number}-${detail.name}`);
+    detail.paperDetailUnits.forEach((question) => {
+      if (COMMON_QUESTION_TYPES.includes(question.questionType)) {
+        const info = parseCommonTypeQuestion(question);
+        struct.push(`${detail.number}-${info}`);
+      } else {
+        let infos = parseNestedTypeQuestion(question);
+        infos.forEach((info) => {
+          struct.push(`${detail.number}-${info}`);
+        });
+      }
+    });
+  });
+  return struct.join("#");
+}
+
+function parseCommonTypeQuestion(question) {
+  const structType = question.questionType;
+  let info = `${question.number}:${structType}`;
+  const choiceQs = ["SINGLE_ANSWER_QUESTION", "MULTIPLE_ANSWER_QUESTION"];
+  if (choiceQs.includes(structType)) {
+    info += `:${question.question.quesOptions.length}`;
+  } else if (structType === "FILL_BLANK_QUESTION") {
+    info += `:${getFillBackClozeCount(question.question.quesOptions)}`;
+  } else {
+    info += ":";
+  }
+
+  return info;
+}
+
+function parseNestedTypeQuestion(question) {
+  let struct = [];
+  let qinfo = `${question.number}-`;
+  question.subQuestions.forEach((subq) => {
+    const info = parseCommonTypeQuestion(subq);
+    struct.push(`${qinfo}-${info}`);
+  });
+  return struct;
+}

+ 16 - 4
src/modules/card/components/CardDesign.vue

@@ -213,7 +213,7 @@ import RightClickMenu from "./RightClickMenu";
 import PageNumber from "./PageNumber";
 import { getPageInitElements } from "../pageModel";
 // test auto build
-import initPaperJson from "../autoBuild/paperJson.json";
+// import initPaperJson from "../autoBuild/paperJson.json";
 import { buildPaperCard } from "../autoBuild/paperCard";
 
 export default {
@@ -241,6 +241,10 @@ export default {
       type: Boolean,
       default: true,
     },
+    paperJson: {
+      type: Object,
+      default: null,
+    },
   },
   data() {
     return {
@@ -255,6 +259,7 @@ export default {
   computed: {
     ...mapState("card", [
       "cardConfig",
+      "paperSimpleStruct",
       "pageDefaultElems",
       "topics",
       "pages",
@@ -282,6 +287,7 @@ export default {
       "setInsetTarget",
       "setPageDefaultElems",
       "initState",
+      "setPaperSimpleStruct",
     ]),
     ...mapActions("card", [
       "resetTopicSeries",
@@ -293,8 +299,9 @@ export default {
       "initTopicsFromPages",
     ]),
     async initCard() {
-      const { cardConfig, pages } = this.content;
+      const { cardConfig, pages, paperSimpleStruct } = this.content;
       this.setCardConfig(cardConfig);
+      this.setPaperSimpleStruct(paperSimpleStruct);
       const pageDefaultElems = getPageInitElements(cardConfig);
       this.setPageDefaultElems(pageDefaultElems);
 
@@ -309,8 +316,12 @@ export default {
       this.addWatch();
     },
     initPageData() {
-      const elements = buildPaperCard(initPaperJson);
-      this.setTopics([...this.pageDefaultElems.elements, ...elements]);
+      if (this.paperJson) {
+        const elements = buildPaperCard(this.paperJson);
+        this.setTopics([...this.pageDefaultElems.elements, ...elements]);
+      }
+      // const elements = buildPaperCard(initPaperJson);
+      // this.setTopics([...this.pageDefaultElems.elements, ...elements]);
       // this.setTopics(this.pageDefaultElems.elements || []);
       this.resetTopicSeries();
       this.$nextTick(() => {
@@ -411,6 +422,7 @@ export default {
               version: CARD_VERSION,
               cardType: "PAPER",
               cardConfig: this.cardConfig,
+              paperSimpleStruct: this.paperSimpleStruct,
               pages: this.pages,
             },
             (k, v) => (k.startsWith("_") ? undefined : v)

+ 1 - 1
src/modules/card/router/index.js

@@ -30,7 +30,7 @@ export const menuRoutes = [
 
 export const editRoutes = [
   {
-    path: "/card/edit/:cardId?",
+    path: "/card/edit/:paperId/:cardId?",
     name: "CardEdit",
     component: () =>
       import(/* webpackChunkName: "card" */ "../views/CardEdit.vue"),

+ 4 - 0
src/modules/card/store/card.js

@@ -17,6 +17,7 @@ import {
 const state = {
   cardConfig: {},
   paperParams: {},
+  paperSimpleStruct: "",
   curElement: {},
   curDragElement: {},
   curPage: {},
@@ -40,6 +41,9 @@ const mutations = {
   setPaperParams(state, paperParams) {
     state.paperParams = paperParams;
   },
+  setPaperSimpleStruct(state, paperSimpleStruct) {
+    state.paperSimpleStruct = paperSimpleStruct;
+  },
   setCurElement(state, curElement) {
     state.curElement = curElement;
   },

+ 31 - 16
src/modules/card/views/CardEdit.vue

@@ -4,6 +4,7 @@
       v-if="dataReady"
       ref="CardDesign"
       :content="cardContent"
+      :paper-json="paperJson"
       @on-preview="toPreview"
       @on-save="toSave"
       @on-submit="toSubmit"
@@ -18,8 +19,9 @@
 </template>
 
 <script>
-import { cardConfigInfos, cardDetail, saveCard } from "../api";
+import { cardConfigInfos, cardDetail, saveCard, paperDetailApi } from "../api";
 import CardDesign from "../components/CardDesign";
+import { getPaperJsonSimpleStructInfo } from "../autoBuild/paperStruct";
 
 export default {
   name: "CardEdit",
@@ -29,7 +31,8 @@ export default {
   data() {
     return {
       cardId: this.$route.params.cardId,
-      prepareTcPCard: { paperId: "" },
+      paperId: this.$route.params.paperId,
+      paperJson: null,
       cardContent: {},
       cardPreviewUrl: "",
       canSave: false,
@@ -46,21 +49,18 @@ export default {
     this.registWindowSubmit();
   },
   beforeDestroy() {
-    // this.$ls.remove("cardId");
-    // this.$ls.remove("prepareTcPCard");
     delete window.submitCardTemp;
   },
   methods: {
     async initCard() {
       this.dataReady = false;
+      const paperRes = await paperDetailApi(this.paperId);
+      this.paperJson = paperRes.data;
+
       if (this.isEdit) {
         await this.getCardTempDetail();
       } else {
-        const cardConfig = await this.getCardConfig();
-        this.cardContent = {
-          pages: [],
-          cardConfig,
-        };
+        await this.initCardContent();
       }
       this.dataReady = true;
     },
@@ -69,14 +69,30 @@ export default {
       // 可能存在题卡内容没有记录的情况
       if (detData.content) {
         this.cardContent = JSON.parse(detData.content);
+        const curPaperSimpleStruct = getPaperJsonSimpleStructInfo(
+          this.paperJson
+        );
+        if (curPaperSimpleStruct !== this.cardContent.paperSimpleStruct) {
+          this.$message.info("试卷结构有变化,将重新生成题卡");
+          this.cardContent = {
+            pages: [],
+            cardConfig: detData.cardConfig,
+            paperSimpleStruct: getPaperJsonSimpleStructInfo(this.paperJson),
+          };
+        }
       } else {
-        let cardConfig = await this.getCardConfig();
-        this.cardContent = {
-          pages: [],
-          cardConfig,
-        };
+        this.$message.info("无题卡内容,将重新生成题卡");
+        await this.initCardContent();
       }
     },
+    async initCardContent() {
+      const cardConfig = await this.getCardConfig();
+      this.cardContent = {
+        pages: [],
+        cardConfig,
+        paperSimpleStruct: getPaperJsonSimpleStructInfo(this.paperJson),
+      };
+    },
     async getCardConfig() {
       const data = await cardConfigInfos();
       if (!data) {
@@ -100,8 +116,7 @@ export default {
       let data = this.$refs.CardDesign.getCardData(htmlContent, model);
       data = {
         ...data,
-        type: "CUSTOM",
-        ...this.prepareTcPCard,
+        paperId: this.paperId,
       };
       if (this.cardId) data.id = this.cardId;
       return data;

+ 12 - 0
src/modules/questions/views/EditPaper.vue

@@ -109,6 +109,9 @@
           <el-button type="info" size="small" @click="showAuditDialog">
             审核记录
           </el-button>
+          <el-button type="info" size="small" @click="toEditCard">
+            编辑题卡
+          </el-button>
         </div>
         <div>
           <el-button type="primary" size="small" plain @click="quesTagShowHide">
@@ -1347,6 +1350,15 @@ export default {
         },
       });
     },
+    toEditCard() {
+      this.$router.push({
+        name: "CardEdit",
+        params: {
+          cardId: null,
+          paperId: this.paperId,
+        },
+      });
+    },
     showAuditDialog() {
       this.auditInfoDialog = true;
     },