|
|
@@ -0,0 +1,57 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+"""admin 前端(F:\\shop\\yoshop2.0-admin)字段驼峰迁移。
|
|
|
+
|
|
|
+Java 端平台后台接口出参/入参统一驼峰,前端 PHP 时代的 snake_case 字段需要同步。
|
|
|
+这里按显式映射替换,避免通用正则误伤 import 路径(lazy_use 等)。
|
|
|
+.vue 只处理 <template> 与 <script>,跳过 <style>。
|
|
|
+"""
|
|
|
+import re
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+ROOT = Path(r"F:\shop\yoshop2.0-admin")
|
|
|
+SRC = ROOT / "src"
|
|
|
+
|
|
|
+# snake_case -> camelCase(全部是接口字段)
|
|
|
+MAP = {
|
|
|
+ "store_id": "storeId",
|
|
|
+ "store_name": "storeName",
|
|
|
+ "create_time": "createTime",
|
|
|
+ "user_name": "userName",
|
|
|
+ "admin_user_id": "adminUserId",
|
|
|
+ "menu_id": "menuId",
|
|
|
+ "api_id": "apiId",
|
|
|
+ "parent_id": "parentId",
|
|
|
+ "is_page": "isPage",
|
|
|
+ "module_key": "moduleKey",
|
|
|
+ "action_mark": "actionMark",
|
|
|
+ "password_confirm": "passwordConfirm",
|
|
|
+ "current_page": "currentPage",
|
|
|
+}
|
|
|
+
|
|
|
+PATTERN = re.compile(r"\b(" + "|".join(sorted(MAP, key=len, reverse=True)) + r")\b")
|
|
|
+
|
|
|
+
|
|
|
+def repl(m):
|
|
|
+ return MAP[m.group(1)]
|
|
|
+
|
|
|
+
|
|
|
+def convert_vue(text):
|
|
|
+ parts = re.split(r"(<style[^>]*>[\s\S]*?</style>)", text)
|
|
|
+ out = []
|
|
|
+ for p in parts:
|
|
|
+ out.append(p if p.startswith("<style") else PATTERN.sub(repl, p))
|
|
|
+ return "".join(out)
|
|
|
+
|
|
|
+
|
|
|
+changed = []
|
|
|
+for f in sorted(list(SRC.rglob("*.vue")) + list(SRC.rglob("*.js"))):
|
|
|
+ text = f.read_text(encoding="utf-8", errors="replace")
|
|
|
+ new = convert_vue(text) if f.suffix == ".vue" else PATTERN.sub(repl, text)
|
|
|
+ if new != text:
|
|
|
+ n = len(PATTERN.findall(text))
|
|
|
+ f.write_text(new, encoding="utf-8", newline="")
|
|
|
+ changed.append((str(f.relative_to(ROOT)), n))
|
|
|
+
|
|
|
+print("改动 %d 个文件" % len(changed))
|
|
|
+for name, n in sorted(changed, key=lambda x: -x[1]):
|
|
|
+ print(" %-56s %d 处" % (name, n))
|