#!/usr/bin/env node /** * D9: energy/index.vue 五维能量页清理 (debt 105) * * 1) 修复 C 批遗留 bug:'BrandColors.xxx' 字符串 -> 变量引用 + 补 import * 2) DIM_CONFIG / avatarGradient / navGradient / memberColor 的 hex 渐变收编模板字符串 * 3) template RadarChart strokeColor/labelColor 绑定 data * 4) style 深海军蓝 #0F1B2D/#1A2744 收编局部 SCSS 变量 */ const fs = require('fs'); const F = 'pages/energy/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, 70)); return; } src = src.split(from).join(to); replaced += cnt; } // ---- 1. import ---- repl( "import { getFamilyEnergySandbox, getFamilyMemberList } from '../../utils/api.js'", "import { getFamilyEnergySandbox, getFamilyMemberList } from '../../utils/api.js'\nimport { BrandColors } from '../../utils/brand-colors.js'" ); // ---- 2. DIM_CONFIG(5 行:color 修字符串 + gradient 模板字符串)---- repl( " { code: 'body', label: '身', icon: '💪', color: 'BrandColors.success', gradient: 'linear-gradient(135deg,#10B981,#34D399)' },", " { code: 'body', label: '身', icon: '💪', color: BrandColors.success, gradient: `linear-gradient(135deg,${BrandColors.success},${BrandColors.successLight3})` }," ); repl( " { code: 'mind', label: '心', icon: '❤️', color: 'BrandColors.primary', gradient: 'linear-gradient(135deg,#F97316,#FB923C)' },", " { code: 'mind', label: '心', icon: '❤️', color: BrandColors.primary, gradient: `linear-gradient(135deg,${BrandColors.primary},${BrandColors.primaryLight})` }," ); repl( " { code: 'wisdom', label: '智', icon: '🧠', color: '#F59E0B', gradient: 'linear-gradient(135deg,#F59E0B,#FBBF24)' },", " { code: 'wisdom', label: '智', icon: '🧠', color: BrandColors.wealth, gradient: `linear-gradient(135deg,${BrandColors.wealth},${BrandColors.warning})` }," ); repl( " { code: 'action', label: '行', icon: '⚡', color: 'BrandColors.primary', gradient: 'linear-gradient(135deg,#F97316,#FB923C)' },", " { code: 'action', label: '行', icon: '⚡', color: BrandColors.primary, gradient: `linear-gradient(135deg,${BrandColors.primary},${BrandColors.primaryLight})` }," ); repl( " { code: 'wealth', label: '富', icon: '💎', color: '#3B82F6', gradient: 'linear-gradient(135deg,#3B82F6,#60A5FA)' }", " { code: 'wealth', label: '富', icon: '💎', color: BrandColors.infoBlue, gradient: `linear-gradient(135deg,${BrandColors.infoBlue},${BrandColors.infoBlueLight})` }" ); // ---- 3. avatarGradient / navGradient 模板字符串 ---- repl( "if (this.currentView === 'family') return 'linear-gradient(135deg,#F97316,#FB923C)'", "if (this.currentView === 'family') return `linear-gradient(135deg,${BrandColors.primary},${BrandColors.primaryLight})`" ); repl( "return 'linear-gradient(135deg,#F97316,#FB923C)'", "return `linear-gradient(135deg,${BrandColors.primary},${BrandColors.primaryLight})`" ); repl( " var dim = DIM_CONFIG[0]", " var dim = DIM_CONFIG[0]" ); // ---- 4. memberColor ---- repl( " if (!member) return 'linear-gradient(135deg,#F97316,#FB923C)'", " if (!member) return `linear-gradient(135deg,${BrandColors.primary},${BrandColors.primaryLight})`" ); repl( " var types = { parent: '#F59E0B', child: 'BrandColors.success', teacher: '#3B82F6' }", " var types = { parent: BrandColors.wealth, child: BrandColors.success, teacher: BrandColors.infoBlue }" ); repl( " parent: 'linear-gradient(135deg,#F59E0B,#FBBF24)',\n child: 'linear-gradient(135deg,#10B981,#34D399)',\n teacher:'linear-gradient(135deg,#3B82F6,#60A5FA)'", " parent: `linear-gradient(135deg,${BrandColors.wealth},${BrandColors.warning})`,\n child: `linear-gradient(135deg,${BrandColors.success},${BrandColors.successLight3})`,\n teacher:`linear-gradient(135deg,${BrandColors.infoBlue},${BrandColors.infoBlueLight})`" ); // ---- 5. template RadarChart ---- repl('strokeColor="#F97316"', ':stroke-color="radarStrokeColor"'); repl('labelColor="#888"', ':label-color="radarLabelColor"'); // data() 注入 radar 色 repl( " currentView: 'self', // self | family", " currentView: 'self', // self | family\n" + " radarStrokeColor: BrandColors.primary, // 雷达描边(品牌橙)\n" + " radarLabelColor: BrandColors.textFaint // 雷达标签(中灰)" ); // ---- 6. style 深海军蓝收编局部变量 ---- const styleIdx = src.indexOf(']*>\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++) { if (/#[0-9a-fA-F]{3,8}\b/.test(lines[i])) { console.log('HEX ' + (i + 1) + ': ' + lines[i].trim()); n++; } } console.log('remaining hex lines:', n);