feat: 添加 TinymceProps 类型定义并更新相关组件以支持新属性

This commit is contained in:
dap
2026-04-08 11:24:16 +08:00
parent 8b20546670
commit f2e99d115a
3 changed files with 29 additions and 12 deletions

View File

@@ -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<StrictComponentType, Component> = {
// 如果你的组件体积比较大,可以使用异步加载

View File

@@ -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<InitOptions>;
plugins?: string;
toolbar?: string;
disabled?: boolean;
}
defineOptions({
name: 'Tinymce',
inheritAttrs: false,
});
const props = withDefaults(defineProps<Props>(), {
const props = withDefaults(defineProps<TinymceProps>(), {
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 });
});
});

View File

@@ -0,0 +1,7 @@
export interface TinymceProps {
height?: number | string;
options?: Partial<InitOptions>;
plugins?: string;
toolbar?: string;
disabled?: boolean;
}