枚举(后端格式化处理)

316 阅读1分钟

聘用形式格式化

分析

99999999996-58-00.png

后端给到我们前端的是一个数字类型的状态码(1, 2),每一个状态码对应有中文说明。我们通过枚举 ********的方式转换成文字即可

操作

把资料复制到项目中

枚举数据存放于我们提供的**资源/枚举**中,可以将枚举下的constant文件夹复制到src/文件夹下。

33333.png

导入页面组件中使用

import EmployeeEnum from '@/constant/employees'

使用

// 枚举
const hireType = {}
EmployeeEnum.hireType.forEach(item => {
  hireType[item.id] = item.value
})
export default {}

定义函数

   fromat(typeNumber) {
      return hireType[typeNumber]
    },

在标签上使用

66666666666666.png

constant枚举文件例如

// 员工
export default {
  // 聘用形式
  hireType: [
    {
      id: 1,
      value: '正式'
    },
    {
      id: 2,
      value: '非正式'
    }
  ],
  // 管理形式
  subjection: [
    {
      id: '1',
      value: '总部'
    },
    {
      id: '2',
      value: '分城市'
    }
  ],
  // 在职状态
  workingState: [
    {
      id: '1',
      value: '在职'
    },
    {
      id: '2',
      value: '离职'
    }
  ],
  // 离职类型
  leaveType: [
    {
      id: '1',
      value: '主动离职'
    },
    {
      id: '2',
      value: '被动离职'
    },
    {
      id: '3',
      value: '退休'
    }
  ],
  // 减员月
  attritionMonth: [
    {
      id: '1',
      value: '离职日本月'
    },
    {
      id: '2',
      value: '离职日次月'
    }
  ],
  }