d9-energy-index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env node
  2. /**
  3. * D9: energy/index.vue 五维能量页清理 (debt 105)
  4. *
  5. * 1) 修复 C 批遗留 bug:'BrandColors.xxx' 字符串 -> 变量引用 + 补 import
  6. * 2) DIM_CONFIG / avatarGradient / navGradient / memberColor 的 hex 渐变收编模板字符串
  7. * 3) template RadarChart strokeColor/labelColor 绑定 data
  8. * 4) style 深海军蓝 #0F1B2D/#1A2744 收编局部 SCSS 变量
  9. */
  10. const fs = require('fs');
  11. const F = 'pages/energy/index.vue';
  12. let src = fs.readFileSync(F, 'utf8');
  13. let replaced = 0;
  14. function repl(from, to) {
  15. const cnt = src.split(from).length - 1;
  16. if (cnt === 0) { console.warn('NOT FOUND:', from.slice(0, 70)); return; }
  17. src = src.split(from).join(to);
  18. replaced += cnt;
  19. }
  20. // ---- 1. import ----
  21. repl(
  22. "import { getFamilyEnergySandbox, getFamilyMemberList } from '../../utils/api.js'",
  23. "import { getFamilyEnergySandbox, getFamilyMemberList } from '../../utils/api.js'\nimport { BrandColors } from '../../utils/brand-colors.js'"
  24. );
  25. // ---- 2. DIM_CONFIG(5 行:color 修字符串 + gradient 模板字符串)----
  26. repl(
  27. " { code: 'body', label: '身', icon: '💪', color: 'BrandColors.success', gradient: 'linear-gradient(135deg,#10B981,#34D399)' },",
  28. " { code: 'body', label: '身', icon: '💪', color: BrandColors.success, gradient: `linear-gradient(135deg,${BrandColors.success},${BrandColors.successLight3})` },"
  29. );
  30. repl(
  31. " { code: 'mind', label: '心', icon: '❤️', color: 'BrandColors.primary', gradient: 'linear-gradient(135deg,#F97316,#FB923C)' },",
  32. " { code: 'mind', label: '心', icon: '❤️', color: BrandColors.primary, gradient: `linear-gradient(135deg,${BrandColors.primary},${BrandColors.primaryLight})` },"
  33. );
  34. repl(
  35. " { code: 'wisdom', label: '智', icon: '🧠', color: '#F59E0B', gradient: 'linear-gradient(135deg,#F59E0B,#FBBF24)' },",
  36. " { code: 'wisdom', label: '智', icon: '🧠', color: BrandColors.wealth, gradient: `linear-gradient(135deg,${BrandColors.wealth},${BrandColors.warning})` },"
  37. );
  38. repl(
  39. " { code: 'action', label: '行', icon: '⚡', color: 'BrandColors.primary', gradient: 'linear-gradient(135deg,#F97316,#FB923C)' },",
  40. " { code: 'action', label: '行', icon: '⚡', color: BrandColors.primary, gradient: `linear-gradient(135deg,${BrandColors.primary},${BrandColors.primaryLight})` },"
  41. );
  42. repl(
  43. " { code: 'wealth', label: '富', icon: '💎', color: '#3B82F6', gradient: 'linear-gradient(135deg,#3B82F6,#60A5FA)' }",
  44. " { code: 'wealth', label: '富', icon: '💎', color: BrandColors.infoBlue, gradient: `linear-gradient(135deg,${BrandColors.infoBlue},${BrandColors.infoBlueLight})` }"
  45. );
  46. // ---- 3. avatarGradient / navGradient 模板字符串 ----
  47. repl(
  48. "if (this.currentView === 'family') return 'linear-gradient(135deg,#F97316,#FB923C)'",
  49. "if (this.currentView === 'family') return `linear-gradient(135deg,${BrandColors.primary},${BrandColors.primaryLight})`"
  50. );
  51. repl(
  52. "return 'linear-gradient(135deg,#F97316,#FB923C)'",
  53. "return `linear-gradient(135deg,${BrandColors.primary},${BrandColors.primaryLight})`"
  54. );
  55. repl(
  56. " var dim = DIM_CONFIG[0]",
  57. " var dim = DIM_CONFIG[0]"
  58. );
  59. // ---- 4. memberColor ----
  60. repl(
  61. " if (!member) return 'linear-gradient(135deg,#F97316,#FB923C)'",
  62. " if (!member) return `linear-gradient(135deg,${BrandColors.primary},${BrandColors.primaryLight})`"
  63. );
  64. repl(
  65. " var types = { parent: '#F59E0B', child: 'BrandColors.success', teacher: '#3B82F6' }",
  66. " var types = { parent: BrandColors.wealth, child: BrandColors.success, teacher: BrandColors.infoBlue }"
  67. );
  68. repl(
  69. " parent: 'linear-gradient(135deg,#F59E0B,#FBBF24)',\n child: 'linear-gradient(135deg,#10B981,#34D399)',\n teacher:'linear-gradient(135deg,#3B82F6,#60A5FA)'",
  70. " parent: `linear-gradient(135deg,${BrandColors.wealth},${BrandColors.warning})`,\n child: `linear-gradient(135deg,${BrandColors.success},${BrandColors.successLight3})`,\n teacher:`linear-gradient(135deg,${BrandColors.infoBlue},${BrandColors.infoBlueLight})`"
  71. );
  72. // ---- 5. template RadarChart ----
  73. repl('strokeColor="#F97316"', ':stroke-color="radarStrokeColor"');
  74. repl('labelColor="#888"', ':label-color="radarLabelColor"');
  75. // data() 注入 radar 色
  76. repl(
  77. " currentView: 'self', // self | family",
  78. " currentView: 'self', // self | family\n" +
  79. " radarStrokeColor: BrandColors.primary, // 雷达描边(品牌橙)\n" +
  80. " radarLabelColor: BrandColors.textFaint // 雷达标签(中灰)"
  81. );
  82. // ---- 6. style 深海军蓝收编局部变量 ----
  83. const styleIdx = src.indexOf('<style');
  84. const before = src.slice(0, styleIdx);
  85. let styleBody = src.slice(styleIdx);
  86. styleBody = styleBody.replace(/(#0F1B2D)(?![0-9a-fA-F])/g, '$c-energy-deep-1');
  87. styleBody = styleBody.replace(/(#1A2744)(?![0-9a-fA-F])/g, '$c-energy-deep-2');
  88. const palette = [
  89. '// ===== 能量页专属色阶(导航/卡面深海军蓝,单页专用;约定见 uni.scss §14)=====',
  90. '$c-energy-deep-1: #0F1B2D; // 导航渐变起(深夜蓝)',
  91. '$c-energy-deep-2: #1A2744; // 导航渐变终 / 卡片底(藏蓝)',
  92. ''
  93. ].join('\n');
  94. styleBody = styleBody.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
  95. src = before + styleBody;
  96. fs.writeFileSync(F, src);
  97. console.log('total replaced:', replaced);
  98. // 校验
  99. const lines = src.split('\n');
  100. let n = 0;
  101. for (let i = 0; i < lines.length; i++) {
  102. if (/#[0-9a-fA-F]{3,8}\b/.test(lines[i])) { console.log('HEX ' + (i + 1) + ': ' + lines[i].trim()); n++; }
  103. }
  104. console.log('remaining hex lines:', n);