优化页面展示

This commit is contained in:
gs committed 2026-09-26 03:58:48 +08:00
1 parent cbcd6b4c7f
commit 1ed38c6648
67 files changed
+4484 -370

No files matched your search

+2 -2
View File
@@ -1,9 +1,9 @@
<script setup lang="ts">
const tabs = [
{ to: '/today', label: '今日' },
{ to: '/timeline', label: '流水' },
{ to: '/timeline', label: '记录' },
{ to: '/stats', label: '统计' },
{ to: '/settings', label: '设置' }
{ to: '/settings', label: '家庭' }
]
</script>
+20 -4
View File
@@ -10,6 +10,7 @@ import type {
FamilyInfo,
FamilyMember,
FeedingMethod,
ServerTimeInfo,
UpdateCareRecordPayload,
UpdateFamilyPayload,
UpdateMemberPayload
@@ -98,15 +99,23 @@ export function getDailySummary(babyId: string) {
return request<DailySummary>(`/api/v1/summary/daily?babyId=${encodeURIComponent(babyId)}`)
}
export function getRecords(babyId: string) {
return request<CareRecord[]>(`/api/v1/records?babyId=${encodeURIComponent(babyId)}`)
export function getRecords(babyId: string, date?: string) {
const query = date
? `/api/v1/records?babyId=${encodeURIComponent(babyId)}&date=${encodeURIComponent(date)}`
: `/api/v1/records?babyId=${encodeURIComponent(babyId)}`
return request<CareRecord[]>(query)
}
export function createFeeding(payload: {
babyId: string
feedingMethod: FeedingMethod
amountMl?: number
breastSide?: 'left' | 'right'
breastSide?: string
durationMinutes?: number
feedingTime?: string
endTime?: string
leftDurationMinutes?: number
rightDurationMinutes?: number
operatorName: string
remark?: string
note?: string
@@ -135,7 +144,9 @@ export function startFeeding(payload: {
export function endFeeding(payload: {
babyId: string
breastSide: 'left' | 'right'
breastSide?: 'left' | 'right'
leftDurationMinutes?: number
rightDurationMinutes?: number
operatorName: string
remark?: string
note?: string
@@ -197,3 +208,8 @@ export function updateRecord(recordId: string, payload: UpdateCareRecordPayload)
body: JSON.stringify({ ...payload, recordId })
})
}
export function getServerTime() {
return request<ServerTimeInfo>('/api/v1/system/time')
}
@@ -2,6 +2,7 @@
import { onMounted, reactive, ref, watch } from 'vue'
import { showToast } from 'vant'
import { useCareStore } from '../../stores/careStore'
import { getLocalDateStr } from '../../utils/format'
const store = useCareStore()
@@ -18,7 +19,7 @@ const showAddBabyModal = ref(false)
const newBabyForm = reactive({
name: '',
gender: 'boy',
birthDate: new Date().toISOString().slice(0, 10),
birthDate: getLocalDateStr(store.getServerNow()),
deliveryType: 'natural',
isDefault: false
})
@@ -58,7 +59,7 @@ async function saveBaby() {
function openAddBabyModal() {
newBabyForm.name = ''
newBabyForm.gender = 'boy'
newBabyForm.birthDate = new Date().toISOString().slice(0, 10)
newBabyForm.birthDate = getLocalDateStr(store.getServerNow())
newBabyForm.deliveryType = 'natural'
newBabyForm.isDefault = false
showAddBabyModal.value = true
@@ -158,11 +159,18 @@ async function handleSetDefaultBaby(babyId: string) {
</div>
<!-- 弹窗:添加新宝宝 -->
<div v-if="showAddBabyModal" class="modal-backdrop" @click.self="showAddBabyModal = false">
<div class="modal-sheet">
<van-popup
v-model:show="showAddBabyModal"
position="bottom"
round
safe-area-inset-bottom
teleport="body"
class="timeline-modal-popup"
>
<div class="modal-sheet-inner">
<div class="modal-header">
<h3>添加宝宝档案</h3>
<button class="close-btn" @click="showAddBabyModal = false">×</button>
<button class="close-btn" type="button" @click="showAddBabyModal = false">×</button>
</div>
<div class="modal-form">
<label>
@@ -192,11 +200,11 @@ async function handleSetDefaultBaby(babyId: string) {
<label for="setDefCheck" style="font-size: 14px; cursor: pointer; color: #1f2933;">设为当前默认关注的宝宝</label>
</div>
<div class="modal-actions">
<button class="secondary-button" @click="showAddBabyModal = false">取消</button>
<button class="save-button" @click="submitAddBaby">确认添加</button>
<button class="secondary-button" type="button" @click="showAddBabyModal = false">取消</button>
<button class="save-button" type="button" @click="submitAddBaby">确认添加</button>
</div>
</div>
</div>
</div>
</van-popup>
</section>
</template>
@@ -135,11 +135,18 @@ function selectOperator(name: string) {
</div>
<!-- 弹窗:添加/编辑家庭成员 -->
<div v-if="showMemberModal" class="modal-backdrop" @click.self="showMemberModal = false">
<div class="modal-sheet">
<van-popup
v-model:show="showMemberModal"
position="bottom"
round
safe-area-inset-bottom
teleport="body"
class="timeline-modal-popup"
>
<div class="modal-sheet-inner">
<div class="modal-header">
<h3>{{ isEditingMember ? '修改照护成员' : '添加照护成员' }}</h3>
<button class="close-btn" @click="showMemberModal = false">×</button>
<button class="close-btn" type="button" @click="showMemberModal = false">×</button>
</div>
<div class="modal-form">
<label>
@@ -174,13 +181,13 @@ function selectOperator(name: string) {
<label for="defOpCheck" style="font-size: 14px; cursor: pointer; color: #1f2933;">设为默认记录人</label>
</div>
<div class="modal-actions">
<button class="secondary-button" @click="showMemberModal = false">取消</button>
<button class="save-button" @click="submitMember">
<button class="secondary-button" type="button" @click="showMemberModal = false">取消</button>
<button class="save-button" type="button" @click="submitMember">
{{ isEditingMember ? '保存修改' : '确认添加' }}
</button>
</div>
</div>
</div>
</div>
</van-popup>
</section>
</template>
@@ -2,6 +2,7 @@
import { reactive, watch } from 'vue'
import { showToast } from 'vant'
import { useCareStore } from '../../stores/careStore'
import { parseFeedingSplitInfo } from '../../utils/format'
import type { CareRecord, ExcretionType, FeedingMethod, RecordType } from '../../types/domain'
const props = defineProps<{
@@ -28,7 +29,9 @@ const editForm = reactive({
durationMinutes: null as number | null,
feedingMethod: 'breastfeed' as FeedingMethod,
amountMl: null as number | null,
breastSide: 'left' as 'left' | 'right',
breastMode: 'both' as 'left' | 'right' | 'both',
leftMinutes: null as number | null,
rightMinutes: null as number | null,
excretionType: 'pee' as ExcretionType,
operatorName: '',
note: ''
@@ -60,11 +63,104 @@ function initFromRecord(record: CareRecord) {
editForm.durationMinutes = record.durationMinutes || null
editForm.feedingMethod = (record.feedingMethod as FeedingMethod) || 'breastfeed'
editForm.amountMl = record.amountMl || null
const noteStr = record.note || record.remark || ''
editForm.breastSide = noteStr.includes('右侧') ? 'right' : 'left'
const splitInfo = (record.leftDurationMinutes != null || record.rightDurationMinutes != null)
? { leftMinutes: record.leftDurationMinutes ?? undefined, rightMinutes: record.rightDurationMinutes ?? undefined }
: parseFeedingSplitInfo(noteStr, record.durationMinutes)
if (splitInfo?.leftMinutes && splitInfo?.rightMinutes) {
editForm.breastMode = 'both'
editForm.leftMinutes = splitInfo.leftMinutes
editForm.rightMinutes = splitInfo.rightMinutes
} else if (splitInfo?.leftMinutes) {
editForm.breastMode = 'left'
editForm.leftMinutes = splitInfo.leftMinutes
editForm.rightMinutes = null
} else if (splitInfo?.rightMinutes) {
editForm.breastMode = 'right'
editForm.rightMinutes = splitInfo.rightMinutes
editForm.leftMinutes = null
} else {
editForm.breastMode = noteStr.includes('右侧') ? 'right' : 'left'
if (record.durationMinutes) {
if (editForm.breastMode === 'left') editForm.leftMinutes = record.durationMinutes
else editForm.rightMinutes = record.durationMinutes
}
}
editForm.excretionType = (record.excretionType as ExcretionType) || 'pee'
editForm.operatorName = record.operatorName || store.operatorName
editForm.note = noteStr
// 清理前置亲喂标签,保留真实备注
editForm.note = noteStr.replace(/亲喂侧:[^;;]+[;;]?\s*/g, '').trim()
if (editForm.recordType === 'feeding' && editForm.feedingMethod === 'breastfeed' && !editForm.hasEndTime && editForm.durationMinutes) {
autoUpdateEndTime()
}
}
function handleBreastModeChange(mode: 'left' | 'right' | 'both') {
editForm.breastMode = mode
const currentTotal = editForm.durationMinutes || 20
if (mode === 'both') {
editForm.leftMinutes = Math.floor(currentTotal / 2) || 10
editForm.rightMinutes = Math.ceil(currentTotal / 2) || 10
editForm.durationMinutes = (editForm.leftMinutes || 0) + (editForm.rightMinutes || 0)
} else if (mode === 'left') {
editForm.leftMinutes = currentTotal || 20
editForm.rightMinutes = null
editForm.durationMinutes = editForm.leftMinutes
} else {
editForm.rightMinutes = currentTotal || 20
editForm.leftMinutes = null
editForm.durationMinutes = editForm.rightMinutes
}
autoUpdateEndTime()
}
function onSplitMinutesChange() {
if (editForm.breastMode === 'both') {
editForm.durationMinutes = (editForm.leftMinutes || 0) + (editForm.rightMinutes || 0)
} else if (editForm.breastMode === 'left') {
editForm.durationMinutes = editForm.leftMinutes || 0
} else {
editForm.durationMinutes = editForm.rightMinutes || 0
}
autoUpdateEndTime()
}
function onTotalDurationChange() {
const total = editForm.durationMinutes || 0
if (editForm.breastMode === 'both') {
editForm.leftMinutes = Math.floor(total / 2)
editForm.rightMinutes = Math.ceil(total / 2)
} else if (editForm.breastMode === 'left') {
editForm.leftMinutes = total
editForm.rightMinutes = null
} else {
editForm.rightMinutes = total
editForm.leftMinutes = null
}
autoUpdateEndTime()
}
function autoUpdateEndTime() {
if (!editForm.startDate || !editForm.startTimeStr || !editForm.durationMinutes) return
try {
const startMs = new Date(`${editForm.startDate}T${editForm.startTimeStr}:00`).getTime()
if (isNaN(startMs)) return
const endMs = startMs + editForm.durationMinutes * 60000
const endDateObj = new Date(endMs)
const y = endDateObj.getFullYear()
const m = String(endDateObj.getMonth() + 1).padStart(2, '0')
const d = String(endDateObj.getDate()).padStart(2, '0')
const hh = String(endDateObj.getHours()).padStart(2, '0')
const mm = String(endDateObj.getMinutes()).padStart(2, '0')
editForm.endDate = `${y}-${m}-${d}`
editForm.endTimeStr = `${hh}:${mm}`
editForm.hasEndTime = true
} catch {
// ignore
}
}
function appendNote(tag: string) {
@@ -83,13 +179,7 @@ async function submitEdit() {
endTime = `${editForm.endDate}T${editForm.endTimeStr}:00`
}
let finalNote = editForm.note
if (editForm.recordType === 'feeding' && editForm.feedingMethod === 'breastfeed' && editForm.breastSide) {
const sideText = editForm.breastSide === 'left' ? '左侧' : '右侧'
if (!finalNote.includes('亲喂侧')) {
finalNote = `亲喂侧: ${sideText}${finalNote ? ';' + finalNote : ''}`
}
}
const finalNote = editForm.note.trim()
try {
await store.editRecord(props.record.recordId, {
@@ -97,6 +187,8 @@ async function submitEdit() {
startTime,
endTime,
durationMinutes: editForm.durationMinutes,
leftDurationMinutes: editForm.recordType === 'feeding' && editForm.feedingMethod === 'breastfeed' ? (editForm.breastMode === 'right' ? null : editForm.leftMinutes) : null,
rightDurationMinutes: editForm.recordType === 'feeding' && editForm.feedingMethod === 'breastfeed' ? (editForm.breastMode === 'left' ? null : editForm.rightMinutes) : null,
feedingMethod: editForm.recordType === 'feeding' ? editForm.feedingMethod : null,
amountMl: editForm.recordType === 'feeding' && editForm.feedingMethod !== 'breastfeed' ? editForm.amountMl : null,
excretionType: editForm.recordType === 'excretion' ? editForm.excretionType : null,
@@ -113,11 +205,19 @@ async function submitEdit() {
</script>
<template>
<div v-if="props.show" class="modal-backdrop" @click.self="emit('update:show', false)">
<div class="modal-sheet">
<van-popup
:show="props.show"
position="bottom"
round
safe-area-inset-bottom
teleport="body"
class="timeline-modal-popup"
@update:show="(val: boolean) => emit('update:show', val)"
>
<div class="modal-sheet-inner">
<div class="modal-header">
<h3>编辑照护记录</h3>
<button class="close-btn" @click="emit('update:show', false)">×</button>
<button class="close-btn" type="button" @click="emit('update:show', false)">×</button>
</div>
<div class="modal-form">
@@ -152,19 +252,19 @@ async function submitEdit() {
</div>
</label>
<!-- 发生时间 -->
<!-- 开始起止时间设置 -->
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px;">
<label>
开始日期
<input v-model="editForm.startDate" type="date" />
<input v-model="editForm.startDate" type="date" @change="autoUpdateEndTime" />
</label>
<label>
开始时间
<input v-model="editForm.startTimeStr" type="time" />
<input v-model="editForm.startTimeStr" type="time" @change="autoUpdateEndTime" />
</label>
</div>
<!-- 喂奶特定字段 -->
<!-- 喂奶专属表单 -->
<template v-if="editForm.recordType === 'feeding'">
<label>
喂养方式
@@ -176,77 +276,72 @@ async function submitEdit() {
</select>
</label>
<div v-if="editForm.feedingMethod === 'breastfeed'">
<label>
亲喂侧
<!-- 亲喂:侧别与分侧耗时 -->
<div v-if="editForm.feedingMethod === 'breastfeed'" style="background: #faf7f2; border: 1px solid #eee5d8; border-radius: 12px; padding: 12px;">
<label style="margin-bottom: 8px;">
亲喂模式
<div class="chip-group">
<button
type="button"
class="chip sm"
:class="{ active: editForm.breastSide === 'left' }"
@click="editForm.breastSide = 'left'"
:class="{ active: editForm.breastMode === 'both' }"
@click="handleBreastModeChange('both')"
>
左侧
双侧 (左右各喂)
</button>
<button
type="button"
class="chip sm"
:class="{ active: editForm.breastSide === 'right' }"
@click="editForm.breastSide = 'right'"
:class="{ active: editForm.breastMode === 'left' }"
@click="handleBreastModeChange('left')"
>
右侧
仅左侧
</button>
<button
type="button"
class="chip sm"
:class="{ active: editForm.breastMode === 'right' }"
@click="handleBreastModeChange('right')"
>
仅右侧
</button>
</div>
</label>
</div>
<div v-else>
<label>
奶量 (ml)
<div style="display: flex; gap: 8px; align-items: center;">
<input v-model.number="editForm.amountMl" type="number" placeholder="输入奶量 ml" />
<div class="chip-group" style="margin: 0;">
<button
v-for="amt in [30, 60, 90, 120]"
:key="amt"
type="button"
class="chip sm"
:class="{ active: editForm.amountMl === amt }"
@click="editForm.amountMl = amt"
>
{{ amt }}
</button>
</div>
</div>
</label>
</div>
</template>
<!-- 分侧耗时 -->
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px;">
<label v-if="editForm.breastMode === 'left' || editForm.breastMode === 'both'">
左侧耗时 (分钟)
<input v-model.number="editForm.leftMinutes" type="number" min="0" max="120" placeholder="分钟" @input="onSplitMinutesChange" />
</label>
<label v-if="editForm.breastMode === 'right' || editForm.breastMode === 'both'">
右侧耗时 (分钟)
<input v-model.number="editForm.rightMinutes" type="number" min="0" max="120" placeholder="分钟" @input="onSplitMinutesChange" />
</label>
</div>
<!-- 睡眠特定字段 -->
<template v-if="editForm.recordType === 'sleep'">
<div style="display: flex; align-items: center; gap: 8px; margin: 4px 0;">
<input id="editHasEnd" v-model="editForm.hasEndTime" type="checkbox" style="width: 18px; height: 18px;" />
<label for="editHasEnd" style="font-size: 14px; cursor: pointer; color: #1f2933;">包含醒来结束时间</label>
</div>
<div v-if="editForm.hasEndTime" style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px;">
<label>
醒来日期
<input v-model="editForm.endDate" type="date" />
</label>
<label>
醒来时间
<input v-model="editForm.endTimeStr" type="time" />
<!-- 总时长 -->
<label style="margin-top: 8px;">
亲喂总时长 (分钟)
<input v-model.number="editForm.durationMinutes" type="number" min="1" max="180" @input="onTotalDurationChange" />
</label>
</div>
<label v-if="!editForm.hasEndTime">
睡眠持续时间 (分钟,可选)
<input v-model.number="editForm.durationMinutes" type="number" placeholder="例如:45" />
<label v-else>
单次奶量 (ml)
<input v-model.number="editForm.amountMl" type="number" min="5" max="400" step="5" />
</label>
</template>
<!-- 排泄特定字段 -->
<!-- 睡眠专属表单 -->
<template v-if="editForm.recordType === 'sleep'">
<label>
睡眠时长 (分钟)
<input v-model.number="editForm.durationMinutes" type="number" min="1" placeholder="留空则按起止时间自动计算" @input="autoUpdateEndTime" />
</label>
</template>
<!-- 排泄专属表单 -->
<template v-if="editForm.recordType === 'excretion'">
<label>
排泄类型
@@ -257,7 +352,7 @@ async function submitEdit() {
:class="{ active: editForm.excretionType === 'pee' }"
@click="editForm.excretionType = 'pee'"
>
💧 嘘嘘 (尿尿)
💧 小便 (尿尿)
</button>
<button
type="button"
@@ -265,13 +360,31 @@ async function submitEdit() {
:class="{ active: editForm.excretionType === 'poop' }"
@click="editForm.excretionType = 'poop'"
>
💩 便便 (大便)
💩 大便 (便便)
</button>
</div>
</label>
</template>
<!-- 记录人选择 -->
<!-- 结束时间(选填/联动) -->
<div style="border-top: 1px dashed #e8e3d8; padding-top: 10px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px;">
<span style="font-size: 13px; font-weight: 700; color: #4b5563;">记录结束时间</span>
<input v-model="editForm.hasEndTime" type="checkbox" style="width: 18px; height: 18px;" />
</div>
<div v-if="editForm.hasEndTime" style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px;">
<label>
结束日期
<input v-model="editForm.endDate" type="date" />
</label>
<label>
结束时间
<input v-model="editForm.endTimeStr" type="time" />
</label>
</div>
</div>
<!-- 记录人 -->
<label>
记录人称谓
<input v-model="editForm.operatorName" placeholder="例如:宝妈、宝爸" />
@@ -307,10 +420,10 @@ async function submitEdit() {
</label>
<div class="modal-actions">
<button class="secondary-button" @click="emit('update:show', false)">取消</button>
<button class="save-button" @click="submitEdit">保存修改</button>
<button class="secondary-button" type="button" @click="emit('update:show', false)">取消</button>
<button class="save-button" type="button" @click="submitEdit">保存修改</button>
</div>
</div>
</div>
</div>
</van-popup>
</template>
@@ -3,6 +3,7 @@ import { reactive, watch } from 'vue'
import { showToast } from 'vant'
import { useCareStore } from '../../stores/careStore'
import type { ExcretionType, FeedingMethod, RecordType } from '../../types/domain'
import { getLocalDateStr, getLocalTimeStr } from '../../utils/format'
const props = defineProps<{
show: boolean
@@ -17,17 +18,20 @@ const store = useCareStore()
const quickNotes = ['拍嗝顺利', '溢奶微量', '金黄色便便', '安睡无闹', '微胀气', '吃得香']
const initialNow = store.getServerNow()
const manualForm = reactive({
recordType: 'feeding' as RecordType,
startDate: new Date().toISOString().slice(0, 10),
startTimeStr: new Date().toTimeString().slice(0, 5),
startDate: getLocalDateStr(initialNow),
startTimeStr: getLocalTimeStr(initialNow),
hasEndTime: false,
endDate: new Date().toISOString().slice(0, 10),
endDate: getLocalDateStr(initialNow),
endTimeStr: '',
durationMinutes: null as number | null,
feedingMethod: 'breastfeed' as FeedingMethod,
amountMl: null as number | null,
breastSide: 'left' as 'left' | 'right',
breastMode: 'both' as 'left' | 'right' | 'both',
leftMinutes: 10 as number | null,
rightMinutes: 10 as number | null,
excretionType: 'pee' as ExcretionType,
operatorName: store.operatorName,
note: ''
@@ -40,20 +44,87 @@ watch(() => props.show, (newVal) => {
})
function initForm() {
const now = new Date()
const now = store.getServerNow()
manualForm.recordType = 'feeding'
manualForm.startDate = now.toISOString().slice(0, 10)
manualForm.startTimeStr = now.toTimeString().slice(0, 5)
manualForm.hasEndTime = false
manualForm.endDate = now.toISOString().slice(0, 10)
manualForm.endTimeStr = ''
manualForm.durationMinutes = null
manualForm.startDate = getLocalDateStr(now)
manualForm.startTimeStr = getLocalTimeStr(now)
manualForm.hasEndTime = true
manualForm.endDate = getLocalDateStr(now)
manualForm.durationMinutes = 20
manualForm.feedingMethod = store.preferences.defaultFeedingMethod || 'breastfeed'
manualForm.amountMl = manualForm.feedingMethod === 'bottle' ? store.preferences.defaultBottleAmount : null
manualForm.breastSide = store.preferences.defaultBreastSide || 'left'
manualForm.amountMl = manualForm.feedingMethod === 'bottle' ? (store.preferences.defaultBottleAmount || 30) : null
manualForm.breastMode = 'both'
manualForm.leftMinutes = 10
manualForm.rightMinutes = 10
manualForm.excretionType = 'pee'
manualForm.operatorName = store.operatorName
manualForm.note = ''
autoUpdateEndTime()
}
function handleBreastModeChange(mode: 'left' | 'right' | 'both') {
manualForm.breastMode = mode
const currentTotal = manualForm.durationMinutes || 20
if (mode === 'both') {
manualForm.leftMinutes = Math.floor(currentTotal / 2) || 10
manualForm.rightMinutes = Math.ceil(currentTotal / 2) || 10
manualForm.durationMinutes = (manualForm.leftMinutes || 0) + (manualForm.rightMinutes || 0)
} else if (mode === 'left') {
manualForm.leftMinutes = currentTotal || 20
manualForm.rightMinutes = null
manualForm.durationMinutes = manualForm.leftMinutes
} else {
manualForm.rightMinutes = currentTotal || 20
manualForm.leftMinutes = null
manualForm.durationMinutes = manualForm.rightMinutes
}
autoUpdateEndTime()
}
function onSplitMinutesChange() {
if (manualForm.breastMode === 'both') {
manualForm.durationMinutes = (manualForm.leftMinutes || 0) + (manualForm.rightMinutes || 0)
} else if (manualForm.breastMode === 'left') {
manualForm.durationMinutes = manualForm.leftMinutes || 0
} else {
manualForm.durationMinutes = manualForm.rightMinutes || 0
}
autoUpdateEndTime()
}
function onTotalDurationChange() {
const total = manualForm.durationMinutes || 0
if (manualForm.breastMode === 'both') {
manualForm.leftMinutes = Math.floor(total / 2)
manualForm.rightMinutes = Math.ceil(total / 2)
} else if (manualForm.breastMode === 'left') {
manualForm.leftMinutes = total
manualForm.rightMinutes = null
} else {
manualForm.rightMinutes = total
manualForm.leftMinutes = null
}
autoUpdateEndTime()
}
function autoUpdateEndTime() {
if (!manualForm.startDate || !manualForm.startTimeStr || !manualForm.durationMinutes) return
try {
const startMs = new Date(`${manualForm.startDate}T${manualForm.startTimeStr}:00`).getTime()
if (isNaN(startMs)) return
const endMs = startMs + manualForm.durationMinutes * 60000
const endDateObj = new Date(endMs)
const y = endDateObj.getFullYear()
const m = String(endDateObj.getMonth() + 1).padStart(2, '0')
const d = String(endDateObj.getDate()).padStart(2, '0')
const hh = String(endDateObj.getHours()).padStart(2, '0')
const mm = String(endDateObj.getMinutes()).padStart(2, '0')
manualForm.endDate = `${y}-${m}-${d}`
manualForm.endTimeStr = `${hh}:${mm}`
manualForm.hasEndTime = true
} catch {
// ignore
}
}
function appendNote(tag: string) {
@@ -71,13 +142,7 @@ async function submitManual() {
endTime = `${manualForm.endDate}T${manualForm.endTimeStr}:00`
}
let finalNote = manualForm.note
if (manualForm.recordType === 'feeding' && manualForm.feedingMethod === 'breastfeed' && manualForm.breastSide) {
const sideText = manualForm.breastSide === 'left' ? '左侧' : '右侧'
if (!finalNote.includes('亲喂侧')) {
finalNote = `亲喂侧: ${sideText}${finalNote ? ';' + finalNote : ''}`
}
}
const finalNote = manualForm.note.trim()
try {
await store.manualLog({
@@ -85,6 +150,8 @@ async function submitManual() {
startTime,
endTime,
durationMinutes: manualForm.durationMinutes,
leftDurationMinutes: manualForm.recordType === 'feeding' && manualForm.feedingMethod === 'breastfeed' ? (manualForm.breastMode === 'right' ? null : manualForm.leftMinutes) : null,
rightDurationMinutes: manualForm.recordType === 'feeding' && manualForm.feedingMethod === 'breastfeed' ? (manualForm.breastMode === 'left' ? null : manualForm.rightMinutes) : null,
feedingMethod: manualForm.recordType === 'feeding' ? manualForm.feedingMethod : null,
amountMl: manualForm.recordType === 'feeding' && manualForm.feedingMethod !== 'breastfeed' ? manualForm.amountMl : null,
excretionType: manualForm.recordType === 'excretion' ? manualForm.excretionType : null,
@@ -101,11 +168,19 @@ async function submitManual() {
</script>
<template>
<div v-if="props.show" class="modal-backdrop" @click.self="emit('update:show', false)">
<div class="modal-sheet">
<van-popup
:show="props.show"
position="bottom"
round
safe-area-inset-bottom
teleport="body"
class="timeline-modal-popup"
@update:show="(val: boolean) => emit('update:show', val)"
>
<div class="modal-sheet-inner">
<div class="modal-header">
<h3>补录照护记录</h3>
<button class="close-btn" @click="emit('update:show', false)">×</button>
<button class="close-btn" type="button" @click="emit('update:show', false)">×</button>
</div>
<div class="modal-form">
@@ -140,19 +215,19 @@ async function submitManual() {
</div>
</label>
<!-- 发生时间 -->
<!-- 开始起止时间设置 -->
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px;">
<label>
开始日期
<input v-model="manualForm.startDate" type="date" />
<input v-model="manualForm.startDate" type="date" @change="autoUpdateEndTime" />
</label>
<label>
开始时间
<input v-model="manualForm.startTimeStr" type="time" />
<input v-model="manualForm.startTimeStr" type="time" @change="autoUpdateEndTime" />
</label>
</div>
<!-- 喂奶特定字段 -->
<!-- 喂奶专属表单 -->
<template v-if="manualForm.recordType === 'feeding'">
<label>
喂养方式
@@ -164,77 +239,72 @@ async function submitManual() {
</select>
</label>
<div v-if="manualForm.feedingMethod === 'breastfeed'">
<label>
亲喂侧
<!-- 亲喂:侧别与分侧耗时 -->
<div v-if="manualForm.feedingMethod === 'breastfeed'" style="background: #faf7f2; border: 1px solid #eee5d8; border-radius: 12px; padding: 12px;">
<label style="margin-bottom: 8px;">
亲喂模式
<div class="chip-group">
<button
type="button"
class="chip sm"
:class="{ active: manualForm.breastSide === 'left' }"
@click="manualForm.breastSide = 'left'"
:class="{ active: manualForm.breastMode === 'both' }"
@click="handleBreastModeChange('both')"
>
左侧
双侧 (左右各喂)
</button>
<button
type="button"
class="chip sm"
:class="{ active: manualForm.breastSide === 'right' }"
@click="manualForm.breastSide = 'right'"
:class="{ active: manualForm.breastMode === 'left' }"
@click="handleBreastModeChange('left')"
>
右侧
仅左侧
</button>
<button
type="button"
class="chip sm"
:class="{ active: manualForm.breastMode === 'right' }"
@click="handleBreastModeChange('right')"
>
仅右侧
</button>
</div>
</label>
</div>
<div v-else>
<label>
奶量 (ml)
<div style="display: flex; gap: 8px; align-items: center;">
<input v-model.number="manualForm.amountMl" type="number" placeholder="输入奶量 ml" />
<div class="chip-group" style="margin: 0;">
<button
v-for="amt in [30, 60, 90, 120]"
:key="amt"
type="button"
class="chip sm"
:class="{ active: manualForm.amountMl === amt }"
@click="manualForm.amountMl = amt"
>
{{ amt }}
</button>
</div>
</div>
</label>
</div>
</template>
<!-- 分侧耗时 -->
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px;">
<label v-if="manualForm.breastMode === 'left' || manualForm.breastMode === 'both'">
左侧耗时 (分钟)
<input v-model.number="manualForm.leftMinutes" type="number" min="0" max="120" placeholder="分钟" @input="onSplitMinutesChange" />
</label>
<label v-if="manualForm.breastMode === 'right' || manualForm.breastMode === 'both'">
右侧耗时 (分钟)
<input v-model.number="manualForm.rightMinutes" type="number" min="0" max="120" placeholder="分钟" @input="onSplitMinutesChange" />
</label>
</div>
<!-- 睡眠特定字段 -->
<template v-if="manualForm.recordType === 'sleep'">
<div style="display: flex; align-items: center; gap: 8px; margin: 4px 0;">
<input id="manualHasEnd" v-model="manualForm.hasEndTime" type="checkbox" style="width: 18px; height: 18px;" />
<label for="manualHasEnd" style="font-size: 14px; cursor: pointer; color: #1f2933;">包含醒来结束时间</label>
</div>
<div v-if="manualForm.hasEndTime" style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px;">
<label>
醒来日期
<input v-model="manualForm.endDate" type="date" />
</label>
<label>
醒来时间
<input v-model="manualForm.endTimeStr" type="time" />
<!-- 总时长 -->
<label style="margin-top: 8px;">
亲喂总时长 (分钟)
<input v-model.number="manualForm.durationMinutes" type="number" min="1" max="180" @input="onTotalDurationChange" />
</label>
</div>
<label v-if="!manualForm.hasEndTime">
睡眠持续时间 (分钟,可选)
<input v-model.number="manualForm.durationMinutes" type="number" placeholder="例如:45" />
<label v-else>
单次奶量 (ml)
<input v-model.number="manualForm.amountMl" type="number" min="5" max="400" step="5" />
</label>
</template>
<!-- 排泄特定字段 -->
<!-- 睡眠专属表单 -->
<template v-if="manualForm.recordType === 'sleep'">
<label>
睡眠时长 (分钟)
<input v-model.number="manualForm.durationMinutes" type="number" min="1" placeholder="留空则按起止时间自动计算" @input="autoUpdateEndTime" />
</label>
</template>
<!-- 排泄专属表单 -->
<template v-if="manualForm.recordType === 'excretion'">
<label>
排泄类型
@@ -245,7 +315,7 @@ async function submitManual() {
:class="{ active: manualForm.excretionType === 'pee' }"
@click="manualForm.excretionType = 'pee'"
>
💧 嘘嘘 (尿尿)
💧 小便 (尿尿)
</button>
<button
type="button"
@@ -253,18 +323,34 @@ async function submitManual() {
:class="{ active: manualForm.excretionType === 'poop' }"
@click="manualForm.excretionType = 'poop'"
>
💩 便便 (大便)
💩 大便 (便便)
</button>
</div>
</label>
</template>
<!-- 记录人选择 -->
<!-- 结束时间(选填/联动) -->
<div style="border-top: 1px dashed #e8e3d8; padding-top: 10px;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px;">
<span style="font-size: 13px; font-weight: 700; color: #4b5563;">记录结束时间</span>
<input v-model="manualForm.hasEndTime" type="checkbox" style="width: 18px; height: 18px;" />
</div>
<div v-if="manualForm.hasEndTime" style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px;">
<label>
结束日期
<input v-model="manualForm.endDate" type="date" />
</label>
<label>
结束时间
<input v-model="manualForm.endTimeStr" type="time" />
</label>
</div>
</div>
<!-- 记录人 -->
<label>
记录人称谓
<div style="display: flex; gap: 8px;">
<input v-model="manualForm.operatorName" placeholder="例如:宝妈、宝爸" />
</div>
<input v-model="manualForm.operatorName" placeholder="例如:宝妈、宝爸" />
<div class="chip-group">
<button
v-for="m in store.members"
@@ -297,10 +383,10 @@ async function submitManual() {
</label>
<div class="modal-actions">
<button class="secondary-button" @click="emit('update:show', false)">取消</button>
<button class="save-button" @click="submitManual">确认补录</button>
<button class="secondary-button" type="button" @click="emit('update:show', false)">取消</button>
<button class="save-button" type="button" @click="submitManual">确定补录</button>
</div>
</div>
</div>
</div>
</van-popup>
</template>
+2 -2
View File
@@ -21,8 +21,8 @@ onMounted(async () => {
<template>
<section class="page">
<header class="page-header">
<p class="eyebrow">设置与配置</p>
<h1>家庭照护维护</h1>
<p class="eyebrow">宝宝与家庭</p>
<h1>家庭照护管理</h1>
<p>{{ currentBabyLabel }}</p>
</header>
+2 -2
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { onMounted } from 'vue'
import { useCareStore } from '../stores/careStore'
import { formatMinutes } from '../utils/format'
import { formatMinutes, formatFeedingMethod } from '../utils/format'
const store = useCareStore()
@@ -42,7 +42,7 @@ onMounted(() => {
<h2>喂奶方式</h2>
</div>
<div class="stat-row" v-for="(count, method) in store.summary?.feedingMethodCounts || {}" :key="method">
<span>{{ method }}</span>
<span>{{ formatFeedingMethod(method as string) }}</span>
<strong>{{ count }} 次</strong>
</div>
<p v-if="!Object.keys(store.summary?.feedingMethodCounts || {}).length" class="empty">暂无喂奶记录。</p>
+226 -47
View File
@@ -1,15 +1,28 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { computed, onMounted, ref, watch } from 'vue'
import { showToast, showConfirmDialog } from 'vant'
import { deleteRecord } from '../api/client'
import { deleteRecord, getRecords } from '../api/client'
import { useCareStore } from '../stores/careStore'
import { formatMinutes, formatTime, recordLabel } from '../utils/format'
import {
formatMinutes,
recordLabel,
getFeedingSplitInfo,
formatRecordTimeRange,
formatCleanNote,
formatDate,
getFriendlyDayLabel
} from '../utils/format'
import type { CareRecord } from '../types/domain'
import TimelineManualModal from '../components/timeline/TimelineManualModal.vue'
import TimelineEditModal from '../components/timeline/TimelineEditModal.vue'
const store = useCareStore()
const loading = ref(false)
const records = ref<CareRecord[]>([])
const filterDate = ref<string>('')
const sortOrder = ref<'desc' | 'asc'>('desc')
// 补录弹窗控制
const showManualModal = ref(false)
@@ -17,10 +30,50 @@ const showManualModal = ref(false)
const showEditModal = ref(false)
const selectedRecord = ref<CareRecord | null>(null)
interface RecordDayGroup {
date: string
dateLabel: string
count: number
records: CareRecord[]
}
async function loadData() {
loading.value = true
try {
await store.load()
const babyId = store.baby?.babyId || store.selectedBabyId
if (babyId) {
records.value = await getRecords(babyId, filterDate.value || undefined)
}
} catch (err: any) {
showToast(err.message || '加载记录失败')
} finally {
loading.value = false
}
}
onMounted(async () => {
await store.load()
await loadData()
})
watch(filterDate, () => {
loadData()
})
watch(() => store.baby?.babyId || store.selectedBabyId, (newId) => {
if (newId) {
loadData()
}
})
function clearFilter() {
filterDate.value = ''
}
function toggleSortOrder() {
sortOrder.value = sortOrder.value === 'desc' ? 'asc' : 'desc'
}
function openManualModal() {
showManualModal.value = true
}
@@ -30,6 +83,11 @@ function openEditModal(record: CareRecord) {
showEditModal.value = true
}
async function handleRecordChanged() {
await loadData()
await store.refreshSummary()
}
async function remove(recordId: string) {
try {
await showConfirmDialog({
@@ -37,75 +95,196 @@ async function remove(recordId: string) {
message: '确定要删除这条照护记录吗?'
})
await deleteRecord(recordId)
await loadData()
await store.refreshSummary()
showToast({ message: '记录已删除', type: 'success' })
} catch {
// cancel
}
}
// 记录按照开始时间按日分组,天内根据 sortOrder 升降序
const groupedRecords = computed<RecordDayGroup[]>(() => {
if (!records.value || !records.value.length) return []
const groupMap = new Map<string, CareRecord[]>()
for (const record of records.value) {
const d = formatDate(record.startTime) || '未知日期'
if (!groupMap.has(d)) {
groupMap.set(d, [])
}
groupMap.get(d)!.push(record)
}
// 日期从近到远倒序(最新日期在最前面)
const sortedDates = Array.from(groupMap.keys()).sort((a, b) => b.localeCompare(a))
return sortedDates.map(date => {
const list = groupMap.get(date) || []
const sortedList = [...list].sort((a, b) => {
const timeA = new Date(a.startTime).getTime()
const timeB = new Date(b.startTime).getTime()
return sortOrder.value === 'desc' ? timeB - timeA : timeA - timeB
})
return {
date,
dateLabel: getFriendlyDayLabel(date),
count: list.length,
records: sortedList
}
})
})
const totalCount = computed(() => records.value.length)
</script>
<template>
<section class="page">
<header class="page-header">
<p class="eyebrow">实时照护记录</p>
<h1>照护流水</h1>
<p class="eyebrow">全周期照护记录</p>
<h1>照护记录</h1>
</header>
<!-- 顶部操作栏 -->
<div class="timeline-header-actions">
<div>
<span style="font-size: 13px; color: #65707d;">
今日已记录 <strong>{{ store.summary?.timeline?.length || 0 }}</strong> 项
<!-- 顶部过滤与排序工具栏 -->
<div class="timeline-toolbar">
<div class="timeline-filter-row">
<!-- 日期过滤输入框 -->
<div class="date-filter-box">
<span class="filter-icon">📅</span>
<input
v-model="filterDate"
type="date"
class="filter-date-input"
aria-label="筛选特定日期"
/>
<button
v-if="filterDate"
type="button"
class="clear-filter-btn"
title="查看全部日期"
@click="clearFilter"
>
✕ 全部
</button>
</div>
<!-- 右侧操作项:天内排序切换与补录 -->
<div class="toolbar-actions">
<button
type="button"
class="sort-toggle-btn"
:class="{ active: sortOrder === 'asc' }"
:title="sortOrder === 'desc' ? '当前:当天内由晚到早(倒序),点击切换为正序' : '当前:当天内由早到晚(正序),点击切换为倒序'"
@click="toggleSortOrder"
>
<span class="sort-icon">{{ sortOrder === 'desc' ? '↓' : '↑' }}</span>
{{ sortOrder === 'desc' ? '时间倒序' : '时间正序' }}
</button>
<button class="primary-pill-button" @click="openManualModal">
+ 补录
</button>
</div>
</div>
<!-- 状态概览提示 -->
<div class="timeline-meta-bar">
<span v-if="filterDate" class="meta-filter-active">
已筛选 <strong>{{ filterDate }}</strong>,共 <strong>{{ totalCount }}</strong> 项记录
</span>
<span v-else class="meta-all-dates">
全部历史记录,共 <strong>{{ totalCount }}</strong> 项(已按日分组)
</span>
</div>
<button class="primary-pill-button" @click="openManualModal">
+ 补录记录
</button>
</div>
<!-- 流水列表 -->
<div class="timeline">
<article
v-for="record in store.summary?.timeline || []"
:key="record.recordId"
class="timeline-item"
<!-- 记录按日分组展示列表 -->
<div v-if="groupedRecords.length" class="timeline-groups">
<section
v-for="group in groupedRecords"
:key="group.date"
class="timeline-day-group"
>
<div style="flex: 1;">
<div style="display: flex; align-items: center; gap: 8px;">
<strong style="font-size: 16px;">
{{ recordLabel(record.recordType, record.feedingMethod || record.excretionType) }}
</strong>
<span v-if="record.amountMl" style="background: #fff1cf; color: #8a540d; font-size: 12px; font-weight: 800; padding: 2px 6px; border-radius: 4px;">
{{ record.amountMl }}ml
</span>
<span v-if="record.durationMinutes" style="background: #eee9ff; color: #5925dc; font-size: 12px; font-weight: 800; padding: 2px 6px; border-radius: 4px;">
{{ formatMinutes(record.durationMinutes) }}
</span>
<!-- 日期分组标头 -->
<div class="timeline-day-header">
<div class="day-header-left">
<span class="day-badge-dot"></span>
<span class="day-title">{{ group.dateLabel }}</span>
</div>
<p>
{{ formatTime(record.startTime) }}
<span v-if="record.endTime"> ~ {{ formatTime(record.endTime) }}</span>
</p>
<p v-if="record.note || record.remark" style="color: #4b5563; font-size: 13px; margin-top: 2px;">
📝 {{ record.note || record.remark }}
</p>
<small>记录人: {{ record.operatorName }}</small>
<span class="day-records-count">共 {{ group.count }} 项</span>
</div>
<div class="item-actions">
<button class="edit-button" @click="openEditModal(record)">编辑</button>
<button class="delete-button" @click="remove(record.recordId)">删除</button>
</div>
</article>
<!-- 当天记录列表 -->
<div class="timeline-day-list">
<article
v-for="record in group.records"
:key="record.recordId"
class="timeline-item"
>
<div style="flex: 1;">
<div style="display: flex; align-items: center; gap: 8px;">
<strong style="font-size: 16px;">
{{ recordLabel(record.recordType, record.feedingMethod || record.excretionType) }}
</strong>
<span v-if="record.amountMl" style="background: #fff1cf; color: #8a540d; font-size: 12px; font-weight: 800; padding: 2px 6px; border-radius: 4px;">
{{ record.amountMl }}ml
</span>
<span v-if="record.durationMinutes" style="background: #eee9ff; color: #5925dc; font-size: 12px; font-weight: 800; padding: 2px 6px; border-radius: 4px;">
{{ formatMinutes(record.durationMinutes) }}
</span>
</div>
<p style="margin: 4px 0 2px; font-weight: 600; color: #374151;">
{{ formatRecordTimeRange(record.startTime, record.endTime) }}
</p>
<!-- 亲喂分侧分别耗时展示 -->
<div v-if="getFeedingSplitInfo(record)" style="display: flex; gap: 6px; margin: 3px 0;">
<span
v-if="getFeedingSplitInfo(record)?.leftMinutes"
style="background: #e0f2fe; color: #0369a1; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px;"
>
左侧: {{ getFeedingSplitInfo(record)?.leftMinutes }}分钟
</span>
<span
v-if="getFeedingSplitInfo(record)?.rightMinutes"
style="background: #fdf2f8; color: #be185d; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 4px;"
>
右侧: {{ getFeedingSplitInfo(record)?.rightMinutes }}分钟
</span>
</div>
<p v-if="formatCleanNote(record.note || record.remark)" style="color: #6b7280; font-size: 13px; margin-top: 2px;">
📝 {{ formatCleanNote(record.note || record.remark) }}
</p>
<small>记录人: {{ record.operatorName }}</small>
</div>
<p v-if="!store.summary?.timeline?.length" class="empty">今天还没有记录,点击上方“+ 补录记录”开始吧。</p>
<div class="item-actions">
<button class="edit-button" @click="openEditModal(record)">编辑</button>
<button class="delete-button" @click="remove(record.recordId)">删除</button>
</div>
</article>
</div>
</section>
</div>
<!-- 空状态 -->
<div v-else-if="!loading" class="timeline-empty-card">
<div style="font-size: 36px; margin-bottom: 8px;">📋</div>
<p v-if="filterDate" style="color: #4b5563; font-weight: 600; margin: 0 0 12px;">
{{ filterDate }} 暂无任何照护记录
</p>
<p v-else style="color: #4b5563; font-weight: 600; margin: 0 0 12px;">
宝宝目前还没有照护记录,点击下方按钮开始补录吧
</p>
<div style="display: flex; gap: 10px; justify-content: center;">
<button v-if="filterDate" class="secondary-btn" @click="clearFilter">查看全部日期</button>
<button class="primary-pill-button" @click="openManualModal">+ 补录记录</button>
</div>
</div>
<!-- 弹窗:补录记录维护组件 -->
<TimelineManualModal v-model:show="showManualModal" />
<TimelineManualModal v-model:show="showManualModal" @success="handleRecordChanged" />
<!-- 弹窗:编辑记录维护组件 -->
<TimelineEditModal v-model:show="showEditModal" :record="selectedRecord" />
<TimelineEditModal v-model:show="showEditModal" :record="selectedRecord" @success="handleRecordChanged" />
</section>
</template>
+656 -91
View File
@@ -1,68 +1,243 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { onMounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { showToast } from 'vant'
import { useCareStore } from '../stores/careStore'
import { formatMinutes, formatTime } from '../utils/format'
import { formatMinutes, formatTime, getLocalDateStr, getLocalTimeStr } from '../utils/format'
const router = useRouter()
const store = useCareStore()
const bottleAmount = ref(30)
const breastSide = ref<'left' | 'right'>('left')
// 喂养聚合 Tab 控制
type FeedingTabType = 'breastfeed' | 'bottle' | 'formula' | 'mixed'
const currentFeedingTab = ref<FeedingTabType>(
(store.preferences.defaultFeedingMethod as FeedingTabType) || 'breastfeed'
)
const babyOptions = computed(() => store.babies.map(baby => ({
text: `${baby.name} · ${baby.ageText}`,
value: baby.babyId
})))
const feedingTabOptions = [
{ value: 'breastfeed' as FeedingTabType, label: '亲喂' },
{ value: 'bottle' as FeedingTabType, label: '瓶喂' },
{ value: 'formula' as FeedingTabType, label: '配方奶' },
{ value: 'mixed' as FeedingTabType, label: '混合喂养' }
]
const memberOptions = computed(() => store.members.map(member => ({
text: member.roleName,
value: member.roleName
})))
const bottleAmount = ref(store.preferences.defaultBottleAmount || 30)
const formulaAmount = ref(store.preferences.defaultBottleAmount || 60)
const mixedAmount = ref(store.preferences.defaultBottleAmount || 40)
const mixedNote = ref('')
const breastSide = ref<'left' | 'right'>(store.preferences.defaultBreastSide || 'left')
const activeFeedingText = computed(() => {
const active = store.summary?.activeFeeding
return active ? `亲喂中 · ${formatTime(active.startTime)}` : '未计时'
})
// 切换抽屉状态
const showBabyPicker = ref(false)
const showMemberPicker = ref(false)
// 一次性亲喂配置
const breastSideMode = ref<'left' | 'right' | 'both'>('both')
const oneClickDuration = ref(20)
watch(
() => store.preferences.defaultBottleAmount,
(val) => {
if (val && typeof val === 'number') {
bottleAmount.value = val
formulaAmount.value = val
mixedAmount.value = val
}
},
{ immediate: true }
)
watch(
() => store.preferences.defaultFeedingMethod,
(val) => {
if (val && !store.bfTimerActive) {
currentFeedingTab.value = val as FeedingTabType
}
},
{ immediate: true }
)
watch(
() => store.bfTimerActive,
(active) => {
if (active) {
currentFeedingTab.value = 'breastfeed'
}
}
)
watch(
() => store.preferences.defaultBreastSide,
(val) => {
if (val && !store.bfTimerActive) {
breastSide.value = val
}
}
)
async function logMixedFeeding() {
await runWithTip(
() => store.logFeeding({
method: 'mixed',
amountMl: mixedAmount.value,
note: mixedNote.value.trim() || undefined
}),
`已记录混合喂养 ${mixedAmount.value}ml`
)
mixedNote.value = ''
}
function getRoleIcon(roleName: string) {
if (!roleName) return '👤'
if (roleName.includes('妈')) return '👩'
if (roleName.includes('爸')) return '👨'
if (roleName.includes('月嫂') || roleName.includes('育儿')) return '🤱'
if (roleName.includes('奶') || roleName.includes('婆')) return '👵'
if (roleName.includes('爷') || roleName.includes('公')) return '👴'
return '👤'
}
function formatSec(seconds: number) {
const m = Math.floor(seconds / 60)
const s = seconds % 60
return `${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`
}
function formatTotalBfTime() {
const total = store.bfLeftSeconds + store.bfRightSeconds
const m = Math.floor(total / 60)
const s = total % 60
return `${m}分${String(s).padStart(2, '0')}秒`
}
function handleCardClick(side: 'left' | 'right') {
if (store.bfTimerActive) {
store.switchBreastfeedSide(side)
} else {
breastSide.value = side
}
}
async function selectBaby(babyId: string, name: string) {
showBabyPicker.value = false
if (babyId === store.baby?.babyId) return
await store.selectBaby(babyId)
showToast({ message: `已切换为宝宝:${name}`, type: 'success' })
}
function selectOperator(name: string) {
showMemberPicker.value = false
if (name === store.operatorName) return
store.setOperatorName(name)
showToast({ message: `已切换记录人为:${name}`, type: 'success' })
}
function goToSettings() {
showBabyPicker.value = false
showMemberPicker.value = false
router.push('/settings')
}
onMounted(() => {
store.load()
})
async function runWithTip(action: () => Promise<void>, message: string) {
await action()
showToast({ message, type: 'success', duration: 1400 })
const operating = ref(false)
async function runWithTip(action: () => Promise<void>, message?: string) {
if (operating.value) return
operating.value = true
try {
await action()
if (message) {
showToast({ message, type: 'success', duration: 1400 })
}
} catch (err: any) {
showToast(err.message || '操作失败')
} finally {
operating.value = false
}
}
async function handleOneClickBreastfeeding() {
if (operating.value) return
const dur = oneClickDuration.value || 20
const now = store.getServerNow()
const startMs = now.getTime() - dur * 60000
const startDate = new Date(startMs)
const startTime = `${getLocalDateStr(startDate)}T${getLocalTimeStr(startDate)}:00`
const endTime = `${getLocalDateStr(now)}T${getLocalTimeStr(now)}:00`
let leftDur: number | undefined
let rightDur: number | undefined
if (breastSideMode.value === 'both') {
leftDur = Math.floor(dur / 2)
rightDur = Math.ceil(dur / 2)
} else if (breastSideMode.value === 'left') {
leftDur = dur
rightDur = 0
} else {
leftDur = 0
rightDur = dur
}
const startStr = `${String(startDate.getHours()).padStart(2, '0')}:${String(startDate.getMinutes()).padStart(2, '0')}`
const endStr = `${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`
await runWithTip(
() => store.logFeeding({
method: 'breastfeed',
durationMinutes: dur,
feedingTime: startTime,
endTime,
leftDurationMinutes: leftDur,
rightDurationMinutes: rightDur,
breastSide: breastSideMode.value
}),
`已记录亲喂 ${dur}分钟(${startStr} ~ ${endStr})`
)
}
</script>
<template>
<section class="page">
<header class="hero clean-hero">
<div>
<p class="eyebrow">{{ store.context?.family.name || '新生儿照护家庭' }}</p>
<h1>{{ store.baby?.name || '宝宝' }}</h1>
<p>{{ store.baby?.ageText || '出生第 3 天' }} · {{ store.operatorName }}记录中</p>
<!-- 顶部一体化温润状态卡片 -->
<header class="today-top-card">
<!-- 顶栏:家庭名称与记录人切换胶囊 -->
<div class="top-row">
<div class="family-badge">
<span class="family-icon">🏡</span>
<span class="family-name">{{ store.context?.family.name || '新生儿照护家庭' }}</span>
</div>
<button class="operator-pill" type="button" @click="showMemberPicker = true">
<span class="operator-avatar">{{ getRoleIcon(store.operatorName) }}</span>
<span class="operator-text">{{ store.operatorName }}</span>
<span class="pill-arrow">▾</span>
</button>
</div>
<!-- 主体:宝宝信息与切换入口 -->
<div class="baby-main-row" @click="showBabyPicker = true">
<div class="baby-avatar-wrap">
<span class="baby-avatar-emoji">👶</span>
<span class="gender-dot" :class="store.baby?.gender || 'boy'"></span>
</div>
<div class="baby-meta">
<div class="baby-name-row">
<h1 class="baby-name">{{ store.baby?.name || '宝宝' }}</h1>
<span class="baby-switch-tag">切换宝宝 ▾</span>
</div>
<div class="baby-tags">
<span class="baby-age-chip">{{ store.baby?.ageText || '出生第 3 天' }}</span>
<span v-if="store.baby?.deliveryType === 'natural'" class="baby-sub-chip">顺产</span>
<span v-else-if="store.baby?.deliveryType === 'c_section'" class="baby-sub-chip">剖腹产</span>
</div>
</div>
</div>
</header>
<p v-if="store.error" class="notice error">{{ store.error }}</p>
<p v-if="store.loading" class="notice">正在加载今日记录...</p>
<section class="context-panel">
<van-dropdown-menu>
<van-dropdown-item
:model-value="store.baby?.babyId"
:options="babyOptions"
title="宝宝"
@update:model-value="value => store.selectBaby(String(value))"
/>
<van-dropdown-item
:model-value="store.operatorName"
:options="memberOptions"
title="记录人"
@update:model-value="value => store.setOperatorName(String(value))"
/>
</van-dropdown-menu>
</section>
<section class="summary-grid">
<article class="metric-card">
<span>喂奶</span>
@@ -86,58 +261,326 @@ async function runWithTip(action: () => Promise<void>, message: string) {
</article>
</section>
<section class="panel">
<!-- 统一喂养聚合面板 -->
<section class="panel feeding-panel">
<div class="panel-title">
<h2>亲喂</h2>
<p>可以计时,也可以一键记录,之后再补调时间。</p>
<div style="display: flex; justify-content: space-between; align-items: center;">
<h2>喂养</h2>
<span v-if="store.bfTimerActive" class="bf-live-badge">亲喂进行中</span>
</div>
<p>支持亲喂、瓶喂、配方奶与混合喂养多模式快捷记录。</p>
</div>
<van-segmented v-model="breastSide" :options="[
{ label: '左侧', value: 'left' },
{ label: '右侧', value: 'right' }
]" />
<div class="feeding-status">
<span>{{ activeFeedingText }}</span>
<strong v-if="store.summary?.activeFeeding">{{ breastSide === 'left' ? '左侧' : '右侧' }}</strong>
</div>
<div class="two-actions">
<van-button
block
round
type="primary"
@click="runWithTip(() => store.toggleBreastfeedTimer(breastSide), store.summary?.activeFeeding ? '已结束本次亲喂,辛苦啦' : '已开始亲喂计时')"
>
{{ store.summary?.activeFeeding ? '结束亲喂' : '开始亲喂' }}
</van-button>
<van-button
block
round
plain
type="primary"
@click="runWithTip(() => store.logFeeding('breastfeed', undefined, breastSide), '已记录一次亲喂')"
>
一键记录
</van-button>
</div>
</section>
<section class="panel">
<div class="panel-title">
<h2>瓶喂</h2>
<p>奶量可调整,默认按当前数值记录。</p>
<!-- 四大喂养方式切换 Tab -->
<div class="feeding-segmented-nav">
<button
v-for="tab in feedingTabOptions"
:key="tab.value"
type="button"
class="feeding-tab-btn"
:class="{ active: currentFeedingTab === tab.value }"
@click="currentFeedingTab = tab.value"
>
{{ tab.label }}
<span v-if="tab.value === 'breastfeed' && store.bfTimerActive" class="tab-live-dot" />
</button>
</div>
<div class="amount-row">
<span>奶量</span>
<van-stepper v-model="bottleAmount" :min="5" :max="300" :step="5" integer />
<strong>{{ bottleAmount }} ml</strong>
<!-- Tab 1: 亲喂 -->
<div v-show="currentFeedingTab === 'breastfeed'" class="feeding-tab-content">
<!-- 左右双侧计时卡片 -->
<div class="bf-dual-grid">
<!-- 左侧 -->
<div
class="bf-side-card"
:class="{
active: store.bfTimerActive && store.bfActiveSide === 'left',
selected: !store.bfTimerActive && breastSide === 'left'
}"
@click="handleCardClick('left')"
>
<div class="bf-card-header">
<span class="bf-card-title">左侧</span>
<span v-if="store.bfTimerActive" class="bf-status-tag" :class="store.bfActiveSide === 'left' ? 'timing' : 'paused'">
{{ store.bfActiveSide === 'left' ? '计时中' : '已暂计' }}
</span>
<span v-else class="bf-status-tag idle">
{{ breastSide === 'left' ? '优先起始' : '点击选择' }}
</span>
</div>
<div class="bf-card-time">
{{ formatSec(store.bfLeftSeconds) }}
</div>
<div v-if="store.bfTimerActive" class="bf-card-footer">
<button
v-if="store.bfActiveSide !== 'left'"
class="bf-switch-chip"
type="button"
:disabled="operating"
@click.stop="!operating && store.switchBreastfeedSide('left')"
>
切至左侧
</button>
<span v-else class="bf-active-hint">正在喂奶</span>
</div>
</div>
<!-- 右侧 -->
<div
class="bf-side-card"
:class="{
active: store.bfTimerActive && store.bfActiveSide === 'right',
selected: !store.bfTimerActive && breastSide === 'right'
}"
@click="handleCardClick('right')"
>
<div class="bf-card-header">
<span class="bf-card-title">右侧</span>
<span v-if="store.bfTimerActive" class="bf-status-tag" :class="store.bfActiveSide === 'right' ? 'timing' : 'paused'">
{{ store.bfActiveSide === 'right' ? '计时中' : '已暂计' }}
</span>
<span v-else class="bf-status-tag idle">
{{ breastSide === 'right' ? '优先起始' : '点击选择' }}
</span>
</div>
<div class="bf-card-time">
{{ formatSec(store.bfRightSeconds) }}
</div>
<div v-if="store.bfTimerActive" class="bf-card-footer">
<button
v-if="store.bfActiveSide !== 'right'"
class="bf-switch-chip"
type="button"
:disabled="operating"
@click.stop="!operating && store.switchBreastfeedSide('right')"
>
切至右侧
</button>
<span v-else class="bf-active-hint">正在喂奶</span>
</div>
</div>
</div>
<!-- 计时汇总横条 -->
<div v-if="store.bfTimerActive" class="bf-summary-bar">
<span>本次亲喂总计:<strong>{{ formatTotalBfTime() }}</strong></span>
<small>(左侧 {{ formatSec(store.bfLeftSeconds) }} · 右侧 {{ formatSec(store.bfRightSeconds) }})</small>
</div>
<!-- 未在计时状态下的亲喂模式与时长配置 -->
<div v-if="!store.bfTimerActive" class="bf-config-box">
<div style="display: flex; justify-content: space-between; align-items: center;">
<span style="font-size: 13px; font-weight: 700; color: #475569;">亲喂模式</span>
<div class="chip-group" style="margin: 0;">
<button
type="button"
class="chip sm"
:class="{ active: breastSideMode === 'both' }"
@click="breastSideMode = 'both'"
>
双侧均喂
</button>
<button
type="button"
class="chip sm"
:class="{ active: breastSideMode === 'left' }"
@click="breastSideMode = 'left'"
>
仅左侧
</button>
<button
type="button"
class="chip sm"
:class="{ active: breastSideMode === 'right' }"
@click="breastSideMode = 'right'"
>
仅右侧
</button>
</div>
</div>
<div style="display: flex; justify-content: space-between; align-items: center; margin-top: 10px;">
<span style="font-size: 13px; font-weight: 700; color: #475569;">一次性记录时长</span>
<div class="chip-group" style="margin: 0;">
<button
v-for="d in [10, 15, 20, 30]"
:key="d"
type="button"
class="chip sm"
:class="{ active: oneClickDuration === d }"
@click="oneClickDuration = d"
>
{{ d }}分钟
</button>
</div>
</div>
<div style="font-size: 12px; color: #64748b; margin-top: 8px; background: #ffffff; padding: 6px 10px; border-radius: 6px; border: 1px dashed #e2e8f0;">
💡 一键记录将按
<strong>
{{ breastSideMode === 'both' ? `左侧 ${Math.floor(oneClickDuration / 2)}分 + 右侧 ${Math.ceil(oneClickDuration / 2)}分(总计 ${oneClickDuration}分)` : breastSideMode === 'left' ? `左侧 ${oneClickDuration}分钟` : `右侧 ${oneClickDuration}分钟` }}
</strong>
自动推导起止时间并入库
</div>
</div>
<!-- 操作按钮区 -->
<div v-if="!store.bfTimerActive" class="two-actions">
<van-button
block
round
type="primary"
:loading="operating"
:disabled="operating"
@click="runWithTip(() => store.startBreastfeedTimer(breastSideMode === 'right' ? 'right' : 'left'), `已开始亲喂计时(${breastSideMode === 'right' ? '右侧开始' : '左侧开始'})`)"
>
开始亲喂 ({{ breastSideMode === 'right' ? '右侧开始' : '左侧开始' }})
</van-button>
<van-button
block
round
plain
type="primary"
:loading="operating"
:disabled="operating"
@click="handleOneClickBreastfeeding"
>
一键记录 {{ oneClickDuration }}分钟
</van-button>
</div>
<div v-else class="two-actions">
<van-button
block
round
type="warning"
:disabled="operating"
@click="store.switchBreastfeedSide(store.bfActiveSide === 'left' ? 'right' : 'left')"
>
⇄ 切换到{{ store.bfActiveSide === 'left' ? '右侧' : '左侧' }}
</van-button>
<van-button
block
round
type="danger"
:loading="operating"
:disabled="operating"
@click="runWithTip(() => store.endBreastfeedTimer(), '已结束本次亲喂,辛苦啦')"
>
结束亲喂
</van-button>
</div>
</div>
<!-- Tab 2: 瓶喂 -->
<div v-show="currentFeedingTab === 'bottle'" class="feeding-tab-content">
<div class="amount-row">
<span>母乳奶量 (ml)</span>
<van-stepper v-model="bottleAmount" :min="5" :max="300" :step="5" integer />
</div>
<div class="quick-amount-chips">
<button
v-for="amt in [30, 60, 90, 120]"
:key="amt"
type="button"
class="chip sm"
:class="{ active: bottleAmount === amt }"
@click="bottleAmount = amt"
>
{{ amt }}ml
</button>
</div>
<van-button
block
round
type="success"
:loading="operating"
:disabled="operating"
@click="runWithTip(() => store.logFeeding('bottle', bottleAmount), `已记录瓶喂 ${bottleAmount}ml`)"
>
记录瓶喂
</van-button>
</div>
<!-- Tab 3: 配方奶 -->
<div v-show="currentFeedingTab === 'formula'" class="feeding-tab-content">
<div class="amount-row">
<span>冲调奶量 (ml)</span>
<van-stepper v-model="formulaAmount" :min="5" :max="300" :step="5" integer />
</div>
<div class="quick-amount-chips">
<button
v-for="amt in [30, 60, 90, 120]"
:key="amt"
type="button"
class="chip sm"
:class="{ active: formulaAmount === amt }"
@click="formulaAmount = amt"
>
{{ amt }}ml
</button>
</div>
<van-button
block
round
type="primary"
style="background: #2b70f0; border-color: #2b70f0;"
:loading="operating"
:disabled="operating"
@click="runWithTip(() => store.logFeeding('formula', formulaAmount), `已记录配方奶 ${formulaAmount}ml`)"
>
记录配方奶
</van-button>
</div>
<!-- Tab 4: 混合喂养 -->
<div v-show="currentFeedingTab === 'mixed'" class="feeding-tab-content">
<div class="amount-row">
<span>补喂奶量 (ml)</span>
<van-stepper v-model="mixedAmount" :min="5" :max="300" :step="5" integer />
</div>
<div class="quick-amount-chips">
<button
v-for="amt in [30, 60, 90, 120]"
:key="amt"
type="button"
class="chip sm"
:class="{ active: mixedAmount === amt }"
@click="mixedAmount = amt"
>
{{ amt }}ml
</button>
</div>
<div style="margin: 8px 0 14px;">
<input
v-model="mixedNote"
placeholder="备注说明(选填,如:先亲喂后补配方)"
style="width: 100%; padding: 8px 12px; border: 1.5px solid #e2e8f0; border-radius: 8px; font-size: 13px; box-sizing: border-box; background: #fafafa;"
/>
<div class="chip-group" style="margin-top: 6px;">
<button
v-for="tag in ['先亲喂后补配方', '纯补配方', '吃得香', '稍微溢奶']"
:key="tag"
type="button"
class="chip sm"
@click="mixedNote = tag"
>
+ {{ tag }}
</button>
</div>
</div>
<van-button
block
round
type="warning"
style="background: #e67e22; border-color: #e67e22;"
:loading="operating"
:disabled="operating"
@click="logMixedFeeding"
>
记录混合喂养
</van-button>
</div>
<van-button
block
round
type="success"
@click="runWithTip(() => store.logFeeding('bottle', bottleAmount), `已记录瓶喂 ${bottleAmount}ml`)"
>
记录瓶喂
</van-button>
</section>
<section class="panel">
@@ -146,15 +589,27 @@ async function runWithTip(action: () => Promise<void>, message: string) {
<p>尿尿、便便和睡眠优先保证动作清晰。</p>
</div>
<div class="action-grid compact-actions">
<button class="primary-action sleep" @click="runWithTip(() => store.toggleSleep(), store.summary?.activeSleep ? '已结束睡眠记录' : '已开始睡眠记录')">
<button
class="primary-action sleep"
:disabled="operating"
@click="runWithTip(() => store.toggleSleep(), store.summary?.activeSleep ? '已结束睡眠记录' : '已开始睡眠记录')"
>
<strong>{{ store.summary?.activeSleep ? '结束睡眠' : '开始睡眠' }}</strong>
<span>{{ store.summary?.activeSleep ? '自动计算时长' : '宝宝睡下了' }}</span>
</button>
<button class="primary-action pee" @click="runWithTip(() => store.logPee(), '已记录一次小便')">
<button
class="primary-action pee"
:disabled="operating"
@click="runWithTip(() => store.logPee(), '已记录一次小便')"
>
<strong>小便</strong>
<span>记录一次</span>
</button>
<button class="primary-action poop" @click="runWithTip(() => store.logPoop(), '已记录一次大便')">
<button
class="primary-action poop"
:disabled="operating"
@click="runWithTip(() => store.logPoop(), '已记录一次大便')"
>
<strong>大便</strong>
<span>记录一次</span>
</button>
@@ -176,5 +631,115 @@ async function runWithTip(action: () => Promise<void>, message: string) {
</div>
</div>
</section>
<!-- 宝宝切换抽屉 -->
<van-popup
v-model:show="showBabyPicker"
position="bottom"
round
safe-area-inset-bottom
teleport="body"
class="switcher-popup"
>
<div class="popup-sheet">
<div class="popup-sheet-header">
<div class="popup-title-group">
<h3>切换宝宝档案</h3>
<span class="popup-subtitle">当前家庭共 {{ store.babies.length }} 位宝宝</span>
</div>
<button class="popup-close-btn" type="button" @click="showBabyPicker = false">✕</button>
</div>
<div class="popup-list">
<div
v-for="baby in store.babies"
:key="baby.babyId"
class="switcher-card"
:class="{ active: baby.babyId === store.baby?.babyId }"
@click="selectBaby(baby.babyId, baby.name)"
>
<div class="switcher-card-left">
<span class="switcher-avatar-circle">👶</span>
<div class="switcher-info">
<div class="switcher-name-row">
<strong class="switcher-name">{{ baby.name }}</strong>
<span v-if="baby.isDefault" class="switcher-badge default">默认</span>
<span v-if="baby.babyId === store.baby?.babyId" class="switcher-badge current">当前照护</span>
</div>
<div class="switcher-sub-row">
<span>{{ baby.ageText }}</span>
<span class="dot-sep">·</span>
<span>{{ baby.gender === 'girl' ? '女宝 👧' : baby.gender === 'boy' ? '男宝 👦' : '宝宝' }}</span>
<span class="dot-sep">·</span>
<span>{{ baby.deliveryType === 'natural' ? '顺产' : '剖腹产' }}</span>
</div>
</div>
</div>
<div class="switcher-check">
<span v-if="baby.babyId === store.baby?.babyId" class="check-icon">✓</span>
</div>
</div>
</div>
<div class="popup-footer">
<button class="popup-footer-btn" type="button" @click="goToSettings">
👶 前往家庭管理宝宝档案
</button>
</div>
</div>
</van-popup>
<!-- 记录人切换抽屉 -->
<van-popup
v-model:show="showMemberPicker"
position="bottom"
round
safe-area-inset-bottom
teleport="body"
class="switcher-popup"
>
<div class="popup-sheet">
<div class="popup-sheet-header">
<div class="popup-title-group">
<h3>选择当前记录人</h3>
<span class="popup-subtitle">本次及后续记录将署名所选看护人</span>
</div>
<button class="popup-close-btn" type="button" @click="showMemberPicker = false">✕</button>
</div>
<div class="popup-list">
<div
v-for="member in store.members"
:key="member.memberId"
class="switcher-card"
:class="{ active: member.roleName === store.operatorName }"
@click="selectOperator(member.roleName)"
>
<div class="switcher-card-left">
<span class="switcher-avatar-circle">{{ getRoleIcon(member.roleName) }}</span>
<div class="switcher-info">
<div class="switcher-name-row">
<strong class="switcher-name">{{ member.roleName }}</strong>
<span v-if="member.defaultOperator" class="switcher-badge default">默认看护</span>
<span v-if="member.roleName === store.operatorName" class="switcher-badge current">记录中</span>
</div>
<div class="switcher-sub-row">
<span>{{ member.roleType === 'owner' ? '家庭创建者' : '照护成员' }}</span>
</div>
</div>
</div>
<div class="switcher-check">
<span v-if="member.roleName === store.operatorName" class="check-icon">✓</span>
</div>
</div>
</div>
<div class="popup-footer">
<button class="popup-footer-btn" type="button" @click="goToSettings">
👨‍👩‍👧 前往家庭管理成员角色
</button>
</div>
</div>
</van-popup>
</section>
</template>
+224 -8
View File
@@ -18,7 +18,8 @@ import {
updateCurrentBaby,
updateFamily,
updateMember,
updateRecord
updateRecord,
getServerTime
} from '../api/client'
import type {
ActionPreferences,
@@ -37,7 +38,7 @@ import type {
const defaultPreferences: ActionPreferences = {
defaultFeedingMethod: 'breastfeed',
defaultBottleAmount: 60,
defaultBottleAmount: 30,
defaultBreastSide: 'left',
defaultSleepMode: 'timer',
quickFeedbackToast: true,
@@ -56,6 +57,36 @@ function loadInitialPreferences(): ActionPreferences {
return defaultPreferences
}
let bfTicker: ReturnType<typeof setInterval> | null = null
function startBfTicker(store: any) {
if (bfTicker) return
bfTicker = setInterval(() => {
if (!store.bfTimerActive) {
stopBfTicker()
return
}
const now = Date.now()
const delta = Math.max(0, Math.floor((now - store.bfLastTickTime) / 1000))
if (delta > 0) {
if (store.bfActiveSide === 'left') {
store.bfLeftSeconds += delta
} else {
store.bfRightSeconds += delta
}
store.bfLastTickTime = now
store.persistBfTimer()
}
}, 1000)
}
function stopBfTicker() {
if (bfTicker) {
clearInterval(bfTicker)
bfTicker = null
}
}
export const useCareStore = defineStore('care', {
state: () => ({
context: null as FamilyContext | null,
@@ -66,14 +97,34 @@ export const useCareStore = defineStore('care', {
summary: null as DailySummary | null,
operatorName: localStorage.getItem('operatorName') || '宝妈',
preferences: loadInitialPreferences() as ActionPreferences,
bfTimerActive: false,
bfActiveSide: 'left' as 'left' | 'right',
bfLeftSeconds: 0,
bfRightSeconds: 0,
bfLastTickTime: 0,
serverOffsetMs: 0,
loading: false,
error: ''
}),
actions: {
async syncServerTime() {
try {
const info = await getServerTime()
if (info && typeof info.timestamp === 'number') {
this.serverOffsetMs = info.timestamp - Date.now()
}
} catch {
// fallback
}
},
getServerNow(): Date {
return new Date(Date.now() + this.serverOffsetMs)
},
async load() {
this.loading = true
this.error = ''
try {
await this.syncServerTime()
this.context = await getFamilyContext()
this.babies = this.context.babies
this.members = this.context.members
@@ -85,6 +136,7 @@ export const useCareStore = defineStore('care', {
if (this.baby) {
localStorage.setItem('selectedBabyId', this.baby.babyId)
this.summary = await getDailySummary(this.baby.babyId)
this.syncBreastfeedTimer()
}
} catch (error) {
this.error = error instanceof Error ? error.message : '加载失败'
@@ -94,7 +146,9 @@ export const useCareStore = defineStore('care', {
},
async refreshSummary() {
if (!this.baby) return
await this.syncServerTime()
this.summary = await getDailySummary(this.baby.babyId)
this.syncBreastfeedTimer()
},
async selectBaby(babyId: string) {
this.selectedBabyId = babyId
@@ -162,23 +216,185 @@ export const useCareStore = defineStore('care', {
await deleteMember(this.context.family.familyId, memberId)
this.members = this.members.filter(m => m.memberId !== memberId)
},
async logFeeding(method: FeedingMethod, amountMl?: number, breastSide?: 'left' | 'right') {
async logFeeding(
payloadOrMethod: {
method: FeedingMethod
amountMl?: number
breastSide?: string
durationMinutes?: number
feedingTime?: string
endTime?: string
leftDurationMinutes?: number
rightDurationMinutes?: number
note?: string
} | FeedingMethod,
amountMl?: number,
breastSide?: string
) {
if (!this.baby) return
await createFeeding({
if (typeof payloadOrMethod === 'string') {
await createFeeding({
babyId: this.baby.babyId,
feedingMethod: payloadOrMethod,
amountMl,
breastSide,
operatorName: this.operatorName
})
} else {
await createFeeding({
babyId: this.baby.babyId,
feedingMethod: payloadOrMethod.method,
amountMl: payloadOrMethod.amountMl,
breastSide: payloadOrMethod.breastSide,
durationMinutes: payloadOrMethod.durationMinutes,
feedingTime: payloadOrMethod.feedingTime,
endTime: payloadOrMethod.endTime,
leftDurationMinutes: payloadOrMethod.leftDurationMinutes,
rightDurationMinutes: payloadOrMethod.rightDurationMinutes,
note: payloadOrMethod.note,
operatorName: this.operatorName
})
}
await this.refreshSummary()
},
persistBfTimer() {
if (!this.baby) return
try {
localStorage.setItem(`bfTimer_${this.baby.babyId}`, JSON.stringify({
activeSide: this.bfActiveSide,
leftSeconds: this.bfLeftSeconds,
rightSeconds: this.bfRightSeconds,
lastTickTime: this.bfLastTickTime
}))
} catch {
// ignore
}
},
clearBfTimerStorage() {
if (!this.baby) return
try {
localStorage.removeItem(`bfTimer_${this.baby.babyId}`)
} catch {
// ignore
}
},
syncBreastfeedTimer() {
if (!this.baby) return
const active = this.summary?.activeFeeding
if (active) {
let restored = false
try {
const raw = localStorage.getItem(`bfTimer_${this.baby.babyId}`)
if (raw) {
const data = JSON.parse(raw)
this.bfActiveSide = data.activeSide === 'right' ? 'right' : 'left'
this.bfLeftSeconds = Number(data.leftSeconds) || 0
this.bfRightSeconds = Number(data.rightSeconds) || 0
const lastTick = Number(data.lastTickTime) || Date.now()
const delta = Math.max(0, Math.floor((Date.now() - lastTick) / 1000))
if (delta > 0) {
if (this.bfActiveSide === 'left') {
this.bfLeftSeconds += delta
} else {
this.bfRightSeconds += delta
}
}
this.bfLastTickTime = Date.now()
this.bfTimerActive = true
restored = true
}
} catch {
// ignore
}
if (!restored) {
const startMs = active.startTime ? new Date(active.startTime).getTime() : Date.now()
const totalElapsed = Math.max(0, Math.floor((Date.now() - startMs) / 1000))
this.bfActiveSide = this.preferences.defaultBreastSide || 'left'
this.bfLeftSeconds = this.bfActiveSide === 'left' ? totalElapsed : 0
this.bfRightSeconds = this.bfActiveSide === 'right' ? totalElapsed : 0
this.bfLastTickTime = Date.now()
this.bfTimerActive = true
}
this.persistBfTimer()
startBfTicker(this)
} else {
if (this.bfTimerActive) {
this.bfTimerActive = false
this.bfLeftSeconds = 0
this.bfRightSeconds = 0
this.clearBfTimerStorage()
stopBfTicker()
}
}
},
async startBreastfeedTimer(breastSide: 'left' | 'right') {
if (!this.baby) return
await startFeeding({
babyId: this.baby.babyId,
feedingMethod: method,
amountMl,
breastSide,
operatorName: this.operatorName
})
this.bfTimerActive = true
this.bfActiveSide = breastSide
this.bfLeftSeconds = 0
this.bfRightSeconds = 0
this.bfLastTickTime = Date.now()
this.persistBfTimer()
startBfTicker(this)
await this.refreshSummary()
},
switchBreastfeedSide(targetSide: 'left' | 'right') {
if (!this.bfTimerActive || this.bfActiveSide === targetSide) return
const now = Date.now()
const delta = Math.max(0, Math.floor((now - this.bfLastTickTime) / 1000))
if (delta > 0) {
if (this.bfActiveSide === 'left') {
this.bfLeftSeconds += delta
} else {
this.bfRightSeconds += delta
}
}
this.bfActiveSide = targetSide
this.bfLastTickTime = now
this.persistBfTimer()
},
async endBreastfeedTimer() {
if (!this.baby) return
if (this.bfTimerActive) {
const now = Date.now()
const delta = Math.max(0, Math.floor((now - this.bfLastTickTime) / 1000))
if (delta > 0) {
if (this.bfActiveSide === 'left') {
this.bfLeftSeconds += delta
} else {
this.bfRightSeconds += delta
}
}
}
const leftMinutes = this.bfLeftSeconds > 0 ? Math.max(1, Math.round(this.bfLeftSeconds / 60)) : 0
const rightMinutes = this.bfRightSeconds > 0 ? Math.max(1, Math.round(this.bfRightSeconds / 60)) : 0
await endFeeding({
babyId: this.baby.babyId,
breastSide: this.bfActiveSide,
leftDurationMinutes: leftMinutes,
rightDurationMinutes: rightMinutes,
operatorName: this.operatorName
})
this.bfTimerActive = false
this.bfLeftSeconds = 0
this.bfRightSeconds = 0
this.clearBfTimerStorage()
stopBfTicker()
await this.refreshSummary()
},
async toggleBreastfeedTimer(breastSide: 'left' | 'right') {
if (!this.baby) return
if (this.summary?.activeFeeding) {
await endFeeding({ babyId: this.baby.babyId, breastSide, operatorName: this.operatorName })
await this.endBreastfeedTimer()
} else {
await startFeeding({ babyId: this.baby.babyId, breastSide, operatorName: this.operatorName })
await this.startBreastfeedTimer(breastSide)
}
await this.refreshSummary()
},
+787 -4
View File
@@ -79,6 +79,353 @@ button {
font-weight: 800;
}
/* 顶部一体化温润状态卡片 */
.today-top-card {
background: linear-gradient(135deg, #fffbf0 0%, #fff6df 100%);
border: 1px solid #f6e6c4;
border-radius: 16px;
padding: 14px 16px;
box-shadow: 0 4px 14px rgba(184, 134, 11, 0.06);
margin-bottom: 12px;
}
.top-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.family-badge {
display: flex;
align-items: center;
gap: 5px;
font-size: 12px;
font-weight: 600;
color: #8c6d3b;
}
.family-icon {
font-size: 14px;
}
.operator-pill {
display: inline-flex;
align-items: center;
gap: 5px;
background: #ffffff;
border: 1px solid #ebd8b2;
border-radius: 999px;
padding: 4px 10px 4px 7px;
cursor: pointer;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
transition: all 0.15s ease;
}
.operator-pill:active {
background: #faf4e8;
transform: scale(0.97);
}
.operator-avatar {
font-size: 14px;
line-height: 1;
}
.operator-text {
font-size: 12px;
font-weight: 700;
color: #5c4314;
}
.pill-arrow {
font-size: 10px;
color: #9c8253;
margin-left: -1px;
}
.baby-main-row {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border-radius: 12px;
background: rgba(255, 255, 255, 0.7);
border: 1px solid rgba(246, 230, 196, 0.6);
cursor: pointer;
transition: all 0.15s ease;
}
.baby-main-row:active {
background: rgba(255, 255, 255, 0.95);
transform: scale(0.99);
}
.baby-avatar-wrap {
position: relative;
width: 44px;
height: 44px;
background: #fffaee;
border: 2px solid #ecd8af;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.baby-avatar-emoji {
font-size: 24px;
line-height: 1;
}
.gender-dot {
position: absolute;
right: -2px;
bottom: -2px;
width: 12px;
height: 12px;
border-radius: 50%;
border: 2px solid #ffffff;
}
.gender-dot.boy {
background: #3b82f6;
}
.gender-dot.girl {
background: #ec4899;
}
.baby-meta {
flex: 1;
min-width: 0;
}
.baby-name-row {
display: flex;
align-items: center;
gap: 8px;
}
.baby-name {
margin: 0;
font-size: 20px;
font-weight: 800;
color: #2c2518;
line-height: 1.2;
}
.baby-switch-tag {
font-size: 11px;
font-weight: 600;
color: #8c6d3b;
background: #fbf2dc;
padding: 1px 6px;
border-radius: 4px;
border: 1px solid #ebd9b5;
}
.baby-tags {
display: flex;
align-items: center;
gap: 6px;
margin-top: 4px;
}
.baby-age-chip {
font-size: 12px;
font-weight: 700;
color: #b45309;
background: #fef3c7;
padding: 2px 7px;
border-radius: 4px;
}
.baby-sub-chip {
font-size: 11px;
font-weight: 600;
color: #65707d;
background: #f1f5f9;
padding: 2px 6px;
border-radius: 4px;
}
/* 切换底部抽屉样式 */
.switcher-popup {
left: 0 !important;
right: 0 !important;
margin: 0 auto !important;
width: min(600px, 100%) !important;
max-width: 600px !important;
max-height: 75vh;
}
.popup-sheet {
padding: 16px 16px 20px;
background: #ffffff;
}
.popup-sheet-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
padding-bottom: 12px;
border-bottom: 1px solid #f1f5f9;
}
.popup-title-group h3 {
margin: 0;
font-size: 17px;
font-weight: 800;
color: #1e293b;
}
.popup-subtitle {
font-size: 12px;
color: #64748b;
margin-top: 2px;
display: block;
}
.popup-close-btn {
background: #f1f5f9;
border: none;
border-radius: 50%;
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
color: #64748b;
font-size: 14px;
cursor: pointer;
}
.popup-list {
display: flex;
flex-direction: column;
gap: 10px;
margin-top: 14px;
max-height: 50vh;
overflow-y: auto;
}
.switcher-card {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 14px;
border: 1.5px solid #e2e8f0;
border-radius: 12px;
background: #f8fafc;
cursor: pointer;
transition: all 0.15s ease;
}
.switcher-card:active {
transform: scale(0.98);
}
.switcher-card.active {
border-color: #10b981;
background: #ecfdf5;
}
.switcher-card-left {
display: flex;
align-items: center;
gap: 12px;
}
.switcher-avatar-circle {
width: 38px;
height: 38px;
border-radius: 50%;
background: #ffffff;
border: 1px solid #e2e8f0;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
}
.switcher-info {
display: flex;
flex-direction: column;
gap: 2px;
}
.switcher-name-row {
display: flex;
align-items: center;
gap: 6px;
}
.switcher-name {
font-size: 15px;
font-weight: 700;
color: #1e293b;
}
.switcher-badge {
font-size: 10px;
font-weight: 700;
padding: 1px 5px;
border-radius: 4px;
}
.switcher-badge.default {
background: #e2e8f0;
color: #475569;
}
.switcher-badge.current {
background: #d1fae5;
color: #065f46;
}
.switcher-sub-row {
display: flex;
align-items: center;
gap: 4px;
font-size: 12px;
color: #64748b;
}
.dot-sep {
color: #cbd5e1;
}
.switcher-check {
font-size: 18px;
font-weight: 800;
color: #10b981;
}
.popup-footer {
margin-top: 16px;
padding-top: 12px;
border-top: 1px solid #f1f5f9;
}
.popup-footer-btn {
width: 100%;
padding: 10px;
background: #f8fafc;
border: 1px dashed #cbd5e1;
border-radius: 8px;
font-size: 13px;
font-weight: 600;
color: #475569;
cursor: pointer;
text-align: center;
}
.popup-footer-btn:active {
background: #f1f5f9;
}
.context-panel {
margin: 12px 0 16px;
overflow: hidden;
@@ -156,6 +503,13 @@ button {
color: #17202a;
}
.primary-action:disabled {
opacity: 0.55;
cursor: not-allowed;
filter: grayscale(0.25);
pointer-events: none;
}
.primary-action strong {
display: block;
font-size: 20px;
@@ -229,8 +583,7 @@ button {
margin-top: 12px;
}
.feeding-status,
.amount-row {
.feeding-status {
grid-template-columns: 1fr auto auto;
align-items: center;
padding: 12px;
@@ -238,13 +591,240 @@ button {
background: #faf7f1;
}
.amount-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 14px;
border-radius: 8px;
background: #faf7f1;
}
.feeding-status span,
.amount-row span {
color: #65707d;
font-weight: 600;
}
.two-actions {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px;
margin-top: 12px;
}
/* 今日主页四大喂养方式聚合 Tab 样式 */
.feeding-segmented-nav {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
background: #f1f5f9;
padding: 4px;
border-radius: 12px;
margin: 10px 0 14px;
}
.feeding-tab-btn {
position: relative;
border: none;
background: transparent;
padding: 8px 4px;
border-radius: 9px;
font-size: 13px;
font-weight: 700;
color: #64748b;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
user-select: none;
}
.feeding-tab-btn.active {
background: #ffffff;
color: #1e293b;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}
.tab-live-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: #10b981;
display: inline-block;
animation: pulse-dot 1.5s infinite;
}
@keyframes pulse-dot {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.4; transform: scale(1.3); }
}
.quick-amount-chips {
display: flex;
gap: 8px;
margin: 8px 0 14px;
}
.quick-amount-chips .chip {
flex: 1;
text-align: center;
}
/* 亲喂分别计时双侧卡片 */
.bf-dual-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 12px;
margin-top: 10px;
}
.bf-side-card {
background: #fdfbf7;
border: 2px solid #ede8de;
border-radius: 12px;
padding: 12px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
min-height: 106px;
cursor: pointer;
transition: all 0.2s ease;
user-select: none;
}
.bf-side-card.selected {
border-color: #2b70f0;
background: #f0f5ff;
}
.bf-side-card.active {
border-color: #10b981;
background: #f0fdf4;
box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}
.bf-card-header {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
}
.bf-card-title {
font-size: 14px;
font-weight: 700;
color: #24292f;
}
.bf-status-tag {
font-size: 11px;
font-weight: 600;
padding: 2px 6px;
border-radius: 4px;
}
.bf-status-tag.timing {
background: #d1fae5;
color: #065f46;
animation: pulse-timing 2s infinite;
}
.bf-status-tag.paused {
background: #fef3c7;
color: #92400e;
}
.bf-status-tag.idle {
background: #f3f4f6;
color: #6b7280;
}
@keyframes pulse-timing {
0%, 100% { opacity: 1; }
50% { opacity: 0.6; }
}
.bf-card-time {
font-size: 26px;
font-weight: 800;
color: #1f2937;
letter-spacing: 0.5px;
margin: 6px 0;
font-variant-numeric: tabular-nums;
}
.bf-side-card.active .bf-card-time {
color: #059669;
}
.bf-card-footer {
width: 100%;
display: flex;
justify-content: center;
margin-top: 4px;
}
.bf-switch-chip {
background: #e0e7ff;
color: #4338ca;
border: none;
border-radius: 999px;
padding: 4px 10px;
font-size: 12px;
font-weight: 600;
cursor: pointer;
width: 100%;
}
.bf-switch-chip:active {
background: #c7d2fe;
}
.bf-switch-chip:disabled {
opacity: 0.5;
cursor: not-allowed;
pointer-events: none;
}
.bf-active-hint {
font-size: 11px;
font-weight: 600;
color: #10b981;
}
.bf-summary-bar {
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
background: #f8fafc;
border: 1px dashed #cbd5e1;
border-radius: 8px;
padding: 8px 12px;
margin-top: 10px;
font-size: 13px;
color: #334155;
}
.bf-config-box {
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 10px;
padding: 10px 12px;
margin-top: 10px;
}
.bf-live-badge {
font-size: 11px;
font-weight: 700;
color: #059669;
background: #d1fae5;
padding: 2px 8px;
border-radius: 999px;
}
.timeline-item:last-child,
@@ -453,6 +1033,31 @@ button {
to { opacity: 1; }
}
/* 全局规范所有底部弹出层在宽屏/PC下的水平居中与宽度自适应 */
.van-popup--bottom {
left: 0 !important;
right: 0 !important;
margin: 0 auto !important;
width: min(600px, 100%) !important;
max-width: 600px !important;
}
.timeline-modal-popup {
left: 0 !important;
right: 0 !important;
margin: 0 auto !important;
width: min(600px, 100%) !important;
max-width: 600px !important;
max-height: 85vh;
}
.modal-sheet-inner {
padding: 20px 20px 32px;
overflow-y: auto;
max-height: 85vh;
background: #ffffff;
}
.modal-sheet {
width: 100%;
max-width: 600px;
@@ -535,6 +1140,185 @@ button {
margin-bottom: 16px;
}
/* 照护记录工具栏与按日分组样式 */
.timeline-toolbar {
margin-bottom: 16px;
background: #ffffff;
border-radius: 14px;
padding: 12px 14px;
border: 1px solid #ede8de;
}
.timeline-filter-row {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 10px;
}
.date-filter-box {
display: flex;
align-items: center;
background: #fdfbf7;
border: 1px solid #e2dbcd;
border-radius: 8px;
padding: 3px 8px;
gap: 6px;
}
.filter-icon {
font-size: 14px;
line-height: 1;
}
.filter-date-input {
border: none;
background: transparent;
font-size: 13px;
font-weight: 600;
color: #2c2518;
font-family: inherit;
outline: none;
padding: 4px 0;
}
.clear-filter-btn {
background: #ecdac5;
color: #794b1a;
border: none;
border-radius: 4px;
font-size: 11px;
font-weight: 700;
padding: 2px 7px;
cursor: pointer;
transition: background 0.15s ease;
}
.clear-filter-btn:hover {
background: #dfc8af;
}
.toolbar-actions {
display: flex;
align-items: center;
gap: 8px;
}
.sort-toggle-btn {
background: #f8fafc;
color: #475569;
border: 1px solid #cbd5e1;
border-radius: 999px;
font-size: 12px;
font-weight: 600;
padding: 6px 12px;
cursor: pointer;
display: flex;
align-items: center;
gap: 4px;
transition: all 0.2s;
}
.sort-toggle-btn:active {
background: #e2e8f0;
}
.sort-toggle-btn.active {
background: #eff6ff;
color: #1d4ed8;
border-color: #93c5fd;
}
.sort-icon {
font-weight: 800;
}
.timeline-meta-bar {
margin-top: 8px;
font-size: 12px;
color: #65707d;
display: flex;
align-items: center;
justify-content: space-between;
}
.meta-filter-active strong {
color: #b45309;
}
.meta-all-dates strong {
color: #1f2937;
}
.timeline-groups {
display: flex;
flex-direction: column;
gap: 16px;
}
.timeline-day-group {
background: #ffffff;
border-radius: 14px;
border: 1px solid #ede8de;
overflow: hidden;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
}
.timeline-day-header {
background: #fdfbf7;
padding: 10px 14px;
border-bottom: 1px solid #f0eae0;
display: flex;
justify-content: space-between;
align-items: center;
}
.day-header-left {
display: flex;
align-items: center;
gap: 8px;
}
.day-badge-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #f59e0b;
}
.day-title {
font-size: 14px;
font-weight: 700;
color: #1f2937;
}
.day-records-count {
font-size: 12px;
font-weight: 600;
color: #8c7853;
background: #fef3c7;
padding: 2px 8px;
border-radius: 999px;
}
.timeline-day-list {
padding: 0 14px;
}
.timeline-day-list .timeline-item:last-child {
border-bottom: none;
}
.timeline-empty-card {
background: #ffffff;
border-radius: 14px;
border: 1px dashed #d1d5db;
padding: 36px 16px;
text-align: center;
margin-top: 16px;
}
.tag-badge {
display: inline-block;
padding: 2px 8px;
@@ -592,8 +1376,7 @@ button {
grid-template-columns: 1fr;
}
.feeding-status,
.amount-row {
.feeding-status {
grid-template-columns: 1fr;
}
}
+15
View File
@@ -43,6 +43,8 @@ export interface CareRecord {
startTime: string
endTime?: string | null
durationMinutes?: number | null
leftDurationMinutes?: number | null
rightDurationMinutes?: number | null
feedingMethod?: FeedingMethod | null
amountMl?: number | null
excretionType?: ExcretionType | null
@@ -84,6 +86,8 @@ export interface CreateManualRecordPayload {
startTime: string
endTime?: string | null
durationMinutes?: number | null
leftDurationMinutes?: number | null
rightDurationMinutes?: number | null
feedingMethod?: FeedingMethod | null
amountMl?: number | null
excretionType?: ExcretionType | null
@@ -96,6 +100,8 @@ export interface UpdateCareRecordPayload {
startTime?: string
endTime?: string | null
durationMinutes?: number | null
leftDurationMinutes?: number | null
rightDurationMinutes?: number | null
feedingMethod?: FeedingMethod | null
amountMl?: number | null
excretionType?: ExcretionType | null
@@ -137,3 +143,12 @@ export interface ApiResponse<T> {
message: string
}
}
export interface ServerTimeInfo {
serverTime: string
currentDate: string
currentTime: string
timeZone: string
timestamp: number
}
+117 -8
View File
@@ -1,9 +1,68 @@
export function formatDate(value?: string | null) {
if (!value) return ''
const date = new Date(value)
return getLocalDateStr(date)
}
export function getLocalDateStr(date: Date = new Date()): string {
const y = date.getFullYear()
const m = String(date.getMonth() + 1).padStart(2, '0')
const d = String(date.getDate()).padStart(2, '0')
return `${y}-${m}-${d}`
}
export function getLocalTimeStr(date: Date = new Date()): string {
const h = String(date.getHours()).padStart(2, '0')
const min = String(date.getMinutes()).padStart(2, '0')
return `${h}:${min}`
}
export function formatTime(value?: string | null) {
if (!value) return '--'
const date = new Date(value)
return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
}
export function getFriendlyDayLabel(dateStr: string): string {
if (!dateStr) return ''
const today = getLocalDateStr(new Date())
const yesterday = getLocalDateStr(new Date(Date.now() - 86400000))
if (dateStr === today) return `${dateStr} · 今天`
if (dateStr === yesterday) return `${dateStr} · 昨天`
const parts = dateStr.split('-')
if (parts.length === 3) {
const d = new Date(Number(parts[0]), Number(parts[1]) - 1, Number(parts[2]))
const days = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
const weekday = days[d.getDay()] || ''
return `${dateStr} · ${weekday}`
}
return dateStr
}
export function formatRecordTimeRange(startTime?: string | null, endTime?: string | null) {
if (!startTime) return '--'
const startDate = formatDate(startTime)
const startT = formatTime(startTime)
if (!endTime) {
return `${startDate} ${startT}`
}
const endDate = formatDate(endTime)
const endT = formatTime(endTime)
if (startDate === endDate) {
return `${startDate} ${startT} ~ ${endT}`
}
return `${startDate} ${startT} ~ ${endDate} ${endT}`
}
export function formatCleanNote(noteOrRemark?: string | null): string {
if (!noteOrRemark) return ''
const cleaned = noteOrRemark
.replace(/亲喂侧\s*:\s*[^;;\n]+([;;]\s*)?/g, '')
.trim()
return cleaned
}
export function formatMinutes(minutes: number) {
const h = Math.floor(minutes / 60)
const m = minutes % 60
@@ -12,16 +71,22 @@ export function formatMinutes(minutes: number) {
return `${h} 小时 ${m} 分钟`
}
export const FEEDING_METHOD_MAP: Record<string, string> = {
breastfeed: '亲喂',
bottle: '瓶喂',
formula: '配方奶',
mixed: '混合喂养',
other: '其他'
}
export function formatFeedingMethod(method?: string | null): string {
if (!method) return '其他'
return FEEDING_METHOD_MAP[method] || method
}
export function recordLabel(type: string, sub?: string | null) {
if (type === 'feeding') {
const map: Record<string, string> = {
breastfeed: '亲喂',
bottle: '瓶喂',
formula: '配方奶',
mixed: '混合',
other: '其他'
}
return `喂奶 · ${map[sub || 'other'] || '其他'}`
return `喂奶 · ${formatFeedingMethod(sub)}`
}
if (type === 'sleep') return '睡眠'
if (type === 'excretion' && sub === 'pee') return '小便'
@@ -29,3 +94,47 @@ export function recordLabel(type: string, sub?: string | null) {
return '记录'
}
export interface FeedingSplitInfo {
leftMinutes?: number
rightMinutes?: number
}
export function parseFeedingSplitInfo(noteOrRemark?: string | null, durationMinutes?: number | null): FeedingSplitInfo | null {
if (!noteOrRemark) return null
const leftMatch = noteOrRemark.match(/左侧\s*(\d+)\s*分钟/)
const rightMatch = noteOrRemark.match(/右侧\s*(\d+)\s*分钟/)
if (leftMatch || rightMatch) {
return {
leftMinutes: leftMatch ? Number(leftMatch[1]) : undefined,
rightMinutes: rightMatch ? Number(rightMatch[1]) : undefined
}
}
if (noteOrRemark.includes('亲喂侧: 左侧') && durationMinutes) {
return { leftMinutes: durationMinutes }
}
if (noteOrRemark.includes('亲喂侧: 右侧') && durationMinutes) {
return { rightMinutes: durationMinutes }
}
return null
}
export function getFeedingSplitInfo(record?: {
leftDurationMinutes?: number | null
rightDurationMinutes?: number | null
remark?: string | null
note?: string | null
durationMinutes?: number | null
} | null): FeedingSplitInfo | null {
if (!record) return null
if ((record.leftDurationMinutes != null && record.leftDurationMinutes > 0) ||
(record.rightDurationMinutes != null && record.rightDurationMinutes > 0)) {
return {
leftMinutes: record.leftDurationMinutes ?? undefined,
rightMinutes: record.rightDurationMinutes ?? undefined
}
}
return parseFeedingSplitInfo(record.remark || record.note, record.durationMinutes)
}