/** * 花期图标库(高清矢量 / 内联 SVG) * * 设计规范: * - 24 x 24 viewBox,线性描边(stroke-width 1.8),圆角端点 * - 通过 CSS background-image 的 base64 SVG 渲染,H5 / App / 小程序一致 * - 颜色运行时注入,天然自适应主题色 * * 全站禁止使用 emoji,一律使用 。 * 后端若返回 emoji(历史数据),由 resolveIcon() 兜底映射为矢量图标名。 */ const PATHS = { flower: '', heart: 'M12 20.2c-.4 0-.8-.1-1.1-.3C6.4 16.7 4 13.6 4 10.4 4 8 5.9 6 8.3 6c1.4 0 2.7.7 3.7 1.9C13 6.7 14.3 6 15.7 6 18.1 6 20 8 20 10.4c0 3.2-2.4 6.3-6.9 9.5-.3.2-.7.3-1.1.3z', 'heart-pulse': 'M12 20.2c-.4 0-.8-.1-1.1-.3C6.4 16.7 4 13.6 4 10.4 4 8 5.9 6 8.3 6c1.4 0 2.7.7 3.7 1.9C13 6.7 14.3 6 15.7 6 18.1 6 20 8 20 10.4c0 3.2-2.4 6.3-6.9 9.5-.3.2-.7.3-1.1.3z M6.6 12.4h2.3l1.2-2.1 1.7 3.6 1.2-2.1h2.1', moon: 'M20.4 14.6A9 9 0 0 1 9.5 3.6a9 9 0 1 0 10.9 11z', sun: '', 'cloud-sun': 'M8.2 17.5h7.6a3.2 3.2 0 0 0 .4-6.3A5.3 5.3 0 0 0 6.1 10 3.5 3.5 0 0 0 8.2 17.5z M15.5 4.2v1.6M20 7.5l-1.2 1.1M11 4.2v1.6M7.6 7.5l1.1 1.1', cloud: 'M8 18.4h8.6a3.3 3.3 0 0 0 .4-6.6A5.5 5.5 0 0 0 6.4 10.3 3.7 3.7 0 0 0 8 18.4z', 'cloud-rain': 'M8 16h8.6a3.3 3.3 0 0 0 .4-6.6A5.5 5.5 0 0 0 6.4 8.1 3.7 3.7 0 0 0 8 16z M9 18.6l-.9 2.2M12.5 18.6l-.9 2.2M16 18.6l-.9 2.2', wind: 'M3 8.4h9.2a2.7 2.7 0 1 0-2.7-2.7M3 12.4h12.3a2.7 2.7 0 1 1-2.7 2.7M3 16.4h6.2', bolt: 'M13.4 2.6 4.8 13.7h5.6L9.6 21.4l9.6-11.6h-5.6z', droplet: 'M12 3.2c1.9 2.2 5 5.9 5 9a5 5 0 0 1-10 0c0-3.1 3.1-6.8 5-9z', droplets: 'M9.5 4.6c1.3 1.6 3.4 4 3.4 6.1a3.4 3.4 0 0 1-6.8 0c0-2.1 2.1-4.5 3.4-6.1z M16.4 11.6c1 1.3 2.7 3.2 2.7 4.9a2.7 2.7 0 0 1-5.4 0c0-1.7 1.7-3.6 2.7-4.9z', waves: 'M2.6 9c2-1.7 3.9-1.7 5.9 0s3.9 1.7 5.9 0 3.9-1.7 5.9 0M2.6 15c2-1.7 3.9-1.7 5.9 0s3.9 1.7 5.9 0 3.9-1.7 5.9 0', calendar: '', 'clock': '', check: 'M5 12.6l4.4 4.4L19 7.2', 'chevron-right': 'M9.4 6.2 15.4 12l-6 5.8', 'chevron-left': 'M14.6 6.2 8.6 12l6 5.8', plus: 'M12 5.2v13.6M5.2 12h13.6', minus: 'M5.2 12h13.6', close: 'M6.4 6.4l11.2 11.2M17.6 6.4 6.4 17.6', edit: 'M4 20h3.8l10-10-3.8-3.8L4 16.2zM14.2 5.8l3.8 3.8', trash: 'M4.6 7h14.8M9.2 7V4.8h5.6V7M6.6 7l1 12.2h8.8L17.4 7', book: 'M5 4.6A2.1 2.1 0 0 1 7.1 2.5H19v15.9H7.1A2.1 2.1 0 0 0 5 20.5zM19 18.4v3.1H7.1A2.1 2.1 0 0 1 5 19.4', clipboard: '', bowl: 'M3.6 11h16.8a8.4 8.4 0 0 1-16.8 0zM8 7.4c0-1.2.9-1.6.9-2.8M12 7c0-1.2.9-1.6.9-2.8M16 7.4c0-1.2.9-1.6.9-2.8', activity: 'M3 12h2.4M18.6 12H21M7 8.4v7.2M17 8.4v7.2M9.6 6.4v11.2M14.4 6.4v11.2M7 12h10', bed: 'M3.4 19V11h13.2a3.6 3.6 0 0 1 3.6 3.6V19M3.4 11V6.4M7 8.6h3.6M3.4 19h17.2', thermometer: 'M14 14.6V5.2a2 2 0 1 0-4 0v9.4a3.7 3.7 0 1 0 4 0zM12 8.4v7.2', pill: 'M10.6 3.4 20.6 13.4a3.6 3.6 0 0 1-5.1 5.1L5.5 8.5a3.6 3.6 0 0 1 5.1-5.1zM8.1 11l5-5', syringe: '', flask: 'M9.6 3h4.8v4.3l4 9.3a2.2 2.2 0 0 1-2 3.1H7.6a2.2 2.2 0 0 1-2-3.1l4-9.3zM7.6 14h8.8', sparkles: 'M12 3.4l1.7 4.2 4.2 1.7-4.2 1.7L12 15.2l-1.7-4.2L6.1 9.3l4.2-1.7zM18.6 14.6l.8 2 2 .8-2 .8-.8 2-.8-2-2-.8 2-.8z', chat: 'M4.6 6.6A2.6 2.6 0 0 1 7.2 4h9.6a2.6 2.6 0 0 1 2.6 2.6v6.8a2.6 2.6 0 0 1-2.6 2.6H9.4L4.6 20z', 'chat-heart': 'M4.6 6.6A2.6 2.6 0 0 1 7.2 4h9.6a2.6 2.6 0 0 1 2.6 2.6v6.8a2.6 2.6 0 0 1-2.6 2.6H9.4L4.6 20zM12 13.2c-2.2-1.6-3.2-2.5-3.2-3.6a1.6 1.6 0 0 1 3.2-.5 1.6 1.6 0 0 1 3.2.5c0 1.1-1 2-3.2 3.6z', shield: 'M12 3.2 19 6v5.2c0 4.4-2.9 7.5-7 8.8-4.1-1.3-7-4.4-7-8.8V6z', 'shield-check': 'M12 3.2 19 6v5.2c0 4.4-2.9 7.5-7 8.8-4.1-1.3-7-4.4-7-8.8V6zM8.8 11.9l2.2 2.2 4.1-4.3', lock: '', bell: 'M6.6 9.8a5.4 5.4 0 0 1 10.8 0c0 3.6 1.4 5 1.4 5H5.2s1.4-1.4 1.4-5zM10.2 18.2a2 2 0 0 0 3.6 0', user: '', users: '', gift: '', star: 'M12 3.6l2.6 5.3 5.8.8-4.2 4.1 1 5.8-5.2-2.8-5.2 2.8 1-5.8L3.6 9.7l5.8-.8z', pause: 'M9.4 5.4v13.2M14.6 5.4v13.2', warning: 'M12 3.8 21.2 20H2.8zM12 9.6v4.2M12 16.6v.2', phone: 'M6.4 3.8h3l1.4 3.7-2 1.6a12 12 0 0 0 5.9 5.9l1.6-2 3.7 1.4v3a2 2 0 0 1-2.2 2A16.5 16.5 0 0 1 4.4 6a2 2 0 0 1 2-2.2z', smartphone: '', wallet: '', chart: 'M4.4 4.2v15.6h15.4M8.4 16.4v-4M12.2 16.4V9.2M16 16.4v-2.6', target: '', 'headphones': 'M4.2 14.4v-2.2a7.8 7.8 0 0 1 15.6 0v2.2M6.6 19.6H5.4a1.2 1.2 0 0 1-1.2-1.2v-3a1.2 1.2 0 0 1 1.2-1.2h1.2zM17.4 19.6h1.2a1.2 1.2 0 0 0 1.2-1.2v-3a1.2 1.2 0 0 0-1.2-1.2h-1.2z', music: '', baby: '', blocks: '', leaf: 'M20.4 3.6c-8.4-.4-13.8 3.6-13.8 9.3a6.3 6.3 0 0 0 6.3 6.3c5.7 0 8.1-6.2 7.5-15.6zM6.4 19.6C8.9 15 12.4 11.6 16.8 9.6', sprout: 'M12 20.6v-6.4M12 14.2C12 10.6 9.4 8 5.8 8c0 3.6 2.6 6.2 6.2 6.2zM12 14.2c0-3.1 2.3-5.4 5.7-5.4 0 3.1-2.3 5.4-5.7 5.4z', eye: 'M2.6 12S6.2 6 12 6s9.4 6 9.4 6-3.6 6-9.4 6-9.4-6-9.4-6zM12 9.4a2.6 2.6 0 1 0 0 5.2 2.6 2.6 0 0 0 0-5.2z', image: '', list: 'M8.4 6.4h11.8M8.4 12h11.8M8.4 17.6h11.8M4.4 6.4v.2M4.4 12v.2M4.4 17.6v.2', home: 'M4.2 11.2 12 4.2l7.8 7v8.6h-5v-5.6H9.2v5.6h-5z', 'arrow-right': 'M4.6 12h14.2M13.4 6.6 19 12l-5.6 5.4' } /** 图标兜底:未知名称统一用圆点,避免出现空白 */ const FALLBACK = '' const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' /** 纯 JS Base64(不依赖平台 API,H5/App/小程序一致) */ function base64(input) { let output = '' let i = 0 while (i < input.length) { const chr1 = input.charCodeAt(i++) const chr2 = i < input.length ? input.charCodeAt(i++) : NaN const chr3 = i < input.length ? input.charCodeAt(i++) : NaN const enc1 = chr1 >> 2 const enc2 = ((chr1 & 3) << 4) | (isNaN(chr2) ? 0 : chr2 >> 4) const enc3 = isNaN(chr2) ? 64 : (((chr2 & 15) << 2) | (isNaN(chr3) ? 0 : chr3 >> 6)) const enc4 = isNaN(chr3) ? 64 : chr3 & 63 output += CHARS.charAt(enc1) + CHARS.charAt(enc2) output += enc3 === 64 ? '=' : CHARS.charAt(enc3) output += enc4 === 64 ? '=' : CHARS.charAt(enc4) } return output } /** 生成 data URI(CSS background-image 可直接使用) */ export function iconUri(name, color = '#E8604C', strokeWidth = 1.8) { const inner = PATHS[name] || FALLBACK // 纯 path 数据(不含标签)自动包裹 ,含 / 的元素原样使用 const body = /^\s*' const svg = '' + body + '' return 'data:image/svg+xml;base64,' + base64(svg) } /** 图标是否存在 */ export function hasIcon(name) { return !!PATHS[name] } /** 可用图标名列表(供自检脚本使用) */ export const ICON_NAMES = Object.keys(PATHS) /* ============================================================ * 语义映射:把后端历史 emoji 字段与业务枚举翻译成矢量图标名 * ============================================================ */ const EMOJI_MAP = { '\u273F': 'flower', '\u2740': 'flower', '\uD83C\uDF38': 'flower', '\uD83C\uDF37': 'flower', '\uD83C\uDF3B': 'sun', '\uD83C\uDF31': 'sprout', '\uD83C\uDF3E': 'sprout', '\uD83C\uDF42': 'leaf', '\uD83E\uDD6C': 'leaf', '\uD83C\uDF19': 'moon', '\u263E': 'moon', '\uD83D\uDE34': 'moon', '\uD83C\uDF24': 'cloud-sun', '\uD83C\uDF27': 'cloud-rain', '\uD83C\uDF2A': 'wind', '\u26A1': 'bolt', '\u2600': 'sun', '\uD83D\uDC9B': 'heart', '\uD83D\uDC9E': 'heart', '\uD83E\uDD1D': 'users', '\uD83E\uDDF8': 'blocks', '\uD83D\uDD4A': 'chat-heart', '\u260E': 'phone', '\uD83D\uDCF1': 'smartphone', '\uD83D\uDD12': 'lock', '\u23F0': 'clock', '\uD83C\uDF72': 'bowl', '\uD83E\uDDD8': 'activity', '\uD83C\uDF21': 'thermometer', '\uD83D\uDC8A': 'pill', '\uD83D\uDC8B': 'heart', '\uD83D\uDCCB': 'clipboard', '\uD83D\uDCC6': 'calendar', '\uD83D\uDCC5': 'calendar', '\uD83D\uDDD3': 'calendar', '\uD83D\uDCDA': 'book', '\uD83D\uDCD6': 'book', '\uD83E\uDDEA': 'flask', '\uD83D\uDC40': 'eye', '\uD83C\uDF7C': 'bowl', '\uD83C\uDFAF': 'target', '\uD83C\uDFA7': 'headphones', '\uD83D\uDECF': 'bed', '\uD83E\uDEC1': 'wind', '\uD83E\uDEE7': 'droplets', '\uD83D\uDCA7': 'droplet', '\uD83C\uDF0A': 'waves', '\uD83C\uDD98': 'warning', '\u26A0': 'warning', '\u270D': 'edit', '\uD83D\uDCAC': 'chat', '\uD83D\uDDE3': 'chat', '\u23F8': 'pause', '\uD83C\uDF81': 'gift', '\uD83C\uDFE0': 'home', '\uD83C\uDFE6': 'wallet', '\u2B50': 'star', '\u2726': 'star', '\u2713': 'check', '\uD83D\uDC89': 'syringe', '\uD83C\uDF5A': 'bowl', '\uD83E\uDD62': 'bowl', '\uD83C\uDF88': 'cloud', '\uD83C\uDF36': 'thermometer', '\uD83E\uDEE5': 'cloud', '\uD83E\uDDE3': 'shield', '\uD83D\uDD25': 'sun', '\uD83D\uDC64': 'user', '\uD83D\uDE1E': 'cloud-rain', '\uD83E\uDEAB': 'bolt', '\uD83D\uDCAB': 'sparkles', '\uD83E\uDEB7': 'flower', '\uD83D\uDED0': 'sparkles', '\uD83D\uDEE1': 'shield' } const CONTENT_TYPE_ICON = { jijing: 'sun', mood: 'cloud', knowledge: 'book', advice: 'bowl', meditation: 'moon', care: 'heart', card: 'chat', conflict: 'pause', firstaid: 'wind', guide: 'calendar', course: 'book', activity: 'blocks', emotion: 'cloud-rain' } const MOOD_ICON = { happy: 'sun', calm: 'cloud-sun', anxious: 'wind', low: 'cloud-rain', angry: 'bolt' } const REMINDER_ICON = { period: 'droplet', ovulation: 'sprout', record: 'edit', medication: 'pill', care: 'heart', fertile: 'sprout', mood: 'cloud', custom: 'bell' } const RELATION_ICON = { partner: 'heart', parent: 'users', friend: 'users' } /** 兜底解析:既支持图标名,也支持历史 emoji */ export function resolveIcon(value, fallback = 'flower') { if (!value) return fallback if (hasIcon(value)) return value if (EMOJI_MAP[value]) return EMOJI_MAP[value] // 兼容带变体选择符的组合 emoji const stripped = String(value).replace(/[\uFE0F\u200D]/g, '') if (EMOJI_MAP[stripped]) return EMOJI_MAP[stripped] return fallback } export function iconForContentType(type) { return CONTENT_TYPE_ICON[type] || 'flower' } export function iconForMood(mood) { return MOOD_ICON[mood] || 'cloud-sun' } export function iconForReminder(type) { return REMINDER_ICON[type] || 'bell' } export function iconForRelation(relation) { return RELATION_ICON[relation] || 'users' } export function iconForSymptom(category) { if (category === 'mood') return 'cloud' if (category === 'flow') return 'droplet' return 'heart-pulse' } export function iconForVaccine(type) { return type === 'checkup' ? 'clipboard' : 'syringe' } export default { iconUri, hasIcon, resolveIcon, iconForContentType, iconForMood, iconForReminder, iconForRelation, iconForSymptom, iconForVaccine, ICON_NAMES }