import { IPublicModelSettingField } from '@alilc/lowcode-types'; import { FormulaSetter, RsDateSetter, LinkdataSetter, RsStringSetter, NumberSetter, RsBoolSetter, } from '../../_setters'; import { FORMULA_TABLE_TYPE, DefaultValueTypeKeys, QuickDefaultOptions, ColumnDataType, } from '@/constants'; export default (isSubForm: boolean) => { // 数据联动支持组件:子表单; 支持类型:文本、数字、日期; const linkdataOption = isSubForm ? { title: '数据联动', value: 'linkdata', } : []; return [ { name: 'defaultValueOption', title: { label: { type: 'i18n', zh_CN: '默认值选项', en_US: 'defaultValueOption', }, tip: { type: 'i18n', zh_CN: '属性: defaultValueOption | 说明: 默认值选项\n@enumdesc 固定值、公式', en_US: 'prop: defaultValueOption | description: defaultValueOption\n@enumdesc fix value、formula、linkage、relate', }, }, condition: (target: IPublicModelSettingField) => { const dataType = target.parent.getPropValue('dataType'); return dataType === ColumnDataType.TEXT; }, setter: { componentName: 'SelectSetter', initialValue: 'fixValue', props: { options: [ { title: '固定值', value: 'fixValue', }, { title: '公式', value: 'formula', }, { title: '快捷配置', value: 'quick', }, ].concat(linkdataOption), }, }, }, { name: 'defaultValueOption', title: { label: { type: 'i18n', zh_CN: '默认值选项', en_US: 'defaultValueOption', }, tip: { type: 'i18n', zh_CN: '属性: defaultValueOption | 说明: 默认值选项\n@enumdesc 固定值、公式', en_US: 'prop: defaultValueOption | description: defaultValueOption\n@enumdesc fix value、formula、linkage、relate', }, }, condition: (target: IPublicModelSettingField) => { const dataType = target.parent.getPropValue('dataType'); return dataType === ColumnDataType.DATE; }, setter: { componentName: 'SelectSetter', initialValue: 'fixValue', props: { options: [ { title: '固定值', value: 'fixValue', }, { title: '今天', value: DefaultValueTypeKeys.TODAY }, { title: '本月', value: DefaultValueTypeKeys.THIS_MONTH }, { title: '本年度', value: DefaultValueTypeKeys.THIS_YEAR }, ].concat(linkdataOption), }, }, extraProps: { setValue: (target: IPublicModelSettingField, value: any) => { if (!value) return; if (value === DefaultValueTypeKeys.TODAY) { target.parent.setPropValue('format', 'YYYY-MM-DD'); } else if (value === DefaultValueTypeKeys.THIS_MONTH) { target.parent.setPropValue('format', 'YYYY-MM'); } else if (value === DefaultValueTypeKeys.THIS_YEAR) { target.parent.setPropValue('format', 'YYYY'); } }, }, }, { name: 'defaultValueOption', title: { label: { type: 'i18n', zh_CN: '默认值选项', en_US: 'defaultValueOption', }, tip: { type: 'i18n', zh_CN: '属性: defaultValueOption | 说明: 默认值选项\n@enumdesc 固定值、公式', en_US: 'prop: defaultValueOption | description: defaultValueOption\n@enumdesc fix value、formula、linkage、relate', }, }, condition: (target: IPublicModelSettingField) => { const dataType = target.parent.getPropValue('dataType'); return dataType === ColumnDataType.NUMBER; }, setter: { componentName: 'SelectSetter', initialValue: 'fixValue', props: { options: [ { title: '固定值', value: 'fixValue', }, { title: '公式', value: 'formula', }, ].concat(linkdataOption), }, }, }, // 开关默认值 { name: 'defaultValueOption', title: { label: { type: 'i18n', zh_CN: '默认值选项', en_US: 'defaultValueOption', }, tip: { type: 'i18n', zh_CN: '属性: defaultValueOption | 说明: 默认值选项\n@enumdesc 固定值、公式', en_US: 'prop: defaultValueOption | description: defaultValueOption\n@enumdesc fix value、formula、linkage、relate', }, }, condition: (target: IPublicModelSettingField) => { const dataType = target.parent.getPropValue('dataType'); return dataType === ColumnDataType.SWITCH; }, setter: { componentName: 'SelectSetter', initialValue: 'fixValue', props: { options: [ { title: '固定值', value: 'fixValue', }, ], }, }, }, // 开关默认值 { name: 'fixValue', title: { label: { type: 'i18n', zh_CN: '', en_US: '', }, tip: { type: 'i18n', zh_CN: '属性: fixValue | 说明: 输入固定值', en_US: 'prop: fixValue | description: Input fixed value', }, }, condition: (target: IPublicModelSettingField) => { const dataType = target.parent.getPropValue('dataType'); return ( dataType === ColumnDataType.SWITCH && target.parent.getPropValue('defaultValueOption') === DefaultValueTypeKeys.FIX_VALUE ); }, propType: 'string', setter: RsBoolSetter, }, { name: 'fixValue', title: { label: { type: 'i18n', zh_CN: '', en_US: '', }, tip: { type: 'i18n', zh_CN: '属性: fixValue | 说明: 输入固定值', en_US: 'prop: fixValue | description: Input fixed value', }, }, condition: (target: IPublicModelSettingField) => { const dataType = target.parent.getPropValue('dataType'); return ( dataType === ColumnDataType.TEXT && target.parent.getPropValue('defaultValueOption') === DefaultValueTypeKeys.FIX_VALUE ); }, propType: 'string', setter: RsStringSetter, }, { name: 'fixValue', title: { label: { type: 'i18n', zh_CN: '', en_US: '', }, tip: { type: 'i18n', zh_CN: '属性: fixValue | 说明: 输入固定值', en_US: 'prop: fixValue | description: Input fixed value', }, }, condition: (target: IPublicModelSettingField) => { const dataType = target.parent.getPropValue('dataType'); return ( dataType === ColumnDataType.NUMBER && target.parent.getPropValue('defaultValueOption') === DefaultValueTypeKeys.FIX_VALUE ); }, setter: { componentName: NumberSetter, props: {}, }, }, { name: 'fixValue', title: { label: { type: 'i18n', zh_CN: '', en_US: '', }, tip: { type: 'i18n', zh_CN: '属性: fixValue | 说明: 输入固定值', en_US: 'prop: fixValue | description: Input fixed value', }, }, condition: (target: IPublicModelSettingField) => { const dataType = target.parent.getPropValue('dataType'); return ( dataType === ColumnDataType.DATE && target.parent.getPropValue('defaultValueOption') === DefaultValueTypeKeys.FIX_VALUE ); }, propType: 'string', setter: RsDateSetter, }, { name: 'formula', title: { label: { type: 'i18n', zh_CN: '', en_US: '', }, tip: { type: 'i18n', zh_CN: '属性: formula | 说明: 输入公式', en_US: 'prop: formula | description: Input formula', }, }, condition: (target: IPublicModelSettingField) => { return target.parent.getPropValue('defaultValueOption') === 'formula'; }, setter: { componentName: FormulaSetter, props: { componentType: FORMULA_TABLE_TYPE, isSubForm, }, }, }, // 快捷配置 { name: 'quickConfiguration', title: { label: { type: 'i18n', zh_CN: '', en_US: '', }, tip: { type: 'i18n', zh_CN: '属性: quickConfiguration | 说明: 数据联动', en_US: 'prop: quickConfiguration | description: quickConfiguration', }, }, condition: (target: IPublicModelSettingField) => { return target.parent.getPropValue('defaultValueOption') === DefaultValueTypeKeys.QUICK; }, setter: { componentName: 'SelectSetter', props: { options: QuickDefaultOptions, }, }, }, { name: 'relatedata', title: { label: { type: 'i18n', zh_CN: '', en_US: '', }, tip: { type: 'i18n', zh_CN: '属性: linkdata | 说明: 数据联动', en_US: 'prop: linkdata | description: Form linkdata', }, }, condition: (target: IPublicModelSettingField) => { return target.parent.getPropValue('defaultValueOption') === DefaultValueTypeKeys.LINKDATA; }, setter: { componentName: LinkdataSetter, props: {}, }, }, ]; };