feat(ui): 全站 emoji 替换为内联 SVG 矢量图标

- 新增 utils/icons.js:61 个 24x24 线性图标(stroke 1.8,圆角端点),
  纯 JS base64 编码生成 data URI,H5/App/小程序一致,任意尺寸不失真
- 新增 components/hq-icon/hq-icon.vue:尺寸/颜色/描边可配置,
  并内置 resolveIcon() 兼容后端历史 emoji 字段(自动映射为矢量图标)
- 18 个页面与组件全部替换:底部导航、首页快捷入口/心语/提醒、周期心情、
  情绪 5 情绪与记录、我的设置项与提醒、会员勾选、备孕任务与同疾锁态、
  急救包/咨询热线、关系卡片、亲子活动、健康建议 Tab、登录页花瓣与输入框、
  内容详情头图、各页空状态
- 新增 scripts/verify/no_emoji_check.py:拦截 emoji/字符图标、
  未定义图标名与未注册组件,纳入回归
- 图标质量已用 SVG 精灵表渲染逐个人工核对;61 图标 XML 解析 100% 通过

验证:no_emoji 0 问题 / 契约 84 接口 0 偏差 / Vue 20-20 / SCSS 19-19
这个提交包含在:
linda
2026-11-06 10:18:13 +08:00
父节点 d243ece39c
当前提交 b167efa86b
共有 21 个文件被更改,包括 698 次插入 和 180 次删除

查看文件

@@ -0,0 +1,55 @@
<template>
<view class="hq-icon" :style="iconStyle"></view>
</template>
<script>
import { iconUri, resolveIcon } from '@/utils/icons.js'
/**
* 矢量图标组件
*
* 用法:
* <hq-icon name="flower" :size="40" color="#E8604C" />
* <hq-icon :name="item.emoji" /> // 兼容后端历史 emoji,自动映射
* <hq-icon name="moon" :size="32" color="#fff" :stroke="2" />
*
* 实现:内联 SVG -> base64 data URI -> CSS background-image,
* 任意尺寸不失真(高清矢量),H5 / App / 小程序渲染一致。
*/
export default {
name: 'hq-icon',
props: {
/** 图标名,或历史 emoji(自动映射) */
name: { type: String, default: 'flower' },
/** 尺寸,单位 rpx */
size: { type: [Number, String], default: 40 },
/** 颜色 */
color: { type: String, default: '#E8604C' },
/** 描边宽度 */
stroke: { type: [Number, String], default: 1.8 }
},
computed: {
iconStyle() {
const name = resolveIcon(this.name)
const uri = iconUri(name, this.color, Number(this.stroke) || 1.8)
const px = Number(this.size) || 40
return {
width: px + 'rpx',
height: px + 'rpx',
backgroundImage: 'url(' + uri + ')'
}
}
}
}
</script>
<style lang="scss" scoped>
.hq-icon {
display: inline-block;
flex-shrink: 0;
background-repeat: no-repeat;
background-position: center center;
background-size: 100% 100%;
vertical-align: middle;
}
</style>

查看文件

@@ -8,7 +8,12 @@
:class="{ 'hq-tab-active': current === item.key }"
@tap="go(item)"
>
<text class="hq-tab-icon">{{ item.icon }}</text>
<hq-icon
:name="item.icon"
:size="40"
:stroke="1.9"
:color="current === item.key ? '#E8604C' : '#C9B4AA'"
/>
<text class="hq-tab-label" :class="{ 'hq-tab-label-active': current === item.key }">{{ item.label }}</text>
</view>
</view>
@@ -16,7 +21,9 @@
</template>
<script>
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
name: 'hq-tabbar',
props: {
current: {
@@ -27,10 +34,10 @@ export default {
data() {
return {
tabs: [
{ key: 'home', label: '首页', icon: '✿', path: '/pages/index/index' },
{ key: 'cycle', label: '周期', icon: '❀', path: '/pages/cycle/index' },
{ key: 'mood', label: '情绪', icon: '☾', path: '/pages/mood/index' },
{ key: 'mine', label: '我的', icon: '✦', path: '/pages/mine/index' }
{ key: 'home', label: '首页', icon: 'home', path: '/pages/index/index' },
{ key: 'cycle', label: '周期', icon: 'flower', path: '/pages/cycle/index' },
{ key: 'mood', label: '情绪', icon: 'moon', path: '/pages/mood/index' },
{ key: 'mine', label: '我的', icon: 'user', path: '/pages/mine/index' }
]
}
},
@@ -73,12 +80,6 @@ export default {
transition: background-color 0.2s ease;
}
.hq-tab-icon {
font-size: 34rpx;
color: #C9B4AA;
line-height: 1.1;
}
.hq-tab-label {
margin-top: 6rpx;
font-size: 22rpx;
@@ -90,10 +91,6 @@ export default {
background-color: #FFF1E9;
}
.hq-tab-active .hq-tab-icon {
color: #E8604C;
}
.hq-tab-label-active {
color: #E8604C;
font-weight: 600;

查看文件

@@ -70,13 +70,34 @@
| 组件 | 文件 | 说明 |
|---|---|---|
| 底部导航 | `components/hq-tabbar/hq-tabbar.vue` | 自定义 TabBar,4 个入口,选中态为暖色胶囊;使用 `reLaunch` 避免页面栈堆积 |
| 矢量图标 | `components/hq-icon/hq-icon.vue` | 基于 `utils/icons.js` 的 SVG 图标组件,支持尺寸/颜色/描边自定义 |
| 底部导航 | `components/hq-tabbar/hq-tabbar.vue` | 自定义 TabBar,4 个入口(home/flower/moon/user 矢量图标),选中态为暖色胶囊 |
| 花瓣日历 | `components/bloom-calendar/bloom-calendar.vue` | 7 列网格;阶段圆点 + 预测空心圈 + 记录小点;今天浅底、选中态渐变填充 |
| 通用样式 | `App.vue` | `.hq-card` `.hq-btn` `.hq-chip` `.hq-cell` `.hq-empty` `.hq-progress` 等 12 个原子类 |
**按钮三态**:主按钮(暖色渐变 + 投影)、幽灵按钮(`#FFF1E9` 底 + 主色字)、朴素按钮(白底 + 细边框)。
**胶囊标签**:未选中 `#FFF4EE` 底 → 选中渐变底白字,用于症状、触发事件、强度等轻量多选。
### 3.1 图标系统(全部矢量,禁止 emoji)
| 项 | 说明 |
|---|---|
| 图标库 | `utils/icons.js`:**61 个** 24×24 线性图标,`stroke-width 1.8`,圆角端点 |
| 渲染方式 | 内联 SVG → base64 `data:` URI → CSS `background-image`,任意尺寸不失真;H5 / App / 小程序一致 |
| 组件 | `<hq-icon name="flower" :size="40" color="#E8604C" :stroke="1.8" />` |
| 主题适配 | 颜色运行时注入,同一图标可随主题/状态变色(无多套图片) |
| 兼容历史数据 | 后端返回的 emoji 字段(如 `cover_emoji`)由 `resolveIcon()` 自动映射成矢量图标 |
| 语义映射 | `iconForContentType / iconForMood / iconForReminder / iconForSymptom / iconForVaccine / iconForRelation` |
**硬规则**
1. 页面与组件中**不允许出现 emoji 或字符图标**(含 ✓ ✿ ☾ ⚡ ☎ 等),一律使用 `<hq-icon>`;
2. 新增图标必须先加入 `utils/icons.js` 的 `PATHS`,再在页面引用;
3. 图标名使用 kebab-case(如 `cloud-rain`、`chat-heart`),禁止内联 SVG 字符串散落在页面里。
**自动化校验**:`python3 scripts/verify/no_emoji_check.py`
- 扫描 28 个前端文件、61 个图标名;
- 拦截 emoji/字符图标、未定义图标名、未注册组件三类问题。
---
## 4. 信息架构与页面地图
@@ -210,14 +231,24 @@ node scripts/verify/scss_compile_check.mjs
```
按 uni-app 的方式把 `uni.scss` 变量注入每个 `<style lang="scss">` 后编译,全部通过。
### 7.5 验证结论
### 7.5 图标规范校验(0 问题)
```bash
python3 scripts/verify/no_emoji_check.py
```
- 全站 28 个前端文件 **0 个 emoji / 0 个字符图标**
- 61 个矢量图标的 SVG 全部通过 XML 解析与标签配对校验
- 所有 `<hq-icon>` 引用名均存在,组件注册完整
### 7.6 验证结论
| 维度 | 结果 |
|---|---|
| 接口连通性 | 48/48 通过(真实线上环境) |
| 前后端契约 | 24 接口 0 偏差 |
| 模板/脚本语法 | 11/11 Vue 文件编译通过 |
| 样式 | 10/10 SCSS 块编译通过 |
| 模板/脚本语法 | 20/20 Vue 文件编译通过 |
| 样式 | 19/19 SCSS 块编译通过 |
| 图标规范 | 61 图标 / 0 emoji |
| 数据一致性 | 库内 24+9 张表,内容 28 条、标签 20 个、套餐 3 档 |
---

查看文件

@@ -17,6 +17,7 @@
- **当前进度**:M1–M9 共 **47 个功能点全部实现并联调通过**(详见 05 文档)
- **变现**:会员订阅为主轴(月/年/终身),课程与咨询/测评为副,按次增值补充;坚持零广告
- **设计**:暖色调(花红 `#E8604C` + 蜜橙 `#F5A65B` + 暖米白 `#FFF9F5`),设计令牌见 `uni.scss`
- **图标**:全站 61 个内联 SVG 矢量图标(`utils/icons.js` + `<hq-icon>`),**禁止使用 emoji 图片**
## 验证脚本
@@ -25,6 +26,7 @@ python3 scripts/verify/api_flow_test.py # 后端接口全链路(82 项断
python3 scripts/verify/contract_check.py # 前后端契约静态校验
node scripts/verify/vue_compile_check.mjs # Vue SFC 编译(需 @vue/compiler-sfc)
node scripts/verify/scss_compile_check.mjs # SCSS 编译(需 sass)
python3 scripts/verify/no_emoji_check.py # 图标规范(禁止 emoji / 图标名与组件注册)
```
## 重要约定

查看文件

@@ -7,7 +7,7 @@
<!-- 危机干预 -->
<view class="crisis" @tap="callHotline">
<text class="crisis-icon">☎</text>
<hq-icon name="phone" :size="34" color="#C9482F" style="margin-right: 16rpx" />
<view class="crisis-body">
<text class="crisis-title">如果此刻很难,请先联系热线</text>
<text class="crisis-sub">全国心理援助热线 12356 · 紧急情况请拨 120</text>
@@ -17,7 +17,9 @@
<!-- 咨询师 -->
<view class="hq-card counselor" v-for="item in counselors" :key="item.id">
<view class="counselor-head">
<view class="counselor-avatar"><text class="counselor-emoji">{{ item.emoji }}</text></view>
<view class="counselor-avatar">
<hq-icon :name="counselorIcon(item)" :size="40" color="#C9482F" />
</view>
<view class="counselor-info">
<view class="counselor-name-row">
<text class="counselor-name">{{ item.name }}</text>
@@ -81,7 +83,7 @@
</view>
<view class="hq-card" v-else>
<view class="hq-empty">
<text class="hq-empty-emoji">🕊</text>
<hq-icon name="chat-heart" :size="72" color="#E6D3C9" />
<text class="hq-empty-text">还没有咨询预约</text>
</view>
</view>
@@ -109,8 +111,11 @@
<script>
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { resolveIcon } from '@/utils/icons.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
counselors: [],
@@ -146,6 +151,9 @@ export default {
})
} catch (e) {}
},
counselorIcon(item) {
return resolveIcon(item && (item.icon || item.emoji), 'flower')
},
priceOf(item, key) {
const price = (item.price && item.price[key]) || 0
return Math.round(price * (item.discount || 1))
@@ -240,7 +248,6 @@ export default {
}
.crisis-icon {
font-size: 34rpx;
margin-right: 16rpx;
}
@@ -281,10 +288,6 @@ export default {
justify-content: center;
}
.counselor-emoji {
font-size: 40rpx;
}
.counselor-info {
flex: 1;
margin-left: 18rpx;

查看文件

@@ -1,7 +1,7 @@
<template>
<view class="hq-page">
<view class="head">
<text class="head-emoji">{{ detail.emoji || '🌸' }}</text>
<hq-icon :name="headIcon" :size="64" color="#E8604C" style="margin-bottom: 16rpx" />
<text class="head-title">{{ detail.title || '' }}</text>
<text class="head-summary" v-if="detail.summary">{{ detail.summary }}</text>
<view class="head-tags">
@@ -35,13 +35,22 @@
<script>
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { resolveIcon, iconForContentType } from '@/utils/icons.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
detail: {}
}
},
computed: {
headIcon() {
if (this.detail && (this.detail.icon || this.detail.emoji)) return resolveIcon(this.detail.icon || this.detail.emoji)
return iconForContentType((this.detail && this.detail.type) || 'jijing')
}
},
onLoad(options) {
if (!store.token) {
uni.reLaunch({ url: '/pages/login/index' })
@@ -72,11 +81,6 @@ export default {
flex-direction: column;
}
.head-emoji {
font-size: 64rpx;
line-height: 1.2;
}
.head-title {
margin-top: 16rpx;
font-size: 44rpx;

查看文件

@@ -73,7 +73,8 @@
:class="{ 'hq-chip-active': form.symptom_ids.indexOf(tag.id) > -1 }"
@tap="toggleTag(tag.id)"
>
<text class="chip-text">{{ tag.icon }} {{ tag.name }}</text>
<hq-icon :name="symptomIcon(tag.category)" :size="24" color="#B5715B" class="chip-icon" />
<text class="chip-text">{{ tag.name }}</text>
</view>
</view>
</view>
@@ -90,7 +91,12 @@
:class="{ 'mood-btn-active': form.mood === m.value }"
@tap="form.mood = form.mood === m.value ? 0 : m.value"
>
<text class="mood-emoji">{{ m.emoji }}</text>
<hq-icon
:name="m.icon"
:size="30"
:stroke="1.9"
:color="form.mood === m.value ? '#E8604C' : '#B5715B'"
/>
</view>
</view>
</view>
@@ -194,6 +200,8 @@
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { today as todayStr, monthOf, addMonths, monthText, dayText, weekText } from '@/utils/date.js'
import { iconForSymptom } from '@/utils/icons.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
import bloomCalendar from '@/components/bloom-calendar/bloom-calendar.vue'
import hqTabbar from '@/components/hq-tabbar/hq-tabbar.vue'
@@ -207,7 +215,7 @@ const EMPTY_FORM = () => ({
})
export default {
components: { bloomCalendar, hqTabbar },
components: { hqIcon, bloomCalendar, hqTabbar },
data() {
return {
month: monthOf(new Date()),
@@ -228,11 +236,11 @@ export default {
{ label: '较多', value: 3 }
],
moodOptions: [
{ emoji: '😞', value: -2 },
{ emoji: '🌧', value: -1 },
{ emoji: '🌤', value: 0 },
{ emoji: '☀️', value: 1 },
{ emoji: '🌻', value: 2 }
{ icon: 'cloud-rain', value: -2 },
{ icon: 'cloud', value: -1 },
{ icon: 'cloud-sun', value: 0 },
{ icon: 'sun', value: 1 },
{ icon: 'heart', value: 2 }
]
}
},
@@ -313,6 +321,9 @@ export default {
selectDay(day) {
this.loadDay(day.date)
},
symptomIcon(category) {
return iconForSymptom(category)
},
toggleTag(id) {
const index = this.form.symptom_ids.indexOf(id)
if (index > -1) {
@@ -478,6 +489,10 @@ export default {
font-size: 24rpx;
}
.chip-icon {
margin-right: 6rpx;
}
.pain-row {
display: flex;
align-items: center;
@@ -531,10 +546,6 @@ export default {
border: 2rpx solid #E8604C;
}
.mood-emoji {
font-size: 30rpx;
}
.sleep-row {
display: flex;
align-items: center;

查看文件

@@ -55,7 +55,7 @@
</view>
<view class="hq-card" v-else>
<view class="hq-empty">
<text class="hq-empty-emoji">🌱</text>
<hq-icon name="sprout" :size="72" color="#E6D3C9" />
<text class="hq-empty-text">本期还没有症状记录</text>
</view>
</view>
@@ -94,8 +94,10 @@
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { monthOf, monthText } from '@/utils/date.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
month: monthOf(new Date()),

查看文件

@@ -49,7 +49,7 @@
</view>
</view>
<view class="hq-empty" v-if="!(data.binds || []).length">
<text class="hq-empty-emoji">🤝</text>
<hq-icon name="users" :size="72" color="#E6D3C9" />
<text class="hq-empty-text">还没有绑定家人\n生成邀请码发给 TA 即可</text>
</view>
</view>
@@ -94,7 +94,7 @@
</view>
<view class="hq-card script" v-for="item in scriptList" :key="item.id" @tap="openContent(item)">
<view class="script-head">
<text class="script-emoji">{{ item.emoji }}</text>
<hq-icon :name="contentIcon(item.type)" :size="30" color="#E8604C" style="margin-right: 12rpx" />
<text class="script-title">{{ item.title }}</text>
</view>
<text class="script-summary">{{ item.summary }}</text>
@@ -128,8 +128,11 @@
<script>
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { iconForContentType } from '@/utils/icons.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
data: {},
@@ -149,6 +152,9 @@ export default {
this.load()
},
methods: {
contentIcon(type) {
return iconForContentType(type)
},
async load() {
try {
const data = await api.familyIndex()
@@ -483,11 +489,6 @@ export default {
align-items: center;
}
.script-emoji {
font-size: 30rpx;
margin-right: 12rpx;
}
.script-title {
font-size: 28rpx;
color: #3E2C27;

查看文件

@@ -20,13 +20,20 @@
:class="{ 'tab-active': active === tab.key }"
@tap="active = tab.key"
>
<text class="tab-text" :class="{ 'tab-text-active': active === tab.key }">{{ tab.icon }} {{ tab.title }}</text>
<view class="tab-inner">
<hq-icon
:name="tab.icon"
:size="26"
:color="active === tab.key ? '#FFFFFF' : '#B5715B'"
/>
<text class="tab-text" :class="{ 'tab-text-active': active === tab.key }">{{ tab.title }}</text>
</view>
</view>
</view>
<view class="hq-card item" v-for="item in currentList" :key="item.id" @tap="open(item)">
<view class="item-left">
<text class="item-emoji">{{ item.emoji }}</text>
<hq-icon :name="contentIcon(item.type)" :size="34" color="#E8604C" />
</view>
<view class="item-body">
<text class="item-title">{{ item.title }}</text>
@@ -40,7 +47,7 @@
<view class="hq-card" v-if="!currentList.length">
<view class="hq-empty">
<text class="hq-empty-emoji">🌾</text>
<hq-icon name="leaf" :size="72" color="#E6D3C9" />
<text class="hq-empty-text">该阶段暂无建议内容\n可以先记录身体状态</text>
</view>
</view>
@@ -54,17 +61,20 @@
<script>
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { iconForContentType } from '@/utils/icons.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
data: {},
active: 'diet',
tabs: [
{ key: 'diet', title: '饮食', icon: '🍲' },
{ key: 'sport', title: '运动', icon: '🧘' },
{ key: 'sleep', title: '睡眠', icon: '🌙' },
{ key: 'pain', title: '痛经', icon: '🌡' }
{ key: 'diet', title: '饮食', icon: 'bowl' },
{ key: 'sport', title: '运动', icon: 'activity' },
{ key: 'sleep', title: '睡眠', icon: 'moon' },
{ key: 'pain', title: '痛经', icon: 'thermometer' }
]
}
},
@@ -82,6 +92,9 @@ export default {
this.load()
},
methods: {
contentIcon(type) {
return iconForContentType(type || 'advice')
},
async load() {
try {
this.data = await api.healthIndex()
@@ -156,9 +169,15 @@ export default {
box-shadow: 0 12rpx 28rpx rgba(232, 96, 76, 0.2);
}
.tab-inner {
display: flex;
align-items: center;
}
.tab-text {
font-size: 24rpx;
color: #8C7367;
margin-left: 8rpx;
}
.tab-text-active {
@@ -182,10 +201,6 @@ export default {
justify-content: center;
}
.item-emoji {
font-size: 32rpx;
}
.item-body {
flex: 1;
margin-left: 20rpx;

查看文件

@@ -4,7 +4,7 @@
<view class="brand">
<view class="brand-left">
<view class="brand-mark">
<text class="brand-mark-flower">✿</text>
<hq-icon name="flower" :size="40" :stroke="1.9" color="#FFFFFF" />
</view>
<view class="brand-text">
<text class="brand-name">花期</text>
@@ -69,7 +69,7 @@
<view class="quick">
<view class="quick-item" v-for="item in quicks" :key="item.label" @tap="go(item)">
<view class="quick-icon" :style="{ backgroundColor: item.bg }">
<text class="quick-icon-text">{{ item.icon }}</text>
<hq-icon :name="item.icon" :size="40" :stroke="1.9" color="#E8604C" />
</view>
<text class="quick-label">{{ item.label }}</text>
</view>
@@ -91,7 +91,7 @@
</view>
<view class="jijing hq-card" v-if="home.jijing" @tap="openJijing">
<view class="jijing-top">
<text class="jijing-emoji">{{ home.jijing.emoji }}</text>
<hq-icon :name="jijingIcon" :size="52" color="#E8604C" style="margin-right: 20rpx" />
<view class="jijing-head">
<text class="jijing-title">{{ home.jijing.title }}</text>
<text class="jijing-summary">{{ home.jijing.summary }}</text>
@@ -110,7 +110,7 @@
</view>
<view class="reminder hq-card">
<view class="reminder-item" v-for="(item, index) in home.reminders" :key="index">
<text class="reminder-icon">{{ item.icon }}</text>
<hq-icon :name="reminderIcon(item.type)" :size="38" color="#F5A65B" style="margin-right: 20rpx" />
<view class="reminder-body">
<text class="reminder-title">{{ item.title }}</text>
<text class="reminder-desc">{{ item.desc }}</text>
@@ -162,27 +162,32 @@
<script>
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { iconForContentType, iconForReminder } from '@/utils/icons.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
import hqTabbar from '@/components/hq-tabbar/hq-tabbar.vue'
export default {
components: { hqTabbar },
components: { hqIcon, hqTabbar },
data() {
return {
home: {},
loading: true,
quicks: [
{ label: '记录身体', icon: '✍', bg: '#FFF1E9', path: '/pages/cycle/index' },
{ label: '情绪日记', icon: '☾', bg: '#F1F0FB', path: '/pages/mood/index' },
{ label: '科学备孕', icon: '🌱', bg: '#EAF4EE', path: '/pages/prepare/index' },
{ label: '健康建议', icon: '🍲', bg: '#FDF6E3', path: '/pages/health/index' },
{ label: '家人共护', icon: '🤝', bg: '#FDECEC', path: '/pages/family/index' },
{ label: '两性关系', icon: '💞', bg: '#F3EBFB', path: '/pages/relation/index' },
{ label: '亲子教育', icon: '🧸', bg: '#EAF6F6', path: '/pages/parenting/index' },
{ label: '心理咨询', icon: '🕊', bg: '#F1F4FB', path: '/pages/consult/index' }
{ label: '记录身体', icon: 'edit', bg: '#FFF1E9', path: '/pages/cycle/index' },
{ label: '情绪日记', icon: 'moon', bg: '#F1F0FB', path: '/pages/mood/index' },
{ label: '科学备孕', icon: 'sprout', bg: '#EAF4EE', path: '/pages/prepare/index' },
{ label: '健康建议', icon: 'bowl', bg: '#FDF6E3', path: '/pages/health/index' },
{ label: '家人共护', icon: 'users', bg: '#FDECEC', path: '/pages/family/index' },
{ label: '两性关系', icon: 'heart', bg: '#F3EBFB', path: '/pages/relation/index' },
{ label: '亲子教育', icon: 'blocks', bg: '#EAF6F6', path: '/pages/parenting/index' },
{ label: '心理咨询', icon: 'chat-heart', bg: '#F1F4FB', path: '/pages/consult/index' }
]
}
},
computed: {
jijingIcon() {
return iconForContentType((this.home.jijing && this.home.jijing.type) || 'jijing')
},
cycle() {
return this.home.cycle || {}
},
@@ -233,6 +238,9 @@ export default {
this.loading = false
}
},
reminderIcon(type) {
return iconForReminder(type)
},
go(item) {
uni.navigateTo({ url: item.path })
},
@@ -281,12 +289,6 @@ export default {
box-shadow: 0 10rpx 24rpx rgba(232, 96, 76, 0.24);
}
.brand-mark-flower {
color: #FFFFFF;
font-size: 36rpx;
line-height: 1;
}
.brand-text {
margin-left: 16rpx;
display: flex;
@@ -503,11 +505,6 @@ export default {
justify-content: center;
}
.quick-icon-text {
font-size: 38rpx;
color: #E8604C;
}
.quick-label {
margin-top: 12rpx;
font-size: 22rpx;

查看文件

@@ -3,9 +3,9 @@
<!-- 品牌区 -->
<view class="hero">
<view class="petals">
<text class="petal petal-1">✿</text>
<text class="petal petal-2">❀</text>
<text class="petal petal-3">✿</text>
<view class="petal petal-1"><hq-icon name="flower" :size="44" :stroke="1.7" color="#F5A65B" /></view>
<view class="petal petal-2"><hq-icon name="flower" :size="60" :stroke="1.8" color="#E8604C" /></view>
<view class="petal petal-3"><hq-icon name="flower" :size="44" :stroke="1.7" color="#F5A65B" /></view>
</view>
<text class="brand">花期</text>
<text class="slogan">温柔记录 · 静待花开</text>
@@ -15,7 +15,7 @@
<!-- 登录表单 -->
<view class="form hq-card">
<view class="input-wrap">
<text class="input-icon">👤</text>
<hq-icon name="user" :size="32" color="#B5715B" class="input-icon" />
<input
class="input"
v-model="account"
@@ -25,7 +25,7 @@
/>
</view>
<view class="input-wrap">
<text class="input-icon">🔒</text>
<hq-icon name="lock" :size="32" color="#B5715B" class="input-icon" />
<input
class="input"
v-model="password"
@@ -56,8 +56,10 @@
<script>
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
account: '',
@@ -121,8 +123,6 @@ export default {
.petal {
position: absolute;
font-size: 44rpx;
color: #F5A65B;
opacity: 0.85;
}
@@ -183,9 +183,8 @@ export default {
}
.input-icon {
font-size: 30rpx;
margin-right: 18rpx;
opacity: 0.7;
opacity: 0.85;
}
.input {

查看文件

@@ -48,7 +48,7 @@
</view>
<view class="plan-check">
<view class="plan-check-circle" :class="{ 'plan-check-circle-active': selected === plan.id }">
<text class="plan-check-text" v-if="selected === plan.id">✓</text>
<hq-icon v-if="selected === plan.id" name="check" :size="18" :stroke="2.4" color="#FFFFFF" />
</view>
<text class="plan-check-label">{{ selected === plan.id ? '已选择' : '点击选择' }}</text>
</view>
@@ -74,8 +74,10 @@
<script>
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
plans: [],
@@ -297,12 +299,6 @@ export default {
border-color: #E8604C;
}
.plan-check-text {
font-size: 20rpx;
color: #FFFFFF;
line-height: 1;
}
.plan-check-label {
margin-left: 12rpx;
font-size: 22rpx;

查看文件

@@ -61,7 +61,7 @@
<view class="hq-card setting-card">
<view class="hq-cell" @tap="chooseLock">
<view class="cell-left">
<text class="cell-icon">🔒</text>
<hq-icon name="lock" :size="32" color="#C79A7B" style="margin-right: 16rpx" />
<text class="hq-cell-label">应用锁</text>
</view>
<view class="cell-right">
@@ -72,7 +72,7 @@
<view class="hq-cell">
<view class="cell-left">
<text class="cell-icon">📱</text>
<hq-icon name="smartphone" :size="32" color="#C79A7B" style="margin-right: 16rpx" />
<text class="hq-cell-label">仅本地存储</text>
</view>
<switch
@@ -96,7 +96,7 @@
<view class="hq-card setting-card">
<view class="hq-cell" v-for="item in remindItems" :key="item.key">
<view class="cell-left">
<text class="cell-icon">{{ item.icon }}</text>
<hq-icon :name="item.icon" :size="32" color="#C79A7B" style="margin-right: 16rpx" />
<text class="hq-cell-label">{{ item.label }}</text>
</view>
<switch
@@ -110,7 +110,7 @@
<picker mode="time" :value="remind.time || '21:00'" @change="onTimeChange">
<view class="hq-cell">
<view class="cell-left">
<text class="cell-icon">⏰</text>
<hq-icon name="clock" :size="32" color="#C79A7B" style="margin-right: 16rpx" />
<text class="hq-cell-label">提醒时间</text>
</view>
<view class="cell-right">
@@ -228,9 +228,10 @@
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import hqTabbar from '@/components/hq-tabbar/hq-tabbar.vue'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqTabbar },
components: { hqIcon, hqTabbar },
data() {
return {
user: {},
@@ -243,10 +244,10 @@ export default {
backups: [],
remind: { period: true, ovulation: true, record: true, care: true, time: '21:00' },
remindItems: [
{ key: 'period', label: '经期来临提醒', icon: '🌸' },
{ key: 'ovulation', label: '排卵日提醒', icon: '🌱' },
{ key: 'record', label: '每日记录提醒', icon: '✍️' },
{ key: 'care', label: '关怀提醒(家人)', icon: '💛' }
{ key: 'period', label: '经期来临提醒', icon: 'droplet' },
{ key: 'ovulation', label: '排卵日提醒', icon: 'sprout' },
{ key: 'record', label: '每日记录提醒', icon: 'edit' },
{ key: 'care', label: '关怀提醒(家人)', icon: 'heart' }
]
}
},
@@ -625,7 +626,6 @@ export default {
}
.cell-icon {
font-size: 30rpx;
margin-right: 16rpx;
}

查看文件

@@ -6,7 +6,7 @@
</view>
<view class="hotline" @tap="callHotline">
<text class="hotline-icon">☎</text>
<hq-icon name="phone" :size="36" color="#C9482F" style="margin-right: 16rpx" />
<view class="hotline-body">
<text class="hotline-title">如果可以,先告诉一个人「我现在不太好」</text>
<text class="hotline-sub">需要专业支持:{{ data.hotline && data.hotline.phone ? data.hotline.phone : '12356' }}</text>
@@ -15,7 +15,7 @@
<view class="hq-card tool" v-for="item in data.list || []" :key="item.id" @tap="open(item)">
<view class="tool-head">
<text class="tool-emoji">{{ item.emoji }}</text>
<hq-icon :name="toolIcon(item)" :size="44" color="#E8604C" style="margin-right: 20rpx" />
<view class="tool-title-wrap">
<text class="tool-title">{{ item.title }}</text>
<text class="tool-summary">{{ item.summary }}</text>
@@ -28,7 +28,7 @@
<view class="hq-card" v-if="!(data.list || []).length">
<view class="hq-empty">
<text class="hq-empty-emoji">🫧</text>
<hq-icon name="droplets" :size="72" color="#E6D3C9" />
<text class="hq-empty-text">加载中…</text>
</view>
</view>
@@ -42,8 +42,11 @@
<script>
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { resolveIcon, iconForContentType } from '@/utils/icons.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
data: { list: [] }
@@ -62,6 +65,12 @@ export default {
this.data = await api.moodFirstaid()
} catch (e) {}
},
toolIcon(item) {
if (item && (item.icon || item.emoji)) {
return resolveIcon(item.icon || item.emoji)
}
return iconForContentType((item && item.type) || 'firstaid')
},
open(item) {
uni.navigateTo({ url: '/pages/content/detail?id=' + item.id })
},
@@ -104,7 +113,6 @@ export default {
}
.hotline-icon {
font-size: 36rpx;
margin-right: 16rpx;
}
@@ -135,12 +143,6 @@ export default {
align-items: flex-start;
}
.tool-emoji {
font-size: 44rpx;
margin-right: 20rpx;
line-height: 1.2;
}
.tool-title-wrap {
flex: 1;
display: flex;

查看文件

@@ -15,7 +15,12 @@
:class="{ 'mood-option-active': form.mood === m.key }"
@tap="form.mood = m.key"
>
<text class="mood-option-emoji">{{ m.emoji }}</text>
<hq-icon
:name="m.icon"
:size="40"
:stroke="1.9"
:color="form.mood === m.key ? '#E8604C' : '#B5715B'"
/>
<text class="mood-option-text" :class="{ 'mood-option-text-active': form.mood === m.key }">{{ m.text }}</text>
</view>
</view>
@@ -121,7 +126,7 @@
<view class="hq-card record-card" v-if="records.length">
<view class="record" v-for="item in records" :key="item.id">
<view class="record-left">
<text class="record-emoji">{{ item.emoji }}</text>
<hq-icon :name="moodIcon(item.mood)" :size="30" :color="item.color" />
</view>
<view class="record-body">
<view class="record-head">
@@ -140,7 +145,7 @@
</view>
<view class="hq-card" v-else>
<view class="hq-empty">
<text class="hq-empty-emoji">☾</text>
<hq-icon name="moon" :size="72" color="#E6D3C9" />
<text class="hq-empty-text">还没有情绪记录\n记录一次,就能看见自己的情绪脉络</text>
</view>
</view>
@@ -152,7 +157,7 @@
</view>
<view class="hq-card content-card" v-for="item in contents" :key="item.id" @tap="openContent(item)">
<view class="content-left">
<text class="content-emoji">{{ item.emoji }}</text>
<hq-icon :name="contentIcon(item.type)" :size="34" color="#E8604C" />
</view>
<view class="content-body">
<text class="content-title">{{ item.title }}</text>
@@ -176,18 +181,20 @@
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { dayText, weekText, today as todayStr } from '@/utils/date.js'
import { iconForMood, iconForContentType } from '@/utils/icons.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
import hqTabbar from '@/components/hq-tabbar/hq-tabbar.vue'
export default {
components: { hqTabbar },
components: { hqIcon, hqTabbar },
data() {
return {
moods: [
{ key: 'happy', text: '开心', emoji: '☀️' },
{ key: 'calm', text: '平静', emoji: '🌤' },
{ key: 'anxious', text: '焦虑', emoji: '🌪' },
{ key: 'low', text: '低落', emoji: '🌧' },
{ key: 'angry', text: '烦躁', emoji: '⚡' }
{ key: 'happy', text: '开心', icon: 'sun' },
{ key: 'calm', text: '平静', icon: 'cloud-sun' },
{ key: 'anxious', text: '焦虑', icon: 'wind' },
{ key: 'low', text: '低落', icon: 'cloud-rain' },
{ key: 'angry', text: '烦躁', icon: 'bolt' }
],
triggerOptions: ['工作', '关系', '身体', '睡眠', '家人', '天气'],
form: {
@@ -243,6 +250,12 @@ export default {
this.contents = (data && data.list) || []
} catch (e) {}
},
moodIcon(mood) {
return iconForMood(mood)
},
contentIcon(type) {
return iconForContentType(type)
},
changeRange(days) {
this.range = days
this.loadTrend()
@@ -354,11 +367,6 @@ export default {
border: 2rpx solid #E8604C;
}
.mood-option-emoji {
font-size: 40rpx;
line-height: 1.2;
}
.mood-option-text {
margin-top: 8rpx;
font-size: 22rpx;
@@ -585,10 +593,6 @@ export default {
justify-content: center;
}
.record-emoji {
font-size: 30rpx;
}
.record-body {
flex: 1;
margin-left: 20rpx;
@@ -660,10 +664,6 @@ export default {
justify-content: center;
}
.content-emoji {
font-size: 32rpx;
}
.content-body {
flex: 1;
margin-left: 20rpx;

查看文件

@@ -64,7 +64,7 @@
<text class="hq-section-more">按月龄推荐</text>
</view>
<view class="hq-card activity" v-for="item in data.activities || []" :key="item.id" @tap="openContent(item)">
<text class="activity-emoji">{{ item.emoji }}</text>
<hq-icon :name="contentIcon(item.type)" :size="32" color="#E8604C" />
<view class="activity-body">
<text class="activity-title">{{ item.title }}</text>
<text class="activity-summary">{{ item.summary }}</text>
@@ -80,7 +80,7 @@
</view>
<view class="task" v-for="item in data.co_tasks || []" :key="item.id" @tap="toggleCoTask(item)">
<view class="task-check" :class="{ 'task-check-done': item.done }">
<text class="task-check-text" v-if="item.done">✓</text>
<hq-icon v-if="item.done" name="check" :size="20" :stroke="2.4" color="#FFFFFF" />
</view>
<text class="task-title" :class="{ 'task-title-done': item.done }">{{ item.title }}</text>
</view>
@@ -138,8 +138,11 @@
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { today as todayStr } from '@/utils/date.js'
import { iconForContentType } from '@/utils/icons.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
data: {},
@@ -177,6 +180,9 @@ export default {
}
} catch (e) {}
},
contentIcon(type) {
return iconForContentType(type)
},
onBirthday(e) {
this.baby.birthday = e.detail.value
},
@@ -447,11 +453,6 @@ export default {
padding: 22rpx 26rpx;
}
.activity-emoji {
font-size: 32rpx;
margin-right: 16rpx;
}
.activity-body {
flex: 1;
display: flex;
@@ -503,11 +504,6 @@ export default {
border-color: #E8604C;
}
.task-check-text {
font-size: 20rpx;
color: #FFFFFF;
}
.task-title {
flex: 1;
font-size: 26rpx;

查看文件

@@ -105,7 +105,7 @@
<view class="task" v-for="item in data.tasks || []" :key="item.id" @tap="toggleTask(item)">
<view class="task-check" :class="{ 'task-check-done': item.done }">
<text class="task-check-text" v-if="item.done">✓</text>
<hq-icon v-if="item.done" name="check" :size="20" :stroke="2.4" color="#FFFFFF" />
</view>
<text class="task-title" :class="{ 'task-title-done': item.done }">{{ item.title }}</text>
<text class="task-due" v-if="item.due_date">{{ item.due_date.slice(5) }}</text>
@@ -124,7 +124,7 @@
<text class="hq-muted" v-if="data.intercourse_locked">会员权益</text>
</view>
<view class="hq-empty" v-if="data.intercourse_locked" @tap="goMember">
<text class="hq-empty-emoji">🔒</text>
<hq-icon name="lock" :size="72" color="#E6D3C9" />
<text class="hq-empty-text">开通会员后可查看受孕窗口、频率与体位建议</text>
</view>
<view class="guide-item" v-else v-for="item in guideList" :key="item.id" @tap="openContent(item)">
@@ -143,8 +143,10 @@
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { today as todayStr } from '@/utils/date.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
data: { tasks: [], lh: [], fertile: [] },
@@ -588,12 +590,6 @@ export default {
border-color: #E8604C;
}
.task-check-text {
font-size: 20rpx;
color: #FFFFFF;
line-height: 1;
}
.task-title {
flex: 1;
font-size: 26rpx;

查看文件

@@ -29,7 +29,7 @@
</view>
<view class="task" v-for="item in data.tasks || []" :key="item.id" @tap="toggleTask(item)">
<view class="task-check" :class="{ 'task-check-done': item.done }">
<text class="task-check-text" v-if="item.done">✓</text>
<hq-icon v-if="item.done" name="check" :size="20" :stroke="2.4" color="#FFFFFF" />
</view>
<text class="task-title" :class="{ 'task-title-done': item.done }">{{ item.title }}</text>
</view>
@@ -46,7 +46,7 @@
</view>
<view class="hq-card card" v-for="item in [...(data.cards || []), ...(data.conflicts || [])]" :key="'c' + item.id" @tap="openContent(item)">
<view class="card-head">
<text class="card-emoji">{{ item.emoji }}</text>
<hq-icon :name="contentIcon(item.type)" :size="30" color="#E8604C" style="margin-right: 12rpx" />
<text class="card-title">{{ item.title }}</text>
<text class="card-lock" v-if="item.locked">会员</text>
</view>
@@ -104,8 +104,11 @@
import api from '@/utils/api.js'
import store from '@/utils/store.js'
import { today as todayStr } from '@/utils/date.js'
import { iconForContentType } from '@/utils/icons.js'
import hqIcon from '@/components/hq-icon/hq-icon.vue'
export default {
components: { hqIcon },
data() {
return {
data: {},
@@ -129,6 +132,9 @@ export default {
this.stats = (data && data.stats) || {}
} catch (e) {}
},
contentIcon(type) {
return iconForContentType(type)
},
startTest(item) {
uni.navigateTo({ url: '/pages/assessment/index?id=' + item.id })
},
@@ -274,12 +280,6 @@ export default {
border-color: #E8604C;
}
.task-check-text {
font-size: 20rpx;
color: #FFFFFF;
line-height: 1;
}
.task-title {
flex: 1;
font-size: 26rpx;
@@ -332,11 +332,6 @@ export default {
align-items: center;
}
.card-emoji {
font-size: 30rpx;
margin-right: 12rpx;
}
.card-title {
flex: 1;
font-size: 28rpx;

查看文件

@@ -0,0 +1,100 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""花期 APP · 图标规范校验
1. 前端源码(.vue / .js)中不得出现 emoji / 字符图标(含 ✓ ✿ ☾ ⚡ 等)
2. <hq-icon name="xxx"> 中的图标名必须存在于 utils/icons.js
3. hq-icon 组件必须在使用的页面中注册
用法:python3 scripts/verify/no_emoji_check.py
"""
import os
import re
import sys
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
SKIP_DIRS = {'server', 'node_modules', '.git', 'docs', 'scripts', 'unpackage', '.hbuilderx'}
# emoji 与常见字符图标(dingbats / 杂项符号 / 变体选择符)
EMOJI_RE = re.compile(
'['
'\U0001F000-\U0001FAFF' # 各种 emoji 面板
'\u2600-\u27BF' # 杂项符号、dingbats(含 ✓ ✿ ❀ ☀ ⚡ ☎ ✍)
'\u2B00-\u2BFF' # 箭头/星形符号
'\uFE0F\u200D' # 变体选择符 / ZWJ
'\u2733-\u2747' # 花形符号
'\u2190-\u21FF' # 箭头
']'
)
issues = []
def load_icon_names():
src = open(os.path.join(ROOT, 'utils/icons.js'), encoding='utf-8').read()
block = src.split('const PATHS = {', 1)[1].split('\n}', 1)[0]
names = []
for line in block.splitlines():
m = re.match(r"\s*'?([a-z][a-z\-]*)'?\s*:", line)
if m:
names.append(m.group(1))
return set(names)
def walk():
files = []
for dp, dirs, fs in os.walk(ROOT):
dirs[:] = [d for d in dirs if d not in SKIP_DIRS]
for f in fs:
if f.endswith(('.vue', '.js')):
files.append(os.path.join(dp, f))
return sorted(files)
def main():
icons = load_icon_names()
files = walk()
print(f"[1] 图标库共 {len(icons)} 个矢量图标,扫描 {len(files)} 个前端文件")
for path in files:
rel = os.path.relpath(path, ROOT)
src = open(path, encoding='utf-8').read()
# 1) emoji 检查
for i, line in enumerate(src.splitlines(), 1):
m = EMOJI_RE.search(line)
if m:
issues.append(f"{rel}:{i} 含 emoji/字符图标 '{m.group(0)}' -> {line.strip()[:60]}")
# 2) 图标名检查(仅静态名与字符串字面量,动态表达式运行时解析)
if not rel.startswith('utils/icons.js'):
for m in re.finditer(r'<hq-icon[^>]*?(?::name="([^"]+)"|name="([^"]+)")', src, re.S):
raw = m.group(1) or m.group(2)
name = raw
lit = re.fullmatch(r"'([a-z][a-z\-]*)'|\"([a-z][a-z\-]*)\"", raw.strip())
if lit:
name = lit.group(1) or lit.group(2)
elif raw.startswith(':') or '{' in raw or '(' in raw or raw.startswith('${'):
continue
elif not re.fullmatch(r'[a-z][a-z\-]*', raw):
continue
if name not in icons:
issues.append(f"{rel} 使用了不存在的图标 '{name}'")
# 3) 组件注册检查(仅 .vue 页面/组件)
is_icon_self = rel.replace(os.sep, '/').endswith('components/hq-icon/hq-icon.vue')
if rel.endswith('.vue') and not is_icon_self and '<hq-icon' in src and 'hqIcon' not in src:
issues.append(f"{rel} 使用 <hq-icon> 但未注册组件 hqIcon")
print(f"[2] emoji 检查 / 图标名检查 / 组件注册检查完成")
print('=' * 66)
if issues:
print(f"发现 {len(issues)} 个问题:")
for i in issues:
print(" ❌ " + i)
sys.exit(1)
print("✅ 全站无 emoji,矢量图标命名与组件注册全部合规")
if __name__ == '__main__':
main()

316
utils/icons.js 普通文件
查看文件

@@ -0,0 +1,316 @@
/**
* 花期图标库(高清矢量 / 内联 SVG)
*
* 设计规范:
* - 24 x 24 viewBox,线性描边(stroke-width 1.8),圆角端点
* - 通过 CSS background-image 的 base64 SVG 渲染,H5 / App / 小程序一致
* - 颜色运行时注入,天然自适应主题色
*
* 全站禁止使用 emoji,一律使用 <hq-icon name="..." />。
* 后端若返回 emoji(历史数据),由 resolveIcon() 兜底映射为矢量图标名。
*/
const PATHS = {
flower:
'<circle cx="12" cy="12" r="2.6"/><circle cx="12" cy="5.4" r="2.9"/><circle cx="18.6" cy="12" r="2.9"/><circle cx="12" cy="18.6" r="2.9"/><circle cx="5.4" cy="12" r="2.9"/>',
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:
'<circle cx="12" cy="12" r="4"/><path d="M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6l1.4 1.4M17 17l1.4 1.4M18.4 5.6 17 7M7 17l-1.4 1.4"/>',
'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:
'<rect x="3.4" y="5" width="17.2" height="15.6" rx="2.6"/><path d="M3.4 9.6h17.2M8.2 2.8v3.4M15.8 2.8v3.4M8.4 14.2h2.2M13.4 14.2h2.2"/>',
'clock':
'<circle cx="12" cy="12" r="8.6"/><path d="M12 7.4v4.9l3.2 1.9"/>',
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:
'<rect x="5" y="4.6" width="14" height="16.8" rx="2.2"/><path d="M9 4.6V3h6v1.6M8.6 10h6.8M8.6 14h6.8"/>',
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:
'<g transform="rotate(45 12 12)"><rect x="9.4" y="6.6" width="5.2" height="10.4" rx="1.4"/><path d="M10.4 3.6h3.2M12 3.6v3M10.2 9h3.6M10.2 12h3.6M12 17v2.4M9.6 21.4h4.8"/></g>',
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: '<rect x="4.6" y="10.4" width="14.8" height="9.6" rx="2.4"/><path d="M8.2 10.4V8a3.8 3.8 0 0 1 7.6 0v2.4M12 14.4v2"/>',
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: '<circle cx="12" cy="8" r="3.6"/><path d="M4.8 20.4a7.4 7.4 0 0 1 14.4 0"/>',
users:
'<circle cx="9" cy="7.6" r="3.1"/><path d="M2.8 20a6.2 6.2 0 0 1 12.4 0M16.4 4.9a3.1 3.1 0 0 1 0 5.9M18.4 20a5.6 5.6 0 0 0-2.2-4.5"/>',
gift: '<rect x="3.6" y="8.6" width="16.8" height="4.6" rx="1.4"/><path d="M5.2 13.2v7.2h13.6v-7.2M12 8.6v11.8M12 8.6C9 8.6 7 7.4 7 5.8A2.2 2.2 0 0 1 9.4 3.6c1.8 0 2.6 2.2 2.6 5zM12 8.6c3 0 5-1.2 5-2.8a2.2 2.2 0 0 0-2.4-2.2c-1.8 0-2.6 2.2-2.6 5z"/>',
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: '<rect x="7" y="2.6" width="10" height="18.8" rx="2.4"/><path d="M10.6 5.4h2.8"/>',
wallet: '<rect x="3.4" y="6" width="17.2" height="12.4" rx="2.4"/><path d="M15.6 12.2H21v3.6h-5.4a1.8 1.8 0 0 1 0-3.6z"/>',
chart: 'M4.4 4.2v15.6h15.4M8.4 16.4v-4M12.2 16.4V9.2M16 16.4v-2.6',
target:
'<circle cx="12" cy="12" r="8.4"/><circle cx="12" cy="12" r="4.4"/><circle cx="12" cy="12" r="1"/>',
'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: '<circle cx="7.4" cy="17.6" r="2.4"/><circle cx="17.4" cy="15.6" r="2.4"/><path d="M9.8 17.6V6.4l10-2v11.2"/>',
baby: '<circle cx="12" cy="12" r="8.6"/><path d="M9 10.4v.2M15 10.4v.2M8.6 14.6a4.6 4.6 0 0 0 6.8 0"/>',
blocks:
'<rect x="3.4" y="3.4" width="7.2" height="7.2" rx="1.6"/><rect x="13.4" y="3.4" width="7.2" height="7.2" rx="1.6"/><rect x="3.4" y="13.4" width="7.2" height="7.2" rx="1.6"/><rect x="13.4" y="13.4" width="7.2" height="7.2" rx="1.6"/>',
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:
'<rect x="3.4" y="4.6" width="17.2" height="14.8" rx="2.2"/><path d="M3.6 16.4l4.6-4.6 3.4 3.4 2.6-2.6 5.8 5.6M15.6 9.4v.2"/>',
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 = '<circle cx="12" cy="12" r="6"/>'
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 数据(不含标签)自动包裹 <path>,含 <circle>/<rect> 的元素原样使用
const body = /^\s*</.test(inner) ? inner : '<path d="' + inner + '"/>'
const svg =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="' +
color +
'" stroke-width="' +
strokeWidth +
'" stroke-linecap="round" stroke-linejoin="round">' +
body +
'</svg>'
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
}