diff --git a/es/types/Page.d.ts b/es/types/Page.d.ts index 14d7d46f..cc293a2f 100644 --- a/es/types/Page.d.ts +++ b/es/types/Page.d.ts @@ -37,32 +37,63 @@ type FeatureDef = ED[T]['CreateSingle']['data'] | (() => ED[T]['CreateSingle']['data']); interface ComponentOption, FrontCxt extends SyncContext, AD extends Record>, FD extends Record, FormedData extends Record, TData extends DataOption, TProperty extends DataOption, TMethod extends Record, EMethod extends Record = {}> { + /** + * 是否为列表组件 + */ isList?: IsList; zombie?: true; getTotal?: { max: number; deviceWidth?: DevideWidth | 'all'; } | number; + /** + * 组件所关联的实体 + */ entity?: T | ((this: ComponentPublicThisType) => T); path?: string; + /** + * 需要监听的features + */ features?: FeatureDef[]; cascadeActions?: (this: ComponentPublicThisType) => { [K in keyof ED[T]['Schema']]?: ActionDef[]; }; + /** + * 需要校验的actions + */ actions?: ActionDef[] | ((this: ComponentPublicThisType) => ActionDef[]); + /** + * 需要获取的数据字段 + * 若嵌套在list中,需要保证父list组件能够覆盖子组件的projection + */ projection?: ED[T]['Selection']['data'] | ((this: ComponentPublicThisType) => ED[T]['Selection']['data'] | undefined); append?: boolean; + /** + * 分页信息 + */ pagination?: Pick | Array & { deviceWidth: DevideWidth; }>; + /** + * 过滤器 + */ filters?: Array<{ filter: NonNullable | ((this: ComponentPublicThisType) => ED[T]['Selection']['filter'] | undefined); '#name'?: string; }>; + /** + * 排序器 + */ sorters?: Array<{ sorter: NonNullable[number] | ((this: ComponentPublicThisType) => ED[T]['Selection']['sorter'] | NonNullable[number]); '#name'?: string; }>; + /** + * 表单数据 + * 在组件渲染前会调用此方法,将返回的数据放入组件的data中 + * @param options 组件获取到的数据 + * @returns 返回给页面的数据 + */ formData?: (options: { data: IsList extends true ? RowWithActions[] : RowWithActions; origin?: IsList extends true ? RowWithActions[] : RowWithActions; @@ -74,8 +105,17 @@ interface ComponentOption FormedData; ns?: T | T[]; + /** + * 声明的State数据 + */ data?: ((this: ComponentPublicThisType) => TData) | TData; + /** + * 需要参数传入的默认prop参数 + */ properties?: TProperty; + /** + * 自定义方法 + */ methods?: TMethod; } export type MiniprogramStyleMethods = { @@ -106,17 +146,63 @@ export type ComponentFullThisType & OakListComponentMethods & OakSingleComponentMethods; export type OakComponentOption, FrontCxt extends SyncContext, AD extends Record>>, FD extends Record, FormedData extends Record, TData extends Record, TProperty extends DataOption, TMethod extends Record, EMethod extends Record = {}> = ComponentOption & Partial<{ + /** + * 生命周期回调 + */ lifetimes: { + /** + * 在组件实例刚刚被创建时执行 + * sync only + */ created?(): void; + /** + * 在组件实例进入页面节点树时执行 + * sync only + */ attached?(): void; + /** + * 在组件实例进入页面节点树时执行 + * async or sync + */ ready?(): any; + /** + * 小程序专用,在组件实例被移动到节点树另一个位置时执行 + * sync only + */ moved?(): void; + /** + * 在组件实例被从页面节点树移除时执行 + * sync only + */ detached?(): void; + /** + * 小程序专用,每当组件方法抛出错误时执行 + * sync only + * @param err 错误信息 + */ error?(err: Error): void; + /** + * 组件所在的页面被展示时执行 + * sync only + */ show?(): void; + /** + * 组件所在的页面被隐藏时执行 + * sync only + */ hide?(): void; + /** + * 组件所在的页面尺寸变化时执行 + * sync only + * @param size 页面尺寸信息 + */ resize?(size: WechatMiniprogram.Page.IResizeOption): void; }; + /** + * 监听器,监听State或者Props的变化 + * 名称:监听的属性名 + * 回调:监听的回调函数 (prev, next) => void + */ listeners: Record, prev: Record, next: Record) => void>; }> & Partial<{ wechatMp: { diff --git a/lib/types/Page.d.ts b/lib/types/Page.d.ts index 14d7d46f..cc293a2f 100644 --- a/lib/types/Page.d.ts +++ b/lib/types/Page.d.ts @@ -37,32 +37,63 @@ type FeatureDef = ED[T]['CreateSingle']['data'] | (() => ED[T]['CreateSingle']['data']); interface ComponentOption, FrontCxt extends SyncContext, AD extends Record>, FD extends Record, FormedData extends Record, TData extends DataOption, TProperty extends DataOption, TMethod extends Record, EMethod extends Record = {}> { + /** + * 是否为列表组件 + */ isList?: IsList; zombie?: true; getTotal?: { max: number; deviceWidth?: DevideWidth | 'all'; } | number; + /** + * 组件所关联的实体 + */ entity?: T | ((this: ComponentPublicThisType) => T); path?: string; + /** + * 需要监听的features + */ features?: FeatureDef[]; cascadeActions?: (this: ComponentPublicThisType) => { [K in keyof ED[T]['Schema']]?: ActionDef[]; }; + /** + * 需要校验的actions + */ actions?: ActionDef[] | ((this: ComponentPublicThisType) => ActionDef[]); + /** + * 需要获取的数据字段 + * 若嵌套在list中,需要保证父list组件能够覆盖子组件的projection + */ projection?: ED[T]['Selection']['data'] | ((this: ComponentPublicThisType) => ED[T]['Selection']['data'] | undefined); append?: boolean; + /** + * 分页信息 + */ pagination?: Pick | Array & { deviceWidth: DevideWidth; }>; + /** + * 过滤器 + */ filters?: Array<{ filter: NonNullable | ((this: ComponentPublicThisType) => ED[T]['Selection']['filter'] | undefined); '#name'?: string; }>; + /** + * 排序器 + */ sorters?: Array<{ sorter: NonNullable[number] | ((this: ComponentPublicThisType) => ED[T]['Selection']['sorter'] | NonNullable[number]); '#name'?: string; }>; + /** + * 表单数据 + * 在组件渲染前会调用此方法,将返回的数据放入组件的data中 + * @param options 组件获取到的数据 + * @returns 返回给页面的数据 + */ formData?: (options: { data: IsList extends true ? RowWithActions[] : RowWithActions; origin?: IsList extends true ? RowWithActions[] : RowWithActions; @@ -74,8 +105,17 @@ interface ComponentOption FormedData; ns?: T | T[]; + /** + * 声明的State数据 + */ data?: ((this: ComponentPublicThisType) => TData) | TData; + /** + * 需要参数传入的默认prop参数 + */ properties?: TProperty; + /** + * 自定义方法 + */ methods?: TMethod; } export type MiniprogramStyleMethods = { @@ -106,17 +146,63 @@ export type ComponentFullThisType & OakListComponentMethods & OakSingleComponentMethods; export type OakComponentOption, FrontCxt extends SyncContext, AD extends Record>>, FD extends Record, FormedData extends Record, TData extends Record, TProperty extends DataOption, TMethod extends Record, EMethod extends Record = {}> = ComponentOption & Partial<{ + /** + * 生命周期回调 + */ lifetimes: { + /** + * 在组件实例刚刚被创建时执行 + * sync only + */ created?(): void; + /** + * 在组件实例进入页面节点树时执行 + * sync only + */ attached?(): void; + /** + * 在组件实例进入页面节点树时执行 + * async or sync + */ ready?(): any; + /** + * 小程序专用,在组件实例被移动到节点树另一个位置时执行 + * sync only + */ moved?(): void; + /** + * 在组件实例被从页面节点树移除时执行 + * sync only + */ detached?(): void; + /** + * 小程序专用,每当组件方法抛出错误时执行 + * sync only + * @param err 错误信息 + */ error?(err: Error): void; + /** + * 组件所在的页面被展示时执行 + * sync only + */ show?(): void; + /** + * 组件所在的页面被隐藏时执行 + * sync only + */ hide?(): void; + /** + * 组件所在的页面尺寸变化时执行 + * sync only + * @param size 页面尺寸信息 + */ resize?(size: WechatMiniprogram.Page.IResizeOption): void; }; + /** + * 监听器,监听State或者Props的变化 + * 名称:监听的属性名 + * 回调:监听的回调函数 (prev, next) => void + */ listeners: Record, prev: Record, next: Record) => void>; }> & Partial<{ wechatMp: {