| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #!/usr/bin/env node
- /**
- * D19: family-dashboard.vue 家庭情绪看板清理 (debt 66)
- * script 五维色板/canvas/吉凶色板全收编 BrandColors;template 内联色绑定 data
- * style #FFF5F7 收编局部变量
- */
- const fs = require('fs');
- const F = 'pages/mind-detail/family-dashboard.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 内联色 ----
- repl(":style=\"{ backgroundColor: '#FFA500' }\"", ":style=\"{ backgroundColor: dataIconColor }\"");
- // ---- 2. import + data ----
- if (!src.includes('utils/brand-colors.js')) {
- const head = src.match(/<script>\r?\n/);
- if (head) src = src.replace(head[0], head[0] + "import { BrandColors } from '../../utils/brand-colors.js'\r\n");
- else console.warn('script tag not found');
- }
- // data 注入 dataIconColor(找 data() { return { 的第一行)
- const dataMatch = src.match(/(data\(\) \{\r?\n return \{\r?\n)/);
- if (dataMatch) {
- src = src.replace(dataMatch[1], dataMatch[1] + ' dataIconColor: BrandColors.goldDeep,\r\n');
- } else {
- console.warn('data() not matched — check data shape');
- }
- // ---- 3. script 五维色板(对象值)----
- repl("'木': '#10B981',", "'木': BrandColors.success,");
- repl("'火': '#FF6B9D',", "'火': BrandColors.mind,");
- repl("'土': '#FF8C42',", "'土': BrandColors.body,");
- repl("'金': '#6366F1',", "'金': BrandColors.wisdom,");
- repl("'水': '#3B82F6',", "'水': BrandColors.infoBlue,");
- // ---- 4. script canvas ----
- repl("ctx.fillStyle = '#FFF5F7'", "ctx.fillStyle = BrandColors.blush");
- repl("ctx.fillStyle = isLucky ? luckyColor : '#9CA3AF'", "ctx.fillStyle = isLucky ? luckyColor : BrandColors.textGray400");
- repl("ctx.strokeStyle = '#FFFFFF'", "ctx.strokeStyle = BrandColors.white", 2);
- repl("ctx.fillStyle = '#FFFFFF'", "ctx.fillStyle = BrandColors.white");
- repl("ctx.strokeStyle = '#F3F4F6'", "ctx.strokeStyle = BrandColors.fillGray100");
- repl("ctx.fillStyle = '#6B7280'", "ctx.fillStyle = BrandColors.textSlate", 2);
- repl("ctx.strokeStyle = '#E5E7EB'", "ctx.strokeStyle = BrandColors.gray200", 2);
- // ---- 5. 吉凶色板 ----
- repl("'大吉': '#EF4444',", "'大吉': BrandColors.danger,");
- repl("'吉': '#F97316',", "'吉': BrandColors.primary,");
- repl("'平': '#FBBF24',", "'平': BrandColors.warning,");
- repl("'凶': '#6366F1',", "'凶': BrandColors.wisdom,");
- repl("'大凶': '#8B5CF6'", "'大凶': BrandColors.violet");
- repl("return colors[level] || '#666666'", "return colors[level] || BrandColors.textBody");
- // ---- 6. style ----
- const styleIdx = src.indexOf('<style');
- const before = src.slice(0, styleIdx);
- let styleBody = src.slice(styleIdx);
- styleBody = styleBody.replace(/#FFF5F7(?![0-9a-fA-F])/gi, '$c-fd-blush');
- const palette = [
- '// ===== 家庭看板专属色阶(单页专用,约定见 uni.scss §14)=====',
- '$c-fd-blush: #FFF5F7; // 画布/卡片浅粉底',
- ''
- ].join('\n');
- styleBody = styleBody.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
- fs.writeFileSync(F, before + styleBody);
- console.log('total replaced:', replaced);
- const out = fs.readFileSync(F, 'utf8');
- const lines = out.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) && L.charAt(0) !== '$') { console.log('HEX ' + (i + 1) + ': ' + L); n++; }
- }
- console.log('remaining non-palette hex:', n);
|