| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """C-2a-3 旧蓝分流·health 集群收尾:gut-flora 三兄弟 + feedback-popup + 五零星页
- 主族为 #4A9BD7(旧蓝-500 变体,页面级 raw hex;$brand-legacy-blue 令牌引用归 C-2b)
- 三分法:
- 选中态/主按钮/装饰竖线/页面 accent 链接 -> $brand-primary
- 浅蓝底信息徽章(level-tag/quote-label/badge-question)-> $uni-info(保徽章 coherent)
- report-header 渐变 -> 站点标准 hero($brand-primary -> $brand-primary-dark)
- JS/模板数据色(防撞色策略,不走 style 验证):
- gut-flora-detail 九系色板 #4A9BD7x2 -> #0EA5E9(保蓝色槽位;翻橙会与 #FF8C42 撞色)
- report-blocks-renderer 模板兜底 '#4A9BD7' -> '#F97316'
- health-report 四系色板头位 '#5B9BD5' -> '#F97316'(与 #FF9800 有列表间距不撞色)
- """
- import io
- import re
- import sys
- ORANGE = '$brand-primary'
- ORANGE_DARK = '$brand-primary-dark'
- INFO = '$uni-info'
- PAGES = {
- 'pages/health/gut-flora-detail.vue': {
- 'blocks': [],
- 'global': [
- ('linear-gradient(135deg, #4A9BD7, #6366F1)', 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK)),
- ('rgba(74,155,215,0.4)', 'rgba(249,115,22,0.4)'),
- ('#4A9BD7', ORANGE),
- ],
- },
- 'pages/health/gut-flora-species-detail.vue': {
- 'blocks': [
- ('.flora-level-tag', [('color: #4A9BD7', 'color: ' + INFO)]),
- ],
- 'global': [
- ('#4A9BD7', ORANGE),
- ],
- },
- 'pages/health/gut-flora-risks-detail.vue': {
- 'blocks': [],
- 'global': [
- ('#4A9BD7', ORANGE),
- ],
- },
- 'pages/health/components/feedback-popup.vue': {
- 'blocks': [
- ('.fb-quote-label', [('color: #4A9BD7', 'color: ' + INFO)]),
- ],
- 'global': [
- ('#4A9BD7', ORANGE),
- ],
- },
- 'pages/health/plan-list.vue': {
- 'blocks': [],
- 'global': [
- ('#4A9BD7', ORANGE),
- ],
- },
- 'pages/health/my-feedback.vue': {
- 'blocks': [],
- 'global': [
- ('color: #4A9BD7', 'color: ' + INFO),
- ],
- },
- 'pages/health/indicator-quicklook.vue': {
- 'blocks': [],
- 'global': [
- ('#4A9BD7', ORANGE),
- ],
- },
- }
- # JS/模板数据色(整文件 targeted,带计数断言;style 块已无旧蓝后执行)
- SCRIPT_SUBS = [
- ('pages/health/gut-flora-detail.vue', "'#4A9BD7'", "'#0EA5E9'", 2),
- ('pages/health/report-blocks-renderer.vue', "'#4A9BD7'", "'#F97316'", 1),
- ('pages/body-detail/health-report.vue', "'#5B9BD5'", "'#F97316'", 1),
- ]
- RESIDUAL_RE = re.compile(r'(?<![0-9A-Fa-f])#(?:5B9BD5|3A7CC4|4A9BD7|63B3ED)(?![0-9A-Fa-f])', re.I)
- RESIDUAL_RGBA = re.compile(r'rgba\((?:91, ?155, ?213|74, ?155, ?215)')
- STYLE_RE = re.compile(r'^[ \t]*<style[^>]*>[\s\S]*?</style>', re.M)
- def apply_block_rules(block, rules, page):
- for sel, pairs in rules:
- lines = block.split('\n')
- idx = None
- for i, ln in enumerate(lines):
- t = ln.strip()
- if t.startswith(sel) and (t.endswith('{') or t.endswith('}')):
- idx = i
- break
- if idx is None:
- raise RuntimeError('%s: 选择器未找到 %s' % (page, sel))
- line = lines[idx]
- if line.strip().endswith('}'):
- # 单行块:选择器与声明同行,仅在行内替换(保留原格式)
- for old, new in pairs:
- n = line.count(old)
- if n != 1:
- raise RuntimeError('%s: 单行块 hit=%d %s :: %s' % (page, n, sel, old))
- line = line.replace(old, new, 1)
- print(' [block·单行] %-22s %-22s -> %s' % (sel, old, new))
- lines[idx] = line
- else:
- end = None
- for j in range(idx + 1, len(lines)):
- if lines[j].strip() == '}':
- end = j
- break
- if end is None:
- raise RuntimeError('%s: 块未闭合 %s' % (page, sel))
- body = lines[idx + 1:end]
- for old, new in pairs:
- btxt = '\n'.join(body)
- n = btxt.count(old)
- if n != 1:
- raise RuntimeError('%s: 块内替换 hit=%d %s :: %s' % (page, n, sel, old))
- body = btxt.replace(old, new, 1).split('\n')
- print(' [block] %-22s %-22s -> %s' % (sel, old, new))
- lines[idx + 1:end] = body
- block = '\n'.join(lines)
- return block
- def apply_global(block, pairs, page):
- for old, new in pairs:
- n = block.count(old)
- if n == 0:
- raise RuntimeError('%s: 全局替换 hit=0 :: %s' % (page, old))
- block = block.replace(old, new)
- print(' %-46s -> %-26s x%d' % (old, new, n))
- return block
- def fix_lang(block, page):
- first, rest = block.split('\n', 1)
- if 'lang="scss"' not in first:
- if '<style scoped>' in first:
- first = first.replace('<style scoped>', '<style scoped lang="scss">', 1)
- elif '<style>' in first:
- first = first.replace('<style>', '<style lang="scss">', 1)
- else:
- raise RuntimeError('%s: 无法识别的 style 标签: %s' % (page, first.strip()))
- print(' [lang] 补 lang="scss"')
- return first + '\n' + rest
- def main():
- for page, cfg in PAGES.items():
- src = io.open(page, encoding='utf-8').read()
- m = STYLE_RE.search(src)
- if not m:
- raise RuntimeError('%s: 未找到 style 块' % page)
- block = m.group(0)
- print('== %s ==' % page)
- block = apply_block_rules(block, cfg['blocks'], page)
- block = apply_global(block, cfg['global'], page)
- block = fix_lang(block, page)
- residual = RESIDUAL_RE.findall(block) + RESIDUAL_RGBA.findall(block)
- if residual:
- raise RuntimeError('%s: style 块替换后残留 %s' % (page, residual))
- src = src[:m.start()] + block + src[m.end():]
- io.open(page, 'w', encoding='utf-8', newline='').write(src)
- print(' style 块残留 0,写盘完成')
- print('-- JS/模板数据色 --')
- for page, old, new, expect in SCRIPT_SUBS:
- src = io.open(page, encoding='utf-8').read()
- n = src.count(old)
- if n != expect:
- raise RuntimeError('%s: 脚本区 %s hit=%d(要求 %d)' % (page, old, n, expect))
- src = src.replace(old, new)
- io.open(page, 'w', encoding='utf-8', newline='').write(src)
- print(' %-46s %s -> %s x%d' % (page, old, new, n))
- print('-- 全文件终检 --')
- for page in list(PAGES.keys()) + [p for p, _, _, _ in SCRIPT_SUBS]:
- src = io.open(page, encoding='utf-8').read()
- residual = RESIDUAL_RE.findall(src) + RESIDUAL_RGBA.findall(src)
- if residual:
- raise RuntimeError('%s: 终检残留 %s' % (page, residual))
- print(' %s 干净' % page)
- print('C-2a-3 完毕')
- if __name__ == '__main__':
- sys.exit(main())
|