d21-gut-flora.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env node
  2. /**
  3. * D21: gut-flora-detail.vue 肠道菌群详情页清理 (debt 60)
  4. * script 9 个指标色收编 BrandColors;style 全局令牌 3 + 局部 Material Teal 色阶 6
  5. */
  6. const fs = require('fs');
  7. const F = 'pages/health/gut-flora-detail.vue';
  8. let src = fs.readFileSync(F, 'utf8');
  9. let replaced = 0;
  10. // ---- 1. import ----
  11. if (!src.includes('utils/brand-colors.js')) {
  12. src = src.replace(
  13. "import HealthKnowledgePopup from '@/pages/health/components/health-knowledge-popup.vue'",
  14. "import HealthKnowledgePopup from '@/pages/health/components/health-knowledge-popup.vue'\nimport { BrandColors } from '../../utils/brand-colors.js'"
  15. );
  16. }
  17. // ---- 2. script 色值 ----
  18. const styleIdx = src.indexOf('<style');
  19. let scriptPart = src.slice(0, styleIdx);
  20. let stylePart = src.slice(styleIdx);
  21. const SCRIPT_MAP = [
  22. ['#0EA5E9', 'BrandColors.infoSky'],
  23. ['#10B981', 'BrandColors.success'],
  24. ['#F59E0B', 'BrandColors.wealth'],
  25. ['#FF8C42', 'BrandColors.body'],
  26. ['#6366F1', 'BrandColors.wisdom'],
  27. ['#FF6B9D', 'BrandColors.mind'],
  28. ['#C62828', 'BrandColors.dangerStrong2'],
  29. ];
  30. for (const [from, to] of SCRIPT_MAP) {
  31. const pat = "'" + from + "'";
  32. const cnt = scriptPart.split(pat).length - 1;
  33. if (cnt === 0) console.warn('SCRIPT NOT FOUND:', from);
  34. scriptPart = scriptPart.split(pat).join(to);
  35. replaced += cnt;
  36. }
  37. // ---- 3. style 全局令牌 ----
  38. const GLOBAL = [
  39. ['#FEF2F2', '$status-danger-tint-2'],
  40. ['#FECACA', '$danger-line'],
  41. ['#1976D2', '$mat-blue'],
  42. ['#FFF8E1', '$mat-amber-tint'],
  43. ['#A5D6A7', '$mat-green-soft'],
  44. ];
  45. for (const [from, to] of GLOBAL) {
  46. const re = new RegExp(from + '(?![0-9a-fA-F])', 'gi');
  47. replaced += (stylePart.match(re) || []).length;
  48. stylePart = stylePart.replace(re, to);
  49. }
  50. // ---- 4. style 局部 Material Teal 色阶 ----
  51. const LOCAL = [
  52. ['#FFB300', '$c-gf-amber'], // amber-700 提示条左边线
  53. ['#795548', '$c-gf-brown'], // brown-500 提示文字
  54. ['#E0F2F1', '$c-gf-teal-bg'], // teal-50 浅底
  55. ['#00897B', '$c-gf-teal'], // teal-600 主色
  56. ['#00695C', '$c-gf-teal-deep'], // teal-800 深档
  57. ['#004D40', '$c-gf-teal-ink'], // teal-900 深文字
  58. ];
  59. for (const [from, to] of LOCAL) {
  60. const re = new RegExp(from + '(?![0-9a-fA-F])', 'gi');
  61. replaced += (stylePart.match(re) || []).length;
  62. stylePart = stylePart.replace(re, to);
  63. }
  64. const palette = [
  65. '// ===== 肠道菌群页专属色阶(Material Teal 提示色族;单页专用,约定见 uni.scss §14)=====',
  66. '$c-gf-amber: #FFB300; // amber-700 提示左边线',
  67. '$c-gf-brown: #795548; // brown-500 提示文字',
  68. '$c-gf-teal-bg: #E0F2F1; // teal-50 浅底',
  69. '$c-gf-teal: #00897B; // teal-600 主色',
  70. '$c-gf-teal-deep: #00695C; // teal-800 深档',
  71. '$c-gf-teal-ink: #004D40; // teal-900 深文字',
  72. ''
  73. ].join('\n');
  74. stylePart = stylePart.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
  75. fs.writeFileSync(F, scriptPart + stylePart);
  76. console.log('total replaced:', replaced);
  77. const out = fs.readFileSync(F, 'utf8');
  78. const lines = out.split('\n');
  79. let n = 0;
  80. for (let i = 0; i < lines.length; i++) {
  81. const L = lines[i].trim();
  82. if (/#[0-9a-fA-F]{3,8}\b/.test(L) && L.charAt(0) !== '$') { console.log('HEX ' + (i + 1) + ': ' + L.slice(0, 100)); n++; }
  83. }
  84. console.log('remaining non-palette hex:', n);