| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #!/usr/bin/env node
- /**
- * D11: relation-detail.vue 天盘关系详情页清理 (debt 81)
- *
- * script 颜色映射全部收编 BrandColors(含 import);
- * canvas 连线灰 gray200;
- * style 全局映射 + 1 个局部变量。
- */
- const fs = require('fs');
- const F = 'pages/tianpan/relation-detail.vue';
- let src = fs.readFileSync(F, 'utf8');
- let replaced = 0;
- function repl(from, to, count) {
- const n = src.split(from).length - 1;
- if (n === 0) { console.warn('NOT FOUND:', from.slice(0, 80)); return; }
- if (count && n !== count) console.warn('count mismatch:', n, 'expected', count, '-', from.slice(0, 50));
- src = src.split(from).join(to);
- replaced += n;
- }
- // ---- 1. import ----
- repl(
- "import { mapActions } from 'vuex'",
- "import { mapActions } from 'vuex'\nimport { BrandColors } from '../../utils/brand-colors.js'"
- );
- // ---- 2. script 角色/维度/分数颜色 ----
- repl(" return '#6B7280'\n }\n var colorMap = {\n 'parent': '#F97316',\n 'child': '#3B82F6',\n 'teacher': '#8B5CF6'\n }",
- " return BrandColors.textSlate\n }\n var colorMap = {\n 'parent': BrandColors.primary,\n 'child': BrandColors.infoBlue,\n 'teacher': BrandColors.violet\n }", 1);
- // member2Color 那份(缩进相同)
- repl(" return '#6B7280'\n }\n var colorMap = {\n 'parent': '#F97316',\n 'child': '#3B82F6',\n 'teacher': '#8B5CF6'\n }",
- " return BrandColors.textSlate\n }\n var colorMap = {\n 'parent': BrandColors.primary,\n 'child': BrandColors.infoBlue,\n 'teacher': BrandColors.violet\n }", 1);
- repl("return colorMap[this.relation.fromMemberRole] || '#6B7280'", "return colorMap[this.relation.fromMemberRole] || BrandColors.textSlate");
- repl("return colorMap[this.relation.toMemberRole] || '#6B7280'", "return colorMap[this.relation.toMemberRole] || BrandColors.textSlate");
- repl(" 'communication': { label: '沟通', description: '沟通频率与质量', color: '#10B981' },", " 'communication': { label: '沟通', description: '沟通频率与质量', color: BrandColors.success },");
- repl(" 'trust': { label: '信任', description: '相互信任程度', color: '#3B82F6' },", " 'trust': { label: '信任', description: '相互信任程度', color: BrandColors.infoBlue },");
- repl(" 'understanding': { label: '理解', description: '相互理解程度', color: '#8B5CF6' },", " 'understanding': { label: '理解', description: '相互理解程度', color: BrandColors.violet },");
- repl(" 'support': { label: '支持', description: '相互支持力度', color: '#F59E0B' },", " 'support': { label: '支持', description: '相互支持力度', color: BrandColors.wealth },");
- repl(" 'harmony': { label: '和谐', description: '关系和谐度', color: '#F97316' }", " 'harmony': { label: '和谐', description: '关系和谐度', color: BrandColors.primary }");
- repl("{ label: key, description: '', color: '#6B7280' }", "{ label: key, description: '', color: BrandColors.textSlate }");
- // ---- 3. canvas ----
- repl("ctx.strokeStyle = '#E5E7EB'", "ctx.strokeStyle = BrandColors.gray200", 2);
- repl("ctx.strokeStyle = '#F97316'", "ctx.strokeStyle = BrandColors.primary");
- repl("ctx.fillStyle = '#F97316'", "ctx.fillStyle = BrandColors.primary");
- // ---- 4. getScoreColor ----
- repl(" if (!score) {\n return '#6B7280'\n }", " if (!score) {\n return BrandColors.textSlate\n }");
- repl(" if (score >= 80) {\n return '#10B981'\n } else if (score >= 60) {\n return '#F59E0B'\n } else {\n return '#EF4444'\n }",
- " if (score >= 80) {\n return BrandColors.success\n } else if (score >= 60) {\n return BrandColors.wealth\n } else {\n return BrandColors.danger\n }");
- // ---- 5. style 块 ----
- const styleIdx = src.indexOf('<style');
- const before = src.slice(0, styleIdx);
- let styleBody = src.slice(styleIdx);
- styleBody = styleBody.replace(/#D1D5DB(?![0-9a-fA-F])/g, '$app-border-strong');
- styleBody = styleBody.replace(/#FFF8F0(?![0-9a-fA-F])/g, '$dim-body-tint');
- styleBody = styleBody.replace(/#7C2D12(?![0-9a-fA-F])/g, '$c-rel-brown');
- const palette = [
- '// ===== 关系详情页专属色阶(单页专用;约定见 uni.scss §14)=====',
- '$c-rel-brown: #7C2D12; // 深棕文字(暖橙卡内)',
- ''
- ].join('\n');
- styleBody = styleBody.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
- src = before + styleBody;
- 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])) {
- const L = lines[i].trim();
- if (L.indexOf('$c-') !== 0) { console.log('HEX ' + (i + 1) + ': ' + L); n++; }
- }
- }
- console.log('remaining hex (excl palette decl):', n);
|