ソースを参照

feat:解决题库试题特殊字符导致构建题卡失败问题

zhangjie 1 年間 前
コミット
a08a94ccbe
2 ファイル変更17 行追加3 行削除
  1. 5 3
      src/modules/card/components/CardBuildDialog.vue
  2. 12 0
      src/plugins/utils.js

+ 5 - 3
src/modules/card/components/CardBuildDialog.vue

@@ -78,7 +78,7 @@ import { getCardHeadModel } from "../../../../card/elementModel";
 import TopicElementPreview from "../../../../card/components/TopicElementPreview";
 import CardView from "../../../../card/components/CardView.vue";
 import CardHeadSample from "../../../../card/elements/card-head/CardHead";
-import { deepCopy, objTypeOf } from "@/plugins/utils";
+import { deepCopy, objTypeOf, removeRichTextValue } from "@/plugins/utils";
 // ceshi
 // import paperData from "./paper.json";
 
@@ -154,9 +154,11 @@ export default {
           attachmentId: res.attachmentId,
         };
         const answerJson = res.answerJson
-          ? JSON.parse(res.answerJson)
+          ? JSON.parse(removeRichTextValue(res.answerJson))
           : { details: [] };
-        const paperJson = res.paperJson ? JSON.parse(res.paperJson) : {};
+        const paperJson = res.paperJson
+          ? JSON.parse(removeRichTextValue(res.paperJson))
+          : {};
         this.rebuildPaperQuestionNumber(answerJson);
         this.rebuildPaperQuestionNumber(paperJson);
         this.parsePaperAnswers(paperJson, answerJson);

+ 12 - 0
src/plugins/utils.js

@@ -450,3 +450,15 @@ export function numberToChinese(num) {
     })
     .join("十");
 }
+
+/**
+ * 移除富文本json字符串中的type=text的value值
+ * @param {string} data 富文本json字符串
+ * @returns 字符串
+ */
+export function removeRichTextValue(data) {
+  return data.replace(
+    /"type":"text","value":"(.*?)"/g,
+    '"type":"text","value":""'
+  );
+}