BAOLH
2025-03-19 625db78c901a3efeced6a07798e4a045bf8b1d00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 表格数据转换函数
export function transformData(result) {
  const mapInfo = {
    '名称': 'name',
    '任务开始时间': 'taskStartDate',
    '任务结束时间': 'taskEndDate',
    '任务工时': 'taskHours',
    '所属员工': 'userId',
    '所属员工ID': 'userIds',
    '绩效工时': 'performanceHours',
    '任务状态': 'taskStatus',
    '任务状态ID': 'taskStatusID',
    '优先度': 'priority',
    '优先度ID': 'priorityID'
  }
  return result.map(item => {
    const zhKeys = Object.keys(item)
    const obj = {}
    zhKeys.forEach(zhKey => {
      const enKey = mapInfo[zhKey]
      if (enKey === 'taskStartDate' || enKey === 'taskEndDate') {
        // obj[enKey] = formatExcelDate(item[zhKey])
        obj[enKey] = formatExcelDate(item[zhKey])
      } else {
        obj[enKey] = item[zhKey]
      }
    })
    return obj
  })
}
// 转换表格时间为2021/1/2格式
// export function formatExcelDate(numb, format = '/') {
//   const time = new Date((numb - 25567) * 24 * 3600000 - 5 * 60 * 1000 - 43 * 1000 - 24 * 3600000 - 8 * 3600000)
//   time.setYear(time.getFullYear())
//   const year = time.getFullYear() + ''
//   const month = time.getMonth() + 1 + ''
//   const date = time.getDate() + ''
//   if (format && format.length === 1) {
//     return year + format + month + format + date
//   }
//   return year + (month < 10 ? '0' + month : month) + (date < 10 ? '0' + date : date)
// }
 
// export function formatExcelDate(numb, format = '-') {
//   const time = new Date((numb - 25569) * 24 * 3600000);
//   let localTimeString = time.toISOString();
 
//   // 格式化为"yyyy-mm-dd HH:MM:SS"
//   localTimeString = localTimeString.replace('T', ' ').split('.')[0].replace(/-/g, format);
 
//   return localTimeString;
// }
 
export function formatExcelDate(numb, format = '-') {
  const seconds = Math.round((numb - 25569) * 24 * 60 * 60);
  const time = new Date(seconds * 1000);
  let localTimeString = time.toISOString();
 
  // 格式化为"yyyy-mm-dd HH:MM:SS"
  localTimeString = localTimeString.replace('T', ' ').split('.')[0].replace(/-/g, format);
 
  return localTimeString;
}