config.data.ts 3.09 KB
import { BasicColumn, FormSchema } from '/@/components/Table';
import { getOrganizationList } from '/@/api/system/system';
import { copyTransFun } from '/@/utils/fnUtils';

// 表格列数据
export const columns: BasicColumn[] = [
  {
    title: '姓名',
    dataIndex: 'username',
    width: 120,
  },
  {
    title: '所属组织',
    dataIndex: 'organizationId',
    width: 160,
  },
  {
    title: '手机',
    dataIndex: 'phone',
    width: 160,
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    width: 160,
  },
  {
    title: '微信',
    dataIndex: 'wechat',
    width: 180,
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 120,
  },

  {
    title: '添加时间',
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    width: 180,
  },
];

// 查询字段
export const searchFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: '联系人姓名',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      placeholder: '请输入联系人姓名',
    },
  },
];

// 弹框配置项
export const formSchema: FormSchema[] = [
  {
    field: 'username',
    label: '联系人姓名',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入联系人姓名',
    },
  },
  {
    field: 'organizationId',
    label: '所属组织',
    component: 'ApiTreeSelect',
    componentProps: {
      api: async () => {
        const data = await getOrganizationList();
        copyTransFun(data as any as any[]);
        return data;
      },
    },
  },
  {
    field: 'phone',
    label: '手机号码',
    component: 'Input',
    componentProps: {
      placeholder: '请输入手机号码',
    },
    rules: [
      {
        required: true,
        validator: (_, value: string) => {
          const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
          if (value === '') {
            return Promise.reject('请输入手机号码');
          } else if (!reg.test(value)) {
            return Promise.reject('请输入正确的手机号码');
          }
          return Promise.resolve();
        },
        trigger: 'blur',
      },
    ],
  },
  {
    field: 'email',
    label: '电子邮箱',
    component: 'Input',
    componentProps: {
      placeholder: '请输入电子邮箱',
    },
    rules: [
      {
        validator: (_, value: string) => {
          const reg = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
          if (value === '') {
            return Promise.resolve();
          } else if (!reg.test(value)) {
            return Promise.reject('请输入正确的电子邮箱');
          }
          return Promise.resolve();
        },
        trigger: 'blur',
      },
    ],
  },
  {
    field: 'wechat',
    label: '微信',
    component: 'Input',
    componentProps: {
      placeholder: '请输入微信号',
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '',
    },
  },
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false,
  },
];