|
@@ -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) {
|