account.data.tsx 5.58 KB
import { getRoleList, getDeptList, getCompanyList } from '/@/api/project/account';
import { Tag } from 'ant-design-vue';
import { BasicColumn, FormSchema } from '/@/components/Table';
// 重新包装getRoleList API,强制过滤生产科角色
const getFilteredRoleList = async (params?: any) => {
  const roles = await getRoleList(params);
  console.log('==== 原始角色列表 ====', roles);
  
  // 确保返回的是数组,并过滤掉ID为6的生产科角色
  if (Array.isArray(roles)) {
    const filtered = roles.filter(item => item.id !== 6);
    console.log('==== 过滤后角色列表 ====', filtered);
    return filtered;
  }
  
  return roles;
};
export const columns: BasicColumn[] = [
  {
    title: '姓名',
    dataIndex: 'chineseName',
    width: 120,
  },
  {
    title: '昵称',
    dataIndex: 'nickName',
    width: 120,
  },
  {
    title: '性别',
    dataIndex: 'gender',
    width: 80,
  },
  {
    title: '手机号',
    dataIndex: 'phone',
    width: 150,
  },
  {
    title: '邮箱',
    dataIndex: 'email',
    width: 300,
  },
  // {
  //   title: '创建时间',
  //   dataIndex: 'createTime',
  //   width: 180,
  // },
  {
    title: '公司',
    dataIndex: 'companyName',
    width: 150,
  },
  {
    title: '部门',
    dataIndex: 'deptName',
    width: 150,
  },
  {
    title: '角色岗位',
    dataIndex: 'roleName',
    width: 150,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 200,
    customRender: (column) => {
      const { record } = column || {};
      return record.status === 10 ? <Tag color="green">正常</Tag> : <Tag color="red">离职</Tag>;
    },
  },
  {
    title: '备注',
    dataIndex: 'remark',
    width: 400,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'chineseName',
    label: '姓名',
    component: 'Input',
    colProps: { span: 3},
  },
  {
    field: 'nickName',
    label: '昵称(英文名)',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field:'companyId',
    label:'公司',
    component:'ApiSelect',
    componentProps: {
      api: getCompanyList,
      labelField: 'name',
      valueField: 'id',
      immediate: true,
      showSearch: true,
      optionFilterProp: 'label',
      filterOption: (input, option) => {
        return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
      },
    },
   colProps: { span: 5 },
  },
  {
    field: 'roleId',
    label: '角色岗位',
    component: 'ApiSelect',
    componentProps: {
      api: getFilteredRoleList,
      labelField: 'description',
      valueField: 'id',
    },
    colProps: { span: 4 },
  },
  {
    field: 'deptId',
    label: '部门',
    component: 'ApiSelect',
    componentProps: {
      api: getDeptList,
      labelField: 'name',
      valueField: 'id',
    },
    colProps: { span: 4 },
  },
  {
    field: 'phone',
    label: '手机号',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'optType',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '正常', value: 10 },
        { label: '离职', value: 20 },
      ],
    },
    colProps: { span: 4 },
  },
];
// 员工账号的完整表单
export const accountFormSchema: FormSchema[] = [
  {
    field: 'chineseName',
    label: '姓名',
    component: 'Input',
    required: true,
  },
  {
    field: 'nickName',
    label: '昵称(英文名)',
    component: 'Input',
    required: true,
    componentProps: {
      disabled: true, // 设置为不可修改
    },
  },
  {
    field: 'gender',
    label: '性别',
    component: 'Select',
    componentProps: {
      options: [
        { label: '男', value: '男' },
        { label: '女', value: '女' },
      ],
    },
    required: true,
  },
  {
    field: 'phone',
    label: '手机号',
    component: 'Input',
    // helpMessage: ['本字段演示异步验证', '不能输入带有admin的用户名'],
    rules: [
      {
        required: true,
        message: '请输入用户名',
      },
    ],
  },
  {
    field:'companyId',
    label:'公司',
    component:'ApiSelect',
    componentProps: {
      api: getCompanyList,
      labelField: 'name',
      valueField: 'id',
      immediate: true,
      showSearch: true,
      optionFilterProp: 'label',
      filterOption: (input, option) => {
        return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
      },
    },
    required: true,
  },
  {
    label: '角色岗位',
    field: 'roleId',
    component: 'ApiSelect',
    componentProps: {
      api: getFilteredRoleList,
      labelField: 'description',
      valueField: 'id',
    },
    required: true,
  },
  {
    label: '角色部门',
    field: 'deptId',
    component: 'ApiSelect',
    componentProps: {
      api: getDeptList,
      labelField: 'name',
      valueField: 'id',
    },
    required: true,
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'InputTextArea',
    required: true,
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
];
// 生产科账号的简化表单(只包含姓名、手机号、邮箱、备注)
export const productionAccountFormSchema: FormSchema[] = [
  {
    field: 'chineseName',
    label: '姓名',
    component: 'Input',
    required: true,
  },
  {
    field: 'phone',
    label: '手机号',
    component: 'Input',
    required: true,
    rules: [
      {
        required: true,
        message: '请输入手机号',
      },
    ],
  },
  {
    label: '邮箱',
    field: 'email',
    component: 'InputTextArea',
    required: true,
  },

  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
];