| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """C-2a-4a 续跑:gates 补修(#3A7CC2 漏网)+ 剩余 10 文件
- 前 8 文件(teacher 7 + gates 主体)已在首跑完成,本脚本不重复。
- gate-lock 新增:锁面板 on-dark accent 文字随品牌族迁移(#8FC5E8 → $brand-primary-light,
- rgba(143,197,232,0.7) → rgba(251,146,60,0.7));reward-energy material 蓝徽章非旧蓝族保留。
- """
- 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)'
- # ---- 前置补修:gates.vue reward-energy 徽章(首跑漏网 #3A7CC2 + rgba(66,165,245,0.15))----
- PRE_FIX = [
- ('pages/profile-extra/gates.vue', [
- ('color: #3A7CC2; background: rgba(66,165,245,0.15);',
- 'color: %s; background: rgba(14,165,233,0.15);' % INFO, 1),
- ]),
- ]
- PAGES = {
- 'pages/profile/report-detail.vue': {
- 'blocks': [],
- 'global': [('#5B9BD5', ORANGE)],
- 'script': [],
- },
- 'pages/profile/components/ProfileMenu.vue': {
- 'blocks': [],
- 'global': [('#5B9BD5', INFO)],
- 'script': [('color="#5B9BD5"', 'color="#F97316"', 1)],
- },
- 'pages/profile-extra/coupons.vue': {
- 'blocks': [],
- 'global': [
- ('color: #5B9BD5', 'color: ' + INFO),
- ('background: #5B9BD5', 'background: ' + ORANGE),
- ],
- '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),
- ('#5B9BD5', ORANGE),
- ],
- 'script': [],
- },
- 'components/gate-lock.vue': {
- 'blocks': [],
- 'global': [
- (GRAD_DARK2, 'linear-gradient(135deg, %s, %s)' % (ORANGE, ORANGE_DARK)),
- ('color: #8FC5E8;', 'color: %s;' % ORANGE_LIGHT),
- ('color: rgba(143,197,232,0.7);', 'color: rgba(251,146,60,0.7);'),
- ],
- '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|3A7CC2|4A9BD7|63B3ED|8FC5E8)(?![0-9A-Fa-f])', re.I)
- RESIDUAL_RGBA = re.compile(r'rgba\((?:91, ?155, ?213|74, ?155, ?215|143, ?197, ?232)')
- STYLE_RE = re.compile(r'^[ \t]*<style[^>]*>[\s\S]*?</style>', re.M)
- 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(' %-52s -> %-30s 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():
- # 前置补修(整文件 targeted)
- for page, subs in PRE_FIX:
- src = io.open(page, encoding='utf-8').read()
- print('== [补修] %s ==' % page)
- for old, new, expect in subs:
- n = src.count(old)
- if n != expect:
- raise RuntimeError('%s: 补修 hit=%d(要求 %d):: %s' % (page, n, expect, old))
- src = src.replace(old, new)
- print(' %-52s -> %s x%d' % (old, new, n))
- io.open(page, 'w', encoding='utf-8', newline='').write(src)
- 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['global']:
- block = apply_global(block, cfg['global'], page)
- block = fix_lang(block, page)
- 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] %-44s -> %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 续跑完毕')
- if __name__ == '__main__':
- sys.exit(main())
|