d10-family-members.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env node
  2. /**
  3. * D10: family-members.vue 家庭成员管理页清理 (debt 90)
  4. *
  5. * 1) script canvas 15 处色收编为 CANVAS_COLORS 常量(引用 BrandColors + import)
  6. * 2) style 全局令牌映射:#FF6B9D->$dim-mind, #EEF2FF->$dim-wisdom-tint-2
  7. * 3) style 专属色收编局部变量:暖米族($c-fam-*) + 紫罗兰族($c-fam-violet-*)
  8. * + Element UI 浅底族($c-elm-*)
  9. * 4) brand-colors.js 补 bodyLight(#FFB366)/primaryDeep(#C2410C)
  10. */
  11. const fs = require('fs');
  12. const F = 'pages/profile-extra/family-members.vue';
  13. let src = fs.readFileSync(F, 'utf8');
  14. let replaced = 0;
  15. function repl(from, to) {
  16. const cnt = src.split(from).length - 1;
  17. if (cnt === 0) { console.warn('NOT FOUND:', from.slice(0, 80)); return; }
  18. src = src.split(from).join(to);
  19. replaced += cnt;
  20. }
  21. // ---- 1. import + CANVAS_COLORS ----
  22. repl(
  23. "<script>\nexport default {",
  24. [
  25. "<script>",
  26. "import { BrandColors } from '../../utils/brand-colors.js'",
  27. "",
  28. "// canvas 画布色板(引用 BrandColors;画布专属浅色保留集中定义,约定见 uni.scss §14)",
  29. "var CANVAS_COLORS = {",
  30. " gradStart: BrandColors.body, // #FF8C42 背景渐变起",
  31. " gradEnd: BrandColors.bodyLight, // #FFB366 背景渐变终",
  32. " cardFace: '#FFFCF5', // 卡片面(米白)",
  33. " cardInk: BrandColors.primaryDeep, // #C2410C 深橙文字",
  34. " cardFaceAlt: '#FFF0E0', // 卡片内底(浅橙)",
  35. " hintText: BrandColors.textMuted, // #999999 占位灰",
  36. " btnStart: BrandColors.body,",
  37. " btnEnd: BrandColors.bodyLight,",
  38. " btnInk: BrandColors.white,",
  39. " dotColors: [BrandColors.body, BrandColors.wisdom, BrandColors.wealth, BrandColors.action, BrandColors.mind]",
  40. "};",
  41. "",
  42. "export default {",
  43. ].join('\n')
  44. );
  45. // ---- 2. canvas 调用处 ----
  46. repl("bgGrad.addColorStop(0, '#FF8C42')", "bgGrad.addColorStop(0, CANVAS_COLORS.gradStart)");
  47. repl("bgGrad.addColorStop(1, '#FFB366')", "bgGrad.addColorStop(1, CANVAS_COLORS.gradEnd)");
  48. repl("ctx.setFillStyle('#FFFCF5')", "ctx.setFillStyle(CANVAS_COLORS.cardFace)");
  49. repl("ctx.setFillStyle('#C2410C')", "ctx.setFillStyle(CANVAS_COLORS.cardInk)");
  50. repl("ctx.setFillStyle('#FFF0E0')", "ctx.setFillStyle(CANVAS_COLORS.cardFaceAlt)");
  51. repl("ctx.setFillStyle('#FF8C42')", "ctx.setFillStyle(CANVAS_COLORS.gradStart)");
  52. repl("ctx.setFillStyle('#999999')", "ctx.setFillStyle(CANVAS_COLORS.hintText)");
  53. repl("btnGrad.addColorStop(0, '#FF8C42')", "btnGrad.addColorStop(0, CANVAS_COLORS.btnStart)");
  54. repl("btnGrad.addColorStop(1, '#FFB366')", "btnGrad.addColorStop(1, CANVAS_COLORS.btnEnd)");
  55. repl("ctx.setFillStyle('#FFFFFF')", "ctx.setFillStyle(CANVAS_COLORS.btnInk)");
  56. repl("var dotColors = ['#FF8C42', '#6366F1', '#F59E0B', '#10B981', '#FF6B9D']",
  57. "var dotColors = CANVAS_COLORS.dotColors");
  58. // ---- 3. style 块 ----
  59. const styleIdx = src.indexOf('<style');
  60. const before = src.slice(0, styleIdx);
  61. let styleBody = src.slice(styleIdx);
  62. // 全局令牌
  63. styleBody = styleBody.replace(/#FF6B9D(?![0-9a-fA-F])/g, '$dim-mind');
  64. styleBody = styleBody.replace(/#EEF2FF(?![0-9a-fA-F])/g, '$dim-wisdom-tint-2');
  65. // 局部变量
  66. const PAL_MAP = [
  67. ['#F5F0EB', '$c-fam-page'],
  68. ['#FFFCF5', '$c-fam-card'],
  69. ['#F0EAE2', '$c-fam-line'],
  70. ['#FFF1E8', '$c-fam-tint'],
  71. ['#6D28D9', '$c-fam-violet-text'],
  72. ['#EDE9FE', '$c-fam-violet-bg'],
  73. ['#C7D2FE', '$c-fam-violet-line'],
  74. ['#f0f9ff', '$c-elm-info-bg'],
  75. ['#EEF0FF', '$c-elm-info-bg-2'],
  76. ['#f0f9eb', '$c-elm-success-bg'],
  77. ['#67c23a', '$c-elm-success-text'],
  78. ['#fef0f0', '$c-elm-danger-bg'],
  79. ['#f56c6c', '$c-elm-danger-text'],
  80. ];
  81. for (const [from, to] of PAL_MAP) {
  82. styleBody = styleBody.split(from).join(to);
  83. }
  84. const palette = [
  85. '// ===== 家员管理页专属色阶(暖米卡片 + 紫罗兰 + Element UI 浅底;单页专用,约定见 uni.scss §14)=====',
  86. '$c-fam-page: #F5F0EB; // 页面底(暖灰米)',
  87. '$c-fam-card: #FFFCF5; // 卡片底(米白)',
  88. '$c-fam-line: #F0EAE2; // 暖分隔线',
  89. '$c-fam-tint: #FFF1E8; // 浅橙底',
  90. '$c-fam-violet-text: #6D28D9; // 紫罗兰文字',
  91. '$c-fam-violet-bg: #EDE9FE; // 紫罗兰底',
  92. '$c-fam-violet-line: #C7D2FE; // 紫罗兰深底(亲密条)',
  93. '$c-elm-info-bg: #f0f9ff; // Element UI 信息浅底',
  94. '$c-elm-info-bg-2: #EEF0FF; // Element UI 蓝浅底',
  95. '$c-elm-success-bg: #f0f9eb; // Element UI 成功浅底',
  96. '$c-elm-success-text: #67c23a; // Element UI 成功文字',
  97. '$c-elm-danger-bg: #fef0f0; // Element UI 危险浅底',
  98. '$c-elm-danger-text: #f56c6c; // Element UI 危险文字',
  99. ''
  100. ].join('\n');
  101. styleBody = styleBody.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
  102. src = before + styleBody;
  103. fs.writeFileSync(F, src);
  104. console.log('total replaced:', replaced);
  105. // 校验
  106. const lines = src.split('\n');
  107. let n = 0;
  108. for (let i = 0; i < lines.length; i++) {
  109. if (/#[0-9a-fA-F]{3,8}\b/.test(lines[i])) {
  110. const L = lines[i].trim();
  111. if (!/^\$c-/.test(L)) { console.log('HEX ' + (i + 1) + ': ' + L); n++; }
  112. }
  113. }
  114. console.log('remaining hex (excl palette decl):', n);