config.data.ts 7.81 KB
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { findDictItemByCode } from '/@/api/system/dict';
import { MessageEnum } from '/@/enums/messageEnum';
export const columns: BasicColumn[] = [
  {
    title: '配置名称',
    dataIndex: 'configName',
    width: 200,
  },
  {
    title: '消息类型',
    dataIndex: 'messageTypeDictText',
    width: 200,
  },
  {
    title: '平台类型',
    dataIndex: 'platformTypeDictText',
    width: 180,
  },
  {
    title: '配置信息',
    dataIndex: 'config',
    width: 180,
    slots: { customRender: 'config' },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 120,
    slots: { customRender: 'status' },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'messageType',
    label: '消息类型',
    component: 'ApiSelect',
    colProps: {
      span: 6,
    },
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'message_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        { label: '已启用', value: 1 },
        { label: '已禁用', value: 0 },
      ],
    },
  },
];

export const isMessage = (type: string) => {
  return type === MessageEnum.IS_SMS;
};
export const isEmail = (type: string) => {
  return type === MessageEnum.IS_EMAIL;
};
export const isDingtalk = (type: string) => {
  return type === MessageEnum.IS_DINGTALK;
};
export const messageTypeIsTencentCloud = (type: string) => {
  return type === 'TENCENT_CLOUD';
};

export const formSchema: FormSchema[] = [
  {
    field: 'configName',
    label: '配置名称',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 30,
      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({ formModel }) {
      return {
        api: async (params: Recordable) => {
          try {
            const result = await findDictItemByCode(params as any);
            if (isMessage(Reflect.get(formModel, 'messageType')))
              return result.filter((item) => item.itemValue !== 'DING_TALK');
            if (isDingtalk(Reflect.get(formModel, 'messageType')))
              return result.filter((item) => item.itemValue === 'DING_TALK');
          } catch (e) {
            // eslint-disable-next-line no-console
            console.error(e);
            return [];
          }
        },
        params: {
          dictCode: 'platform_type',
        },
        labelField: 'itemText',
        valueField: 'itemValue',
      };
    },
    ifShow: ({ values }) =>
      isMessage(Reflect.get(values, 'messageType')) ||
      isDingtalk(Reflect.get(values, 'messageType')),
  },
  {
    field: 'appId',
    label: 'appId',
    required: true,
    component: 'InputPassword',
    componentProps: {
      maxLength: 36,
      placeholder: '请输入appId',
    },
    ifShow: ({ values }) => messageTypeIsTencentCloud(Reflect.get(values, 'platformType')),
  },
  {
    field: 'secretId',
    label: 'secretId',
    required: true,
    component: 'InputPassword',
    helpMessage: ['腾讯云:API密钥参考地址: https://console.cloud.tencent.com/cam/capi'],
    componentProps: {
      maxLength: 36,
      placeholder: '请输入secretId',
    },
    ifShow: ({ values }) => messageTypeIsTencentCloud(Reflect.get(values, 'platformType')),
  },
  {
    field: 'secretKey',
    label: 'secretKey',
    required: true,
    componentProps: {
      placeholder: '请输入secretKey',
    },

    component: 'InputPassword',
    ifShow: ({ values }) => messageTypeIsTencentCloud(Reflect.get(values, 'platformType')),
  },
  {
    field: 'accessKeyId',
    label: 'accessKeyId',
    required: true,
    component: 'InputPassword',
    helpMessage: ['阿里云:API密钥参考地址:https://ram.console.aliyun.com/manage/ak'],
    componentProps: {
      maxLength: 36,
      placeholder: '请输入accessKeyId',
    },
    ifShow: ({ values }) =>
      isMessage(Reflect.get(values, 'messageType')) &&
      !messageTypeIsTencentCloud(Reflect.get(values, 'platformType')),
  },
  {
    field: 'accessKeySecret',
    label: 'accessKeySecret',
    required: true,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入accessKeySecret',
    },

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

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

    component: 'InputNumber',
    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'username',
    label: '用户名',
    required: true,
    componentProps: {
      maxLength: 255,
      placeholder: '请输入用户名',
    },
    component: 'Input',
    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: '请输入消息配置',
    },
  },
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入主键',
    },
  },
  {
    field: 'agentId',
    label: 'agentId',
    component: 'InputPassword',
    required: true,
    ifShow: ({ values }) => isDingtalk(Reflect.get(values, 'messageType')),
    componentProps: {
      maxLength: 36,
      placeholder: '请输入agentId',
    },
  },
  {
    field: 'clientId',
    label: 'clientId',
    component: 'InputPassword',
    required: true,
    ifShow: ({ values }) => isDingtalk(Reflect.get(values, 'messageType')),
    componentProps: {
      maxLength: 36,
      placeholder: '请输入clientID',
    },
  },
  {
    field: 'clientSecret',
    label: 'clientSecret',
    component: 'InputPassword',
    ifShow: ({ values }) => isDingtalk(Reflect.get(values, 'messageType')),
    required: true,
    componentProps: {
      placeholder: '请输入clientSecret',
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '启用', value: 1 },
        { label: '停用', value: 0 },
      ],
    },
  },
  {
    label: '备注',
    field: 'remark',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入备注',
    },
    component: 'InputTextArea',
  },
  {
    label: '租户ID',
    field: 'tenantId',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入租户ID',
    },
  },
];