优化页面展示

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

@@ -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>