d8-emotion-checkin.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/env node
  2. /**
  3. * D8: emotion-checkin.vue 情绪打卡页清理 (debt 108)
  4. *
  5. * 1) 修复 C 批遗留 bug:7 处 'BrandColors.xxx' 字符串 -> BrandColors.xxx 变量引用 + 补 import
  6. * 2) aiEmotionColors 8 情绪色收编(#3B82F6->infoBlue, #8B5CF6->violet, #6B9BD2->emotionSadness,
  7. * #F59E0B->wealth, #9CA3AF->textGray400, #7C3AED->violetDeep)
  8. * 3) plutchikEmotions 8 色收编(emotionJoy/Trust/Fear/Surprise/Sadness/Disgust/Anger + BrandColors.body)
  9. * 4) emotionPool 4 段 ~12 色收编
  10. * 5) template 4 处内联色(borderColor #eee + 3 slider activeColor)绑定 data
  11. */
  12. const fs = require('fs');
  13. const F = 'pages/mind-detail/emotion-checkin.vue';
  14. let src = fs.readFileSync(F, 'utf8');
  15. let replaced = 0;
  16. function repl(from, to) {
  17. const cnt = src.split(from).length - 1;
  18. if (cnt === 0) { console.warn('NOT FOUND:', from.slice(0, 70)); return; }
  19. src = src.split(from).join(to);
  20. replaced += cnt;
  21. }
  22. // ---- 1. import + 字符串 bug 修复 ----
  23. if (!src.includes('utils/brand-colors.js')) {
  24. src = src.replace(
  25. "import { pickImage } from '@/utils/image-picker.js'",
  26. "import { pickImage } from '@/utils/image-picker.js'\nimport { BrandColors } from '../../utils/brand-colors.js'"
  27. );
  28. }
  29. // 字符串 -> 变量
  30. repl("'开心': 'BrandColors.success',", "'开心': BrandColors.success,");
  31. repl("'生气': 'BrandColors.danger',", "'生气': BrandColors.danger,");
  32. repl("{ type: 'anticipation',icon: '\\uD83E\\uDD29', label: '期待', color: 'BrandColors.body' }",
  33. "{ type: 'anticipation',icon: '\\uD83E\\uDD29', label: '期待', color: BrandColors.body }");
  34. repl("{ label: '开心', base: 38, color: 'BrandColors.success' }", "{ label: '开心', base: 38, color: BrandColors.success }");
  35. repl("{ label: '满足', base: 25, color: 'BrandColors.success' }", "{ label: '满足', base: 25, color: BrandColors.success }");
  36. repl("{ label: '开心', base: 15, color: 'BrandColors.success' }", "{ label: '开心', base: 15, color: BrandColors.success }");
  37. repl("{ label: '生气', base: 25, color: 'BrandColors.danger' }", "{ label: '生气', base: 25, color: BrandColors.danger }");
  38. // ---- 2. aiEmotionColors 色板 ----
  39. repl("'平静': '#3B82F6',", "'平静': BrandColors.infoBlue,");
  40. repl("'惊喜': '#8B5CF6',", "'惊喜': BrandColors.violet,");
  41. repl("'难过': '#6B9BD2',", "'难过': BrandColors.emotionSadness,");
  42. repl("'紧张': '#F59E0B',", "'紧张': BrandColors.wealth,");
  43. repl("'疲惫': '#9CA3AF',", "'疲惫': BrandColors.textGray400,");
  44. repl("'害怕': '#7C3AED'", "'害怕': BrandColors.violetDeep'");
  45. // ---- 3. plutchikEmotions 色板 ----
  46. repl("{ type: 'joy', icon: '\\uD83D\\uDE04', label: '开心', color: '#FFD93D' }",
  47. "{ type: 'joy', icon: '\\uD83D\\uDE04', label: '开心', color: BrandColors.emotionJoy }");
  48. repl("{ type: 'trust', icon: '\\uD83E\\uDD1D', label: '信任', color: '#6BCB77' }",
  49. "{ type: 'trust', icon: '\\uD83E\\uDD1D', label: '信任', color: BrandColors.emotionTrust }");
  50. repl("{ type: 'fear', icon: '\\uD83D\\uDE31', label: '恐惧', color: '#9B59B6' }",
  51. "{ type: 'fear', icon: '\\uD83D\\uDE31', label: '恐惧', color: BrandColors.emotionFear }");
  52. repl("{ type: 'surprise', icon: '\\uD83D\\uDE32', label: '惊讶', color: '#FF9FF3' }",
  53. "{ type: 'surprise', icon: '\\uD83D\\uDE32', label: '惊讶', color: BrandColors.emotionSurprise }");
  54. repl("{ type: 'sadness', icon: '\\uD83D\\uDE22', label: '悲伤', color: '#6B9BD2' }",
  55. "{ type: 'sadness', icon: '\\uD83D\\uDE22', label: '悲伤', color: BrandColors.emotionSadness }");
  56. repl("{ type: 'disgust', icon: '\\uD83E\\uDD2E', label: '厌恶', color: '#A0A0A0' }",
  57. "{ type: 'disgust', icon: '\\uD83E\\uDD2E', label: '厌恶', color: BrandColors.emotionDisgust }");
  58. repl("{ type: 'anger', icon: '\\uD83D\\uDE21', label: '愤怒', color: '#FF6B6B' }",
  59. "{ type: 'anger', icon: '\\uD83D\\uDE21', label: '愤怒', color: BrandColors.emotionAnger }");
  60. // ---- 4. emotionPool 4 段 ----
  61. // Q1
  62. repl("{ label: '兴奋', base: 22, color: '#8B5CF6' },", "{ label: '兴奋', base: 22, color: BrandColors.violet },");
  63. repl("{ label: '惊喜', base: 18, color: '#FF9FF3' },", "{ label: '惊喜', base: 18, color: BrandColors.emotionSurprise },");
  64. repl("{ label: '满足', base: 12, color: '#3B82F6' },", "{ label: '满足', base: 12, color: BrandColors.infoBlue },");
  65. repl("{ label: '期待', base: 10, color: '#F59E0B' }", "{ label: '期待', base: 10, color: BrandColors.wealth }");
  66. // Q2
  67. repl("{ label: '平静', base: 32, color: '#3B82F6' },", "{ label: '平静', base: 32, color: BrandColors.infoBlue },");
  68. repl("{ label: '放松', base: 20, color: '#6B9BD2' },", "{ label: '放松', base: 20, color: BrandColors.emotionSadness },");
  69. repl("{ label: '无聊', base: 8, color: '#9CA3AF' }", "{ label: '无聊', base: 8, color: BrandColors.textGray400 }");
  70. // Q3
  71. repl("{ label: '紧张', base: 30, color: '#F59E0B' },", "{ label: '紧张', base: 30, color: BrandColors.wealth },");
  72. repl("{ label: '烦躁', base: 20, color: '#FF6B6B' },", "{ label: '烦躁', base: 20, color: BrandColors.emotionAnger },");
  73. repl("{ label: '恐惧', base: 15, color: '#7C3AED' },", "{ label: '恐惧', base: 15, color: BrandColors.violetDeep },");
  74. repl("{ label: '厌恶', base: 10, color: '#A0A0A0' }", "{ label: '厌恶', base: 10, color: BrandColors.emotionDisgust }");
  75. // Q4
  76. repl("{ label: '难过', base: 32, color: '#6B9BD2' },", "{ label: '难过', base: 32, color: BrandColors.emotionSadness },");
  77. repl("{ label: '疲惫', base: 28, color: '#9CA3AF' },", "{ label: '疲惫', base: 28, color: BrandColors.textGray400 },");
  78. repl("{ label: '低落', base: 20, color: '#6B7280' },", "{ label: '低落', base: 20, color: BrandColors.textSlate },");
  79. repl("{ label: '平静', base: 12, color: '#3B82F6' },", "{ label: '平静', base: 12, color: BrandColors.infoBlue },");
  80. repl("{ label: '无聊', base: 8, color: '#9CA3AF' }", "{ label: '无聊', base: 8, color: BrandColors.textGray400 }");
  81. // ---- 5. template 内联色 -> data ----
  82. repl(":style=\"{ borderColor: selectedEmotionType === em.type ? em.color : '#eee' }\"",
  83. ":style=\"{ borderColor: selectedEmotionType === em.type ? em.color : emotionNeutralBorder }\"");
  84. repl("activeColor=\"#FF6B9D\"", ":active-color=\"emotionSliderIntensity\"");
  85. repl("activeColor=\"#10B981\"", ":active-color=\"emotionSliderEnergy\"");
  86. repl("activeColor=\"#F59E0B\"", ":active-color=\"emotionSliderStress\"");
  87. // data() 注入 4 个绑定色
  88. repl(
  89. " affectArousal: 5, // 1-10",
  90. " affectArousal: 5, // 1-10\n" +
  91. " emotionNeutralBorder: BrandColors.hairline2, // 未选中情绪描边"
  92. );
  93. repl(
  94. " intensityLevel: 5,",
  95. " emotionSliderIntensity: BrandColors.mind, // 强度滑条主色\n emotionSliderEnergy: BrandColors.action, // 精力滑条主色\n emotionSliderStress: BrandColors.wealth, // 压力滑条主色\n intensityLevel: 5,"
  96. );
  97. fs.writeFileSync(F, src);
  98. console.log('total replaced:', replaced);
  99. // 校验
  100. const lines = src.split('\n');
  101. let n = 0;
  102. for (let i = 0; i < lines.length; i++) {
  103. if (/#[0-9a-fA-F]{3,8}\b/.test(lines[i])) { console.log('HEX ' + (i + 1) + ': ' + lines[i].trim()); n++; }
  104. }
  105. console.log('remaining hex lines:', n);