# -*- coding: utf-8 -*- """维客线索分类映射工具(W1-AI-CLOSURE 组 5)。 集中管理维客线索的"中文分类 → 视觉/显示属性"映射,供 customer_service 和 task_manager 共用,避免重复定义。 来源权威: - 6 类 categoryColor: docs/miniprogram-dev/design-system/VI-DESIGN-SYSTEM.md §2.1 - source 三态: docs/ai/system-prompts/app8_consolidation.md §五 - 用户拍板(2026-05-06): AI 来源统一显示为 "AI"(前端拼 "By:AI") """ from __future__ import annotations from types import MappingProxyType # 6 类客户线索分类 → tag_color(英文别名,前端 clue-card 接收) # VI-DESIGN-SYSTEM §2.1 权威映射(玩法偏好=orange,与 demo 早期 purple 不一致以本规范为准) CATEGORY_TAG_COLOR: MappingProxyType[str, str] = MappingProxyType({ "客户基础": "primary", "消费习惯": "success", "玩法偏好": "orange", "促销偏好": "gold", "促销接受": "gold", # App8 prompt 里的别名 "社交关系": "purple", "重要反馈": "error", }) # 6 类客户线索分类 → 默认 emoji(用于手工录入/AI 输出 emoji 为空时的兜底) CATEGORY_EMOJI_FALLBACK: MappingProxyType[str, str] = MappingProxyType({ "客户基础": "👤", "消费习惯": "💰", "玩法偏好": "🎮", "促销偏好": "🎁", "促销接受": "🎁", "社交关系": "👥", "重要反馈": "⚠️", }) # 数据库 source 字段 → 显示用名称(用户拍板:AI 类全显示 "AI",手工 fallback "系统") # 实际 source 优先级:recorded_by_name > SOURCE_DISPLAY_NAME[source] SOURCE_DISPLAY_NAME: MappingProxyType[str, str] = MappingProxyType({ "manual": "系统", "ai_consumption": "AI", "ai_note": "AI", }) def format_category_tag(category: str) -> str: """把 category 中文字面量格式化为 clue-card tag(强制 2+2 两行)。 db 存的是 4 字字面量(如 "消费习惯"),demo 标杆 wxml `white-space: pre-line` 依赖 `\n` 强制 2+2 布局("消费\n习惯")。如果不强制,4 字在 72rpx 容器内可能被 css 自动换成 3+1 / 1+3 而非 2+2,视觉错位。 输入空 / 长度 != 4 / 含 \n 的字符串原样返回。 """ if not category or "\n" in category: return category or "" if len(category) == 4: return f"{category[:2]}\n{category[2:]}" return category