d17-report-confirm.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env node
  2. /**
  3. * D17: report-confirm.vue 报告确认页清理 (debt 69)
  4. * 与 report-detail 同色板:全局令牌 6 色 + 局部 $c-rpcf-* 8 色
  5. */
  6. const fs = require('fs');
  7. const F = 'pages/health/report-confirm.vue';
  8. let src = fs.readFileSync(F, 'utf8');
  9. const styleIdx = src.indexOf('<style');
  10. const before = src.slice(0, styleIdx);
  11. let styleBody = src.slice(styleIdx);
  12. const GLOBAL = [
  13. ['#D32F2F', '$fortune-0-ink'],
  14. ['#FFF8E1', '$mat-amber-tint'],
  15. ['#F57F17', '$mat-amber-strong'],
  16. ['#66BB6A', '$mat-green-light-2'],
  17. ['#43A047', '$mat-green-base-2'],
  18. ['#FFD54F', '$uni-warning-light'],
  19. ];
  20. for (const [f, t] of GLOBAL) {
  21. const esc = f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  22. styleBody = styleBody.replace(new RegExp(esc + '(?![0-9a-fA-F])', 'gi'), t);
  23. }
  24. const PAL = [
  25. ['#E8EDF2', '$c-rpcf-line'],
  26. ['#F8FAFB', '$c-rpcf-card'],
  27. ['#FFF0F0', '$c-rpcf-red-bg'],
  28. ['#FFC107', '$c-rpcf-amber-deep'],
  29. ['#FF8A65', '$c-rpcf-orange-1'],
  30. ['#FF5722', '$c-rpcf-orange-2'],
  31. ['#EF9A9A', '$c-rpcf-red-1'],
  32. ['#E53935', '$c-rpcf-red-2'],
  33. ];
  34. for (const [f, t] of PAL) {
  35. const esc = f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  36. styleBody = styleBody.replace(new RegExp(esc + '(?![0-9a-fA-F])', 'gi'), t);
  37. }
  38. const palette = [
  39. '// ===== 报告确认页专属色阶(与 report-detail 同族 Material 渐变;单页专用,约定见 uni.scss §14)=====',
  40. '$c-rpcf-line: #E8EDF2; // 浅灰分隔线',
  41. '$c-rpcf-card: #F8FAFB; // 卡片底(浅灰白)',
  42. '$c-rpcf-red-bg: #FFF0F0; // 警示浅红底',
  43. '$c-rpcf-amber-deep:#FFC107; // Material 琥珀深档',
  44. '$c-rpcf-orange-1: #FF8A65; // 低档渐变起',
  45. '$c-rpcf-orange-2: #FF5722; // 低档渐变终',
  46. '$c-rpcf-red-1: #EF9A9A; // 无档渐变起',
  47. '$c-rpcf-red-2: #E53935; // 无档渐变终',
  48. ''
  49. ].join('\n');
  50. styleBody = styleBody.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
  51. fs.writeFileSync(F, before + styleBody);
  52. console.log('D17 done');
  53. // 重读校验
  54. const out = fs.readFileSync(F, 'utf8');
  55. const lines = out.split('\n');
  56. let n = 0;
  57. for (let i = 0; i < lines.length; i++) {
  58. const L = lines[i].trim();
  59. if (/#[0-9a-fA-F]{3,8}\b/.test(L) && L.charAt(0) !== '$') { console.log('HEX ' + (i + 1) + ': ' + L); n++; }
  60. }
  61. console.log('remaining non-palette hex:', n);