import env from '../../app/env'; import BSL from '../../typings'; type UiUpdate = () => void; export interface Options { /** 默认值 */ defaultValue?: T; /** 是否必填 */ required?: boolean; /** 用于触发UI更新的函数,如果传入null则采用从全局更新的模式 */ uiUpdate?: UiUpdate; } let helperId = 0; abstract class Helper { constructor(options?: Options) { this.required = options?.required || false; this.update = options?.uiUpdate; } /** 用于在小程序EventMessage中作为消息来源的判断 */ public readonly id = ++helperId; public readonly name = env.bslComponent; /** 在表单提交时,是否必填 */ protected readonly required: boolean; /** ui更新函数, 仅在框架内部使用 */ protected update?: UiUpdate; /** 当前值,只用作读取,切勿直接赋值 */ public abstract value: T; /** value的状态,可用于表单验证 */ public abstract state: BSL.RequestState; /** 改变value的值 */ public abstract onChange(value: T): boolean; /** 获取value的值 */ public getValue = (): T => { return this.value; } public abstract clear(): void; } export default Helper;