export class EmopItemClass { /** * 控件类型 */ mode: 'str' | 'lov' | 'bool' | 'date' | 'num' | 'textarea' | 'password' | 'button' | 'radio'; /** * 控件值 */ value: any; /** * 数据为空时显示的文本,mode为button时为按钮的显示值 */ placeholder?: string = ''; /** * 是否禁止输入 */ disabled?: boolean; /** * 当输入框修改内容后的回调函数 */ onChange?: Function = undefined; /** * 失去焦点的回调函数 */ onBlur?: Function = undefined; /** * 按下回车的回调函数 */ onEnter?: Function = undefined; /** * 选项值,当mode为lov该配置有效 */ options?: { key: string, val: string; }[]; /** * 是否支持手动写入,当mode为lov时该配置有效 */ tags?: boolean; /** * 是否支持多选,当mode为lov时该配置有效 */ multiple?: boolean; /** * 是否允许清除 */ allowClear?: boolean; /** * 打开下拉框时的回调函数,当mode为lov时该配置有效 */ onOpen?: Function; /** * 使单选模式可搜索 */ showSearch?: boolean; /** * 最小值,当mode为num时该配置有效 */ min?: number; /** * 最大值,当mode为num时该配置有效 */ max?: number; /** * 步进值,当mode为num时该配置有效 */ step?: number; /** * 文本域的默认行数,当mode为num时该配置有效 */ row?: number; /** * 按钮点击后的回调函数,当mode为button时该配置有效 */ onClick?: Function; btn?: { size?: 'large' | 'small' | 'default'; shape?: 'circle' | 'round'; type?: 'primary' | 'dashed' | 'link' | 'text'; danger?: boolean; block?: boolean; loading?: boolean; ghost?: boolean; }; constructor(constructorData: EmopItemClass) { for (const key in constructorData) { this[key] = constructorData[key]; } // 设置控件私有属性 switch (constructorData.mode) { case 'num': this.min = constructorData.min || -Infinity; this.max = constructorData.max || Infinity; this.step = constructorData.step || 1; break; case 'button': this.btn = { size: constructorData.btn?.size || 'default', shape: constructorData.btn?.shape || undefined, type: constructorData.btn?.type || 'primary', danger: constructorData.btn?.danger || false, block: constructorData.btn?.block || false, loading: constructorData.btn?.loading || false, ghost: constructorData.btn?.ghost || false, }; break; case 'lov': this.options = constructorData.options || []; this.tags = constructorData.tags || false; this.multiple = constructorData.multiple || false; this.allowClear = constructorData.allowClear || false; this.showSearch = constructorData.showSearch || true; this.onOpen = constructorData.onOpen || undefined; break; case 'textarea': if (constructorData.row !== undefined) this.row = 3; default: break; } } }