import type { FormState } from '@sinoui/rx-form-state'; import type { AsyncParallelHook, AsyncSeriesBailHook, SyncHook, UnsetAdditionalOptions } from 'tapable'; import type { SendWorkflowInitRequestType } from '../core-flow'; import type FormValues from './FormValues'; import type PermissionItem from './PermissionItem'; import type UserInfo from './UserInfo'; /** * 详情页级别钩子类型 */ export interface DetailPageHooksType { /** * 在产生最终的表单权限时调用,用来收集自定义的权限控制数据。 * * ```typescript * hooks.permission.tap('ExtendName', (currentUser, permissionItemList) => { * permissionItemList.push({ * name: 'field_1', // 表单字段或者按钮名称 * hidden: false, // 控制 field_1 字段显示出来 * readOnly: true, // 控制 field_1 字段只读 * }); * }); * ``` */ permission: SyncHook<[ UserInfo, PermissionItem[] ], void, UnsetAdditionalOptions>; /** * 表单值监听同步钩子。在表单值发生变化时调用,用来监听表单数据变化。 * * > 注意:`valueChange` 钩子不支持异步更新表单值,请使用 `valueChangeAsync` 钩子。 * * ```typescript * hooks.valueChange.tap('ExtendName', (prevValue, nextValue) => { * // 控制台输出变化前后的值 * console.log( * `表单值发生变化:${JSON.stringify(prevValue)}=======>${JSON.stringify( * nextValue * )}` * ); * }); * ``` * * 更新表单值: * * ```typescript * hooks.valueChange.tap('计算总价格', (prevValue, nextValue) => { * nextValue.total = nextValue.price * nextValue.count; * }); * ``` */ valueChange: SyncHook<[FormValues, FormValues]>; /** * 表单值监听异步钩子。在表单值发生变化时调用,可以用来异步更新表单数据变化。 * * ```typescript * hooks.valueChangeAsync.tapPromise('计算总价格', async (prevValue, nextValue) => { * if (prevValue.price !== nextValue.price || prevValue.count !== nextValue.count) { * nextValue.total = await calcTotalPriceFromRemoteServer(nextValue.price, nextValue.count); * } * }); * ``` */ valueChangeAsync: AsyncParallelHook<[FormValues, FormValues]>; /** * 监听表单上的按钮点击行为。在执行智能表单内部按钮回调函数之前调用此钩子。 * * 在点击按钮时调用,如果返回 false,则按钮本身绑定的函数则不会被调用 * * ```typescript * hooks.beforeButtonClick.tapPromise('ExtendName', async (buttonId) => { * if (buttonId === "save") { console.log("保存按钮被点击了。"); // 返回 true,阻止调用智能表单内部保存方法 return false; } * }); * ``` */ beforeButtonClick: AsyncSeriesBailHook; /** * 监听表单按钮点击钩子 */ fieldButtonClick: AsyncSeriesBailHook; /** * 表单同步校验钩子 */ formValidate: SyncHook<[FormValues, { [x: string]: string | undefined; }]>; /** * 表单异步校验钩子 */ formValidateAsync: AsyncParallelHook<[FormValues, FormValues]>; /** * 子表单同步校验钩子 */ subFormValidate: SyncHook<[ FormValues, FormValues, FormValues, string, { [x: string]: string | undefined; } ]>; /** * 子表单异步校验钩子 */ subFormValidateAsync: AsyncParallelHook<[ FormValues, FormValues, FormValues, string, FormState, FormValues ]>; /** * 子表单表单值变化同步监听钩子 */ subFormValueChange: SyncHook<[FormValues, FormValues, string, FormValues[]]>; /** * 子表单表单值变化异步监听钩子 */ subFormValueChangeAsync: AsyncParallelHook<[ FormValues, FormValues, string, FormValues[] ]>; /** * 流程提交前的钩子,允许改变流程提交的初始数据。如: * * ```ts * hooks.beforeSendWorkflow.tap('attr1字段中添加待办url', (request) => { * request.attr1 = genWaitdoUrl(); * }); * ``` */ beforeSendWorkflow: SyncHook<[SendWorkflowInitRequestType]>; }