import { IPublicModelSettingField } from '@alilc/lowcode-types'; import { RsBoolSetter, NumberSetter, RsStringSetter, RadioGroupSetter, FieldsSelectSetter, RsArraySetter, RsObjectSetter, RsFunButtonSetter, } from '../../_setters'; import subColumnsFileds from './sub-columns-filed'; import actionBarButtons from './actionbar-buttons'; import columnsProps from './columns-props'; import linkProps from '../link'; import rsIdProps from './rsid'; import { DEFAULT_PAGE_SIZE, UUID, DEFAULT_DUPLI_FUN, FORMULA_UPFORM_TYPE } from '@/constants'; import actionColumnProp from './action-column-prop'; import treeProps from './tree-props'; import mainLinkedProp from './main-linked-prop'; import { uuid } from '../../_utils/utils'; const getRowActionProps = (isEditable = false) => linkProps .filter((item: Record) => !['urlParams', 'pageParams'].includes(item.name)) .map((item: any) => { const { name } = item; if (name === 'url') { return { ...item, name: 'newPageLink', title: { label: '跳转页面', tip: 'newPageLink | 新增跳转页面', }, condition: (target: IPublicModelSettingField) => { return !target.getProps().getPropValue('newRow') || !isEditable; }, }; } else if (name === 'recordLinkParams') { return { ...item, name: 'newPageRecordLinkParams', title: { label: '当前行参数', }, condition: (target: IPublicModelSettingField) => { return !target.getProps().getPropValue('newRow') || !isEditable; }, }; } else if (name === 'params') { return { ...item, name: 'newPageParams', title: { label: '自定义参数', }, condition: (target: IPublicModelSettingField) => { return !target.getProps().getPropValue('newRow') || !isEditable; }, }; } else { return { ...item, condition: (target: IPublicModelSettingField) => { return !target.getProps().getPropValue('newRow') || !isEditable; }, }; } }); const excludeProps = ['isLinkPageDetail', 'newPageTitle']; const subRemoteCondition = (target: IPublicModelSettingField) => { const showExpandable = !!target.getProps().getPropValue('showExpandable'); const subRemote = !!target.getProps().getPropValue('subRemote'); return showExpandable && subRemote; }; const getExpandableProps = () => { return linkProps .filter((item: any) => !excludeProps.includes(item.name)) .map((item: any) => { const { name } = item; if (name === 'url') { return { ...item, name: 'subUrl', title: { label: '展开行接口', tip: 'subUrl | 展开行接口', }, condition: subRemoteCondition, }; } else if (name === 'recordLinkParams') { return { ...item, name: 'subRecordParams', title: { label: '当前行参数', tip: 'subRecordParams | 表格当前行参数', }, condition: subRemoteCondition, }; } else if (name === 'params') { return { ...item, name: 'subParams', title: { label: '自定义参数', tip: 'subParams | 自定义参数', }, condition: subRemoteCondition, }; } else { return { ...item, condition: subRemoteCondition, }; } }); }; const getDataSourceLinkProps = (isEditable = true, isSubForm = false, isLinked = false) => { let includedParams = ['url', 'paramsTitle', 'params']; if (isSubForm || isLinked) { includedParams = ['url', 'paramsTitle', 'params', 'urlParams', 'pageParams']; } return linkProps .filter((item: Record) => includedParams.includes(item.name)) .map((item: Record) => { const { name } = item; if (name === 'url') { return { ...item, title: { label: '请求接口', tip: 'url | 获取数据接口', }, }; } return item; }); }; export const getHeadDetailSumProps = () => { return [ { title: { label: { type: 'i18n', zh_CN: '头明细合计', en_US: 'fields calculate', }, tip: { type: 'i18n', zh_CN: '属性: fieldsCalculate | 说明: 计算子表单中某一列的数字总和,结果显示在主表单或者关联面板上帧的某个字段上', en_US: 'prop: fieldsCalculate | description: fields calculate', }, }, }, { name: 'fieldsCalculate', title: { label: { type: 'i18n', zh_CN: '头明细合计', en_US: 'fields calculate', }, tip: { type: 'i18n', zh_CN: '属性: fieldsCalculate | 说明: 计算子表单中某一列的数字总和,结果显示在主表单或者关联面板上帧的某个字段上', en_US: 'prop: fieldsCalculate | description: fields calculate', }, }, extraProps: { display: 'plain', }, setter: { componentName: RsArraySetter, props: { itemSetter: { componentName: RsObjectSetter, props: { config: { items: [ { name: 'key', title: { label: '', }, setter: RsStringSetter, defaultValue: () => uuid(), condition: () => { return false; }, }, { name: 'subFormField', important: true, isRequired: true, title: { label: { type: 'i18n', zh_CN: '明细字段', en_US: 'subFormField', }, tip: { type: 'i18n', zh_CN: '属性: subFormField | 说明: 明细字段', en_US: 'prop: subFormField | description: subFormField', }, }, setter: { componentName: FieldsSelectSetter, initialValue: '', props: { fieldTypes: ['number'], }, }, }, { name: 'mainFormField', important: true, isRequired: true, title: { label: { type: 'i18n', zh_CN: '主表字段', en_US: 'mainFormField', }, tip: { type: 'i18n', zh_CN: '属性: mainFormField | 说明: 主表字段', en_US: 'prop: mainFormField | description: mainFormField', }, }, setter: { componentName: FieldsSelectSetter, props: { componentType: FORMULA_UPFORM_TYPE, fieldTypes: ['number'], }, }, }, ], }, }, }, }, }, }, ]; }; /** * 表格基础属性配置 * @param isEditable 是否是可编辑表格 * @param isSubForm 是否是子表单 * @param isLinked 是否是关联表格/表单 */ export default function baseTableProps(isEditable = false, isSubForm = false, isLinked = false) { return [ rsIdProps, { name: 'enableCrossPageRefresh', title: { label: '跨页面刷新', tip: 'enableCrossPageRefresh | 是否启用跨页面刷新,如子页面数据更新后,父页面表格数据自动刷新', }, propType: 'bool', setter: { componentName: RsBoolSetter, initialValue: () => false, }, condition: (target: IPublicModelSettingField) => { const newRow = target.getProps().getPropValue('newRow'); return !newRow; }, }, { name: 'isLinked', title: { label: '关联表单', tip: 'isLinked | 是否关联表单', }, propType: 'bool', setter: { componentName: RsBoolSetter, initialValue: () => isLinked, }, condition: () => { return isLinked; }, }, columnsProps(isEditable, isSubForm), isLinked ? mainLinkedProp : { condition: () => { return false; }, }, { title: '行操作设置', name: 'rowAction', display: 'accordion', type: 'group', extraProps: { defaultCollapsed: true, }, items: [ { name: 'selectionMode', title: { label: '行选择模式', tip: 'selectionMode | 行选择模式:多选或者单选', }, setter: { componentName: 'RadioGroupSetter', initialValue: 'checkbox', props: { options: [ { label: '无', value: 'none', }, { label: '多选', value: 'checkbox', }, { label: '单选', value: 'radio', }, ], }, }, }, { name: 'newRow', title: { label: '表格内新增', tip: 'newRow | 是否在当前表格上新增,否则打开新页面新增' }, propType: 'bool', setter: RsBoolSetter, defaultValue: true, condition: () => { return isEditable && !isLinked; }, }, { name: 'enableDoubleClick', title: { label: '双击跳转', tip: 'enableDoubleClick | 是否启用双击行跳转', }, propType: 'bool', setter: { componentName: RsBoolSetter, initialValue: () => true, }, condition: (target: IPublicModelSettingField) => { return ( !target.getProps().getPropValue('newRow') || (!isEditable && !isSubForm && !isLinked) ); }, }, { name: 'newRowPosition', title: { label: '新增行位置', tip: 'newRowPosition | 新增行位置' }, propType: 'string', setter: { componentName: RadioGroupSetter, initialValue: 'first', props: { options: [ { title: '行首', value: 'first' }, { title: '行尾', value: 'last' }, ], }, }, condition: (target: IPublicModelSettingField) => { return ( (!!target.getProps().getPropValue('newRow') && isEditable) || isSubForm || isLinked ); }, }, ...getRowActionProps(isEditable), { name: 'summaryColumns', title: { label: { type: 'i18n', zh_CN: '合计字段', en_US: 'summaryColumns', }, tip: { type: 'i18n', zh_CN: '属性: summaryColumns | 说明: 合计字段', en_US: 'prop: summaryColumns | description: summaryColumns', }, }, setter: { componentName: FieldsSelectSetter, initialValue: '', props: { mode: 'multiple', fieldTypes: ['number'], }, }, }, ], }, { title: '数据源', name: 'dataSourceSection', display: 'accordion', type: 'group', extraProps: { defaultCollapsed: true, }, items: [ // { // name: 'fetchConfig', // title: { // label: { // type: 'i18n', // zh_CN: '数据源配置', // en_US: 'queryBtnVisible', // }, // }, // propType: 'string', // setter: { // componentName: FetchSetter, // props: { // isIncludeQueryFilter: true, // isIncludeCurrentTable: true, // componentType: 'Table', // }, // }, // }, { name: 'rowKey', title: { label: '行Key', tip: 'rowKey | 表格行 key 的取值,数字的唯一字段', }, propType: 'string', setter: RsStringSetter, defaultValue: UUID, }, ...getDataSourceLinkProps(isEditable, isSubForm, isLinked), ], }, { title: '验重设置', name: 'checkForDuplicates', extraProps: { display: 'accordion', defaultCollapsed: true, }, type: 'field', setter: { componentName: RsArraySetter, props: { itemSetter: { componentName: RsObjectSetter, props: { config: { items: [ { name: 'DupliKey', title: { label: '验重字段', tip: '需要验重的字段', }, display: 'inline', isRequired: true, setter: { componentName: FieldsSelectSetter, initialValue: () => { return []; }, props: { mode: 'multiple', customValue: (item: any) => { return item.name + (item.name ? `(${item.fieldId || ''})` : item.fieldId); }, }, }, }, { name: 'DupliCondition', title: '验重条件', display: 'inline', isRequired: true, setter: { componentName: RsFunButtonSetter, props: { defaultValue: DEFAULT_DUPLI_FUN, header: '验重条件函数', style: { justifyContent: 'flex-start', }, }, }, }, ], }, }, }, initialValue: [], }, }, }, actionBarButtons(), actionColumnProp(), { title: '外观', display: 'accordion', type: 'group', extraProps: { defaultCollapsed: true, }, items: [ { name: 'contentHeight', title: { label: '内容高度', tip: 'contentHeight | 内容高度(px)' }, propType: 'string', setter: 'NumberSetter', }, { name: 'showIndex', title: { label: '显示序号', tip: 'showIndex | 是否序号' }, propType: 'bool', setter: RsBoolSetter, defaultValue: true, }, // { // name: 'showHeader', // title: { label: '显示表头', tip: 'showHeader | 是否显示表头' }, // propType: 'bool', // setter: RsBoolSetter, // defaultValue: true, // }, { name: 'bordered', title: { label: '显示边框', tip: 'bordered | 是否展示外边框和列边框', }, propType: 'bool', defaultValue: true, setter: RsBoolSetter, }, ], }, { title: '可展开', display: 'accordion', type: 'group', name: 'rowexpand', extraProps: { defaultCollapsed: true, }, items: [ { name: 'showExpandable', title: { label: '显示展开行', tip: 'showExpandable | 是否显示展开行', }, propType: 'bool', setter: { componentName: RsBoolSetter, defaultValue: false, }, }, { name: 'subRemote', title: { label: '远程获取', tip: 'subRemote | 是否远程获取数据,否则从行数据中获取', }, propType: 'bool', setter: { componentName: RsBoolSetter, initialValue: () => true, }, condition: (target: IPublicModelSettingField) => { const showExpandable = !!target.getProps().getPropValue('showExpandable'); return showExpandable; }, }, { name: 'subDataField', title: { label: '取值字段', tip: 'subDataField | 行取值字段', }, propType: 'string', setter: { componentName: RsStringSetter, defaultValue: '', }, condition: (target: IPublicModelSettingField) => { const showExpandable = !!target.getProps().getPropValue('showExpandable'); const subRemote = !!target.getProps().getPropValue('subRemote'); return showExpandable && !subRemote; }, }, ...getExpandableProps(), subColumnsFileds, ], }, { title: '分页', name: 'paginationSection', display: 'accordion', type: 'group', extraProps: { defaultCollapsed: true, }, items: [ { name: 'showPagination', title: { label: '显示分页', tip: 'pagination | 显示分页' }, propType: 'bool', setter: { componentName: RsBoolSetter, initialValue: true, }, }, // { // name: 'paginationPosition', // title: { label: '分页位置', tip: 'pagination.position | 分页位置' }, // setter: { // componentName: RadioGroupSetter, // props: { // options: [ // { // title: '左', // value: 'bottomLeft', // }, // { // title: '中', // value: 'bottomCenter', // }, // { // title: '右', // value: 'bottomRight', // }, // ], // }, // initialValue: 'bottomRight', // }, // condition: { // type: 'JSFunction', // value: 'target => !!target.getProps().getPropValue("showPagination")', // }, // }, { name: 'pagination.pageSize', title: { label: '每页条数', tip: 'pagination.pageSize | 每页条数' }, propType: 'number', setter: { componentName: NumberSetter, initialValue: DEFAULT_PAGE_SIZE, }, condition: { type: 'JSFunction', value: 'target => !!target.getProps().getPropValue("showPagination")', }, }, ], }, treeProps, ]; }