From 7f5466662946584edaf034c96014e8b8fd180279 Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Sat, 10 Jan 2026 13:44:50 +0800 Subject: [PATCH] =?UTF-8?q?chore(util):=20=E5=A2=9E=E5=8A=A0=E8=9B=87?= =?UTF-8?q?=E5=BD=A2=E5=91=BD=E5=90=8D=E8=BD=AC=E9=A9=BC=E5=B3=B0=E5=91=BD?= =?UTF-8?q?=E5=90=8D=EF=BC=88=E9=80=92=E5=BD=92=E5=A4=84=E7=90=86=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E4=B8=AD=E7=9A=84=E6=89=80=E6=9C=89=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=90=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/js/util.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/common/js/util.js b/common/js/util.js index 9977c54..c6a7c57 100644 --- a/common/js/util.js +++ b/common/js/util.js @@ -1204,5 +1204,32 @@ export default { (typeof qh !== 'undefined' && qh.platform === 'huawei'); // #endif return true; + }, + + /** + * 蛇形命名转驼峰命名 + * @param {string} str 蛇形命名字符串 + * @returns {string} 驼峰命名字符串 + */ + snakeToCamel(str) { + return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()); + }, + + /** + * 蛇形命名转驼峰命名(递归处理对象中的所有属性名) + * @param {Object} obj 包含蛇形命名字符串属性的对象 + * @returns {Object} 驼峰命名字符串属性的对象 + */ + snakeToCamelForObj(obj) { + if (typeof obj !== 'object' || obj === null) return obj; + if (Array.isArray(obj)) return obj.map(this.snakeToCamelForObj.bind(this)); + const newObj = {}; + for (const key in obj) { + if (Object.hasOwnProperty.call(obj, key)) { + const newKey = this.snakeToCamel(key); + newObj[newKey] = this.snakeToCamelForObj(obj[key]); + } + } + return newObj; } } \ No newline at end of file