转换前的数据
format(results) {
const mapInfo = {
'入职日期': 'timeOfEntry',
'手机号': 'mobile',
'姓名': 'username',
'转正日期': 'correctionTime',
'工号': 'workNumber',
'部门': 'departmentName',
'聘用形式': 'formOfEmployment'
}
console.log(results)
// return []
const res = results.map(obj => {
// obj属性名是中文
// 1. 取出所有的属性名 ---> 数组
// 2 循环这个数组
// 向newObj中补充键值对
// 键:从中文->英文
// 值: obj中的值
const newObj = {}
const zhKeys = Object.keys(obj)
zhKeys.forEach(zhkey => {
const enKey = mapInfo[zhkey]
// if(当前的key是日期相关的,要额外处理)
if (enKey === 'timeOfEntry' || enKey === 'correctionTime') {
// excel中的日期格式和编程语言中的格式不一致,要转换
// 44892 -------> 2022-11-11
newObj[enKey] = new Date(formatExcelDate(obj[zhkey]))
} else {
newObj[enKey] = obj[zhkey]
}
})
return newObj
})
return res
}
转换后的数据