config.data.ts 3.87 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: 'username',
    width: 100,
  },
  {
    title: '所属组织',
    dataIndex: 'department',
    width: 200,
  },
  {
    title: '手机',
    dataIndex: 'phone',
    width: 160,
  },
  {
    title: '邮箱',
    dataIndex: 'label',
    width: 160,
  },
  {
    title: '微信',
    dataIndex: 'deviceInfo',
    width: 180,
  },
  {
    title: '备注',
    dataIndex: 'deviceState',
    width: 120,
  },
  {
    title: '添加人',
    dataIndex: 'lastConnectTime',
    width: 180,
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    width: 180,
  },
  {
    title: '添加时间',
    dataIndex: 'createTime',
    width: 180,
  },
];

// 查询字段
export const searchFormSchema: FormSchema[] = [
  {
    field: 'department',
    label: '所属组织',
    component: 'TreeSelect',
    componentProps: {
      placeholder: '请选择组织',
    },
    colProps: { span: 6 },
  },
  {
    field: 'username',
    label: '用户名',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      placeholder: '请输入姓名、手机号或邮箱',
    },
  },
];

// 弹框配置项
export const formSchema: FormSchema[] = [
  {
    field: 'configName',
    label: '联系人姓名',
    required: true,
    component: 'Input',
  },
  {
    field: 'messageType',
    label: '所属组织',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'message_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
  {
    field: 'platformType',
    label: '手机号码',
    required: true,
    component: 'Input',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'platform_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
  {
    field: 'accessKeyId',
    label: 'accessKeyId',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'accessKeySecret',
    label: 'accessKeySecret',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'host',
    label: '服务器地址',
    defaultValue: 'smtp.163.com',
    required: true,
    component: 'Input',
    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'port',
    label: '端口',
    defaultValue: 25,
    required: true,
    component: 'InputNumber',
    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'username',
    label: '用户名',
    required: true,
    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,
  },
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    show: false,
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '启用', value: 1 },
        { label: '停用', value: 0 },
      ],
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
];

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