| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #!/usr/bin/env node
- /**
- * D21: gut-flora-detail.vue 肠道菌群详情页清理 (debt 60)
- * script 9 个指标色收编 BrandColors;style 全局令牌 3 + 局部 Material Teal 色阶 6
- */
- const fs = require('fs');
- const F = 'pages/health/gut-flora-detail.vue';
- let src = fs.readFileSync(F, 'utf8');
- let replaced = 0;
- // ---- 1. import ----
- if (!src.includes('utils/brand-colors.js')) {
- src = src.replace(
- "import HealthKnowledgePopup from '@/pages/health/components/health-knowledge-popup.vue'",
- "import HealthKnowledgePopup from '@/pages/health/components/health-knowledge-popup.vue'\nimport { BrandColors } from '../../utils/brand-colors.js'"
- );
- }
- // ---- 2. script 色值 ----
- const styleIdx = src.indexOf('<style');
- let scriptPart = src.slice(0, styleIdx);
- let stylePart = src.slice(styleIdx);
- const SCRIPT_MAP = [
- ['#0EA5E9', 'BrandColors.infoSky'],
- ['#10B981', 'BrandColors.success'],
- ['#F59E0B', 'BrandColors.wealth'],
- ['#FF8C42', 'BrandColors.body'],
- ['#6366F1', 'BrandColors.wisdom'],
- ['#FF6B9D', 'BrandColors.mind'],
- ['#C62828', 'BrandColors.dangerStrong2'],
- ];
- for (const [from, to] of SCRIPT_MAP) {
- const pat = "'" + from + "'";
- const cnt = scriptPart.split(pat).length - 1;
- if (cnt === 0) console.warn('SCRIPT NOT FOUND:', from);
- scriptPart = scriptPart.split(pat).join(to);
- replaced += cnt;
- }
- // ---- 3. style 全局令牌 ----
- const GLOBAL = [
- ['#FEF2F2', '$status-danger-tint-2'],
- ['#FECACA', '$danger-line'],
- ['#1976D2', '$mat-blue'],
- ['#FFF8E1', '$mat-amber-tint'],
- ['#A5D6A7', '$mat-green-soft'],
- ];
- for (const [from, to] of GLOBAL) {
- const re = new RegExp(from + '(?![0-9a-fA-F])', 'gi');
- replaced += (stylePart.match(re) || []).length;
- stylePart = stylePart.replace(re, to);
- }
- // ---- 4. style 局部 Material Teal 色阶 ----
- const LOCAL = [
- ['#FFB300', '$c-gf-amber'], // amber-700 提示条左边线
- ['#795548', '$c-gf-brown'], // brown-500 提示文字
- ['#E0F2F1', '$c-gf-teal-bg'], // teal-50 浅底
- ['#00897B', '$c-gf-teal'], // teal-600 主色
- ['#00695C', '$c-gf-teal-deep'], // teal-800 深档
- ['#004D40', '$c-gf-teal-ink'], // teal-900 深文字
- ];
- for (const [from, to] of LOCAL) {
- const re = new RegExp(from + '(?![0-9a-fA-F])', 'gi');
- replaced += (stylePart.match(re) || []).length;
- stylePart = stylePart.replace(re, to);
- }
- const palette = [
- '// ===== 肠道菌群页专属色阶(Material Teal 提示色族;单页专用,约定见 uni.scss §14)=====',
- '$c-gf-amber: #FFB300; // amber-700 提示左边线',
- '$c-gf-brown: #795548; // brown-500 提示文字',
- '$c-gf-teal-bg: #E0F2F1; // teal-50 浅底',
- '$c-gf-teal: #00897B; // teal-600 主色',
- '$c-gf-teal-deep: #00695C; // teal-800 深档',
- '$c-gf-teal-ink: #004D40; // teal-900 深文字',
- ''
- ].join('\n');
- stylePart = stylePart.replace(/(<style[^>]*>\s*\n)/, '$1' + palette + '\n');
- fs.writeFileSync(F, scriptPart + stylePart);
- console.log('total replaced:', replaced);
- const out = fs.readFileSync(F, 'utf8');
- const lines = out.split('\n');
- let n = 0;
- for (let i = 0; i < lines.length; i++) {
- const L = lines[i].trim();
- if (/#[0-9a-fA-F]{3,8}\b/.test(L) && L.charAt(0) !== '$') { console.log('HEX ' + (i + 1) + ': ' + L.slice(0, 100)); n++; }
- }
- console.log('remaining non-palette hex:', n);
|