create.config.ts 1.45 KB
import { AttributeConfiguration } from '../../../src/components/AttributeConfiguration';
import { FormSchema, useComponentRegister } from '/@/components/Form';
import { isObject } from '/@/utils/is';
import { useRuleChainI18n } from '../../../hook/useRuleChainI18n';

const { tLabel, tPlaceholder, t } = useRuleChainI18n('action', 'saveToCustomTable');

export enum SaveToCustomTableFieldsEnum {
  FIELDS_MAPPING = 'fieldsMapping',
  TABLE_NAME = 'tableName',
}

useComponentRegister('AttributeConfiguration', AttributeConfiguration);
export const formSchemas: FormSchema[] = [
  {
    field: SaveToCustomTableFieldsEnum.TABLE_NAME,
    component: 'Input',
    label: tLabel(SaveToCustomTableFieldsEnum.TABLE_NAME),
    required: true,
    componentProps: {
      placeholder: tPlaceholder(SaveToCustomTableFieldsEnum.TABLE_NAME),
    },
  },
  {
    field: SaveToCustomTableFieldsEnum.FIELDS_MAPPING,
    component: 'AttributeConfiguration',
    label: tLabel(SaveToCustomTableFieldsEnum.FIELDS_MAPPING),
    required: true,
    valueField: 'value',
    changeEvent: 'update:value',
    rules: [
      {
        required: true,
        validator(_rule, value) {
          if (!isObject(value) || !Object.keys(value).length)
            return Promise.reject(
              t('rule.chain.action.saveToCustomTable.fields.filesMappingValidateMsg')
            );
          return Promise.resolve();
        },
      },
    ],
    slot: SaveToCustomTableFieldsEnum.FIELDS_MAPPING,
  },
];