#!/usr/bin/env node /** * D18: emotion-trend.vue 情绪趋势页清理 (debt 69) * * 1) template 5 个 legend-step 内联 background -> class(SCSS 变量) * 2) script 天气色板/canvas 色收编 BrandColors + 补 key * 3) style 局部变量/全局映射 */ const fs = require('fs'); const F = 'pages/mind-detail/emotion-trend.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, 90)); return; } src = src.split(from).join(to); replaced += cnt; } // ---- 1. template legend-step 内联 -> 语义 class ---- repl('', ''); repl('', ''); repl('', ''); repl('', ''); repl('', ''); // ---- 2. script 天气色板 / canvas ---- repl("sunny: { icon: '\\u2600\\uFE0F', label: '心情很好', color: '#FFB347' }", "sunny: { icon: '\\u2600\\uFE0F', label: '心情很好', color: BrandColors.weatherSunny }"); repl("cloudy: { icon: '\\u26C5', label: '一般般', color: '#A0A0A0' }", "cloudy: { icon: '\\u26C5', label: '一般般', color: BrandColors.emotionDisgust }"); repl("rainy: { icon: '\\uD83C\\uDF27\\uFE0F', label: '有点难过', color: '#6B9BD2' }", "rainy: { icon: '\\uD83C\\uDF27\\uFE0F', label: '有点难过', color: BrandColors.emotionSadness }"); repl("stormy: { icon: '\\u26A1', label: '很烦躁', color: '#8B5CF6' }", "stormy: { icon: '\\u26A1', label: '很烦躁', color: BrandColors.violet }"); repl("rainbow: { icon: '\\uD83C\\uDF08', label: '特别开心', color: '#FF6B9D' }", "rainbow: { icon: '\\uD83C\\uDF08', label: '特别开心', color: BrandColors.mind }"); repl("color: '#ccc' }", "color: BrandColors.textGhost }"); repl("ctx.setStrokeStyle('#E0E0E0')", "ctx.setStrokeStyle(BrandColors.hairline)"); repl("ctx.setFillStyle('#999')", "ctx.setFillStyle(BrandColors.textMuted)"); repl("ctx.setStrokeStyle('#F0F0F0')", "ctx.setStrokeStyle(BrandColors.fill)"); repl("var lineColor = avg >= 5 ? '#10B981' : '#FF6B9D'", "var lineColor = avg >= 5 ? BrandColors.success : BrandColors.mind"); repl("color = '#10B981'", "color = BrandColors.success"); repl("color = '#FFD93D'", "color = BrandColors.emotionJoy"); repl("color = '#FF6B9D'", "color = BrandColors.mind"); // ---- 3. import ---- const hasImport = src.includes('utils/brand-colors.js'); if (!hasImport) { const m = src.match(/