YY 2 年之前
父节点
当前提交
ccacb7473a
共有 1 个文件被更改,包括 26 次插入26 次删除
  1. 26 26
      src/components/frame/wang-editor.vue

+ 26 - 26
src/components/frame/wang-editor.vue

@@ -8,57 +8,57 @@
 </template>
 
 <script lang="ts" setup>
-import '@wangeditor/editor/dist/css/style.css'; // 引入 css
-import { Editor, Toolbar } from '@wangeditor/editor-for-vue';
-import type { Ref } from 'vue';
-import { ref, toRefs, onBeforeUnmount, shallowRef, computed } from 'vue';
+import '@wangeditor/editor/dist/css/style.css' // 引入 css
+import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
+import type { Ref } from 'vue'
+import { ref, toRefs, onBeforeUnmount, shallowRef, computed } from 'vue'
 interface EmitEvent {
-  (e: 'update:modelValue', params: string): void;
+  (e: 'update:modelValue', params: string): void
 }
 // #region 参数传递
 const props = defineProps({
   modelValue: { type: String, default: () => '' },
   mode: { type: String, default: () => 'default' },
   url: { type: String, default: () => '' }
-});
-const { modelValue } = toRefs(props);
-const { mode } = toRefs(props);
-const { url } = toRefs(props);
+})
+const { modelValue } = toRefs(props)
+const { mode } = toRefs(props)
+const { url } = toRefs(props)
 // #endregion
 
-const editorRef = shallowRef();
+const editorRef = shallowRef()
 const onCreated = (editor: string) => {
-  editorRef.value = Object.seal(editor); // 一定要用 Object.seal() ,否则会报错
-};
+  editorRef.value = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
+}
 
-const emit = defineEmits<EmitEvent>();
+const emit = defineEmits<EmitEvent>()
 const valueHtml = computed({
   get() {
-    return modelValue.value;
+    return modelValue.value
   },
   set(value: string) {
-    emit('update:modelValue', value);
+    emit('update:modelValue', value)
   }
-});
+})
 const customPicInsert = (result: { errcode: number; uri: string; name: string }, insertFn: any) => {
-  const { errcode, uri, name } = result;
-  const url = `${import.meta.env.VITE_APP_HOST}${uri}`;
+  const { errcode, uri, name } = result
+  const url = `${import.meta.env.VITE_APP_HOST}${uri}`
   if (errcode === 0) {
-    insertFn(url, name);
+    insertFn(url, name)
   }
-};
+}
 let editorConfig: Ref<object> = ref({
   placeholder: '请输入内容...',
   MENU_CONF: { uploadImage: { server: url, customInsert: customPicInsert } }
-});
+})
 let toolbarConfig: Ref<object> = ref({
   // excludeKeys: ['insertImage', 'insertVideo', 'uploadVideo', 'video'],
-});
+})
 onBeforeUnmount(() => {
-  const editor = editorRef.value;
-  if (editor == null) return;
-  editor.destroy();
-});
+  const editor = editorRef.value
+  if (editor == null) return
+  editor.destroy()
+})
 </script>
 
 <style src="@wangeditor/editor/dist/css/style.css"></style>