feat:【antd/ele】【组件】tinymce 封装的代码统一

This commit is contained in:
YunaiV
2025-11-20 15:19:45 +08:00
parent f425b821b3
commit 5147e75331
3 changed files with 21 additions and 36 deletions

View File

@@ -17,10 +17,9 @@ const props = defineProps({
type: Boolean, type: Boolean,
}, },
fullscreen: { fullscreen: {
// 图片上传,是否放到全屏的位置
default: false, default: false,
type: Boolean, type: Boolean,
}, }, // 图片上传,是否放到全屏的位置
}); });
const emit = defineEmits(['uploading', 'done', 'error']); const emit = defineEmits(['uploading', 'done', 'error']);

View File

@@ -2,8 +2,6 @@
import type { IPropTypes } from '@tinymce/tinymce-vue/lib/cjs/main/ts/components/EditorPropTypes'; import type { IPropTypes } from '@tinymce/tinymce-vue/lib/cjs/main/ts/components/EditorPropTypes';
import type { Editor as EditorType } from 'tinymce/tinymce'; import type { Editor as EditorType } from 'tinymce/tinymce';
import type { PropType } from 'vue';
import { import {
computed, computed,
nextTick, nextTick,
@@ -35,37 +33,26 @@ type InitOptions = IPropTypes['init'];
defineOptions({ name: 'Tinymce', inheritAttrs: false }); defineOptions({ name: 'Tinymce', inheritAttrs: false });
const props = defineProps({ const props = withDefaults(defineProps<TinymacProps>(), {
options: { height: 400,
type: Object as PropType<Partial<InitOptions>>, width: 'auto',
default: () => ({}), options: () => ({}),
}, plugins: defaultPlugins,
toolbar: { toolbar: defaultToolbar,
type: String, showImageUpload: true,
default: defaultToolbar,
},
plugins: {
type: String,
default: defaultPlugins,
},
height: {
type: [Number, String] as PropType<number | string>,
required: false,
default: 400,
},
width: {
type: [Number, String] as PropType<number | string>,
required: false,
default: 'auto',
},
showImageUpload: {
type: Boolean,
default: true,
},
}); });
const emit = defineEmits(['change']); const emit = defineEmits(['change']);
interface TinymacProps {
options?: Partial<InitOptions>;
toolbar?: string;
plugins?: string;
height?: number | string;
width?: number | string;
showImageUpload?: boolean;
}
/** 外部使用 v-model 绑定值 */ /** 外部使用 v-model 绑定值 */
const modelValue = defineModel('modelValue', { default: '', type: String }); const modelValue = defineModel('modelValue', { default: '', type: String });
@@ -151,7 +138,7 @@ const initOptions = computed((): InitOptions => {
'bold italic | quicklink h2 h3 blockquote quickimage quicktable', 'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
toolbar_mode: 'sliding', toolbar_mode: 'sliding',
...options, ...options,
images_upload_handler: (blobInfo) => { images_upload_handler: (blobInfo: any) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const file = blobInfo.blob() as File; const file = blobInfo.blob() as File;
const { httpRequest } = useUpload(); const { httpRequest } = useUpload();
@@ -165,9 +152,9 @@ const initOptions = computed((): InitOptions => {
}); });
}); });
}, },
setup: (editor) => { setup: (editor: EditorType) => {
editorRef.value = editor; editorRef.value = editor;
editor.on('init', (e) => initSetup(e)); editor.on('init', (e: any) => initSetup(e));
}, },
}; };
}); });

View File

@@ -17,10 +17,9 @@ const props = defineProps({
type: Boolean, type: Boolean,
}, },
fullscreen: { fullscreen: {
// 图片上传,是否放到全屏的位置
default: false, default: false,
type: Boolean, type: Boolean,
}, }, // 图片上传,是否放到全屏的位置
}); });
const emit = defineEmits(['uploading', 'done', 'error']); const emit = defineEmits(['uploading', 'done', 'error']);