tmp_c2a4b.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """C-2a-4b 旧蓝分流·大家伙批次 7 文件
  4. child-index(16) / parent-index(6) / index-home(3 JS) / wuxing-sandbox(5) /
  5. articles.vue(4) / dimension-detail(3 JS) / member-detail(1 JS)
  6. 关键决策:
  7. - child-index:clay 设计系统整体迁移品牌橙(注释/渐变/边框/阴影);数据类目槽
  8. task-cat--life / quick-icon--growth -> sky-600 rgba(2,132,199,x)(防与 study/tasks 的
  9. sky-500 rgba(14,165,233,x) 及既有橙槽撞色)
  10. - parent-index:stat-icon-orange/act-add 名橙实蓝 -> 恢复品牌橙语义(主行动角色);
  11. milestone-trophy/pending-icon--blue/advice -> info 蓝;JS 渐变蓝槽 -> info 蓝渐变
  12. (数组第 4 槽已是橙,禁撞色)
  13. - wuxing-sandbox:深海军蓝面板上的旧蓝族仅翻「品牌氛围层」——ambient 光晕 + toggle 选中态;
  14. #8FC5E8 面板 chrome(title/badge/energy/toggle-inactive)与 #42A5F5 水行语义保留
  15. (chrome 翻橙会与火行 #FF6B35 撞色)
  16. - articles.vue:弃 $c-brand-legacy 局部声明(含 C-2 移交注释块),内联到用法
  17. - dimension-detail canvas / member-detail:JS 真实 hex(禁 SCSS 变量)
  18. """
  19. import io
  20. import re
  21. import sys
  22. ORANGE = '$brand-primary'
  23. ORANGE_DARK = '$brand-primary-dark'
  24. ORANGE_LIGHT = '$brand-primary-light'
  25. # 每文件:[(old, new, expect_hit)] 按序施加;fix_lang=True 时补 lang="scss"
  26. JOBS = [
  27. # ---- 1. child-index:clay 设计系统整体迁移 ----
  28. ('pages/home-pages/child-index.vue', True, [
  29. ('色彩体系:品牌蓝(#5B9BD5)+浅蓝(#8FC5E8)', '色彩体系:品牌橙(#F97316)+浅橙(#FB923C)', 1),
  30. ('积分卡片 — Flat Rounded 蓝色渐变', '积分卡片 — Flat Rounded 橙色渐变', 1),
  31. ('border: 4rpx solid #8FC5E8;', 'border: 4rpx solid %s;' % ORANGE_LIGHT, 1),
  32. ('rgba(143,197,232,0.30)', 'rgba(251,146,60,0.30)', 1),
  33. ('linear-gradient(145deg, #8FC5E8, #5B9BD5);',
  34. 'linear-gradient(145deg, %s, %s);' % (ORANGE_LIGHT, ORANGE), 1),
  35. ('border: 4rpx solid #3A7CC4;', 'border: 4rpx solid %s;' % ORANGE_DARK, 1),
  36. ('rgba(91,155,213,0.25)', 'rgba(249,115,22,0.25)', 1),
  37. ('rgba(91,155,213,0.18)', 'rgba(249,115,22,0.18)', 1),
  38. # 数据类目槽(值唯一,防撞色)
  39. ('rgba(91,155,213,0.12)', 'rgba(2,132,199,0.12)', 1), # task-cat--life
  40. ('rgba(91,155,213,0.15)', 'rgba(2,132,199,0.15)', 1), # quick-icon--growth
  41. # 中性 clay 阴影随品牌族
  42. ('rgba(91,155,213,0.08)', 'rgba(249,115,22,0.08)', 3),
  43. ('rgba(91,155,213,0.06)', 'rgba(249,115,22,0.06)', 3),
  44. ]),
  45. # ---- 2. parent-index:同名不同色需整行定位 ----
  46. ('pages/home-pages/parent-index.vue', False, [
  47. ("'linear-gradient(135deg, #5B9BD5, #8FC5E8)',",
  48. "'linear-gradient(135deg, #0EA5E9, #38BDF8)',", 1),
  49. ('.stat-icon-orange { background: rgba(91, 155, 213, 0.12); }',
  50. '.stat-icon-orange { background: rgba(249,115,22,0.12); }', 1),
  51. ('.milestone-trophy { background: rgba(91, 155, 213, 0.12); }',
  52. '.milestone-trophy { background: rgba(14,165,233,0.12); }', 1),
  53. ('.pending-icon--blue { background: rgba(91,155,213,0.12); }',
  54. '.pending-icon--blue { background: rgba(14,165,233,0.12); }', 1),
  55. ('background: rgba(91,155,213,0.1);', 'background: rgba(14,165,233,0.1);', 1),
  56. ('.act-add { background: rgba(91, 155, 213, 0.12); }',
  57. '.act-add { background: rgba(249,115,22,0.12); }', 1),
  58. ]),
  59. # ---- 3. index-home:JS 渐变蓝槽 x3(第 4 槽已橙,禁撞色)----
  60. ('pages/index-home/index.vue', False, [
  61. ("'linear-gradient(135deg, #5B9BD5, #8FC5E8)',",
  62. "'linear-gradient(135deg, #0EA5E9, #38BDF8)',", 3),
  63. ]),
  64. # ---- 4. wuxing-sandbox:氛围层 + 选中态翻橙,chrome/水行保留 ----
  65. ('components/wuxing-sandbox.vue', True, [
  66. ('rgba(91, 155, 213, 0.04)', 'rgba(249,115,22,0.04)', 1),
  67. ('rgba(66, 165, 245, 0.03)', 'rgba(251,146,60,0.03)', 1),
  68. ('rgba(91,155,213,0.10)', 'rgba(249,115,22,0.10)', 1),
  69. ('linear-gradient(135deg, #5B9BD5, #3A7CC2);',
  70. 'linear-gradient(135deg, %s, %s);' % (ORANGE, ORANGE_DARK), 1),
  71. ('border-color: #5B9BD5;', 'border-color: %s;' % ORANGE, 1),
  72. ]),
  73. # ---- 5. articles.vue:弃局部声明,内联到用法 ----
  74. ('pages/mind-detail/articles.vue', False, [
  75. ('// C-2 待翻转:旧品牌蓝残留(filter-chip.active 底色 / article-category 前景 + 浅底)。\n'
  76. '// B 批纪律保原值令牌化,翻转移交 C-2 角色分流(此处为品牌交互用法,预案翻品牌橙)\n'
  77. '$c-brand-legacy: #5B9BD5;\n'
  78. '$c-brand-legacy-tint: rgba(91,155,213,0.1);\n', '', 1),
  79. ('background: $c-brand-legacy;', 'background: %s;' % ORANGE, 1),
  80. ('color: $c-brand-legacy;', 'color: %s;' % ORANGE, 1),
  81. ('background: $c-brand-legacy-tint;', 'background: rgba(249,115,22,0.1);', 1),
  82. ]),
  83. # ---- 6. dimension-detail:canvas JS 真实 hex ----
  84. ('pages/body-detail/dimension-detail.vue', False, [
  85. ("ctx.setStrokeStyle('#4A9BD7')", "ctx.setStrokeStyle('#F97316')", 1),
  86. ("ctx.setFillStyle('rgba(74, 155, 215, 0.1)')",
  87. "ctx.setFillStyle('rgba(249,115,22,0.1)')", 1),
  88. ("ctx.setFillStyle('#4A9BD7')", "ctx.setFillStyle('#F97316')", 1),
  89. ]),
  90. # ---- 7. member-detail:home 槽 -> 品牌橙(与 FamilyRelationGraph home 一致)----
  91. ('pages/member-detail/member-detail.vue', False, [
  92. ("color: '#5B9BD5', gradient: 'linear-gradient(135deg, #5B9BD5, #3A7CC4)'",
  93. "color: '#F97316', gradient: 'linear-gradient(135deg, #F97316, #EA580C)'", 1),
  94. ]),
  95. ]
  96. RESIDUAL_RE = re.compile(
  97. r'(?<![0-9A-Fa-f])#(?:5B9BD5|3A7CC4|3A7CC2|4A9BD7|63B3ED|8FC5E8)(?![0-9A-Fa-f])', re.I)
  98. RESIDUAL_RGBA = re.compile(r'rgba\((?:91, ?155, ?213|74, ?155, ?215|143, ?197, ?232)')
  99. STYLE_RE = re.compile(r'^[ \t]*<style[^>]*>[\s\S]*?</style>', re.M)
  100. def fix_lang(src, page):
  101. m = STYLE_RE.search(src)
  102. block = m.group(0)
  103. first, rest = block.split('\n', 1)
  104. if 'lang=' not in first:
  105. if '<style scoped>' in first:
  106. first = first.replace('<style scoped>', '<style scoped lang="scss">', 1)
  107. elif '<style>' in first:
  108. first = first.replace('<style>', '<style lang="scss">', 1)
  109. else:
  110. raise RuntimeError('%s: 无法识别的 style 标签: %s' % (page, first.strip()))
  111. print(' [lang] 补 lang="scss"')
  112. src = src[:m.start()] + first + '\n' + rest + src[m.end():]
  113. return src
  114. def main():
  115. for page, need_lang, subs in JOBS:
  116. src = io.open(page, encoding='utf-8').read()
  117. print('== %s ==' % page)
  118. for old, new, expect in subs:
  119. n = src.count(old)
  120. if n != expect:
  121. raise RuntimeError('%s: hit=%d(要求 %d):: %r' % (page, n, expect, old[:60]))
  122. src = src.replace(old, new)
  123. label = (old[:50] + '…') if len(old) > 50 else old
  124. print(' %-52s -> %-30s x%d' % (label.replace('\n', '\\n'), new[:30], n))
  125. if need_lang:
  126. src = fix_lang(src, page)
  127. io.open(page, 'w', encoding='utf-8', newline='').write(src)
  128. residual = RESIDUAL_RE.findall(src) + RESIDUAL_RGBA.findall(src)
  129. if residual:
  130. raise RuntimeError('%s: 终检残留 %s' % (page, residual))
  131. print('C-2a-4b 执行完毕')
  132. if __name__ == '__main__':
  133. sys.exit(main())