Selaa lähdekoodia

Merge branches 'dev_1.3.4' and 'dev_1.3.4' of http://git.qmth.com.cn/union-question/union-question-web into dev_1.3.4

刘洋 6 kuukautta sitten
vanhempi
commit
cd62d35dc6
2 muutettua tiedostoa jossa 38 lisäystä ja 2 poistoa
  1. 37 2
      src/components/vEditor/components/VMenu.vue
  2. 1 0
      src/modules/question/api.js

+ 37 - 2
src/components/vEditor/components/VMenu.vue

@@ -113,6 +113,7 @@
     <!-- FormulaEditor  -->
     <formula-editor
       ref="FormulaDialog"
+      :content="curLatex"
       @confirm="formulaConfirm"
     ></formula-editor>
     <!-- <formula-dialog
@@ -145,16 +146,27 @@ export default {
     return {
       curEditFocusRange: null,
       ttsVoice: null,
+      curLatex: "",
     };
   },
 
   methods: {
-    voiceConfirm(blob) {
+    async voiceConfirm(blob) {
       const file = new File([blob], `${new Date().getTime()}.wav`, {
         type: "audio/wav",
       });
       console.log("file", file);
-      uploadAudioHandle.bind(this.$parent)(file);
+      let result = true;
+      await uploadAudioHandle
+        .bind(this.$parent)(file)
+        .catch(() => {
+          result = false;
+        });
+      if (!result) {
+        this.$message.error("音频保存错误,请重新尝试!");
+        return;
+      }
+      this.$refs.TtsDialog.cancel();
     },
     openVoiceDialog() {
       this.$refs.TtsDialog.open();
@@ -236,6 +248,28 @@ export default {
       this.curEditFocusRange.collapse();
       this.$parent.emitJSON();
     },
+    getSelectionLatex() {
+      const sel = window.getSelection();
+      let contents = "";
+      if (sel.getRangeAt && sel.rangeCount) {
+        const range = sel.getRangeAt(0);
+        contents = range.cloneContents();
+      }
+
+      let image = "";
+      // console.dir(contents);
+      if (contents && contents.childNodes) {
+        for (let i = 0, len = contents.childNodes.length; i < len; i++) {
+          const el = contents.childNodes[i];
+          if (el.tagName === "IMG" && el.getAttribute("data-latex")) {
+            image = el;
+            break;
+          }
+        }
+      }
+      const imgLatex = image && image.getAttribute("data-latex");
+      return imgLatex || "";
+    },
     // formula
     /**
      * @param {Event} event
@@ -247,6 +281,7 @@ export default {
         this.editorFocus();
       }
       this.curEditFocusRange = window.getSelection().getRangeAt(0);
+      this.curLatex = this.getSelectionLatex();
       this.$refs.FormulaDialog.open();
     },
     checkDomInEditor(dom) {

+ 1 - 0
src/modules/question/api.js

@@ -412,6 +412,7 @@ export const asyncTaskDownloadApi = (taskId) => {
     {},
     {
       params: { taskId },
+      responseType: "blob",
     }
   );
 };