template.data.ts 4.35 KB
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { findDictItemByCode } from '/@/api/system/dict';
import { findMessageConfig } from '/@/api/message/config';
import { isMessage } from '/@/views/message/config/config.data';

export const columns: BasicColumn[] = [
  {
    title: '模板名称',
    dataIndex: 'templateName',
    width: 200,
  },
  {
    title: '配置名称',
    dataIndex: 'messageConfig.configName',
    width: 180,
    slots: { customRender: 'config' },
  },
  {
    title: '配置类型',
    dataIndex: 'messageTypeDictText',
    width: 100,
  },
  {
    title: '模板编码',
    dataIndex: 'templateCode',
    width: 180,
  },
  {
    title: '签名信息',
    dataIndex: 'signName',
    width: 180,
  },
  {
    title: '模板用途',
    dataIndex: 'templatePurposeDictText',
    width: 180,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 100,
    slots: { customRender: 'status' },
  },
  {
    title: '模板用途',
    dataIndex: 'templatePurpose',
    width: 180,
    ifShow: false,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'templateName',
    label: '模板名称',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: {
      maxLength: 32,
      placeholder: '请输入模板名称',
    },
    dynamicRules: () => {
      return [
        {
          required: false,
          validator: (_, value) => {
            if (String(value).length > 32) {
              return Promise.reject('字数不超过32个字');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
  {
    field: 'templateCode',
    label: '模板编码',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: {
      maxLength: 20,
      placeholder: '请输入模板编码',
    },
    dynamicRules: () => {
      return [
        {
          required: false,
          validator: (_, value) => {
            if (String(value).length > 20) {
              return Promise.reject('字数不超过20个字');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入主键',
    },
  },
  {
    field: 'messageType',
    label: '消息类型',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'message_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
  {
    field: 'messageConfigId',
    label: '配置名称',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: findMessageConfig,
      params: {
        messageType: ({ values }) => Reflect.get(values, 'messageType'),
      },
      immediate: true,
      labelField: 'configName',
      valueField: 'id',
    },
  },
  {
    field: 'templateName',
    label: '模板名称',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 32,
      placeholder: '请输入模板名称',
    },
  },
  {
    field: 'templateCode',
    label: '模板编号',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 20,
      placeholder: '请输入模板编号',
    },

    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'signName',
    label: '签名',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 32,
      placeholder: '请输入签名',
    },

    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'templatePurpose',
    label: '模板用途',
    required: true,
    component: 'ApiSelect',
    helpMessage: ['用户登录、忘记密码模板平台只提供"code"参数'],
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'template_purpose',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
  {
    field: 'tenantId',
    label: '租户ID',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入租户ID',
    },
  },
];