account.data.ts 3.7 KB
import { getAllRoleList, isAccountExist } from '/@/api/system/system';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';

export const columns: BasicColumn[] = [
  {
    title: '用户名',
    dataIndex: 'username',
    width: 120,
  },
  {
    title: '姓名',
    dataIndex: 'realName',
    width: 120,
  },
  {
    title: '手机号码',
    dataIndex: 'phoneNumber',
    width: 120,
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    width: 120,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: '状态',
    dataIndex: 'userStatusEnum',
    width: 120,
    slots: {customRender: 'status'}
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: '用户名',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'realName',
    label: '姓名',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const accountFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show:false
  },
  {
    field: 'username',
    label: '用户名',
    component: 'Input',
    colProps: { span: 12 },
    dynamicDisabled:false,
    dynamicRules:({values}) =>{
      return [
        {
          message: '请输入用户名',
          required: true,
        },
        {
          validator(_, value) {
            return new Promise((resolve, reject) => {
              if(value == '')
              {
                reject('请输入用户名');
              }else {
                if(values.username !=undefined && values.id == undefined){
                  isAccountExist(value)
                    .then((data) => {
                      if(data.data !=null){
                        reject('用户已存在');
                      }else{
                        resolve()
                      }
                    });
                }else{
                  resolve()
                }
              }
            });
          },
        },
      ];
    }
  },
  {
    field: 'password',
    label: '密码',
    component: 'InputPassword',
    required: true,
    colProps: { span: 12 },
  },
  {
    field: 'realName',
    label: '姓名',
    component: 'Input',
    colProps: { span: 12 },
    required: true,
  },
  {
    label: '角色',
    field: 'roleIds',
    component: 'ApiSelect',
    colProps: { span: 12 },
    componentProps: {
      mode: 'multiple',
      api: getAllRoleList,
      labelField: 'name',
      valueField: 'id',
    },
    rules: [
      {
        required: true,
        message: '请选择角色',
        type: 'array',
      },
    ],
    required: true,
  },
  {
    label: '手机号',
    field: 'phoneNumber',
    component: 'Input',
    colProps: { span: 12 },
    required: true,
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'Input',
    colProps: { span: 12 },
    required: true,
  },
  {
    field: 'accountExpireTime',
    label: '有效期: ',
    component: 'DatePicker',
    colProps: { span: 12 },
    componentProps:{
      showTime:true,
      format:'YYYY-MM-DD HH:mm:ss'
    }
  },
  {
    field: 'enabled',
    label: '状态',
    component: 'RadioButtonGroup',
    colProps: { span: 12 },
    defaultValue: true,
    componentProps: {
      options: [
        {label: '启用', value: true},
        {label: '禁用', value: false},
      ],
    },
  },
  {
    field: 'deptId',
    label: '所属部门',
    component: 'TreeSelect',
    componentProps: {
      replaceFields: {
        title: 'deptName',
        key: 'id',
        value: 'id',
      },
    },
    required: true,
  },
  {
    field: 'groupIds',
    label: ' ',
    component: 'Input',
    slot:'groupId',
  },
];