/** * 标准化属性名 * 将三种设备[监控设备],[治理设备],[生产设备]对象的属性名统一格式化 * @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 };