d19-family-dashboard.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env node
  2. /**
  3. * D19: family-dashboard.vue 家庭情绪看板清理 (debt 66)
  4. * script 五维色板/canvas/吉凶色板全收编 BrandColors;template 内联色绑定 data
  5. * style #FFF5F7 收编局部变量
  6. */
  7. const fs = require('fs');
  8. const F = 'pages/mind-detail/family-dashboard.vue';
  9. let src = fs.readFileSync(F, 'utf8');
  10. let replaced = 0;
  11. function repl(from, to) {
  12. const cnt = src.split(from).length - 1;
  13. if (cnt === 0) { console.warn('NOT FOUND:', from.slice(0, 90)); return; }
  14. src = src.split(from).join(to);
  15. replaced += cnt;
  16. }
  17. // ---- 1. template 内联色 ----
  18. repl(":style=\"{ backgroundColor: '#FFA500' }\"", ":style=\"{ backgroundColor: dataIconColor }\"");
  19. // ---- 2. import + data ----
  20. if (!src.includes('utils/brand-colors.js')) {
  21. const head = src.match(/<script>\r?\n/);
  22. if (head) src = src.replace(head[0], head[0] + "import { BrandColors } from '../../utils/brand-colors.js'\r\n");
  23. else console.warn('script tag not found');
  24. }
  25. // data 注入 dataIconColor(找 data() { return { 的第一行)
  26. const dataMatch = src.match(/(data\(\) \{\r?\n return \{\r?\n)/);
  27. if (dataMatch) {
  28. src = src.replace(dataMatch[1], dataMatch[1] + ' dataIconColor: BrandColors.goldDeep,\r\n');
  29. } else {
  30. console.warn('data() not matched — check data shape');
  31. }
  32. // ---- 3. script 五维色板(对象值)----
  33. repl("'木': '#10B981',", "'木': BrandColors.success,");
  34. repl("'火': '#FF6B9D',", "'火': BrandColors.mind,");
  35. repl("'土': '#FF8C42',", "'土': BrandColors.body,");
  36. repl("'金': '#6366F1',", "'金': BrandColors.wisdom,");
  37. repl("'水': '#3B82F6',", "'水': BrandColors.infoBlue,");
  38. // ---- 4. script canvas ----
  39. repl("ctx.fillStyle = '#FFF5F7'", "ctx.fillStyle = BrandColors.blush");
  40. repl("ctx.fillStyle = isLucky ? luckyColor : '#9CA3AF'", "ctx.fillStyle = isLucky ? luckyColor : BrandColors.textGray400");
  41. repl("ctx.strokeStyle = '#FFFFFF'", "ctx.strokeStyle = BrandColors.white", 2);
  42. repl("ctx.fillStyle = '#FFFFFF'", "ctx.fillStyle = BrandColors.white");
  43. repl("ctx.strokeStyle = '#F3F4F6'", "ctx.strokeStyle = BrandColors.fillGray100");
  44. repl("ctx.fillStyle = '#6B7280'", "ctx.fillStyle = BrandColors.textSlate", 2);
  45. repl("ctx.strokeStyle = '#E5E7EB'", "ctx.strokeStyle = BrandColors.gray200", 2);
  46. // ---- 5. 吉凶色板 ----
  47. repl("'大吉': '#EF4444',", "'大吉': BrandColors.danger,");
  48. repl("'吉': '#F97316',", "'吉': BrandColors.primary,");
  49. repl("'平': '#FBBF24',", "'平': BrandColors.warning,");
  50. repl("'凶': '#6366F1',", "'凶': BrandColors.wisdom,");
  51. repl("'大凶': '#8B5CF6'", "'大凶': BrandColors.violet");
  52. repl("return colors[level] || '#666666'", "return colors[level] || BrandColors.textBody");
  53. // ---- 6. style ----
  54. const styleIdx = src.indexOf('<style');
  55. const before = src.slice(0, styleIdx);
  56. let styleBody = src.slice(styleIdx);
  57. styleBody = styleBody.replace(/#FFF5F7(?![0-9a-fA-F])/gi, '$c-fd-blush');
  58. const palette = [
  59. '// ===== 家庭看板专属色阶(单页专用,约定见 uni.scss §14)=====',
  60. '$c-fd-blush: #FFF5F7; // 画布/卡片浅粉底',
  61. ''
  62. ].join('\n');
  63. styleBody = styleBody.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
  64. fs.writeFileSync(F, before + styleBody);
  65. console.log('total replaced:', replaced);
  66. const out = fs.readFileSync(F, 'utf8');
  67. const lines = out.split('\n');
  68. let n = 0;
  69. for (let i = 0; i < lines.length; i++) {
  70. const L = lines[i].trim();
  71. if (/#[0-9a-fA-F]{3,8}\b/.test(L) && L.charAt(0) !== '$') { console.log('HEX ' + (i + 1) + ': ' + L); n++; }
  72. }
  73. console.log('remaining non-palette hex:', n);