| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #!/usr/bin/env node
- /**
- * D8: emotion-checkin.vue 情绪打卡页清理 (debt 108)
- *
- * 1) 修复 C 批遗留 bug:7 处 'BrandColors.xxx' 字符串 -> BrandColors.xxx 变量引用 + 补 import
- * 2) aiEmotionColors 8 情绪色收编(#3B82F6->infoBlue, #8B5CF6->violet, #6B9BD2->emotionSadness,
- * #F59E0B->wealth, #9CA3AF->textGray400, #7C3AED->violetDeep)
- * 3) plutchikEmotions 8 色收编(emotionJoy/Trust/Fear/Surprise/Sadness/Disgust/Anger + BrandColors.body)
- * 4) emotionPool 4 段 ~12 色收编
- * 5) template 4 处内联色(borderColor #eee + 3 slider activeColor)绑定 data
- */
- const fs = require('fs');
- const F = 'pages/mind-detail/emotion-checkin.vue';
- let src = fs.readFileSync(F, 'utf8');
- let replaced = 0;
- function repl(from, to) {
- const cnt = src.split(from).length - 1;
- if (cnt === 0) { console.warn('NOT FOUND:', from.slice(0, 70)); return; }
- src = src.split(from).join(to);
- replaced += cnt;
- }
- // ---- 1. import + 字符串 bug 修复 ----
- if (!src.includes('utils/brand-colors.js')) {
- src = src.replace(
- "import { pickImage } from '@/utils/image-picker.js'",
- "import { pickImage } from '@/utils/image-picker.js'\nimport { BrandColors } from '../../utils/brand-colors.js'"
- );
- }
- // 字符串 -> 变量
- repl("'开心': 'BrandColors.success',", "'开心': BrandColors.success,");
- repl("'生气': 'BrandColors.danger',", "'生气': BrandColors.danger,");
- repl("{ type: 'anticipation',icon: '\\uD83E\\uDD29', label: '期待', color: 'BrandColors.body' }",
- "{ type: 'anticipation',icon: '\\uD83E\\uDD29', label: '期待', color: BrandColors.body }");
- repl("{ label: '开心', base: 38, color: 'BrandColors.success' }", "{ label: '开心', base: 38, color: BrandColors.success }");
- repl("{ label: '满足', base: 25, color: 'BrandColors.success' }", "{ label: '满足', base: 25, color: BrandColors.success }");
- repl("{ label: '开心', base: 15, color: 'BrandColors.success' }", "{ label: '开心', base: 15, color: BrandColors.success }");
- repl("{ label: '生气', base: 25, color: 'BrandColors.danger' }", "{ label: '生气', base: 25, color: BrandColors.danger }");
- // ---- 2. aiEmotionColors 色板 ----
- repl("'平静': '#3B82F6',", "'平静': BrandColors.infoBlue,");
- repl("'惊喜': '#8B5CF6',", "'惊喜': BrandColors.violet,");
- repl("'难过': '#6B9BD2',", "'难过': BrandColors.emotionSadness,");
- repl("'紧张': '#F59E0B',", "'紧张': BrandColors.wealth,");
- repl("'疲惫': '#9CA3AF',", "'疲惫': BrandColors.textGray400,");
- repl("'害怕': '#7C3AED'", "'害怕': BrandColors.violetDeep'");
- // ---- 3. plutchikEmotions 色板 ----
- repl("{ type: 'joy', icon: '\\uD83D\\uDE04', label: '开心', color: '#FFD93D' }",
- "{ type: 'joy', icon: '\\uD83D\\uDE04', label: '开心', color: BrandColors.emotionJoy }");
- repl("{ type: 'trust', icon: '\\uD83E\\uDD1D', label: '信任', color: '#6BCB77' }",
- "{ type: 'trust', icon: '\\uD83E\\uDD1D', label: '信任', color: BrandColors.emotionTrust }");
- repl("{ type: 'fear', icon: '\\uD83D\\uDE31', label: '恐惧', color: '#9B59B6' }",
- "{ type: 'fear', icon: '\\uD83D\\uDE31', label: '恐惧', color: BrandColors.emotionFear }");
- repl("{ type: 'surprise', icon: '\\uD83D\\uDE32', label: '惊讶', color: '#FF9FF3' }",
- "{ type: 'surprise', icon: '\\uD83D\\uDE32', label: '惊讶', color: BrandColors.emotionSurprise }");
- repl("{ type: 'sadness', icon: '\\uD83D\\uDE22', label: '悲伤', color: '#6B9BD2' }",
- "{ type: 'sadness', icon: '\\uD83D\\uDE22', label: '悲伤', color: BrandColors.emotionSadness }");
- repl("{ type: 'disgust', icon: '\\uD83E\\uDD2E', label: '厌恶', color: '#A0A0A0' }",
- "{ type: 'disgust', icon: '\\uD83E\\uDD2E', label: '厌恶', color: BrandColors.emotionDisgust }");
- repl("{ type: 'anger', icon: '\\uD83D\\uDE21', label: '愤怒', color: '#FF6B6B' }",
- "{ type: 'anger', icon: '\\uD83D\\uDE21', label: '愤怒', color: BrandColors.emotionAnger }");
- // ---- 4. emotionPool 4 段 ----
- // Q1
- repl("{ label: '兴奋', base: 22, color: '#8B5CF6' },", "{ label: '兴奋', base: 22, color: BrandColors.violet },");
- repl("{ label: '惊喜', base: 18, color: '#FF9FF3' },", "{ label: '惊喜', base: 18, color: BrandColors.emotionSurprise },");
- repl("{ label: '满足', base: 12, color: '#3B82F6' },", "{ label: '满足', base: 12, color: BrandColors.infoBlue },");
- repl("{ label: '期待', base: 10, color: '#F59E0B' }", "{ label: '期待', base: 10, color: BrandColors.wealth }");
- // Q2
- repl("{ label: '平静', base: 32, color: '#3B82F6' },", "{ label: '平静', base: 32, color: BrandColors.infoBlue },");
- repl("{ label: '放松', base: 20, color: '#6B9BD2' },", "{ label: '放松', base: 20, color: BrandColors.emotionSadness },");
- repl("{ label: '无聊', base: 8, color: '#9CA3AF' }", "{ label: '无聊', base: 8, color: BrandColors.textGray400 }");
- // Q3
- repl("{ label: '紧张', base: 30, color: '#F59E0B' },", "{ label: '紧张', base: 30, color: BrandColors.wealth },");
- repl("{ label: '烦躁', base: 20, color: '#FF6B6B' },", "{ label: '烦躁', base: 20, color: BrandColors.emotionAnger },");
- repl("{ label: '恐惧', base: 15, color: '#7C3AED' },", "{ label: '恐惧', base: 15, color: BrandColors.violetDeep },");
- repl("{ label: '厌恶', base: 10, color: '#A0A0A0' }", "{ label: '厌恶', base: 10, color: BrandColors.emotionDisgust }");
- // Q4
- repl("{ label: '难过', base: 32, color: '#6B9BD2' },", "{ label: '难过', base: 32, color: BrandColors.emotionSadness },");
- repl("{ label: '疲惫', base: 28, color: '#9CA3AF' },", "{ label: '疲惫', base: 28, color: BrandColors.textGray400 },");
- repl("{ label: '低落', base: 20, color: '#6B7280' },", "{ label: '低落', base: 20, color: BrandColors.textSlate },");
- repl("{ label: '平静', base: 12, color: '#3B82F6' },", "{ label: '平静', base: 12, color: BrandColors.infoBlue },");
- repl("{ label: '无聊', base: 8, color: '#9CA3AF' }", "{ label: '无聊', base: 8, color: BrandColors.textGray400 }");
- // ---- 5. template 内联色 -> data ----
- repl(":style=\"{ borderColor: selectedEmotionType === em.type ? em.color : '#eee' }\"",
- ":style=\"{ borderColor: selectedEmotionType === em.type ? em.color : emotionNeutralBorder }\"");
- repl("activeColor=\"#FF6B9D\"", ":active-color=\"emotionSliderIntensity\"");
- repl("activeColor=\"#10B981\"", ":active-color=\"emotionSliderEnergy\"");
- repl("activeColor=\"#F59E0B\"", ":active-color=\"emotionSliderStress\"");
- // data() 注入 4 个绑定色
- repl(
- " affectArousal: 5, // 1-10",
- " affectArousal: 5, // 1-10\n" +
- " emotionNeutralBorder: BrandColors.hairline2, // 未选中情绪描边"
- );
- repl(
- " intensityLevel: 5,",
- " emotionSliderIntensity: BrandColors.mind, // 强度滑条主色\n emotionSliderEnergy: BrandColors.action, // 精力滑条主色\n emotionSliderStress: BrandColors.wealth, // 压力滑条主色\n intensityLevel: 5,"
- );
- fs.writeFileSync(F, src);
- console.log('total replaced:', replaced);
- // 校验
- const lines = src.split('\n');
- let n = 0;
- for (let i = 0; i < lines.length; i++) {
- if (/#[0-9a-fA-F]{3,8}\b/.test(lines[i])) { console.log('HEX ' + (i + 1) + ': ' + lines[i].trim()); n++; }
- }
- console.log('remaining hex lines:', n);
|