无人机管理后台前端(已迁走)
张含笑
2025-06-14 74f3a7dcedba7e9aeac99287c3daf666a726d1d6
src/utils/util.js
@@ -447,4 +447,24 @@
   if (!url) return ''
   const lastDotIndex = url.lastIndexOf('.')
   return `${url.substring(0, lastDotIndex)}_show${url.substring(lastDotIndex)}`
}
// key驼峰转换为下划线
export function camelToSnake (obj) {
  if (typeof obj !== 'object' || obj === null) {
    return obj
  }
  if (Array.isArray(obj)) {
    return obj.map(item => camelToSnake(item))
  }
  const newObj = {}
  for (const key in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, key)) {
      const newKey = key.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()
      newObj[newKey] = camelToSnake(obj[key])
    }
  }
  return newObj
}