datas.ts 4.17 KB
export type objectProps = Record<string, any>;
export interface propsProps {
  title: string
  apiParams: objectProps
}

export interface datasProps {
  storage?: boolean;      // 全局缓存数据
  title: string;          // 数据列标题
  // 展示名称为 name字段,值为 Id, 如果你想展示其他字段内容可以通过此函数返回修改后的数据
  itemRender?: (item: objectProps) => objectProps;
  // 每页展示数据条数, (0:全部查询,后续不会在触发任何接口)
  pageSize?: number;
  // find 列表查询配置
  find: {
    // 查询接口
    apiUrl: string;
    // 默认传递 pageNumber , pageSize, name 参数, 可直接以对象形式追加参数 也可以通过函数返回
    apiParams?: objectProps | ((params: objectProps, name: string) => objectProps);    // 参数
    // 接口返回 列表字段名称
    apiResult?: 'result' | string;
    // 根据额外props 修改 title 内容 ,同时额外传入其他查询条件
    props?: Record<string, propsProps>
  }
  get?: {
    // get 接口
    apiUrl: string;
    // get接口查询条件, 默认 { id:item[rowKey] }
    apiParams?: (params: objectProps) => objectProps;
    // 接口返回 数据对象名称
    apiResult?: 'data' | string;
  }
}

export type DataType = 'employee'     // 员工
  | 'employeeLeve'                      // 离职员工
  | 'user'                              // 用户
  | 'job'                               // 职位
  | 'location'                          // 地址(主数据维护信息)
  | 'nationList'                        // 民族
  | 'recruitmentChannel'                // 招聘渠道
  | 'bank'                              // 银行
  | 'level'                             // 职级
  | 'place'                             // 场所
  | 'goodsName'                         // 商品名称
  | 'machine'                           // 机器
  | 'machineName'                       // 机器名称

export default {
  employee: {
    storage: true,
    title: '员工',
    itemRender: (item: any) => {
      const { lastName, firstName } = item;
      return { ...item, name: (lastName || '') + (firstName || '') }
    },
    find: {
      apiUrl: 'xn.master.employee.find',
      props: {
        isProbation: {
          title: '试用期员工',
          apiParams: {
            employeeStatus: 'PROBATION',
          }
        }
      }
    },
    get: {
      apiUrl: 'xn.master.employee.get',
      apiResult: 'employee'
    }
  },
  employeeLeve: {
    storage: true,
    title: '离职员工',
    itemRender: (item: any) => {
      const { userName, lastName, firstName } = item;
      return {
        ...item,
        name: userName || (lastName || '') + (firstName || ''),
      }
    },
    find: { apiUrl: 'hr.employee.human.leave.find' },
    get: {
      apiUrl: 'hr.employee.human.info.get',
      apiResult: 'employeeView'
    }
  },
  user: {
    storage: true,
    title: '用户',
    find: { apiUrl: 'api.user.user.find' },
    get: { apiUrl: 'api.user.user.get', apiResult: 'user' }
  },
  job: {
    pageSize: 0,
    title: '职位',
    find: { apiUrl: 'api.hr.job.search' }
  },
  location: {
    pageSize: 0,
    title: '地址',
    find: { apiUrl: 'xn.master.location.find' }
  },
  nationList: {
    pageSize: 0,
    title: '名族',
    find: { apiUrl: 'xn.basic.nationList.get', apiResult: 'nationList' }
  },
  recruitmentChannel: {
    pageSize: 0,
    title: '招聘渠道',
    find: { apiUrl: 'xn.master.recruitmentChannel.find' }
  },
  bank: {
    pageSize: 0,
    title: '银行',
    find: { apiUrl: 'api.foundation.bank.find' }
  },
  level: {
    pageSize: 0,
    title: '职级',
    find: { apiUrl: 'hr.master.employee.level.find' }
  },
  place: {
    pageSize: 0,
    title: '场所',
    find: { apiUrl: 'hr.master.employee.level.find' }
  },
  goodsName: {
    pageSize: 0,
    title: '商品名称',
    find: { apiUrl: 'hr.master.employee.level.find' }
  },
  machine: {
    pageSize: 0,
    title: '机器',
    find: { apiUrl: 'hr.master.employee.level.find' }
  },
  machineName: {
    pageSize: 0,
    title: '机器名称',
    find: { apiUrl: 'hr.master.employee.level.find' }
  },
} as {
    [key in DataType]: datasProps
  };