riku
2025-09-18 c1d2051abc8ca88cd07f0d7c56c0dbf8165d5c33
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
/**
 * 标准化属性名
 * 将三种设备[监控设备],[治理设备],[生产设备]对象的属性名统一格式化
 * @param {*} data
 */
function formatDevice(data) {
  // 将一个js对象中所有di,wi,pi开头的属性全部改成去掉这些前缀并且重新变为驼峰式命名
  const newObj = {};
  for (const key in data) {
    let newKey = key;
    if (key.startsWith('di')) {
      newKey = key.substring(2);
    } else if (key.startsWith('wi')) {
      newKey = key.substring(2);
    } else if (key.startsWith('pi')) {
      newKey = key.substring(2);
    }
    newKey = newKey.charAt(0).toLowerCase() + newKey.slice(1);
    newObj[newKey] = data[key];
  }
  return newObj;
}
 
function formatDeviceList(dataList) {
  return dataList.map((v) => formatDevice(v));
}
 
export { formatDevice, formatDeviceList };