xuruiqian
2025-06-04 17ce21955b4e3402d3d5868b52e50bfdd55bc572
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<template>
  <div class="editor-div" style="border: 1px solid #ccc">
    <Toolbar
        style="border-bottom: 1px solid #ccc"
        :editor="editorRef"
        :defaultConfig="editorToolbarConfig"
        :mode="editorMode"
    />
    <Editor :style="{height: `${props.height}`}"
            v-model="editorValueHtml"
            :defaultConfig="editorConfig"
            :mode="editorMode"
            @onCreated="handleEditorCreated"
    />
    <div>
      <el-link href="https://www.latexlive.com/" target="_blank">LaTeX公式在线编辑器</el-link>
    </div>
  </div>
</template>
 
<script>
import {getCurrentInstance, onBeforeUnmount, onMounted, reactive, toRefs, shallowRef, ref} from "vue";
import '@wangeditor/editor/dist/css/style.css';
import {Editor, Toolbar} from '@wangeditor/editor-for-vue';
import {getFileUploadUrl} from "@/api/common";
 
export default {
  name: "wangEditorExt",
  components: {Editor, Toolbar},
  props: {
    content: "",
    height: "",
  },
  setup(props) {
    let {proxy} = getCurrentInstance();
    const state = reactive({});
 
    const editorRef = shallowRef();
    const editorToolbarConfig = {
      insertKeys: {
        index: 0,
        keys: [
          'insertFormula', // “插入公式”菜单
          // 'editFormula' // “编辑公式”菜单
        ],
      },
    };
    const editorConfig = {
      placeholder: `${proxy.$t('message.PleaseInput')}`,
      // 选中公式时的悬浮菜单
      hoverbarKeys: {
        formula: {
          menuKeys: ['editFormula'], // “编辑公式”菜单
        },
      },
    };
    const editorValueHtml = shallowRef(props.content);
    const editorMode = shallowRef('default');// 或 'simple',
 
    onMounted(() => {
      Init();
    });
    onBeforeUnmount(() => {
      const editor = editorRef.value
      if (editor != null)
        editor.destroy()
    });
    const handleEditorCreated = (editor) => {
      editorRef.value = editor // 记录 editor 实例,重要!
 
      let config = editor.getMenuConfig('uploadImage') // 获取 uploadImage 的当前配置
      config.server = getFileUploadUrl();
      config.fieldName = 'file';
      // 上传之前触发
      config.onBeforeUpload = (file) => {
        return file
      };
 
      // 上传进度的回调函数
      config.onProgress = (progress) => {
 
      };
 
      // 单个文件上传成功之后
      config.onSuccess = (file, res) => {
 
      };
 
      // 单个文件上传失败
      config.onFailed = (file, res) => {
 
      };
 
      // 上传错误,或者触发 timeout 超时
      config.onError = (file, err, res) => {
 
      };
    }
    const exportvalue = () => {
      return editorRef.value.getHtml();
    }
    const Init = () => {
 
    };
 
    return {
      ...toRefs(state),
      editorRef,
      editorToolbarConfig,
      editorConfig,
      editorMode,
      editorValueHtml, handleEditorCreated,
      exportvalue, props
    }
  },
}
</script>
 
<style scoped lang="scss">
.editor-div ::v-deep(.w-e-text-container .w-e-scroll) {
  min-height: 310px !important; //!important是重点,因为原div是行内样式设置的高度300px*/
}
</style>