优化行为

This commit is contained in:
gs committed 2026-09-26 21:47:16 +08:00
1 parent 1ed38c6648
commit 80c73fd46c
44 files changed
+2742 -198

No files matched your search

+43 -2
View File
@@ -2,7 +2,9 @@ import type {
ApiResponse,
BabyProfile,
CareRecord,
CareQuickRule,
CreateBabyPayload,
CreateFamilyPayload,
CreateManualRecordPayload,
CreateMemberPayload,
DailySummary,
@@ -10,6 +12,7 @@ import type {
FamilyInfo,
FamilyMember,
FeedingMethod,
JoinFamilyPayload,
ServerTimeInfo,
UpdateCareRecordPayload,
UpdateFamilyPayload,
@@ -35,8 +38,23 @@ export function getCurrentBaby() {
return request<BabyProfile>('/api/v1/babies/current')
}
export function getFamilyContext() {
return request<FamilyContext>('/api/v1/families/current-context')
export function getFamilyContext(familyId?: string) {
const query = familyId ? `?familyId=${encodeURIComponent(familyId)}` : ''
return request<FamilyContext>(`/api/v1/families/current-context${query}`)
}
export function createFamily(payload: CreateFamilyPayload) {
return request<FamilyContext>('/api/v1/families', {
method: 'POST',
body: JSON.stringify(payload)
})
}
export function joinFamily(payload: JoinFamilyPayload) {
return request<FamilyContext>('/api/v1/families/join', {
method: 'POST',
body: JSON.stringify(payload)
})
}
export function updateCurrentBaby(payload: Pick<BabyProfile, 'name' | 'gender' | 'birthDate' | 'deliveryType'>) {
@@ -95,6 +113,25 @@ export function deleteMember(familyId: string, memberId: string) {
})
}
export function getQuickRules(familyId?: string) {
const query = familyId ? `?familyId=${encodeURIComponent(familyId)}` : ''
return request<CareQuickRule[]>(`/api/v1/families/quick-rules${query}`)
}
export function saveQuickRule(payload: Omit<CareQuickRule, 'ruleId'> & { ruleId?: string }) {
return request<CareQuickRule>('/api/v1/families/quick-rules', {
method: 'POST',
body: JSON.stringify(payload)
})
}
export function deleteQuickRule(ruleId: string) {
return request<void>('/api/v1/families/quick-rules/delete', {
method: 'POST',
body: JSON.stringify({ ruleId })
})
}
export function getDailySummary(babyId: string) {
return request<DailySummary>(`/api/v1/summary/daily?babyId=${encodeURIComponent(babyId)}`)
}
@@ -116,6 +153,8 @@ export function createFeeding(payload: {
endTime?: string
leftDurationMinutes?: number
rightDurationMinutes?: number
effectiveFeedingMinutes?: number
pauseSegmentsJson?: string
operatorName: string
remark?: string
note?: string
@@ -147,6 +186,8 @@ export function endFeeding(payload: {
breastSide?: 'left' | 'right'
leftDurationMinutes?: number
rightDurationMinutes?: number
effectiveFeedingMinutes?: number
pauseSegmentsJson?: string
operatorName: string
remark?: string
note?: string
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { onMounted, reactive } from 'vue'
import { showToast } from 'vant'
import { computed, onMounted, reactive, ref } from 'vue'
import { showConfirmDialog, showToast } from 'vant'
import { useCareStore } from '../../stores/careStore'
import type { ActionPreferences } from '../../types/domain'
import type { ActionPreferences, CareQuickAction, CareQuickRule } from '../../types/domain'
const store = useCareStore()
@@ -15,8 +15,22 @@ const actionForm = reactive<ActionPreferences>({
autoBurpReminder: true
})
const editingRuleId = ref<string | null>(null)
const ruleForm = reactive({
name: '',
actions: ['diaper', 'feeding', 'sleep'] as CareQuickAction[],
diaperOffsetMinutes: 0,
feedingOffsetMinutes: 5,
sleepAfterFeedingMinutes: 5,
enabled: true,
sortOrder: 100
})
const enabledRules = computed(() => store.quickRules.filter(rule => rule.enabled))
onMounted(() => {
syncActionForm()
store.reloadQuickRules()
})
function syncActionForm() {
@@ -27,78 +41,246 @@ function saveActions() {
store.savePreferences(actionForm)
showToast({ message: '照护行为偏好已更新', type: 'success' })
}
function resetRuleForm() {
editingRuleId.value = null
ruleForm.name = ''
ruleForm.actions = ['diaper', 'feeding', 'sleep']
ruleForm.diaperOffsetMinutes = 0
ruleForm.feedingOffsetMinutes = 5
ruleForm.sleepAfterFeedingMinutes = 5
ruleForm.enabled = true
ruleForm.sortOrder = 100
}
function editRule(rule: CareQuickRule) {
editingRuleId.value = rule.ruleId
ruleForm.name = rule.name
ruleForm.actions = [...rule.actions]
ruleForm.diaperOffsetMinutes = rule.diaperOffsetMinutes
ruleForm.feedingOffsetMinutes = rule.feedingOffsetMinutes
ruleForm.sleepAfterFeedingMinutes = rule.sleepAfterFeedingMinutes
ruleForm.enabled = rule.enabled
ruleForm.sortOrder = rule.sortOrder
}
function toggleAction(action: CareQuickAction) {
if (ruleForm.actions.includes(action)) {
ruleForm.actions = ruleForm.actions.filter(item => item !== action)
} else {
ruleForm.actions = [...ruleForm.actions, action]
}
}
function actionText(actions: CareQuickAction[]) {
const map: Record<CareQuickAction, string> = {
diaper: '换尿布',
feeding: '喂奶',
sleep: '睡觉'
}
return actions.map(action => map[action]).join('、')
}
async function saveQuickRule() {
if (!ruleForm.name.trim()) {
showToast('请填写常用补记名称')
return
}
if (!ruleForm.actions.length) {
showToast('至少选择一个照护动作')
return
}
const payload = {
familyId: store.context?.family.familyId || '',
name: ruleForm.name.trim(),
actions: ruleForm.actions,
diaperOffsetMinutes: ruleForm.diaperOffsetMinutes || 0,
feedingOffsetMinutes: ruleForm.feedingOffsetMinutes || 0,
sleepAfterFeedingMinutes: ruleForm.sleepAfterFeedingMinutes || 0,
enabled: ruleForm.enabled,
sortOrder: ruleForm.sortOrder || 100
}
if (editingRuleId.value) {
await store.updateQuickRule(editingRuleId.value, payload)
showToast({ message: '常用补记已更新', type: 'success' })
} else {
await store.addQuickRule(payload)
showToast({ message: '常用补记已添加', type: 'success' })
}
resetRuleForm()
}
async function removeRule(rule: CareQuickRule) {
try {
await showConfirmDialog({
title: '删除常用补记',
message: `确定删除“${rule.name}”吗?`
})
await store.deleteQuickRule(rule.ruleId)
if (editingRuleId.value === rule.ruleId) {
resetRuleForm()
}
showToast({ message: '已删除', type: 'success' })
} catch {
// cancel
}
}
</script>
<template>
<section class="panel form-panel">
<div>
<span class="eyebrow">照护行为偏好</span>
<p style="margin: 2px 0 0; color: #65707d; font-size: 13px;">自定义默认喂养、睡眠及操作习惯</p>
</div>
<div class="action-mobile-page">
<section class="panel action-mobile-card">
<div class="action-card-head">
<div>
<span class="eyebrow">照护习惯</span>
<h3>默认记录偏好</h3>
</div>
<button class="mini-save-btn" type="button" @click="saveActions">保存</button>
</div>
<label>
默认喂养方式
<select v-model="actionForm.defaultFeedingMethod">
<option value="breastfeed">亲喂 (母乳)</option>
<option value="bottle">瓶喂 (母乳)</option>
<option value="formula">配方奶</option>
<option value="mixed">混合喂养</option>
</select>
</label>
<div class="mobile-setting-block">
<div class="mobile-setting-title">
<strong>默认喂养方式</strong>
<span>今日页和补记会优先使用</span>
</div>
<div class="mobile-option-grid">
<button type="button" class="mobile-option" :class="{ active: actionForm.defaultFeedingMethod === 'breastfeed' }" @click="actionForm.defaultFeedingMethod = 'breastfeed'">亲喂</button>
<button type="button" class="mobile-option" :class="{ active: actionForm.defaultFeedingMethod === 'bottle' }" @click="actionForm.defaultFeedingMethod = 'bottle'">挤出母乳</button>
<button type="button" class="mobile-option" :class="{ active: actionForm.defaultFeedingMethod === 'formula' }" @click="actionForm.defaultFeedingMethod = 'formula'">配方奶</button>
<button type="button" class="mobile-option" :class="{ active: actionForm.defaultFeedingMethod === 'mixed' }" @click="actionForm.defaultFeedingMethod = 'mixed'">混合喂养</button>
</div>
</div>
<label>
默认单次瓶喂奶量 (ml)
<div style="display: flex; gap: 8px; align-items: center;">
<input v-model.number="actionForm.defaultBottleAmount" type="number" min="10" max="300" step="5" />
<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: actionForm.defaultBottleAmount === amt }"
@click="actionForm.defaultBottleAmount = amt"
>
{{ amt }}ml
<div class="mobile-setting-block">
<div class="mobile-setting-title">
<strong>挤出母乳默认奶量</strong>
<span>ml</span>
</div>
<div class="amount-mobile-row">
<input v-model.number="actionForm.defaultBottleAmount" type="number" min="10" max="300" step="5" />
<div class="amount-chip-grid">
<button
v-for="amt in [30, 60, 90, 120]"
:key="amt"
type="button"
class="chip sm"
:class="{ active: actionForm.defaultBottleAmount === amt }"
@click="actionForm.defaultBottleAmount = amt"
>
{{ amt }}ml
</button>
</div>
</div>
</div>
<div class="mobile-setting-block">
<div class="mobile-setting-title">
<strong>亲喂优先侧</strong>
<span>开始计时时默认侧</span>
</div>
<div class="mobile-option-grid two">
<button type="button" class="mobile-option" :class="{ active: actionForm.defaultBreastSide === 'left' }" @click="actionForm.defaultBreastSide = 'left'">左侧优先</button>
<button type="button" class="mobile-option" :class="{ active: actionForm.defaultBreastSide === 'right' }" @click="actionForm.defaultBreastSide = 'right'">右侧优先</button>
</div>
</div>
<div class="mobile-setting-block">
<div class="mobile-setting-title">
<strong>睡眠记录</strong>
<span>选择常用方式</span>
</div>
<div class="mobile-option-grid two">
<button type="button" class="mobile-option" :class="{ active: actionForm.defaultSleepMode === 'timer' }" @click="actionForm.defaultSleepMode = 'timer'">开始/醒来</button>
<button type="button" class="mobile-option" :class="{ active: actionForm.defaultSleepMode === 'manual' }" @click="actionForm.defaultSleepMode = 'manual'">补记完成</button>
</div>
</div>
<div class="mobile-switch-list">
<label class="mobile-switch-row">
<span>
<strong>记录成功反馈</strong>
<small>快速操作成功后轻提示</small>
</span>
<input v-model="actionForm.quickFeedbackToast" type="checkbox" />
</label>
<label class="mobile-switch-row">
<span>
<strong>喂奶后拍嗝提醒</strong>
<small>亲喂/挤出母乳结束后提示</small>
</span>
<input v-model="actionForm.autoBurpReminder" type="checkbox" />
</label>
</div>
</section>
<section class="panel action-mobile-card">
<div class="action-card-head">
<div>
<span class="eyebrow">常用补记</span>
<h3>一组照护动作</h3>
</div>
</div>
<div class="quick-rule-card active">
<strong>完整照护</strong>
<span>系统内置:换尿布、喂奶、睡觉</span>
</div>
<div v-if="enabledRules.length" class="quick-rule-list">
<div v-for="rule in enabledRules" :key="rule.ruleId" class="quick-rule-card mobile-rule-card">
<div>
<strong>{{ rule.name }}</strong>
<span>{{ actionText(rule.actions) }}</span>
</div>
<div class="item-actions">
<button class="edit-button" type="button" @click="editRule(rule)">编辑</button>
<button class="delete-button" type="button" @click="removeRule(rule)">删除</button>
</div>
</div>
</div>
<div class="quick-rule-editor mobile-rule-editor">
<strong>{{ editingRuleId ? '编辑常用补记' : '添加常用补记' }}</strong>
<label>
名称
<input v-model="ruleForm.name" placeholder="例如:夜里只喂奶" />
</label>
<label>
包含哪些事
<div class="mobile-option-grid three">
<button type="button" class="mobile-option" :class="{ active: ruleForm.actions.includes('diaper') }" @click="toggleAction('diaper')">换尿布</button>
<button type="button" class="mobile-option" :class="{ active: ruleForm.actions.includes('feeding') }" @click="toggleAction('feeding')">喂奶</button>
<button type="button" class="mobile-option" :class="{ active: ruleForm.actions.includes('sleep') }" @click="toggleAction('sleep')">睡觉</button>
</div>
</label>
<div class="mobile-offset-list">
<label>
换尿布偏移
<input v-model.number="ruleForm.diaperOffsetMinutes" type="number" min="0" max="120" />
<span>分钟</span>
</label>
<label>
喂奶偏移
<input v-model.number="ruleForm.feedingOffsetMinutes" type="number" min="0" max="120" />
<span>分钟</span>
</label>
<label>
喂完多久睡
<input v-model.number="ruleForm.sleepAfterFeedingMinutes" type="number" min="0" max="120" />
<span>分钟</span>
</label>
</div>
<div class="modal-actions">
<button v-if="editingRuleId" class="secondary-button" type="button" @click="resetRuleForm">取消</button>
<button class="save-button" type="button" @click="saveQuickRule">
{{ editingRuleId ? '保存' : '添加' }}
</button>
</div>
</div>
</label>
<label>
默认亲喂优先侧
<select v-model="actionForm.defaultBreastSide">
<option value="left">左侧优先 (Left)</option>
<option value="right">右侧优先 (Right)</option>
</select>
</label>
<label>
睡眠默认模式
<select v-model="actionForm.defaultSleepMode">
<option value="timer">计时器模式(开始/醒来两步计时)</option>
<option value="manual">快捷录入模式(记录已完成的睡眠)</option>
</select>
</label>
<div style="border-top: 1px solid #f0ece5; padding-top: 12px; display: grid; gap: 12px;">
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<strong style="font-size: 14px; display: block;">记录成功温馨反馈</strong>
<span style="font-size: 12px; color: #65707d;">快速操作成功后弹出轻提示</span>
</div>
<input v-model="actionForm.quickFeedbackToast" type="checkbox" style="width: 22px; height: 22px;" />
</div>
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<strong style="font-size: 14px; display: block;">亲喂/瓶喂后拍嗝提醒</strong>
<span style="font-size: 12px; color: #65707d;">每次喂养结束后友好提示竖抱拍嗝</span>
</div>
<input v-model="actionForm.autoBurpReminder" type="checkbox" style="width: 22px; height: 22px;" />
</div>
</div>
<button class="save-button" @click="saveActions">保存行为偏好设置</button>
</section>
</section>
</div>
</template>
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, reactive, ref, watch } from 'vue'
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { showToast } from 'vant'
import { useCareStore } from '../../stores/careStore'
import { getLocalDateStr } from '../../utils/format'
@@ -16,6 +16,7 @@ const babyForm = reactive({
// 添加宝宝弹窗
const showAddBabyModal = ref(false)
const showEditBabyModal = ref(false)
const newBabyForm = reactive({
name: '',
gender: 'boy',
@@ -24,6 +25,23 @@ const newBabyForm = reactive({
isDefault: false
})
const currentGenderLabel = computed(() => {
if (!store.baby) return '-'
return store.baby.gender === 'girl' ? '女宝' : '男宝'
})
const currentDeliveryLabel = computed(() => {
if (!store.baby) return '-'
if (store.baby.deliveryType === 'c_section') return '剖宫产'
if (store.baby.deliveryType === 'unknown') return '暂不设置'
return '顺产'
})
const currentBabySummary = computed(() => {
if (!store.baby) return '-'
return `${store.baby.birthDate} · ${currentGenderLabel.value} · ${currentDeliveryLabel.value}`
})
onMounted(() => {
syncBabyForm()
})
@@ -52,9 +70,15 @@ async function saveBaby() {
birthDate: babyForm.birthDate,
deliveryType: babyForm.deliveryType
})
showEditBabyModal.value = false
showToast({ message: '宝宝档案已更新', type: 'success' })
}
function openEditBabyModal() {
syncBabyForm()
showEditBabyModal.value = true
}
// 打开添加宝宝弹窗
function openAddBabyModal() {
newBabyForm.name = ''
@@ -99,66 +123,98 @@ async function handleSetDefaultBaby(babyId: string) {
</script>
<template>
<section class="panel">
<section class="panel baby-overview-panel">
<div class="timeline-header-actions">
<div>
<span class="eyebrow">宝宝管理</span>
<p style="margin: 2px 0 0; color: #65707d; font-size: 13px;">选择或维护宝宝档案</p>
<span class="eyebrow">家庭里的宝宝</span>
</div>
<button class="primary-pill-button" @click="openAddBabyModal">
+ 添加宝宝
<button class="icon-text-button" type="button" @click="openAddBabyModal">
添加
</button>
</div>
<!-- 宝宝切换卡片 -->
<div class="chip-group" style="margin-bottom: 16px;">
<div v-if="store.baby" class="baby-profile compact">
<div>
<span class="eyebrow">当前照护</span>
<strong>{{ store.baby.name }}</strong>
<p>{{ store.baby.ageText }}</p>
</div>
<button class="icon-text-button" type="button" @click="openEditBabyModal">改</button>
</div>
<div v-if="store.baby" class="baby-compact-row">
<span>宝宝档案</span>
<strong>{{ currentBabySummary }}</strong>
</div>
<div class="baby-list">
<button
v-for="b in store.babies"
:key="b.babyId"
class="chip"
class="baby-list-item"
:class="{ active: store.baby?.babyId === b.babyId }"
type="button"
@click="store.selectBaby(b.babyId)"
>
{{ b.name }} ({{ b.ageText }})
<span v-if="b.isDefault" class="tag-badge default">默认</span>
<span>
<strong>{{ b.name }}</strong>
<small>{{ b.ageText }}</small>
</span>
<em v-if="b.isDefault">默认</em>
</button>
</div>
<div v-if="store.baby && store.babies.length > 1 && !store.baby.isDefault" style="margin-bottom: 16px;">
<button class="secondary-button" style="font-size: 13px;" @click="handleSetDefaultBaby(store.baby.babyId)">
设为全局默认宝宝
<div v-if="store.baby && store.babies.length > 1 && !store.baby.isDefault" class="baby-default-action">
<button class="secondary-button" type="button" @click="handleSetDefaultBaby(store.baby.babyId)">
设为当前默认宝宝
</button>
</div>
<!-- 当前宝宝修改表单 -->
<div class="form-panel" style="border-top: 1px solid #f0ece5; padding-top: 16px;">
<label>
宝宝昵称
<input v-model="babyForm.name" placeholder="请输入宝宝名字或乳名" />
</label>
<label>
出生日期
<input v-model="babyForm.birthDate" type="date" />
</label>
<label>
性别
<select v-model="babyForm.gender">
<option value="boy">男宝</option>
<option value="girl">女宝</option>
</select>
</label>
<label>
分娩方式
<select v-model="babyForm.deliveryType">
<option value="natural">顺产 (Natural)</option>
<option value="c_section">剖宫产 (C-Section)</option>
<option value="unknown">暂不设置</option>
</select>
</label>
<button class="save-button" @click="saveBaby">保存宝宝信息</button>
</div>
<van-popup
v-model:show="showEditBabyModal"
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" type="button" @click="showEditBabyModal = false">×</button>
</div>
<div class="modal-form">
<label>
宝宝昵称
<input v-model="babyForm.name" placeholder="请输入宝宝名字或乳名" />
</label>
<label>
出生日期
<input v-model="babyForm.birthDate" type="date" />
</label>
<label>
性别
<select v-model="babyForm.gender">
<option value="boy">男宝</option>
<option value="girl">女宝</option>
</select>
</label>
<label>
分娩方式
<select v-model="babyForm.deliveryType">
<option value="natural">顺产</option>
<option value="c_section">剖宫产</option>
<option value="unknown">暂不设置</option>
</select>
</label>
<div class="modal-actions">
<button class="secondary-button" type="button" @click="showEditBabyModal = false">取消</button>
<button class="save-button" type="button" @click="saveBaby">保存宝宝档案</button>
</div>
</div>
</div>
</van-popup>
<!-- 弹窗:添加新宝宝 -->
<van-popup
v-model:show="showAddBabyModal"
position="bottom"
@@ -1,15 +1,33 @@
<script setup lang="ts">
import { onMounted, reactive, watch } from 'vue'
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { showToast } from 'vant'
import { useCareStore } from '../../stores/careStore'
const store = useCareStore()
const showEditModal = ref(false)
const showCreateModal = ref(false)
const showJoinModal = ref(false)
const familyForm = reactive({
name: '',
inviteCode: ''
})
const createFamilyForm = reactive({
name: '',
roleName: '宝妈',
inviteCode: ''
})
const joinFamilyForm = reactive({
inviteCode: '',
roleName: '宝妈'
})
const family = computed(() => store.context?.family)
const familyName = computed(() => family.value?.name || '新生儿照护家庭')
const inviteCode = computed(() => family.value?.inviteCode || '暂未设置')
onMounted(() => {
syncFamilyForm()
})
@@ -34,12 +52,74 @@ async function saveFamily() {
name: familyForm.name.trim(),
inviteCode: familyForm.inviteCode.trim()
})
showEditModal.value = false
showToast({ message: '家庭信息已保存', type: 'success' })
} catch (err: any) {
showToast(err.message || '保存失败')
}
}
function startEdit() {
syncFamilyForm()
showEditModal.value = true
}
function openCreateFamilyModal() {
createFamilyForm.name = ''
createFamilyForm.roleName = store.operatorName || '宝妈'
createFamilyForm.inviteCode = ''
showCreateModal.value = true
}
function openJoinFamilyModal() {
joinFamilyForm.inviteCode = ''
joinFamilyForm.roleName = store.operatorName || '宝妈'
showJoinModal.value = true
}
async function submitCreateFamily() {
if (!createFamilyForm.name.trim()) {
showToast('请输入家庭名称')
return
}
if (!createFamilyForm.roleName.trim()) {
showToast('请输入你的称谓')
return
}
try {
await store.createFamily({
name: createFamilyForm.name.trim(),
roleName: createFamilyForm.roleName.trim(),
inviteCode: createFamilyForm.inviteCode.trim() || undefined
})
showCreateModal.value = false
showToast({ message: '家庭已创建', type: 'success' })
} catch (err: any) {
showToast(err.message || '创建失败')
}
}
async function submitJoinFamily() {
if (!joinFamilyForm.inviteCode.trim()) {
showToast('请输入成员加入码')
return
}
if (!joinFamilyForm.roleName.trim()) {
showToast('请输入你的称谓')
return
}
try {
await store.joinFamily({
inviteCode: joinFamilyForm.inviteCode.trim(),
roleName: joinFamilyForm.roleName.trim()
})
showJoinModal.value = false
showToast({ message: '已加入家庭', type: 'success' })
} catch (err: any) {
showToast(err.message || '加入失败')
}
}
function generateInviteCode() {
const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'
let res = 'BT'
@@ -48,43 +128,144 @@ function generateInviteCode() {
}
familyForm.inviteCode = res
}
async function copyInviteCode() {
if (!family.value?.inviteCode) {
showToast('暂无成员加入码')
return
}
try {
await navigator.clipboard.writeText(family.value.inviteCode)
showToast({ message: '成员加入码已复制', type: 'success' })
} catch {
showToast('复制失败,请手动复制')
}
}
</script>
<template>
<section class="panel form-panel">
<div>
<span class="eyebrow">家庭基础设置</span>
<p style="margin: 2px 0 0; color: #65707d; font-size: 13px;">维护家庭名称与成员共享邀请码</p>
<section class="panel family-overview-panel">
<div class="family-profile">
<div>
<span class="eyebrow">家庭核心信息</span>
<strong>{{ familyName }}</strong>
<p>家庭编号:{{ family?.familyId || '-' }}</p>
</div>
<button class="icon-text-button" type="button" aria-label="编辑家庭资料" @click="startEdit">
改
</button>
</div>
<label>
家庭名称
<input v-model="familyForm.name" placeholder="例如:新生儿照护家庭、幸福小家" />
</label>
<label>
家庭邀请码
<div style="display: flex; gap: 8px;">
<input v-model="familyForm.inviteCode" placeholder="共享邀请码" style="flex: 1;" />
<button class="secondary-button" type="button" @click="generateInviteCode">随机生成</button>
</div>
</label>
<div class="settings-list" style="margin: 8px 0;">
<div>
<span>家庭编号</span>
<strong>{{ store.context?.family.familyId || '-' }}</strong>
</div>
<div>
<span>宝宝总数</span>
<strong>{{ store.babies.length }} 个宝宝</strong>
</div>
<div>
<span>成员人数</span>
<strong>{{ store.members.length }} 位成员</strong>
</div>
<div class="family-compact-row">
<span>成员加入码</span>
<button type="button" @click="copyInviteCode">
<strong>{{ inviteCode }}</strong>
<small>复制</small>
</button>
</div>
<button class="save-button" @click="saveFamily">保存家庭信息</button>
<div class="family-onboarding-actions">
<button type="button" @click="openCreateFamilyModal">新建家庭</button>
<button type="button" @click="openJoinFamilyModal">加入家庭</button>
</div>
<van-popup
v-model:show="showEditModal"
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" type="button" @click="showEditModal = false">×</button>
</div>
<div class="modal-form">
<label>
家庭名称
<input v-model="familyForm.name" placeholder="例如:新生儿照护家庭、幸福小家" />
</label>
<label>
成员加入码
<div style="display: flex; gap: 8px;">
<input v-model="familyForm.inviteCode" placeholder="给家人加入使用" style="flex: 1;" />
<button class="secondary-button" type="button" @click="generateInviteCode">随机生成</button>
</div>
</label>
<div class="modal-actions">
<button class="secondary-button" type="button" @click="showEditModal = false">取消</button>
<button class="save-button" type="button" @click="saveFamily">保存家庭信息</button>
</div>
</div>
</div>
</van-popup>
<van-popup
v-model:show="showCreateModal"
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" type="button" @click="showCreateModal = false">×</button>
</div>
<div class="modal-form">
<label>
家庭名称
<input v-model="createFamilyForm.name" placeholder="例如:新生儿照护家庭" />
</label>
<label>
我的称谓
<input v-model="createFamilyForm.roleName" placeholder="例如:宝妈、宝爸" />
</label>
<label>
成员加入码
<input v-model="createFamilyForm.inviteCode" placeholder="可不填,系统自动生成" />
</label>
<div class="modal-actions">
<button class="secondary-button" type="button" @click="showCreateModal = false">取消</button>
<button class="save-button" type="button" @click="submitCreateFamily">创建家庭</button>
</div>
</div>
</div>
</van-popup>
<van-popup
v-model:show="showJoinModal"
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" type="button" @click="showJoinModal = false">×</button>
</div>
<div class="modal-form">
<label>
成员加入码
<input v-model="joinFamilyForm.inviteCode" placeholder="输入家人分享的加入码" />
</label>
<label>
我的称谓
<input v-model="joinFamilyForm.roleName" placeholder="例如:宝妈、宝爸" />
</label>
<div class="modal-actions">
<button class="secondary-button" type="button" @click="showJoinModal = false">取消</button>
<button class="save-button" type="button" @click="submitJoinFamily">加入家庭</button>
</div>
</div>
</div>
</van-popup>
</section>
</template>
@@ -270,7 +270,7 @@ async function submitEdit() {
喂养方式
<select v-model="editForm.feedingMethod">
<option value="breastfeed">亲喂 (母乳)</option>
<option value="bottle">瓶喂 (母乳)</option>
<option value="bottle">挤出母乳</option>
<option value="formula">配方奶</option>
<option value="mixed">混合喂养</option>
</select>
@@ -1,12 +1,13 @@
<script setup lang="ts">
import { reactive, watch } from 'vue'
import { computed, reactive, ref, watch } from 'vue'
import { showToast } from 'vant'
import { useCareStore } from '../../stores/careStore'
import type { ExcretionType, FeedingMethod, RecordType } from '../../types/domain'
import type { CareQuickRule, CreateManualRecordPayload, ExcretionType, FeedingMethod, RecordType } from '../../types/domain'
import { getLocalDateStr, getLocalTimeStr } from '../../utils/format'
const props = defineProps<{
show: boolean
initialMode?: ManualMode
}>()
const emit = defineEmits<{
@@ -18,7 +19,57 @@ const store = useCareStore()
const quickNotes = ['拍嗝顺利', '溢奶微量', '金黄色便便', '安睡无闹', '微胀气', '吃得香']
type ManualMode = 'quick' | 'detail'
type DiaperChoice = 'pee' | 'poop' | 'both'
type FeedingQuickChoice = 'breastfeed20' | 'breastfeed10' | 'bottle' | 'formula'
type Draft = Omit<CreateManualRecordPayload, 'babyId'> & {
draftId: string
title: string
}
const mode = ref<ManualMode>('quick')
const selectedRuleId = ref('system_full_care')
const drafts = ref<Draft[]>([])
const savingQuick = ref(false)
const timePresets = [
{ label: '刚刚', minutesAgo: 0 },
{ label: '10分钟前', minutesAgo: 10 },
{ label: '20分钟前', minutesAgo: 20 },
{ label: '半小时前', minutesAgo: 30 }
]
const initialNow = store.getServerNow()
const quickForm = reactive({
date: getLocalDateStr(initialNow),
time: getLocalTimeStr(initialNow),
diaper: 'pee' as DiaperChoice,
feeding: 'breastfeed20' as FeedingQuickChoice,
operatorName: store.operatorName,
note: ''
})
const systemQuickRule: CareQuickRule = {
ruleId: 'system_full_care',
familyId: 'system',
name: '完整照护',
actions: ['diaper', 'feeding', 'sleep'],
diaperOffsetMinutes: 0,
feedingOffsetMinutes: 5,
sleepAfterFeedingMinutes: 5,
enabled: true,
sortOrder: 0
}
const quickRules = computed<CareQuickRule[]>(() => [
systemQuickRule,
...store.quickRules.filter(rule => rule.enabled)
])
const selectedRule = computed(() => quickRules.value.find(rule => rule.ruleId === selectedRuleId.value) || quickRules.value[0])
const ruleNeedsDiaper = computed(() => selectedRule.value.actions.includes('diaper'))
const ruleNeedsFeeding = computed(() => selectedRule.value.actions.includes('feeding'))
const ruleNeedsSleep = computed(() => selectedRule.value.actions.includes('sleep'))
const manualForm = reactive({
recordType: 'feeding' as RecordType,
startDate: getLocalDateStr(initialNow),
@@ -40,9 +91,227 @@ const manualForm = reactive({
watch(() => props.show, (newVal) => {
if (newVal) {
initForm()
initQuickForm()
}
})
function initQuickForm() {
const now = store.getServerNow()
quickForm.date = getLocalDateStr(now)
quickForm.time = getLocalTimeStr(now)
quickForm.operatorName = store.operatorName
quickForm.diaper = 'pee'
quickForm.feeding = defaultFeedingChoice()
quickForm.note = ''
selectedRuleId.value = quickRules.value[0]?.ruleId || 'system_full_care'
drafts.value = []
mode.value = props.initialMode || 'quick'
}
function defaultFeedingChoice(): FeedingQuickChoice {
const method = store.preferences.defaultFeedingMethod
if (method === 'bottle') return 'bottle'
if (method === 'formula') return 'formula'
return 'breastfeed20'
}
function applyTimePreset(minutesAgo: number) {
const base = new Date(store.getServerNow().getTime() - minutesAgo * 60000)
quickForm.date = getLocalDateStr(base)
quickForm.time = getLocalTimeStr(base)
}
function addMinutes(date: Date, minutes: number): Date {
return new Date(date.getTime() + minutes * 60000)
}
function toPayloadTime(date: Date): string {
return `${getLocalDateStr(date)}T${getLocalTimeStr(date)}:00`
}
function draftId() {
return `draft_${Date.now()}_${Math.random().toString(16).slice(2)}`
}
function buildFeedingDraft(start: Date): Draft {
const operatorName = quickForm.operatorName || store.operatorName
const baseNote = quickForm.note.trim() || null
if (quickForm.feeding === 'bottle' || quickForm.feeding === 'formula') {
const amount = store.preferences.defaultBottleAmount || (quickForm.feeding === 'bottle' ? 30 : 60)
return {
draftId: draftId(),
title: quickForm.feeding === 'bottle' ? `挤出母乳 ${amount}ml` : `配方奶 ${amount}ml`,
recordType: 'feeding',
startTime: toPayloadTime(start),
endTime: null,
durationMinutes: null,
leftDurationMinutes: null,
rightDurationMinutes: null,
feedingMethod: quickForm.feeding,
amountMl: amount,
excretionType: null,
operatorName,
note: baseNote
}
}
const duration = quickForm.feeding === 'breastfeed10' ? 10 : 20
const end = addMinutes(start, duration)
return {
draftId: draftId(),
title: `亲喂 ${duration}分钟`,
recordType: 'feeding',
startTime: toPayloadTime(start),
endTime: toPayloadTime(end),
durationMinutes: duration,
leftDurationMinutes: Math.floor(duration / 2),
rightDurationMinutes: Math.ceil(duration / 2),
feedingMethod: 'breastfeed',
amountMl: null,
excretionType: null,
operatorName,
note: baseNote
}
}
function buildSleepDraft(start: Date): Draft {
return {
draftId: draftId(),
title: '开始睡觉',
recordType: 'sleep',
startTime: toPayloadTime(start),
endTime: null,
durationMinutes: null,
leftDurationMinutes: null,
rightDurationMinutes: null,
feedingMethod: null,
amountMl: null,
excretionType: null,
operatorName: quickForm.operatorName || store.operatorName,
note: quickForm.note.trim() || null
}
}
function buildExcretionDraft(type: ExcretionType, start: Date): Draft {
return {
draftId: draftId(),
title: type === 'pee' ? '小便' : '大便',
recordType: 'excretion',
startTime: toPayloadTime(start),
endTime: null,
durationMinutes: null,
leftDurationMinutes: null,
rightDurationMinutes: null,
feedingMethod: null,
amountMl: null,
excretionType: type,
operatorName: quickForm.operatorName || store.operatorName,
note: quickForm.note.trim() || null
}
}
function generateDrafts() {
if (!quickForm.date || !quickForm.time) {
showToast('请选择大概时间')
return
}
const anchor = new Date(`${quickForm.date}T${quickForm.time}:00`)
if (isNaN(anchor.getTime())) {
showToast('时间格式不正确')
return
}
const nextDrafts: Draft[] = []
if (ruleNeedsDiaper.value) {
const diaperTime = addMinutes(anchor, selectedRule.value.diaperOffsetMinutes || 0)
if (quickForm.diaper === 'pee' || quickForm.diaper === 'both') {
nextDrafts.push(buildExcretionDraft('pee', diaperTime))
}
if (quickForm.diaper === 'poop' || quickForm.diaper === 'both') {
nextDrafts.push(buildExcretionDraft('poop', diaperTime))
}
}
let feedingEnd = anchor
if (ruleNeedsFeeding.value) {
const feedingStart = addMinutes(anchor, selectedRule.value.feedingOffsetMinutes || 0)
const feedingDraft = buildFeedingDraft(feedingStart)
nextDrafts.push(feedingDraft)
feedingEnd = feedingDraft.endTime ? new Date(feedingDraft.endTime) : addMinutes(feedingStart, 15)
}
if (ruleNeedsSleep.value) {
const sleepStart = ruleNeedsFeeding.value
? addMinutes(feedingEnd, selectedRule.value.sleepAfterFeedingMinutes || 0)
: anchor
nextDrafts.push(buildSleepDraft(sleepStart))
}
drafts.value = nextDrafts
}
function removeDraft(id: string) {
drafts.value = drafts.value.filter(item => item.draftId !== id)
}
function updateDraftStart(draft: Draft, value: string) {
if (!value) return
const oldStart = new Date(draft.startTime)
const oldEnd = draft.endTime ? new Date(draft.endTime) : null
draft.startTime = `${quickForm.date}T${value}:00`
if (oldEnd && !isNaN(oldStart.getTime()) && !isNaN(oldEnd.getTime())) {
const durationMs = oldEnd.getTime() - oldStart.getTime()
draft.endTime = toPayloadTime(new Date(new Date(draft.startTime).getTime() + durationMs))
}
}
function updateDraftDuration(draft: Draft, value: number | null) {
if (!value || value <= 0) return
draft.durationMinutes = value
if (draft.feedingMethod === 'breastfeed') {
draft.leftDurationMinutes = Math.floor(value / 2)
draft.rightDurationMinutes = Math.ceil(value / 2)
}
draft.endTime = toPayloadTime(addMinutes(new Date(draft.startTime), value))
draft.title = draft.feedingMethod === 'breastfeed' ? `亲喂 ${value}分钟` : draft.title
}
function updateDraftAmount(draft: Draft, value: number | null) {
if (!value || value <= 0) return
draft.amountMl = value
draft.title = draft.feedingMethod === 'formula' ? `配方奶 ${value}ml` : `挤出母乳 ${value}ml`
}
async function submitDrafts() {
if (!drafts.value.length) {
showToast('请先生成补记明细')
return
}
savingQuick.value = true
try {
await store.manualLogMany(drafts.value.map(({ draftId: _draftId, title: _title, ...payload }) => payload))
emit('update:show', false)
emit('success')
showToast({ message: `已补记 ${drafts.value.length} 条照护记录`, type: 'success' })
} catch (err: any) {
showToast(err.message || '补记失败')
} finally {
savingQuick.value = false
}
}
function draftStartTime(draft: Draft) {
return draft.startTime.split('T')[1]?.slice(0, 5) || ''
}
function quickRuleActionText(rule: CareQuickRule) {
const names: string[] = []
if (rule.actions.includes('diaper')) names.push('换尿布')
if (rule.actions.includes('feeding')) names.push('喂奶')
if (rule.actions.includes('sleep')) names.push('睡觉')
return names.join('、')
}
function initForm() {
const now = store.getServerNow()
manualForm.recordType = 'feeding'
@@ -183,7 +452,133 @@ async function submitManual() {
<button class="close-btn" type="button" @click="emit('update:show', false)">×</button>
</div>
<div class="modal-form">
<div class="manual-mode-tabs">
<button type="button" :class="{ active: mode === 'quick' }" @click="mode = 'quick'">常用补记</button>
<button type="button" :class="{ active: mode === 'detail' }" @click="mode = 'detail'">补一条详细记录</button>
</div>
<div v-if="mode === 'quick'" class="quick-manual-panel">
<label class="quick-section">
系统内置
<div class="quick-rule-grid">
<button
v-for="rule in quickRules"
:key="rule.ruleId"
type="button"
class="quick-rule-card"
:class="{ active: selectedRuleId === rule.ruleId }"
@click="selectedRuleId = rule.ruleId; drafts = []"
>
<strong>{{ rule.name }}</strong>
<span>{{ quickRuleActionText(rule) }}</span>
</button>
</div>
</label>
<div class="quick-config-hint">
家庭里的其他常用补记,可在「家庭 · 行为」中添加和调整。
</div>
<div class="quick-section">
<span class="quick-label">大概时间</span>
<div class="quick-time-presets">
<button
v-for="preset in timePresets"
:key="preset.label"
type="button"
class="chip sm"
@click="applyTimePreset(preset.minutesAgo); drafts = []"
>
{{ preset.label }}
</button>
</div>
<div class="quick-two-cols">
<label>
日期
<input v-model="quickForm.date" type="date" @change="drafts = []" />
</label>
<label>
时间
<input v-model="quickForm.time" type="time" @change="drafts = []" />
</label>
</div>
</div>
<label v-if="ruleNeedsDiaper" class="quick-section">
尿布里有
<div class="chip-group">
<button type="button" class="chip" :class="{ active: quickForm.diaper === 'pee' }" @click="quickForm.diaper = 'pee'; drafts = []">小便</button>
<button type="button" class="chip" :class="{ active: quickForm.diaper === 'poop' }" @click="quickForm.diaper = 'poop'; drafts = []">大便</button>
<button type="button" class="chip" :class="{ active: quickForm.diaper === 'both' }" @click="quickForm.diaper = 'both'; drafts = []">都有</button>
</div>
</label>
<label v-if="ruleNeedsFeeding" class="quick-section">
喂奶大概
<div class="chip-group">
<button type="button" class="chip" :class="{ active: quickForm.feeding === 'breastfeed20' }" @click="quickForm.feeding = 'breastfeed20'; drafts = []">亲喂20分钟</button>
<button type="button" class="chip" :class="{ active: quickForm.feeding === 'breastfeed10' }" @click="quickForm.feeding = 'breastfeed10'; drafts = []">亲喂10分钟</button>
<button type="button" class="chip" :class="{ active: quickForm.feeding === 'bottle' }" @click="quickForm.feeding = 'bottle'; drafts = []">挤出母乳默认量</button>
<button type="button" class="chip" :class="{ active: quickForm.feeding === 'formula' }" @click="quickForm.feeding = 'formula'; drafts = []">配方奶默认量</button>
</div>
</label>
<label class="quick-section">
记录人
<input v-model="quickForm.operatorName" placeholder="例如:宝妈、宝爸" @input="drafts = []" />
</label>
<label class="quick-section">
备注说明
<input v-model="quickForm.note" placeholder="选填,例如:状态好" @input="drafts = []" />
</label>
<button class="save-button" type="button" @click="generateDrafts">
生成明细
</button>
<div v-if="drafts.length" class="draft-panel">
<div class="draft-panel-title">
<strong>请确认这些明细</strong>
<span>{{ selectedRule.name }}</span>
</div>
<article v-for="draft in drafts" :key="draft.draftId" class="draft-card">
<div class="draft-card-header">
<strong>{{ draft.title }}</strong>
<button type="button" class="delete-button" @click="removeDraft(draft.draftId)">删除</button>
</div>
<div class="draft-fields">
<label>
时间
<input :value="draftStartTime(draft)" type="time" @input="updateDraftStart(draft, ($event.target as HTMLInputElement).value)" />
</label>
<label v-if="draft.recordType === 'excretion'">
类型
<select v-model="draft.excretionType">
<option value="pee">小便</option>
<option value="poop">大便</option>
</select>
</label>
<label v-if="draft.recordType === 'feeding' && draft.feedingMethod === 'breastfeed'">
亲喂分钟
<input :value="draft.durationMinutes || 20" type="number" min="1" max="180" @input="updateDraftDuration(draft, Number(($event.target as HTMLInputElement).value))" />
</label>
<label v-if="draft.recordType === 'feeding' && draft.feedingMethod !== 'breastfeed'">
奶量 ml
<input :value="draft.amountMl || 30" type="number" min="5" max="400" step="5" @input="updateDraftAmount(draft, Number(($event.target as HTMLInputElement).value))" />
</label>
</div>
</article>
<div class="modal-actions">
<button class="secondary-button" type="button" @click="drafts = []">重新生成</button>
<button class="save-button" type="button" :disabled="savingQuick" @click="submitDrafts">
{{ savingQuick ? '保存中...' : `保存 ${drafts.length} 条记录` }}
</button>
</div>
</div>
</div>
<div v-else class="modal-form">
<!-- 记录类型选择 -->
<label>
记录类型
@@ -233,7 +628,7 @@ async function submitManual() {
喂养方式
<select v-model="manualForm.feedingMethod">
<option value="breastfeed">亲喂 (母乳)</option>
<option value="bottle">瓶喂 (母乳)</option>
<option value="bottle">挤出母乳</option>
<option value="formula">配方奶</option>
<option value="mixed">混合喂养</option>
</select>
+6 -10
View File
@@ -7,7 +7,7 @@ import MemberSettingsTab from '../components/settings/MemberSettingsTab.vue'
import ActionSettingsTab from '../components/settings/ActionSettingsTab.vue'
const store = useCareStore()
const activeTab = ref('baby')
const activeTab = ref('family')
const currentBabyLabel = computed(() =>
store.baby ? `${store.baby.name} · ${store.baby.ageText}` : '未选择宝宝'
@@ -27,22 +27,18 @@ onMounted(async () => {
</header>
<van-tabs v-model:active="activeTab" shrink animated swipeable>
<!-- Tab 1: 宝宝维护 -->
<van-tab title="宝宝" name="baby">
<!-- 家庭入口:一个家庭下管理多个宝宝与家庭资料 -->
<van-tab title="家庭" name="family">
<FamilySettingsTab />
<BabySettingsTab />
</van-tab>
<!-- Tab 2: 家庭维护 -->
<van-tab title="家庭" name="family">
<FamilySettingsTab />
</van-tab>
<!-- Tab 3: 成员维护 -->
<!-- 成员维护 -->
<van-tab title="成员" name="members">
<MemberSettingsTab />
</van-tab>
<!-- Tab 4: 行为偏好维护 -->
<!-- 行为偏好维护 -->
<van-tab title="行为" name="actions">
<ActionSettingsTab />
</van-tab>
+11 -5
View File
@@ -25,6 +25,7 @@ const sortOrder = ref<'desc' | 'asc'>('desc')
// 补录弹窗控制
const showManualModal = ref(false)
const manualInitialMode = ref<'quick' | 'detail'>('quick')
// 编辑弹窗控制
const showEditModal = ref(false)
@@ -74,7 +75,8 @@ function toggleSortOrder() {
sortOrder.value = sortOrder.value === 'desc' ? 'asc' : 'desc'
}
function openManualModal() {
function openManualModal(mode: 'quick' | 'detail' = 'quick') {
manualInitialMode.value = mode
showManualModal.value = true
}
@@ -181,8 +183,11 @@ const totalCount = computed(() => records.value.length)
<span class="sort-icon">{{ sortOrder === 'desc' ? '↓' : '↑' }}</span>
{{ sortOrder === 'desc' ? '时间倒序' : '时间正序' }}
</button>
<button class="primary-pill-button" @click="openManualModal">
+ 补录
<button class="primary-pill-button" @click="openManualModal('quick')">
+ 补记照护
</button>
<button class="secondary-pill-button" @click="openManualModal('detail')">
补单次
</button>
</div>
</div>
@@ -277,12 +282,13 @@ const totalCount = computed(() => records.value.length)
</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>
<button class="primary-pill-button" @click="openManualModal('quick')">+ 补记照护</button>
<button class="secondary-pill-button" @click="openManualModal('detail')">补单次</button>
</div>
</div>
<!-- 弹窗:补录记录维护组件 -->
<TimelineManualModal v-model:show="showManualModal" @success="handleRecordChanged" />
<TimelineManualModal v-model:show="showManualModal" :initial-mode="manualInitialMode" @success="handleRecordChanged" />
<!-- 弹窗:编辑记录维护组件 -->
<TimelineEditModal v-model:show="showEditModal" :record="selectedRecord" @success="handleRecordChanged" />
+21 -10
View File
@@ -15,7 +15,7 @@ const currentFeedingTab = ref<FeedingTabType>(
const feedingTabOptions = [
{ value: 'breastfeed' as FeedingTabType, label: '亲喂' },
{ value: 'bottle' as FeedingTabType, label: '瓶喂' },
{ value: 'bottle' as FeedingTabType, label: '挤出母乳' },
{ value: 'formula' as FeedingTabType, label: '配方奶' },
{ value: 'mixed' as FeedingTabType, label: '混合喂养' }
]
@@ -191,6 +191,7 @@ async function handleOneClickBreastfeeding() {
endTime,
leftDurationMinutes: leftDur,
rightDurationMinutes: rightDur,
effectiveFeedingMinutes: dur,
breastSide: breastSideMode.value
}),
`已记录亲喂 ${dur}分钟(${startStr} ~ ${endStr})`
@@ -268,7 +269,7 @@ async function handleOneClickBreastfeeding() {
<h2>喂养</h2>
<span v-if="store.bfTimerActive" class="bf-live-badge">亲喂进行中</span>
</div>
<p>支持亲喂、瓶喂、配方奶与混合喂养多模式快捷记录。</p>
<p>支持亲喂、挤出母乳、配方奶与混合喂养多模式快捷记录。</p>
</div>
<!-- 四大喂养方式切换 Tab -->
@@ -302,7 +303,7 @@ async function handleOneClickBreastfeeding() {
<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' ? '计时中' : '已暂计' }}
{{ store.bfActiveSide === 'left' ? (store.bfPaused ? '暂停中' : '计时中') : '已暂计' }}
</span>
<span v-else class="bf-status-tag idle">
{{ breastSide === 'left' ? '优先起始' : '点击选择' }}
@@ -337,7 +338,7 @@ async function handleOneClickBreastfeeding() {
<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' ? '计时中' : '已暂计' }}
{{ store.bfActiveSide === 'right' ? (store.bfPaused ? '暂停中' : '计时中') : '已暂计' }}
</span>
<span v-else class="bf-status-tag idle">
{{ breastSide === 'right' ? '优先起始' : '点击选择' }}
@@ -364,7 +365,7 @@ async function handleOneClickBreastfeeding() {
<!-- 计时汇总横条 -->
<div v-if="store.bfTimerActive" class="bf-summary-bar">
<span>本次亲喂总计:<strong>{{ formatTotalBfTime() }}</strong></span>
<small>(左侧 {{ formatSec(store.bfLeftSeconds) }} · 右侧 {{ formatSec(store.bfRightSeconds) }})</small>
<small>(左侧 {{ formatSec(store.bfLeftSeconds) }} · 右侧 {{ formatSec(store.bfRightSeconds) }}{{ store.bfPaused ? ' · 已暂停' : '' }})</small>
</div>
<!-- 未在计时状态下的亲喂模式与时长配置 -->
@@ -455,9 +456,19 @@ async function handleOneClickBreastfeeding() {
round
type="warning"
:disabled="operating"
@click="store.switchBreastfeedSide(store.bfActiveSide === 'left' ? 'right' : 'left')"
@click="store.bfPaused ? store.resumeBreastfeedTimer(store.bfActiveSide === 'left' ? 'right' : 'left') : store.switchBreastfeedSide(store.bfActiveSide === 'left' ? 'right' : 'left')"
>
⇄ 切换到{{ store.bfActiveSide === 'left' ? '右侧' : '左侧' }}
⇄ {{ store.bfPaused ? '切换并继续' : '切换到' }}{{ store.bfActiveSide === 'left' ? '右侧' : '左侧' }}
</van-button>
<van-button
block
round
plain
type="primary"
:disabled="operating"
@click="store.bfPaused ? store.resumeBreastfeedTimer() : store.pauseBreastfeedTimer()"
>
{{ store.bfPaused ? '继续亲喂' : '暂停一会' }}
</van-button>
<van-button
block
@@ -472,7 +483,7 @@ async function handleOneClickBreastfeeding() {
</div>
</div>
<!-- Tab 2: 瓶喂 -->
<!-- Tab 2: 挤出母乳 -->
<div v-show="currentFeedingTab === 'bottle'" class="feeding-tab-content">
<div class="amount-row">
<span>母乳奶量 (ml)</span>
@@ -496,9 +507,9 @@ async function handleOneClickBreastfeeding() {
type="success"
:loading="operating"
:disabled="operating"
@click="runWithTip(() => store.logFeeding('bottle', bottleAmount), `已记录瓶喂 ${bottleAmount}ml`)"
@click="runWithTip(() => store.logFeeding('bottle', bottleAmount), `已记录挤出母乳 ${bottleAmount}ml`)"
>
记录瓶喂
记录挤出母乳
</van-button>
</div>
+189 -5
View File
@@ -1,9 +1,11 @@
import { defineStore } from 'pinia'
import {
createBaby,
createFamily as apiCreateFamily,
createFeeding,
createManualRecord,
createMember,
deleteQuickRule as apiDeleteQuickRule,
createPee,
createPoop,
deleteMember,
@@ -11,26 +13,32 @@ import {
endSleep,
getDailySummary,
getFamilyContext,
getQuickRules,
getServerTime,
joinFamily as apiJoinFamily,
setDefaultBaby as apiSetDefaultBaby,
saveQuickRule as apiSaveQuickRule,
startFeeding,
startSleep,
updateBaby,
updateCurrentBaby,
updateFamily,
updateMember,
updateRecord,
getServerTime
updateRecord
} from '../api/client'
import type {
ActionPreferences,
BabyProfile,
CareQuickRule,
CreateBabyPayload,
CreateFamilyPayload,
CreateManualRecordPayload,
CreateMemberPayload,
DailySummary,
FamilyContext,
FamilyMember,
FeedingMethod,
JoinFamilyPayload,
UpdateCareRecordPayload,
UpdateFamilyPayload,
UpdateMemberPayload
@@ -59,6 +67,22 @@ function loadInitialPreferences(): ActionPreferences {
let bfTicker: ReturnType<typeof setInterval> | null = null
interface BreastfeedPauseSegment {
startTime: string
endTime: string
durationSeconds: number
}
function toLocalDateTimeString(date: Date) {
const y = date.getFullYear()
const m = String(date.getMonth() + 1).padStart(2, '0')
const d = String(date.getDate()).padStart(2, '0')
const hh = String(date.getHours()).padStart(2, '0')
const mm = String(date.getMinutes()).padStart(2, '0')
const ss = String(date.getSeconds()).padStart(2, '0')
return `${y}-${m}-${d}T${hh}:${mm}:${ss}`
}
function startBfTicker(store: any) {
if (bfTicker) return
bfTicker = setInterval(() => {
@@ -66,6 +90,7 @@ function startBfTicker(store: any) {
stopBfTicker()
return
}
if (store.bfPaused) return
const now = Date.now()
const delta = Math.max(0, Math.floor((now - store.bfLastTickTime) / 1000))
if (delta > 0) {
@@ -93,14 +118,19 @@ export const useCareStore = defineStore('care', {
babies: [] as BabyProfile[],
members: [] as FamilyMember[],
selectedBabyId: localStorage.getItem('selectedBabyId') || '',
activeFamilyId: localStorage.getItem('activeFamilyId') || '',
baby: null as BabyProfile | null,
summary: null as DailySummary | null,
operatorName: localStorage.getItem('operatorName') || '宝妈',
preferences: loadInitialPreferences() as ActionPreferences,
quickRules: [] as CareQuickRule[],
bfTimerActive: false,
bfActiveSide: 'left' as 'left' | 'right',
bfLeftSeconds: 0,
bfRightSeconds: 0,
bfPaused: false,
bfPauseStartedAt: 0,
bfPauseSegments: [] as BreastfeedPauseSegment[],
bfLastTickTime: 0,
serverOffsetMs: 0,
loading: false,
@@ -125,9 +155,16 @@ export const useCareStore = defineStore('care', {
this.error = ''
try {
await this.syncServerTime()
this.context = await getFamilyContext()
this.context = await getFamilyContext(this.activeFamilyId)
this.activeFamilyId = this.context.family.familyId
localStorage.setItem('activeFamilyId', this.activeFamilyId)
this.babies = this.context.babies
this.members = this.context.members
this.quickRules = await getQuickRules(this.context.family.familyId)
if (this.selectedBabyId && !this.babies.some(baby => baby.babyId === this.selectedBabyId)) {
this.selectedBabyId = ''
localStorage.removeItem('selectedBabyId')
}
if (!this.selectedBabyId && this.babies[0]) {
this.selectedBabyId = this.babies[0].babyId
}
@@ -144,6 +181,48 @@ export const useCareStore = defineStore('care', {
this.loading = false
}
},
applyFamilyContext(context: FamilyContext) {
this.context = context
this.activeFamilyId = context.family.familyId
localStorage.setItem('activeFamilyId', this.activeFamilyId)
this.babies = context.babies
this.members = context.members
this.quickRules = []
this.selectedBabyId = ''
localStorage.removeItem('selectedBabyId')
const selected = this.babies[0]
this.baby = selected || null
if (selected) {
this.selectedBabyId = selected.babyId
localStorage.setItem('selectedBabyId', selected.babyId)
}
const defaultMember = this.members.find(member => member.defaultOperator) || this.members[0]
if (defaultMember) {
this.setOperatorName(defaultMember.roleName)
}
},
async createFamily(payload: CreateFamilyPayload) {
const context = await apiCreateFamily(payload)
this.applyFamilyContext(context)
await this.reloadQuickRules()
if (this.baby) {
await this.refreshSummary()
} else {
this.summary = null
}
return context
},
async joinFamily(payload: JoinFamilyPayload) {
const context = await apiJoinFamily(payload)
this.applyFamilyContext(context)
await this.reloadQuickRules()
if (this.baby) {
await this.refreshSummary()
} else {
this.summary = null
}
return context
},
async refreshSummary() {
if (!this.baby) return
await this.syncServerTime()
@@ -164,6 +243,23 @@ export const useCareStore = defineStore('care', {
this.preferences = { ...this.preferences, ...prefs }
localStorage.setItem('actionPreferences', JSON.stringify(this.preferences))
},
async reloadQuickRules() {
const familyId = this.context?.family.familyId
this.quickRules = await getQuickRules(familyId)
},
async addQuickRule(rule: Omit<CareQuickRule, 'ruleId'>) {
const saved = await apiSaveQuickRule(rule)
await this.reloadQuickRules()
return saved
},
async updateQuickRule(ruleId: string, rule: Omit<CareQuickRule, 'ruleId'>) {
await apiSaveQuickRule({ ...rule, ruleId })
await this.reloadQuickRules()
},
async deleteQuickRule(ruleId: string) {
await apiDeleteQuickRule(ruleId)
await this.reloadQuickRules()
},
async saveBaby(payload: Pick<BabyProfile, 'name' | 'gender' | 'birthDate' | 'deliveryType'>) {
this.baby = this.baby ? await updateBaby(this.baby.babyId, payload) : await updateCurrentBaby(payload)
this.babies = this.babies.map(baby => baby.babyId === this.baby?.babyId ? this.baby! : baby)
@@ -226,6 +322,8 @@ export const useCareStore = defineStore('care', {
endTime?: string
leftDurationMinutes?: number
rightDurationMinutes?: number
effectiveFeedingMinutes?: number
pauseSegmentsJson?: string
note?: string
} | FeedingMethod,
amountMl?: number,
@@ -251,6 +349,8 @@ export const useCareStore = defineStore('care', {
endTime: payloadOrMethod.endTime,
leftDurationMinutes: payloadOrMethod.leftDurationMinutes,
rightDurationMinutes: payloadOrMethod.rightDurationMinutes,
effectiveFeedingMinutes: payloadOrMethod.effectiveFeedingMinutes,
pauseSegmentsJson: payloadOrMethod.pauseSegmentsJson,
note: payloadOrMethod.note,
operatorName: this.operatorName
})
@@ -264,6 +364,9 @@ export const useCareStore = defineStore('care', {
activeSide: this.bfActiveSide,
leftSeconds: this.bfLeftSeconds,
rightSeconds: this.bfRightSeconds,
paused: this.bfPaused,
pauseStartedAt: this.bfPauseStartedAt,
pauseSegments: this.bfPauseSegments,
lastTickTime: this.bfLastTickTime
}))
} catch {
@@ -290,9 +393,12 @@ export const useCareStore = defineStore('care', {
this.bfActiveSide = data.activeSide === 'right' ? 'right' : 'left'
this.bfLeftSeconds = Number(data.leftSeconds) || 0
this.bfRightSeconds = Number(data.rightSeconds) || 0
this.bfPaused = !!data.paused
this.bfPauseStartedAt = Number(data.pauseStartedAt) || 0
this.bfPauseSegments = Array.isArray(data.pauseSegments) ? data.pauseSegments : []
const lastTick = Number(data.lastTickTime) || Date.now()
const delta = Math.max(0, Math.floor((Date.now() - lastTick) / 1000))
if (delta > 0) {
if (!this.bfPaused && delta > 0) {
if (this.bfActiveSide === 'left') {
this.bfLeftSeconds += delta
} else {
@@ -312,6 +418,9 @@ export const useCareStore = defineStore('care', {
this.bfActiveSide = this.preferences.defaultBreastSide || 'left'
this.bfLeftSeconds = this.bfActiveSide === 'left' ? totalElapsed : 0
this.bfRightSeconds = this.bfActiveSide === 'right' ? totalElapsed : 0
this.bfPaused = false
this.bfPauseStartedAt = 0
this.bfPauseSegments = []
this.bfLastTickTime = Date.now()
this.bfTimerActive = true
}
@@ -322,6 +431,9 @@ export const useCareStore = defineStore('care', {
this.bfTimerActive = false
this.bfLeftSeconds = 0
this.bfRightSeconds = 0
this.bfPaused = false
this.bfPauseStartedAt = 0
this.bfPauseSegments = []
this.clearBfTimerStorage()
stopBfTicker()
}
@@ -338,6 +450,9 @@ export const useCareStore = defineStore('care', {
this.bfActiveSide = breastSide
this.bfLeftSeconds = 0
this.bfRightSeconds = 0
this.bfPaused = false
this.bfPauseStartedAt = 0
this.bfPauseSegments = []
this.bfLastTickTime = Date.now()
this.persistBfTimer()
startBfTicker(this)
@@ -345,6 +460,11 @@ export const useCareStore = defineStore('care', {
},
switchBreastfeedSide(targetSide: 'left' | 'right') {
if (!this.bfTimerActive || this.bfActiveSide === targetSide) return
if (this.bfPaused) {
this.bfActiveSide = targetSide
this.persistBfTimer()
return
}
const now = Date.now()
const delta = Math.max(0, Math.floor((now - this.bfLastTickTime) / 1000))
if (delta > 0) {
@@ -358,9 +478,54 @@ export const useCareStore = defineStore('care', {
this.bfLastTickTime = now
this.persistBfTimer()
},
pauseBreastfeedTimer() {
if (!this.bfTimerActive || this.bfPaused) 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.bfPaused = true
this.bfPauseStartedAt = now
this.bfLastTickTime = now
this.persistBfTimer()
},
resumeBreastfeedTimer(targetSide?: 'left' | 'right') {
if (!this.bfTimerActive || !this.bfPaused) return
const now = Date.now()
const pauseStart = this.bfPauseStartedAt || now
const durationSeconds = Math.max(0, Math.floor((now - pauseStart) / 1000))
this.bfPauseSegments.push({
startTime: toLocalDateTimeString(new Date(pauseStart)),
endTime: toLocalDateTimeString(new Date(now)),
durationSeconds
})
if (targetSide) {
this.bfActiveSide = targetSide
}
this.bfPaused = false
this.bfPauseStartedAt = 0
this.bfLastTickTime = now
this.persistBfTimer()
},
async endBreastfeedTimer() {
if (!this.baby) return
if (this.bfTimerActive) {
if (this.bfTimerActive && this.bfPaused) {
const now = Date.now()
const pauseStart = this.bfPauseStartedAt || now
this.bfPauseSegments.push({
startTime: toLocalDateTimeString(new Date(pauseStart)),
endTime: toLocalDateTimeString(new Date(now)),
durationSeconds: Math.max(0, Math.floor((now - pauseStart) / 1000))
})
this.bfPaused = false
this.bfPauseStartedAt = 0
this.bfLastTickTime = now
} else if (this.bfTimerActive) {
const now = Date.now()
const delta = Math.max(0, Math.floor((now - this.bfLastTickTime) / 1000))
if (delta > 0) {
@@ -373,18 +538,24 @@ export const useCareStore = defineStore('care', {
}
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
const effectiveMinutes = leftMinutes + rightMinutes
await endFeeding({
babyId: this.baby.babyId,
breastSide: this.bfActiveSide,
leftDurationMinutes: leftMinutes,
rightDurationMinutes: rightMinutes,
effectiveFeedingMinutes: effectiveMinutes,
pauseSegmentsJson: this.bfPauseSegments.length ? JSON.stringify(this.bfPauseSegments) : undefined,
operatorName: this.operatorName
})
this.bfTimerActive = false
this.bfLeftSeconds = 0
this.bfRightSeconds = 0
this.bfPaused = false
this.bfPauseStartedAt = 0
this.bfPauseSegments = []
this.clearBfTimerStorage()
stopBfTicker()
await this.refreshSummary()
@@ -426,6 +597,19 @@ export const useCareStore = defineStore('care', {
await this.refreshSummary()
return res
},
async manualLogMany(payloads: Array<Omit<CreateManualRecordPayload, 'babyId'>>) {
if (!this.baby || payloads.length === 0) return []
const results = []
for (const payload of payloads) {
const res = await createManualRecord({
...payload,
babyId: this.baby.babyId
})
results.push(res)
}
await this.refreshSummary()
return results
},
async editRecord(recordId: string, payload: UpdateCareRecordPayload) {
const res = await updateRecord(recordId, payload)
await this.refreshSummary()
+658
View File
@@ -575,6 +575,313 @@ button {
text-align: right;
}
.family-overview-panel,
.baby-overview-panel {
display: grid;
gap: 10px;
}
.family-profile {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
padding: 0 0 12px;
border-bottom: 1px solid #f0ece5;
}
.family-profile strong {
display: block;
margin-top: 4px;
color: #17202a;
font-size: 22px;
line-height: 1.2;
word-break: break-word;
}
.family-profile p {
margin: 5px 0 0;
color: #65707d;
font-size: 12px;
line-height: 1.35;
word-break: break-all;
}
.family-profile-label {
display: block;
color: #65707d;
font-size: 13px;
font-weight: 800;
}
.icon-text-button {
flex: 0 0 auto;
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 30px;
min-width: 44px;
padding: 6px 10px;
border-radius: 999px;
background: transparent;
color: #6b4a1d;
border: 1px solid #eadfcc;
font-size: 12px;
font-weight: 900;
cursor: pointer;
}
.icon-text-button::before {
content: "";
width: 10px;
height: 10px;
margin-right: 4px;
background: currentColor;
clip-path: polygon(74% 0, 100% 26%, 31% 95%, 0 100%, 5% 69%);
}
.icon-text-button:hover {
background: #eee6d9;
}
.family-compact-row {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
padding: 2px 0;
}
.family-compact-row > span {
color: #65707d;
font-size: 13px;
font-weight: 800;
}
.family-compact-row button {
min-width: 0;
display: inline-flex;
align-items: baseline;
gap: 8px;
padding: 7px 10px;
border-radius: 8px;
background: #faf7f1;
color: #1f2933;
cursor: pointer;
}
.family-compact-row button:active {
background: #f4efe6;
}
.family-compact-row strong {
font-size: 16px;
line-height: 1.2;
}
.family-compact-row small {
color: #8a540d;
font-size: 12px;
font-weight: 800;
}
.family-onboarding-actions {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
}
.family-onboarding-actions button {
padding: 9px 10px;
border-radius: 8px;
background: #f8fafc;
color: #475569;
border: 1px dashed #cbd5e1;
font-size: 13px;
font-weight: 800;
cursor: pointer;
}
.family-onboarding-actions button:active {
background: #eef2f7;
}
.family-core-grid {
display: grid;
grid-template-columns: 1fr;
gap: 10px;
}
.family-core-grid div,
.copy-info-tile {
min-width: 0;
padding: 13px;
border-radius: 8px;
background: #faf7f1;
}
.copy-info-tile {
display: grid;
gap: 5px;
width: 100%;
border: 1px solid transparent;
color: #1f2933;
text-align: left;
cursor: pointer;
}
.copy-info-tile:active {
border-color: #d4c2a1;
background: #f4efe6;
}
.family-core-grid span,
.copy-info-tile span,
.family-id-row span {
display: block;
color: #65707d;
font-size: 12px;
font-weight: 800;
}
.family-core-grid strong,
.copy-info-tile strong {
display: block;
margin-top: 5px;
color: #1f2933;
font-size: 22px;
line-height: 1.25;
word-break: break-word;
}
.copy-info-tile small {
color: #8a540d;
font-size: 12px;
font-weight: 800;
}
.family-id-row {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid #f0ece5;
}
.family-id-row strong {
min-width: 0;
color: #1f2933;
font-size: 13px;
text-align: right;
word-break: break-all;
}
.baby-profile {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
padding: 0 0 12px;
border-bottom: 1px solid #f0ece5;
}
.baby-profile strong {
display: block;
margin-top: 4px;
color: #17202a;
font-size: 22px;
line-height: 1.2;
word-break: break-word;
}
.baby-profile p {
margin: 5px 0 0;
color: #65707d;
font-size: 12px;
}
.baby-compact-row {
display: grid;
gap: 4px;
padding: 2px 0 4px;
}
.baby-compact-row span {
color: #65707d;
font-size: 13px;
font-weight: 800;
}
.baby-compact-row strong {
color: #1f2933;
font-size: 14px;
line-height: 1.35;
}
.baby-list {
display: grid;
gap: 6px;
padding-top: 2px;
}
.baby-list-item {
display: flex;
justify-content: space-between;
align-items: center;
gap: 12px;
padding: 9px 11px;
border: 1px solid #ebe4d8;
border-radius: 8px;
background: #fffdfa;
color: #1f2933;
text-align: left;
cursor: pointer;
}
.baby-list-item.active {
border-color: #1f7a5c;
background: #effaf5;
}
.baby-list-item span {
display: grid;
gap: 2px;
min-width: 0;
}
.baby-list-item strong {
font-size: 14px;
}
.baby-list-item small {
color: #65707d;
font-size: 12px;
}
.baby-list-item em {
flex: 0 0 auto;
padding: 2px 7px;
border-radius: 6px;
background: #d1fadf;
color: #027a48;
font-size: 11px;
font-style: normal;
font-weight: 800;
}
.baby-default-action {
display: flex;
justify-content: flex-end;
padding-top: 2px;
}
.form-actions {
display: grid;
grid-template-columns: 0.8fr 1.2fr;
gap: 10px;
}
.feeding-status,
.amount-row,
.two-actions {
@@ -961,6 +1268,25 @@ button {
background: #734509;
}
.secondary-pill-button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 6px;
padding: 10px 16px;
border-radius: 999px;
background: #f4efe6;
color: #5d6470;
border: 1px solid #e4d8c6;
font-weight: 800;
font-size: 14px;
cursor: pointer;
}
.secondary-pill-button:hover {
background: #eee6d9;
}
.chip-group {
display: flex;
flex-wrap: wrap;
@@ -1106,6 +1432,338 @@ button {
gap: 16px;
}
.manual-mode-tabs {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 6px;
padding: 4px;
margin-bottom: 16px;
border-radius: 12px;
background: #f4efe6;
}
.manual-mode-tabs button {
padding: 9px 8px;
border-radius: 9px;
background: transparent;
color: #65707d;
font-weight: 800;
cursor: pointer;
}
.manual-mode-tabs button.active {
background: #ffffff;
color: #8a540d;
box-shadow: 0 2px 8px rgba(80, 64, 43, 0.08);
}
.quick-manual-panel {
display: grid;
gap: 14px;
}
.quick-section {
display: grid;
gap: 8px;
color: #4b5563;
font-size: 14px;
font-weight: 800;
}
.quick-label {
color: #4b5563;
font-size: 14px;
font-weight: 800;
}
.quick-rule-grid {
display: grid;
gap: 8px;
}
.quick-rule-card {
display: grid;
gap: 3px;
padding: 11px 12px;
border: 1px solid #ebe4d8;
border-radius: 10px;
background: #fffdfa;
color: #1f2933;
text-align: left;
cursor: pointer;
}
.quick-rule-card.active {
border-color: #b7791f;
background: #fff7e6;
box-shadow: 0 0 0 2px rgba(183, 121, 31, 0.1);
}
.quick-rule-card span {
color: #65707d;
font-size: 12px;
font-weight: 600;
}
.quick-config-hint {
padding: 10px 12px;
border-radius: 10px;
background: #f8fafc;
color: #65707d;
font-size: 12px;
font-weight: 700;
}
.quick-time-presets {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.quick-two-cols,
.draft-fields {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px;
}
.quick-section input,
.quick-section select,
.draft-fields input,
.draft-fields select {
width: 100%;
border: 1px solid #ded6c8;
border-radius: 10px;
padding: 11px 12px;
background: #fffdfa;
color: #1f2933;
font-size: 14px;
}
.draft-panel {
display: grid;
gap: 10px;
padding-top: 4px;
}
.draft-panel-title {
display: flex;
justify-content: space-between;
gap: 10px;
color: #1f2933;
}
.draft-panel-title span {
color: #65707d;
font-size: 12px;
font-weight: 700;
}
.draft-card {
display: grid;
gap: 10px;
padding: 12px;
border: 1px solid #ebe4d8;
border-radius: 10px;
background: #faf7f1;
}
.draft-card-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.quick-rule-list,
.quick-rule-editor {
display: grid;
gap: 10px;
}
.quick-rule-editor {
padding-top: 12px;
border-top: 1px solid #f0ece5;
}
.action-mobile-page {
display: grid;
gap: 14px;
}
.action-mobile-card {
display: grid;
gap: 16px;
}
.action-card-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.action-card-head h3 {
margin: 3px 0 0;
font-size: 20px;
}
.mini-save-btn {
padding: 8px 14px;
border-radius: 999px;
background: #238565;
color: #ffffff;
font-size: 13px;
font-weight: 800;
}
.mobile-setting-block {
display: grid;
gap: 10px;
}
.mobile-setting-title {
display: flex;
justify-content: space-between;
gap: 10px;
align-items: flex-end;
}
.mobile-setting-title strong {
color: #1f2933;
font-size: 15px;
}
.mobile-setting-title span {
color: #65707d;
font-size: 12px;
font-weight: 700;
}
.mobile-option-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
}
.mobile-option-grid.two {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.mobile-option-grid.three {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.mobile-option {
min-height: 46px;
padding: 10px 8px;
border: 1px solid #eadfce;
border-radius: 12px;
background: #fffdfa;
color: #4b5563;
font-weight: 800;
}
.mobile-option.active {
border-color: #9a5f11;
background: #fff3d7;
color: #74470a;
box-shadow: 0 0 0 2px rgba(154, 95, 17, 0.08);
}
.amount-mobile-row {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 10px;
align-items: center;
}
.amount-mobile-row input,
.mobile-rule-editor input,
.mobile-offset-list input {
width: 100%;
border: 1px solid #ded6c8;
border-radius: 12px;
padding: 12px;
background: #fffdfa;
color: #1f2933;
font-size: 16px;
font-weight: 800;
}
.amount-chip-grid {
display: grid;
grid-template-columns: repeat(2, auto);
gap: 6px;
}
.mobile-switch-list {
display: grid;
gap: 8px;
padding-top: 4px;
border-top: 1px solid #f0ece5;
}
.mobile-switch-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
padding: 10px 0;
}
.mobile-switch-row span {
display: grid;
gap: 3px;
}
.mobile-switch-row strong {
color: #1f2933;
font-size: 14px;
}
.mobile-switch-row small {
color: #65707d;
font-size: 12px;
}
.mobile-switch-row input {
width: 24px;
height: 24px;
flex-shrink: 0;
}
.mobile-rule-card {
display: flex;
justify-content: space-between;
align-items: center;
gap: 10px;
}
.mobile-rule-editor label {
display: grid;
gap: 8px;
color: #4b5563;
font-size: 14px;
font-weight: 800;
}
.mobile-offset-list {
display: grid;
gap: 8px;
}
.mobile-offset-list label {
grid-template-columns: 1fr 82px auto;
align-items: center;
}
.mobile-offset-list span {
color: #65707d;
font-size: 12px;
font-weight: 700;
}
.modal-form label {
display: grid;
gap: 6px;
+30
View File
@@ -1,6 +1,7 @@
export type FeedingMethod = 'breastfeed' | 'bottle' | 'formula' | 'mixed' | 'other'
export type RecordType = 'feeding' | 'sleep' | 'excretion'
export type ExcretionType = 'pee' | 'poop'
export type CareQuickAction = 'diaper' | 'feeding' | 'sleep'
export interface BabyProfile {
babyId: string
@@ -45,6 +46,8 @@ export interface CareRecord {
durationMinutes?: number | null
leftDurationMinutes?: number | null
rightDurationMinutes?: number | null
effectiveFeedingMinutes?: number | null
pauseSegmentsJson?: string | null
feedingMethod?: FeedingMethod | null
amountMl?: number | null
excretionType?: ExcretionType | null
@@ -80,6 +83,18 @@ export interface ActionPreferences {
autoBurpReminder: boolean
}
export interface CareQuickRule {
ruleId: string
familyId: string
name: string
actions: CareQuickAction[]
diaperOffsetMinutes: number
feedingOffsetMinutes: number
sleepAfterFeedingMinutes: number
enabled: boolean
sortOrder: number
}
export interface CreateManualRecordPayload {
babyId: string
recordType: RecordType
@@ -88,6 +103,8 @@ export interface CreateManualRecordPayload {
durationMinutes?: number | null
leftDurationMinutes?: number | null
rightDurationMinutes?: number | null
effectiveFeedingMinutes?: number | null
pauseSegmentsJson?: string | null
feedingMethod?: FeedingMethod | null
amountMl?: number | null
excretionType?: ExcretionType | null
@@ -102,6 +119,8 @@ export interface UpdateCareRecordPayload {
durationMinutes?: number | null
leftDurationMinutes?: number | null
rightDurationMinutes?: number | null
effectiveFeedingMinutes?: number | null
pauseSegmentsJson?: string | null
feedingMethod?: FeedingMethod | null
amountMl?: number | null
excretionType?: ExcretionType | null
@@ -123,6 +142,17 @@ export interface UpdateFamilyPayload {
inviteCode?: string | null
}
export interface CreateFamilyPayload {
name: string
roleName: string
inviteCode?: string | null
}
export interface JoinFamilyPayload {
inviteCode: string
roleName: string
}
export interface CreateMemberPayload {
roleName: string
roleType?: string
+1 -1
View File
@@ -73,7 +73,7 @@ export function formatMinutes(minutes: number) {
export const FEEDING_METHOD_MAP: Record<string, string> = {
breastfeed: '亲喂',
bottle: '瓶喂',
bottle: '挤出母乳',
formula: '配方奶',
mixed: '混合喂养',
other: '其他'