| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """C-2a-4a 旧蓝分流·跨面长尾第一批:teacher 7 + profile 6 + 散页 5 = 18 文件 30 处
- 三分法同 C-2a-3;徽章配浅蓝底(#EAF4FC/#f0f7ff)→ $uni-info 保 coherent;
- vis-option.active 选中态浅底 #E8F4FD → $uni-primary-pale(与橙边框成套);
- JS/模板数据色按各自上下文(FamilyRelationGraph home 槽 / DimensionArticles 渐变槽)。
- """
- import io
- import re
- import sys
- ORANGE = '$brand-primary'
- ORANGE_DARK = '$brand-primary-dark'
- ORANGE_LIGHT = '$brand-primary-light'
- INFO = '$uni-info'
- PALE = '$uni-primary-pale'
- GRAD_DARK = 'linear-gradient(135deg, #5B9BD5, #3A7CC4)'
- GRAD_DARK2 = 'linear-gradient(135deg, #5B9BD5, #3A7CC2)'
- GRAD_LIGHT = 'linear-gradient(135deg, #5B9BD5, #8FC5E8)'
- PAGES = {
- # ---- teacher 集群 ----
- 'pages/teacher/review-family.vue': {
- 'blocks': [('.badge', [('color: #4A9BD7', 'color: ' + INFO)])],
- 'global': [('#4A9BD7', ORANGE)],
- 'script': [],
- },
- 'pages/teacher/review-workbench.vue': {
- 'blocks': [('.badge', [('color: #4A9BD7', 'color: ' + INFO)])],
- 'global': [],
- 'script': [],
- },
- 'pages/teacher/plan-detail.vue': {
- 'blocks': [],
- 'global': [('#4A9BD7', ORANGE)],
- 'script': [],
- },
- 'pages/teacher/plan-list.vue': {
- 'blocks': [],
- 'global': [('#4A9BD7', ORANGE)],
- 'script': [],
- },
- 'pages/teacher/plan-create.vue': {
- 'blocks': [],
- 'global': [('#4A9BD7', ORANGE)],
- 'script': [],
- },
- 'pages/teacher/index.vue': {
- 'blocks': [],
- 'global': [('#5B9BD5', ORANGE)],
- 'script': [],
- },
- 'pages/teacher/families.vue': {
- 'blocks': [],
- 'global': [('#4A9BD7', ORANGE)],
- 'script': [],
- },
- # ---- profile 集群 ----
- 'pages/profile-extra/gates.vue': {
- 'blocks': [],
- 'global': [('#5B9BD5', ORANGE)],
- 'script': [],
- },
- 'pages/profile/report-detail.vue': {
- 'blocks': [],
- 'global': [('#5B9BD5', ORANGE)],
- 'script': [],
- },
- 'pages/profile/components/ProfileMenu.vue': {
- 'blocks': [],
- 'global': [('#5B9BD5', INFO)], # style 块仅 intent-reselect-link 一处(链接→info)
- 'script': [('color="#5B9BD5"', 'color="#F97316"', 1)], # 模板 switch 组件色
- },
- 'pages/profile-extra/coupons.vue': {
- 'blocks': [],
- 'global': [
- ('color: #5B9BD5', 'color: ' + INFO), # card-scope 徽章(配 #f0f7ff 浅蓝底)
- ('background: #5B9BD5', 'background: ' + ORANGE), # member-guide-btn 主按钮
- ],
- 'script': [],
- },
- 'pages/profile/report-management.vue': {
- 'blocks': [],
- 'global': [('#5B9BD5', ORANGE)],
- 'script': [],
- },
- 'pages/profile/index.vue': {
- 'blocks': [],
- 'global': [(GRAD_DARK, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK))],
- 'script': [],
- },
- # ---- 散页 ----
- 'pages/home-pages/member-home-detail.vue': {
- 'blocks': [],
- 'global': [
- (GRAD_DARK, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK)),
- ('#5B9BD5', ORANGE),
- ],
- 'script': [],
- },
- 'pages/article-center/article-edit.vue': {
- 'blocks': [],
- 'global': [
- ('#E8F4FD', PALE), # vis-option.active 选中态浅底(与橙边框成套)
- ('#5B9BD5', ORANGE),
- ],
- 'script': [],
- },
- 'components/gate-lock.vue': {
- 'blocks': [],
- 'global': [(GRAD_DARK2, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK))],
- 'script': [],
- },
- 'components/FamilyRelationGraph.vue': {
- 'blocks': [],
- 'global': [],
- 'script': [("home: '#5B9BD5',", "home: '#F97316',", 1)],
- },
- 'components/DimensionArticles.vue': {
- 'blocks': [],
- 'global': [],
- 'script': [(GRAD_LIGHT, "'linear-gradient(135deg, %s, %s)'" % (ORANGE, ORANGE_LIGHT), 1)],
- },
- }
- RESIDUAL_RE = re.compile(r'(?<![0-9A-Fa-f])#(?:5B9BD5|3A7CC4|4A9BD7|63B3ED|3A7CC2)(?![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·单行] %-16s %-20s -> %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] %-16s %-20s -> %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(' %-44s -> %-24s 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)
- if cfg['blocks'] or cfg['global']:
- 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():]
- for old, new, expect in cfg['script']:
- n = src.count(old)
- if n != expect:
- raise RuntimeError('%s: 脚本区 %s hit=%d(要求 %d)' % (page, old, n, expect))
- src = src.replace(old, new)
- print(' [script] %-36s -> %s x%d' % (old, new, n))
- io.open(page, 'w', encoding='utf-8', newline='').write(src)
- # 全文件终检
- residual = RESIDUAL_RE.findall(src) + RESIDUAL_RGBA.findall(src)
- if residual:
- raise RuntimeError('%s: 终检残留 %s' % (page, residual))
- print('C-2a-4a 完毕(18 文件)')
- if __name__ == '__main__':
- sys.exit(main())
|