From f2e99d115a024cbcca5d5c64d96b19deca67d4f9 Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Wed, 8 Apr 2026 11:24:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20TinymceProps=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89=E5=B9=B6=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=BB=84=E4=BB=B6=E4=BB=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=96=B0=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web-antd/src/adapter/component/index.ts | 20 +++++++++++++++++-- .../src/components/tinymce/src/editor.vue | 14 ++++--------- .../src/components/tinymce/src/type.d.ts | 7 +++++++ 3 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 apps/web-antd/src/components/tinymce/src/type.d.ts diff --git a/apps/web-antd/src/adapter/component/index.ts b/apps/web-antd/src/adapter/component/index.ts index 52154db69..3f46d0031 100644 --- a/apps/web-antd/src/adapter/component/index.ts +++ b/apps/web-antd/src/adapter/component/index.ts @@ -23,6 +23,7 @@ import type { SwitchProps, TextAreaProps, TimePickerProps, + TimeRangePickerProps, TreeSelectProps, UploadProps, } from 'antdv-next'; @@ -36,6 +37,9 @@ import type { } from '@vben/common-ui'; import type { Recordable } from '@vben/types'; +import type { TinymceProps } from '#/components/tinymce/src/type'; +import type { BaseUploadProps } from '#/components/upload/src/props'; + import { computed, defineAsyncComponent, defineComponent, h, ref } from 'vue'; import { ApiComponent, globalShareState, IconPicker } from '@vben/common-ui'; @@ -201,9 +205,9 @@ type StrictComponentType = export type ComponentType = BaseFormComponentType | StrictComponentType; /** - * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 + * 组件 Props 定义 */ -export interface ComponentPropsMap { +interface ComponentPropsMapDef { ApiCascader: ApiComponentSharedProps & CascaderProps; ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; @@ -214,7 +218,9 @@ export interface ComponentPropsMap { DatePicker: DatePickerProps; DefaultButton: ButtonProps; Divider: DividerProps; + FileUpload: BaseUploadProps; IconPicker: IconPickerProps; + ImageUpload: BaseUploadProps; Input: InputProps; InputNumber: InputNumberProps; InputPassword: InputProps; @@ -224,15 +230,25 @@ export interface ComponentPropsMap { RadioGroup: RadioGroupProps; RangePicker: RangePickerProps; Rate: RateProps; + RichTextarea: TinymceProps; Select: SelectProps; Space: SpaceProps; Switch: SwitchProps; Textarea: TextAreaProps; TimePicker: TimePickerProps; + TimeRangePicker: TimeRangePickerProps; TreeSelect: TreeSelectProps; Upload: UploadProps; } +/** + * 与 {@link StrictComponentType} 一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 + * 通过 mapped type 约束: StrictComponentType 新增成员但 ComponentPropsMapDef 未添加对应键时会编译报错 + */ +export type ComponentPropsMap = { + [K in StrictComponentType]: ComponentPropsMapDef[K]; +}; + async function initComponentAdapter() { const components: Record = { // 如果你的组件体积比较大,可以使用异步加载 diff --git a/apps/web-antd/src/components/tinymce/src/editor.vue b/apps/web-antd/src/components/tinymce/src/editor.vue index 9965fb610..d9273c8c7 100644 --- a/apps/web-antd/src/components/tinymce/src/editor.vue +++ b/apps/web-antd/src/components/tinymce/src/editor.vue @@ -2,6 +2,8 @@ import type { IPropTypes } from '@tinymce/tinymce-vue/lib/cjs/main/ts/components/EditorPropTypes'; import type { Editor as EditorType } from 'tinymce/tinymce'; +import type { TinymceProps } from './type'; + import type { AxiosProgressEvent, UploadResult } from '#/api'; import { computed, nextTick, ref, shallowRef, useAttrs, watch } from 'vue'; @@ -20,20 +22,12 @@ import { type InitOptions = IPropTypes['init']; -interface Props { - height?: number | string; - options?: Partial; - plugins?: string; - toolbar?: string; - disabled?: boolean; -} - defineOptions({ name: 'Tinymce', inheritAttrs: false, }); -const props = withDefaults(defineProps(), { +const props = withDefaults(defineProps(), { height: 400, options: () => ({}), plugins: defaultPlugins, @@ -165,7 +159,7 @@ const initOptions = computed((): InitOptions => { }) .catch((error) => { console.error('tinymce上传图片失败:', error); - // eslint-disable-next-line prefer-promise-reject-errors + reject({ message: error.message, remove: true }); }); }); diff --git a/apps/web-antd/src/components/tinymce/src/type.d.ts b/apps/web-antd/src/components/tinymce/src/type.d.ts new file mode 100644 index 000000000..a4e517fb4 --- /dev/null +++ b/apps/web-antd/src/components/tinymce/src/type.d.ts @@ -0,0 +1,7 @@ +export interface TinymceProps { + height?: number | string; + options?: Partial; + plugins?: string; + toolbar?: string; + disabled?: boolean; +}