d27-health-report.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env node
  2. /**
  3. * D27: health-report.vue 健康报告页清理 (debt 51 -> 0)
  4. * SVG 属性色绑定 data;script 指标色/canvas 色收编 BrandColors
  5. */
  6. const fs = require('fs');
  7. const F = 'pages/body-detail/health-report.vue';
  8. let src = fs.readFileSync(F, 'utf8');
  9. let replaced = 0;
  10. function repl(from, to) {
  11. const cnt = src.split(from).length - 1;
  12. if (cnt === 0) { console.warn('NOT FOUND: ' + from.slice(0, 100)); return; }
  13. src = src.split(from).join(to);
  14. replaced += cnt;
  15. }
  16. // ---- 1. import ----
  17. if (!src.includes('utils/brand-colors.js')) {
  18. const m = src.match(/<script>\r?\n/);
  19. if (m) src = src.replace(m[0], m[0] + "import { BrandColors } from '../../utils/brand-colors.js'\r\n");
  20. else console.warn('script tag not found');
  21. }
  22. // ---- 2. SVG 属性 ----
  23. repl('stroke="#EEEEEE"', ':stroke="svgTrack"');
  24. repl('fill="#333"', ':fill="svgInk"');
  25. repl('fill="#999"', ':fill="svgMuted"');
  26. repl(' healthReport: null,', ' healthReport: null,\r\n svgTrack: BrandColors.hairline2,\r\n svgInk: BrandColors.textStrong,\r\n svgMuted: BrandColors.textMuted,');
  27. // ---- 3. script 指标色 ----
  28. repl("color:'#F97316'", "color:BrandColors.primary");
  29. repl("color:'#4CAF50'", "color:BrandColors.matGreen");
  30. repl("color:'#FF9800'", "color:BrandColors.matOrange");
  31. repl("color:'#2196F3'", "color:BrandColors.matBlue");
  32. // ---- 4. 评分色档 ----
  33. repl("var color = '#4CAF50'", "var color = BrandColors.matGreen");
  34. repl("color = '#F44336'", "color = BrandColors.matRed");
  35. repl("color = '#FFC107'", "color = BrandColors.amber");
  36. // ---- 5. canvas ----
  37. repl("return '#EF4444'", "return BrandColors.danger");
  38. repl("return '#F59E0B'", "return BrandColors.wealth");
  39. repl("return '#10B981'", "return BrandColors.success");
  40. repl("ctx.setStrokeStyle('#E5E7EB')", "ctx.setStrokeStyle(BrandColors.gray200)");
  41. repl("ctx.setStrokeStyle('#F97316')", "ctx.setStrokeStyle(BrandColors.primary)");
  42. repl("ctx.setFillStyle('#6B7280')", "ctx.setFillStyle(BrandColors.textSlate)");
  43. fs.writeFileSync(F, src);
  44. console.log('total replaced:', replaced);
  45. const lines = src.split('\n');
  46. let n = 0;
  47. for (let i = 0; i < lines.length; i++) {
  48. if (/#[0-9a-fA-F]{3,8}\b/.test(lines[i])) { console.log('HEX ' + (i + 1) + ': ' + lines[i].trim().slice(0, 110)); n++; }
  49. }
  50. console.log('remaining hex lines:', n);