device.profile.data.ts 5.28 KB
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { findDictItemByCode } from '/@/api/system/dict';
import { MessageEnum } from '/@/enums/messageEnum';
// import { getOrganizationList } from '/@/api/system/system';
// import { copyTransFun } from '/@/utils/fnUtils';
import { numberRule } from '/@/utils/rules';

export const columns: BasicColumn[] = [
  {
    title: '配置名称',
    dataIndex: 'name',
    width: 200,
  },
  {
    title: '传输协议',
    dataIndex: 'transportType',
    width: 200,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: '描述',
    dataIndex: 'description',
    width: 180,
  },
];

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

export const isMessage = (type: string) => {
  return type === MessageEnum.IS_SMS;
};
export const isEmail = (type: string) => {
  return type === MessageEnum.IS_EMAIL;
};

export const formSchema: FormSchema[] = [
  {
    field: 'configName',
    label: '配置名称',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入配置名称',
    },
  },
  {
    field: 'messageType',
    label: '消息类型',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'message_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
  {
    field: 'platformType',
    label: '平台类型',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'platform_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'accessKeyId',
    label: 'accessKeyId',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 36,
      placeholder: '请输入accessKeyId',
    },

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

    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'host',
    label: '服务器地址',
    defaultValue: 'smtp.163.com',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 36,
      placeholder: '请输入accessKeySecret',
    },

    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'port',
    label: '端口',
    defaultValue: 25,
    required: true,
    component: 'InputNumber',
    rules: numberRule,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入端口',
    },

    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'username',
    label: '用户名',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入用户名',
    },

    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'password',
    label: '密码',
    required: true,
    component: 'InputPassword',
    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'config',
    label: '消息配置',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 255,
      placeholder: '请输入消息配置',
    },
    dynamicRules: () => {
      return [
        {
          required: false,
          validator: (_, value) => {
            if (String(value).length > 255) {
              return Promise.reject('字数不超过255个字');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入主键',
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '启用', value: 1 },
        { label: '停用', value: 0 },
      ],
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入备注',
    },
    dynamicRules: () => {
      return [
        {
          required: false,
          validator: (_, value) => {
            if (String(value).length > 255) {
              return Promise.reject('字数不超过255个字');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
];