| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/usr/bin/env node
- /**
- * D27: health-report.vue 健康报告页清理 (debt 51 -> 0)
- * SVG 属性色绑定 data;script 指标色/canvas 色收编 BrandColors
- */
- const fs = require('fs');
- const F = 'pages/body-detail/health-report.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, 100)); return; }
- src = src.split(from).join(to);
- replaced += cnt;
- }
- // ---- 1. import ----
- if (!src.includes('utils/brand-colors.js')) {
- const m = src.match(/<script>\r?\n/);
- if (m) src = src.replace(m[0], m[0] + "import { BrandColors } from '../../utils/brand-colors.js'\r\n");
- else console.warn('script tag not found');
- }
- // ---- 2. SVG 属性 ----
- repl('stroke="#EEEEEE"', ':stroke="svgTrack"');
- repl('fill="#333"', ':fill="svgInk"');
- repl('fill="#999"', ':fill="svgMuted"');
- repl(' healthReport: null,', ' healthReport: null,\r\n svgTrack: BrandColors.hairline2,\r\n svgInk: BrandColors.textStrong,\r\n svgMuted: BrandColors.textMuted,');
- // ---- 3. script 指标色 ----
- repl("color:'#F97316'", "color:BrandColors.primary");
- repl("color:'#4CAF50'", "color:BrandColors.matGreen");
- repl("color:'#FF9800'", "color:BrandColors.matOrange");
- repl("color:'#2196F3'", "color:BrandColors.matBlue");
- // ---- 4. 评分色档 ----
- repl("var color = '#4CAF50'", "var color = BrandColors.matGreen");
- repl("color = '#F44336'", "color = BrandColors.matRed");
- repl("color = '#FFC107'", "color = BrandColors.amber");
- // ---- 5. canvas ----
- repl("return '#EF4444'", "return BrandColors.danger");
- repl("return '#F59E0B'", "return BrandColors.wealth");
- repl("return '#10B981'", "return BrandColors.success");
- repl("ctx.setStrokeStyle('#E5E7EB')", "ctx.setStrokeStyle(BrandColors.gray200)");
- repl("ctx.setStrokeStyle('#F97316')", "ctx.setStrokeStyle(BrandColors.primary)");
- repl("ctx.setFillStyle('#6B7280')", "ctx.setFillStyle(BrandColors.textSlate)");
- 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().slice(0, 110)); n++; }
- }
- console.log('remaining hex lines:', n);
|