|
@@ -0,0 +1,83 @@
|
|
|
|
|
+<script setup lang="ts">
|
|
|
|
|
+import '@wangeditor/editor/dist/css/style.css'
|
|
|
|
|
+
|
|
|
|
|
+// @ts-ignore
|
|
|
|
|
+import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
|
|
|
|
|
+import { useAppStore } from '@/stores/app'
|
|
|
|
|
+import type { IEditorConfig } from '@wangeditor/editor'
|
|
|
|
|
+import { uploadFile, uploadFileOld } from '@/api/file'
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+const props = withDefaults(defineProps<{
|
|
|
|
|
+ modelValue: string
|
|
|
|
|
+ mode?: 'default' | 'simple'
|
|
|
|
|
+}>(), {
|
|
|
|
|
+ mode: 'default'
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+const emit = defineEmits<{
|
|
|
|
|
+ 'update:modelValue': [string]
|
|
|
|
|
+}>()
|
|
|
|
|
+
|
|
|
|
|
+const editorRef = shallowRef()
|
|
|
|
|
+const valueHtml = computed({
|
|
|
|
|
+ get: () => props.modelValue,
|
|
|
|
|
+ set: (value) => emit('update:modelValue', value)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+const appStore = useAppStore()
|
|
|
|
|
+
|
|
|
|
|
+const editorConfig: Partial<IEditorConfig> = {
|
|
|
|
|
+ placeholder: '请输入内容...',
|
|
|
|
|
+ MENU_CONF: {
|
|
|
|
|
+ uploadImage: {
|
|
|
|
|
+ async customUpload(file: File, insertFn: (url: string) => void) {
|
|
|
|
|
+ const result = await uploadFile(file)
|
|
|
|
|
+ insertFn(result.url)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+const toolbarConfig = {}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+const handleCreated = (editor: typeof Editor) => {
|
|
|
|
|
+ editorRef.value = editor // 记录 editor 实例,重要!
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 组件销毁时,也及时销毁编辑器
|
|
|
|
|
+//
|
|
|
|
|
+
|
|
|
|
|
+onBeforeUnmount(() => {
|
|
|
|
|
+ const editor = editorRef.value
|
|
|
|
|
+ if (editor == null) return
|
|
|
|
|
+ editor.destroy()
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<template>
|
|
|
|
|
+ <div class="w-full border-2">
|
|
|
|
|
+
|
|
|
|
|
+ <Toolbar
|
|
|
|
|
+ style="border-bottom: 1px solid #ccc"
|
|
|
|
|
+ :editor="editorRef"
|
|
|
|
|
+ :defaultConfig="toolbarConfig"
|
|
|
|
|
+ :mode="mode"
|
|
|
|
|
+ />
|
|
|
|
|
+ <Editor
|
|
|
|
|
+ style="height: 500px; overflow-y: hidden;"
|
|
|
|
|
+ v-model="valueHtml"
|
|
|
|
|
+ :defaultConfig="editorConfig"
|
|
|
|
|
+ :mode="mode"
|
|
|
|
|
+ @onCreated="handleCreated"
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<style scoped>
|
|
|
|
|
+
|
|
|
|
|
+</style>
|