文件
huaqiapp/pages/cycle/index.vue
linda 5ea1b461f3 feat: 花期 V1.0 纵向切片(暖色调设计系统 + 周期/情绪/会员全链路)
前端(uni-app · Vue3)
- 设计系统:uni.scss 品牌令牌(花红 #E8604C / 蜜橙 #F5A65B / 暖米白 #FFF9F5),
  App.vue 全局原子类(卡片/按钮/胶囊/单元格/空态/进度)
- 页面:登录、首页(聚合)、周期(花瓣日历+当日记录+预测+概览)、情绪(记录+趋势+日记+疗愈)、
  我的(资料/会员/隐私/提醒)、健康报告、会员套餐、内容详情
- 组件:hq-tabbar(自定义底栏)、bloom-calendar(阶段日历)
- 基础层:utils/{config,request,store,api,date}.js(统一 token、401 处理、接口集中定义)

后端(FastAdmin / ThinkPHP 5.0)
- 新增 api 控制器:Home / Cycle / Mood / Content / Member / Setting,User 增补 detail、updateprofile
- 新增服务层:CycleService(四阶段计算、预测、月历、汇总)、MemberService(权益判定)
- 新增表:fa_cycle / fa_cycle_log / fa_symptom_tag / fa_mood_log / fa_content /
  fa_content_category / fa_member_plan / fa_member_order / fa_user_setting
- 初始化数据:20 个症状标签、28 条内容(心语/科普/知识/食谱/运动/睡眠/痛经/冥想)、3 档会员

验证(全部通过)
- 接口全链路 48 项断言(登录→周期→首页→情绪→内容→会员→设置→资料)
- 前后端契约静态校验 24 个接口 0 偏差
- Vue SFC 编译 11/11、SCSS 编译 10/10
- 验证脚本见 scripts/verify/,报告见 docs/04-前端设计系统与联调验证.md
2026-11-05 22:54:02 +08:00

696 行
15 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="hq-page">
<!-- 月份切换 -->
<view class="month-bar">
<view class="month-nav" @tap="changeMonth(-1)">
<text class="month-nav-text">‹</text>
</view>
<view class="month-title">
<text class="month-title-text">{{ monthLabel }}</text>
<text class="month-title-sub" v-if="cycle.has_data">{{ cycle.phase_text }} · 周期第 {{ cycle.day }} 天</text>
</view>
<view class="month-nav" @tap="changeMonth(1)">
<text class="month-nav-text">›</text>
</view>
</view>
<!-- 花瓣日历 -->
<bloom-calendar :days="days" :month="month" :selected="selected" @select="selectDay" />
<!-- 选中日详情 + 记录 -->
<view class="hq-card day-card">
<view class="day-head">
<view class="day-head-left">
<text class="day-date">{{ selectedLabel }}</text>
<text class="day-week">{{ selectedWeek }}</text>
</view>
<view class="day-phase" :style="{ backgroundColor: phaseColor + '1A', color: phaseColor }">
<text class="day-phase-text">{{ phaseText }}</text>
</view>
</view>
<view class="hq-divider"></view>
<!-- 经血量 -->
<view class="field">
<text class="field-label">经血量</text>
<view class="chip-row">
<view
v-for="item in flowOptions"
:key="item.value"
class="hq-chip"
:class="{ 'hq-chip-active': form.flow === item.value }"
@tap="form.flow = item.value"
>
<text class="chip-text">{{ item.label }}</text>
</view>
</view>
</view>
<!-- 痛经程度 -->
<view class="field">
<text class="field-label">痛经程度</text>
<view class="pain-row">
<view
v-for="n in 5"
:key="n"
class="pain-dot"
:class="{ 'pain-dot-active': form.pain_level >= n }"
@tap="form.pain_level = form.pain_level === n ? 0 : n"
></view>
<text class="pain-text">{{ painLabel }}</text>
</view>
</view>
<!-- 症状标签 -->
<view class="field">
<text class="field-label">身体感受</text>
<view class="chip-row">
<view
v-for="tag in tags"
:key="tag.id"
class="hq-chip"
:class="{ 'hq-chip-active': form.symptom_ids.indexOf(tag.id) > -1 }"
@tap="toggleTag(tag.id)"
>
<text class="chip-text">{{ tag.icon }} {{ tag.name }}</text>
</view>
</view>
</view>
<!-- 情绪 & 睡眠 -->
<view class="two-col">
<view class="col">
<text class="field-label">心情</text>
<view class="mood-row">
<view
v-for="m in moodOptions"
:key="m.value"
class="mood-btn"
: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>
</view>
</view>
</view>
<view class="col">
<text class="field-label">睡眠(小时)</text>
<view class="sleep-row">
<view class="sleep-btn" @tap="changeSleep(-0.5)"><text class="sleep-btn-text">−</text></view>
<text class="sleep-value">{{ form.sleep_hours || '—' }}</text>
<view class="sleep-btn" @tap="changeSleep(0.5)"><text class="sleep-btn-text">+</text></view>
</view>
</view>
</view>
<!-- 备注 -->
<view class="field">
<text class="field-label">备注</text>
<input
class="note-input"
v-model="form.note"
placeholder="今天身体的感觉,想对自己说点什么…"
placeholder-class="note-placeholder"
maxlength="500"
/>
</view>
<view class="hq-btn save-btn" @tap="saveLog">
<text class="save-btn-text">{{ saving ? '保存中…' : '保存今日记录' }}</text>
</view>
</view>
<!-- 记录经期 -->
<view class="hq-card">
<view class="hq-section-head">
<text class="hq-section-title">记录经期</text>
<text class="hq-muted">用于预测,可随时修改</text>
</view>
<view class="cycle-form">
<picker mode="date" :value="cycleForm.start_date" :end="today" @change="onStartChange">
<view class="date-picker">
<text class="date-picker-label">开始</text>
<text class="date-picker-value">{{ cycleForm.start_date || '选择日期' }}</text>
</view>
</picker>
<picker mode="date" :value="cycleForm.end_date" :end="today" @change="onEndChange">
<view class="date-picker">
<text class="date-picker-label">结束</text>
<text class="date-picker-value">{{ cycleForm.end_date || '选择日期' }}</text>
</view>
</picker>
</view>
<view class="hq-btn-ghost cycle-save" @tap="saveCycle">
<text class="cycle-save-text">保存经期</text>
</view>
</view>
<!-- 周期概览 -->
<view class="hq-card">
<view class="hq-section-head">
<text class="hq-section-title">我的周期</text>
<text class="hq-section-more" @tap="goReport">健康报告 ›</text>
</view>
<view class="stat-row">
<view class="stat">
<text class="stat-value">{{ summary.cycle_length || 28 }}</text>
<text class="stat-label">平均周期(天)</text>
</view>
<view class="stat">
<text class="stat-value">{{ summary.period_length || 5 }}</text>
<text class="stat-label">经期(天)</text>
</view>
<view class="stat">
<text class="stat-value">{{ summary.regularity || 0 }}</text>
<text class="stat-label">{{ summary.regularity_text || '规律性' }}</text>
</view>
</view>
</view>
<!-- 预测 -->
<view class="hq-card" v-if="predict.list && predict.list.length">
<view class="hq-section-head">
<text class="hq-section-title">未来经期预测</text>
</view>
<view class="predict-item" v-for="(p, i) in predict.list" :key="i">
<view class="predict-left">
<text class="predict-date">{{ p.start }} ~ {{ p.end }}</text>
<text class="predict-sub">排卵日 {{ p.ovulation }} · 易孕 {{ p.fertile_start }} 至 {{ p.fertile_end }}</text>
</view>
<text class="predict-tag">{{ p.days_from_now > 0 ? p.days_from_now + ' 天后' : '已过期' }}</text>
</view>
</view>
<view class="footer">
<text class="footer-text">预测基于历史记录推算,仅供参考</text>
</view>
<hq-tabbar current="cycle" />
</view>
</template>
<script>
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 bloomCalendar from '@/components/bloom-calendar/bloom-calendar.vue'
import hqTabbar from '@/components/hq-tabbar/hq-tabbar.vue'
const EMPTY_FORM = () => ({
flow: 0,
pain_level: 0,
symptom_ids: [],
mood: 0,
sleep_hours: null,
note: ''
})
export default {
components: { bloomCalendar, hqTabbar },
data() {
return {
month: monthOf(new Date()),
days: [],
cycle: {},
selected: todayStr(),
tags: [],
form: EMPTY_FORM(),
summary: {},
predict: { list: [] },
cycleForm: { start_date: '', end_date: '' },
today: todayStr(),
saving: false,
flowOptions: [
{ label: '无', value: 0 },
{ label: '少量', value: 1 },
{ label: '中等', value: 2 },
{ label: '较多', value: 3 }
],
moodOptions: [
{ emoji: '😞', value: -2 },
{ emoji: '🌧', value: -1 },
{ emoji: '🌤', value: 0 },
{ emoji: '☀️', value: 1 },
{ emoji: '🌻', value: 2 }
]
}
},
computed: {
monthLabel() {
return monthText(this.month)
},
selectedLabel() {
return dayText(this.selected)
},
selectedWeek() {
return weekText(this.selected)
},
selectedDay() {
return this.days.find((d) => d.date === this.selected) || {}
},
phaseText() {
return this.selectedDay.phase_text || '待记录'
},
phaseColor() {
return this.selectedDay.color || '#C79A7B'
},
painLabel() {
const map = { 0: '无痛', 1: '轻微', 2: '可忍', 3: '明显', 4: '较重', 5: '难忍' }
return map[this.form.pain_level] || '无痛'
}
},
onShow() {
if (!store.token) {
uni.reLaunch({ url: '/pages/login/index' })
return
}
this.load()
},
onPullDownRefresh() {
this.load().finally(() => uni.stopPullDownRefresh())
},
methods: {
async load() {
try {
const [cal, summary, predict] = await Promise.all([
api.cycleCalendar(this.month),
api.cycleSummary(),
api.cyclePredict()
])
this.days = (cal && cal.list) || []
this.cycle = (cal && cal.cycle) || {}
this.summary = summary || {}
this.predict = predict || { list: [] }
await this.loadDay(this.selected)
if (this.cycle.has_data && !this.cycleForm.start_date) {
this.cycleForm.start_date = this.cycle.start_date
this.cycleForm.end_date = this.cycle.start_date
}
} catch (e) {}
},
async loadDay(date) {
this.selected = date
try {
const data = await api.cycleLogInfo(date)
this.tags = (data && data.tags) || []
const log = (data && data.log) || {}
this.form = {
flow: log.flow || 0,
pain_level: log.pain_level || 0,
symptom_ids: Array.isArray(log.symptom_ids) ? log.symptom_ids : [],
mood: log.mood || 0,
sleep_hours: log.sleep_hours ? Number(log.sleep_hours) : null,
note: log.note || ''
}
} catch (e) {}
},
changeMonth(delta) {
this.month = addMonths(this.month, delta)
this.load()
},
selectDay(day) {
this.loadDay(day.date)
},
toggleTag(id) {
const index = this.form.symptom_ids.indexOf(id)
if (index > -1) {
this.form.symptom_ids.splice(index, 1)
} else {
this.form.symptom_ids.push(id)
}
},
changeSleep(delta) {
const current = this.form.sleep_hours === null ? 7 : this.form.sleep_hours
let next = Math.round((current + delta) * 2) / 2
next = Math.min(14, Math.max(0, next))
this.form.sleep_hours = next
},
async saveLog() {
if (this.saving) return
this.saving = true
try {
await api.cycleLog({
log_date: this.selected,
flow: this.form.flow,
pain_level: this.form.pain_level,
symptom_ids: this.form.symptom_ids.join(','),
mood: this.form.mood,
sleep_hours: this.form.sleep_hours === null ? '' : this.form.sleep_hours,
note: this.form.note
})
uni.showToast({ title: '已保存', icon: 'none' })
this.load()
} catch (e) {
} finally {
this.saving = false
}
},
onStartChange(e) {
this.cycleForm.start_date = e.detail.value
if (!this.cycleForm.end_date || this.cycleForm.end_date < this.cycleForm.start_date) {
this.cycleForm.end_date = this.cycleForm.start_date
}
},
onEndChange(e) {
this.cycleForm.end_date = e.detail.value
},
async saveCycle() {
if (!this.cycleForm.start_date) {
uni.showToast({ title: '请选择开始日期', icon: 'none' })
return
}
try {
await api.cycleSave({
start_date: this.cycleForm.start_date,
end_date: this.cycleForm.end_date || this.cycleForm.start_date
})
uni.showToast({ title: '经期已记录', icon: 'none' })
this.load()
} catch (e) {}
},
goReport() {
uni.navigateTo({ url: '/pages/cycle/report?month=' + this.month })
}
}
}
</script>
<style lang="scss" scoped>
.month-bar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 0 24rpx;
}
.month-nav {
width: 72rpx;
height: 72rpx;
border-radius: 24rpx;
background-color: #FFFFFF;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 24rpx rgba(232, 96, 76, 0.08);
}
.month-nav-text {
font-size: 36rpx;
color: #E8604C;
line-height: 1;
}
.month-title {
display: flex;
flex-direction: column;
align-items: center;
}
.month-title-text {
font-size: 34rpx;
font-weight: 600;
color: #3E2C27;
letter-spacing: 2rpx;
}
.month-title-sub {
margin-top: 4rpx;
font-size: 22rpx;
color: #8C7367;
}
.day-card {
margin-top: 24rpx;
}
.day-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.day-head-left {
display: flex;
align-items: baseline;
}
.day-date {
font-size: 34rpx;
font-weight: 600;
color: #3E2C27;
}
.day-week {
margin-left: 12rpx;
font-size: 24rpx;
color: #8C7367;
}
.day-phase {
padding: 8rpx 22rpx;
border-radius: 999rpx;
}
.day-phase-text {
font-size: 22rpx;
font-weight: 500;
}
.field {
margin-top: 24rpx;
}
.field-label {
font-size: 26rpx;
color: #8C7367;
margin-bottom: 16rpx;
display: block;
}
.chip-row {
display: flex;
flex-wrap: wrap;
}
.chip-text {
font-size: 24rpx;
}
.pain-row {
display: flex;
align-items: center;
}
.pain-dot {
width: 44rpx;
height: 12rpx;
border-radius: 999rpx;
background-color: #F5E7DF;
margin-right: 10rpx;
}
.pain-dot-active {
background: linear-gradient(90deg, #F5A65B 0%, #E8604C 100%);
}
.pain-text {
margin-left: 12rpx;
font-size: 22rpx;
color: #B9A79E;
}
.two-col {
display: flex;
margin-top: 24rpx;
}
.col {
flex: 1;
}
.mood-row {
display: flex;
align-items: center;
}
.mood-btn {
width: 64rpx;
height: 64rpx;
border-radius: 20rpx;
background-color: #FFF4EE;
display: flex;
align-items: center;
justify-content: center;
margin-right: 10rpx;
}
.mood-btn-active {
background-color: #FFE6DC;
border: 2rpx solid #E8604C;
}
.mood-emoji {
font-size: 30rpx;
}
.sleep-row {
display: flex;
align-items: center;
}
.sleep-btn {
width: 56rpx;
height: 56rpx;
border-radius: 18rpx;
background-color: #FFF4EE;
display: flex;
align-items: center;
justify-content: center;
}
.sleep-btn-text {
font-size: 28rpx;
color: #E8604C;
line-height: 1;
}
.sleep-value {
width: 90rpx;
text-align: center;
font-size: 28rpx;
color: #3E2C27;
}
.note-input {
height: 88rpx;
padding: 0 24rpx;
background-color: #FFF9F5;
border-radius: 20rpx;
font-size: 26rpx;
color: #3E2C27;
}
.note-placeholder {
color: #C9B4AA;
font-size: 24rpx;
}
.save-btn {
margin-top: 32rpx;
}
.save-btn-text {
font-size: 30rpx;
color: #FFFFFF;
letter-spacing: 2rpx;
}
.cycle-form {
display: flex;
justify-content: space-between;
}
.date-picker {
flex: 1;
background-color: #FFF9F5;
border-radius: 20rpx;
padding: 20rpx 24rpx;
margin-right: 16rpx;
display: flex;
flex-direction: column;
}
.date-picker-label {
font-size: 22rpx;
color: #B9A79E;
}
.date-picker-value {
margin-top: 6rpx;
font-size: 28rpx;
color: #3E2C27;
}
.cycle-save {
margin-top: 24rpx;
height: 80rpx;
}
.cycle-save-text {
font-size: 28rpx;
color: #E8604C;
}
.stat-row {
display: flex;
align-items: center;
}
.stat {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
}
.stat-value {
font-size: 44rpx;
font-weight: 600;
color: #E8604C;
}
.stat-label {
margin-top: 4rpx;
font-size: 22rpx;
color: #8C7367;
}
.predict-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20rpx 0;
}
.predict-item + .predict-item {
border-top: 2rpx solid #F5E7DF;
}
.predict-left {
flex: 1;
display: flex;
flex-direction: column;
}
.predict-date {
font-size: 28rpx;
color: #3E2C27;
}
.predict-sub {
margin-top: 4rpx;
font-size: 22rpx;
color: #B9A79E;
}
.predict-tag {
font-size: 22rpx;
color: #E8604C;
background-color: #FFF1E9;
padding: 6rpx 16rpx;
border-radius: 999rpx;
}
.footer {
padding: 8rpx 0 24rpx;
text-align: center;
}
.footer-text {
font-size: 20rpx;
color: #C9B4AA;
}
</style>