| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #!/usr/bin/env node
- /**
- * D13: tianpan/index.vue 家庭天盘页清理 (debt 78)
- *
- * 1) 修复字符串 bug:'BrandColors.*' -> 变量 + import
- * 2) script canvas/colorMap 色收编 BrandColors.*
- * 3) style 全局映射 4 色 + 局部变量 5 色
- */
- const fs = require('fs');
- const F = 'pages/tianpan/index.vue';
- let src = fs.readFileSync(F, 'utf8');
- let replaced = 0;
- function repl(from, to) {
- const cnt = src.split(from).length - 1;
- if (cnt === 0) { console.warn('NOT FOUND:', from.slice(0, 80)); return; }
- src = src.split(from).join(to);
- replaced += cnt;
- }
- // ---- 1. import ----
- repl(
- "<script>\nexport default {",
- "<script>\nimport { BrandColors } from '../../utils/brand-colors.js'\n\nexport default {"
- );
- // ---- 2. script canvas ----
- repl("ctx.fillStyle = '#FFF8F0'", "ctx.fillStyle = BrandColors.bodyTint");
- repl("var elementColors = ['BrandColors.success', '#FF6B9D', 'BrandColors.body', 'BrandColors.wisdom', '#F59E0B']",
- "var elementColors = [BrandColors.success, BrandColors.mind, BrandColors.body, BrandColors.wisdom, BrandColors.wealth]");
- repl("ctx.fillStyle = '#1F2937'", "ctx.fillStyle = BrandColors.textGray800");
- repl("ctx.fillStyle = '#6B7280'", "ctx.fillStyle = BrandColors.textSlate");
- repl("ctx.strokeStyle = '#FFF'", "ctx.strokeStyle = BrandColors.white");
- repl("ctx.fillStyle = '#FFF'", "ctx.fillStyle = BrandColors.white");
- repl("ctx.strokeStyle = '#F59E0B'", "ctx.strokeStyle = BrandColors.wealth");
- // ---- 3. colorMap ----
- repl(" 'parent': 'BrandColors.primary',\n 'child': '#3B82F6',\n 'teacher': '#8B5CF6'",
- " 'parent': BrandColors.primary,\n 'child': BrandColors.infoBlue,\n 'teacher': BrandColors.violet");
- repl("return colorMap[role] || '#6B7280'", "return colorMap[role] || BrandColors.textSlate");
- repl("var colors = { body: 'BrandColors.body', mind: '#FF6B9D', wisdom: 'BrandColors.wisdom', action: 'BrandColors.success', wealth: '#F59E0B' }",
- "var colors = { body: BrandColors.body, mind: BrandColors.mind, wisdom: BrandColors.wisdom, action: BrandColors.success, wealth: BrandColors.wealth }");
- repl("return colors[key] || '#6B7280'", "return colors[key] || BrandColors.textSlate");
- // ---- 4. style 块 ----
- const styleIdx = src.indexOf('<style');
- const before = src.slice(0, styleIdx);
- let styleBody = src.slice(styleIdx);
- const GLOBAL = [
- ['#FFF8F0', '$dim-body-tint'],
- ['#D1D5DB', '$app-border-strong'],
- ['#F5F0FF', '$facade-violet-tint'],
- ['#7C3AED', '$facade-violet-deep'],
- ];
- const PAL = [
- ['#FDBA74', '$c-tp-orange'],
- ['#7C2D12', '$c-tp-brown-deep'],
- ['#9A3412', '$c-tp-brown'],
- ['#E0D4FF', '$c-tp-violet-soft'],
- ['#6D28D9', '$c-tp-violet-text'],
- ];
- for (const [f, t] of [...GLOBAL, ...PAL]) {
- const esc = f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
- styleBody = styleBody.replace(new RegExp(esc + '(?![0-9a-fA-F])', 'g'), t);
- }
- const palette = [
- '// ===== 天盘页专属色阶(暖橙提示 + 紫罗兰软阶;单页专用,约定见 uni.scss §14)=====',
- '$c-tp-orange: #FDBA74; // 暖橙(徽章渐变档)',
- '$c-tp-brown-deep: #7C2D12; // 深棕文字(暖卡内)',
- '$c-tp-brown: #9A3412; // 棕橙文字(橙卡内)',
- '$c-tp-violet-soft: #E0D4FF; // 紫罗兰软底渐变终',
- '$c-tp-violet-text: #6D28D9; // 紫罗兰文字',
- ''
- ].join('\n');
- styleBody = styleBody.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
- src = before + styleBody;
- fs.writeFileSync(F, src);
- console.log('total replaced:', replaced);
- // 校验
- const lines = src.split('\n');
- let n = 0;
- for (let i = 0; i < lines.length; i++) {
- const L = lines[i].trim();
- if (/#[0-9a-fA-F]{3,8}\b/.test(L) && !/^\$c-/.test(L)) { console.log('HEX ' + (i + 1) + ': ' + L); n++; }
- }
- console.log('remaining non-palette hex:', n);
|