| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #!/usr/bin/env node
- /**
- * D3: sleep-checkin.vue 睡眠主题清理 (debt 126)
- * - script 4 行质量条渐变 -> BrandColors 模板字符串
- * - style 7 色映射全局等值令牌
- * - 睡眠主题专属色(雪夜蓝 + 米黄族 + 极浅蓝)收编为页面级局部变量
- */
- const fs = require('fs');
- const F = 'pages/growth/sleep-checkin.vue';
- let src = fs.readFileSync(F, 'utf8');
- // --- 1. script 渐变 -> BrandColors ---
- const SCRIPT_REPL = [
- [
- "if (score >= 8) item._barBg = 'linear-gradient(90deg,#818CF8,#6366F1)'",
- "if (score >= 8) item._barBg = `linear-gradient(90deg, ${BrandColors.wisdomLight}, ${BrandColors.wisdom})`",
- ],
- [
- "else if (score >= 6) item._barBg = 'linear-gradient(90deg,#34D399,#10B981)'",
- "else if (score >= 6) item._barBg = `linear-gradient(90deg, ${BrandColors.successLight3}, ${BrandColors.success})`",
- ],
- [
- "else if (score >= 4) item._barBg = 'linear-gradient(90deg,#FBBF24,#F59E0B)'",
- "else if (score >= 4) item._barBg = `linear-gradient(90deg, ${BrandColors.warning}, ${BrandColors.wealth})`",
- ],
- [
- "else item._barBg = 'linear-gradient(90deg,#FB7185,#EF4444)'",
- "else item._barBg = `linear-gradient(90deg, ${BrandColors.dangerLight2}, ${BrandColors.danger})`",
- ],
- ];
- for (const [from, to] of SCRIPT_REPL) {
- if (!src.includes(from)) { console.warn('SCRIPT LINE NOT FOUND:', from.slice(0, 50)); continue; }
- src = src.replace(from, to);
- }
- // --- 2. import BrandColors(若未存在)---
- if (!src.includes('brand-colors')) {
- src = src.replace(/(<script>\n)/, '$1import { BrandColors } from \'../../utils/brand-colors.js\'\n');
- }
- // --- 3. style 区块 ---
- const styleIdx = src.indexOf('<style');
- const before = src.slice(0, styleIdx);
- let styleBody = src.slice(styleIdx);
- // 3a. 全局令牌映射(等值)
- const GLOBAL_MAP = [
- ['#EEF2FF', '$dim-wisdom-tint-2'], // x3
- ['#E0E7FF', '$accent-indigo-tint'], // x3
- ['#B45309', '$status-warning-strong-2'],// x1
- ['#4338CA', '$accent-indigo-ink'], // x2
- ['#F87171', '$status-danger-light'], // x1
- ['#059669', '$status-success-deep'], // x1
- ['#4F46E5', '$dim-wisdom-deep'], // x3
- ];
- // 3b. 专属色 -> 局部变量
- const PALETTE_MAP = [
- ['#EEF1F8', '$c-night-page'], // 页面底(深夜蓝灰)
- ['#3B4A8C', '$c-night-1'], // 雪夜蓝渐变档 1
- ['#2A3470', '$c-night-2'], // 雪夜蓝渐变档 2
- ['#1B2350', '$c-night-3'], // 雪夜蓝渐变档 3
- ['#FFE9A8', '$c-moon-soft'], // 月光浅黄
- ['#FFD166', '$c-moon'], // 月光主黄
- ['#FFB84D', '$c-moon-deep'], // 月光深黄
- ['#FF9F68', '$c-dusk-1'], // 暮色橙渐档 1
- ['#FF7A45', '$c-dusk-2'], // 暮色橙渐档 2
- ['#4A2A00', '$c-sepia-ink'], // 深棕文字(暖卡内)
- ['#F8FAFF', '$c-sky-ghost'], // 极浅蓝(卡底)
- ['#F1F5FF', '$c-sky-soft'], // 浅蓝(卡内底)
- ['#EDF1F7', '$c-sky-line'], // 浅蓝分隔线
- ];
- for (const [from, to] of [...GLOBAL_MAP, ...PALETTE_MAP]) {
- const esc = from.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
- styleBody = styleBody.replace(new RegExp(esc + '(?![0-9a-fA-F])', 'g'), to);
- }
- // 插入局部调色板
- const palette = [
- '// ===== 睡眠页专属色阶(雪夜蓝 + 月光米黄,单页主题专用;约定见 uni.scss §14)=====',
- '$c-night-page: #EEF1F8; // 页面底(深夜蓝灰)',
- '$c-night-1: #3B4A8C; // 雪夜蓝渐变档 1(起点)',
- '$c-night-2: #2A3470; // 雪夜蓝渐变档 2(中段)',
- '$c-night-3: #1B2350; // 雪夜蓝渐变档 3(终点)',
- '$c-moon-soft: #FFE9A8; // 月光浅黄',
- '$c-moon: #FFD166; // 月光主黄(星星/月牙)',
- '$c-moon-deep: #FFB84D; // 月光深黄',
- '$c-dusk-1: #FF9F68; // 暮色橙渐档 1',
- '$c-dusk-2: #FF7A45; // 暮色橙渐档 2',
- '$c-sepia-ink: #4A2A00; // 深棕文字(暖卡内)',
- '$c-sky-ghost: #F8FAFF; // 极浅蓝(卡底)',
- '$c-sky-soft: #F1F5FF; // 浅蓝(卡内底)',
- '$c-sky-line: #EDF1F7; // 浅蓝分隔线',
- ''
- ].join('\n');
- styleBody = styleBody.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
- fs.writeFileSync(F, before + styleBody);
- console.log('D3 done');
|