优化代码结构
This commit is contained in:
1 parent
8c7a9040d2
commit
cbcd6b4c7f
97 files changed
+4350
-1183
No files matched your search
@@ -0,0 +1,306 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, watch } from 'vue'
|
||||
import { showToast } from 'vant'
|
||||
import { useCareStore } from '../../stores/careStore'
|
||||
import type { ExcretionType, FeedingMethod, RecordType } from '../../types/domain'
|
||||
|
||||
const props = defineProps<{
|
||||
show: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:show', value: boolean): void
|
||||
(e: 'success'): void
|
||||
}>()
|
||||
|
||||
const store = useCareStore()
|
||||
|
||||
const quickNotes = ['拍嗝顺利', '溢奶微量', '金黄色便便', '安睡无闹', '微胀气', '吃得香']
|
||||
|
||||
const manualForm = reactive({
|
||||
recordType: 'feeding' as RecordType,
|
||||
startDate: new Date().toISOString().slice(0, 10),
|
||||
startTimeStr: new Date().toTimeString().slice(0, 5),
|
||||
hasEndTime: false,
|
||||
endDate: new Date().toISOString().slice(0, 10),
|
||||
endTimeStr: '',
|
||||
durationMinutes: null as number | null,
|
||||
feedingMethod: 'breastfeed' as FeedingMethod,
|
||||
amountMl: null as number | null,
|
||||
breastSide: 'left' as 'left' | 'right',
|
||||
excretionType: 'pee' as ExcretionType,
|
||||
operatorName: store.operatorName,
|
||||
note: ''
|
||||
})
|
||||
|
||||
watch(() => props.show, (newVal) => {
|
||||
if (newVal) {
|
||||
initForm()
|
||||
}
|
||||
})
|
||||
|
||||
function initForm() {
|
||||
const now = new Date()
|
||||
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.feedingMethod = store.preferences.defaultFeedingMethod || 'breastfeed'
|
||||
manualForm.amountMl = manualForm.feedingMethod === 'bottle' ? store.preferences.defaultBottleAmount : null
|
||||
manualForm.breastSide = store.preferences.defaultBreastSide || 'left'
|
||||
manualForm.excretionType = 'pee'
|
||||
manualForm.operatorName = store.operatorName
|
||||
manualForm.note = ''
|
||||
}
|
||||
|
||||
function appendNote(tag: string) {
|
||||
manualForm.note = manualForm.note ? `${manualForm.note},${tag}` : tag
|
||||
}
|
||||
|
||||
async function submitManual() {
|
||||
if (!manualForm.startDate || !manualForm.startTimeStr) {
|
||||
showToast('请选择开始时间')
|
||||
return
|
||||
}
|
||||
const startTime = `${manualForm.startDate}T${manualForm.startTimeStr}:00`
|
||||
let endTime: string | null = null
|
||||
if (manualForm.hasEndTime && manualForm.endDate && manualForm.endTimeStr) {
|
||||
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 : ''}`
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
await store.manualLog({
|
||||
recordType: manualForm.recordType,
|
||||
startTime,
|
||||
endTime,
|
||||
durationMinutes: manualForm.durationMinutes,
|
||||
feedingMethod: manualForm.recordType === 'feeding' ? manualForm.feedingMethod : null,
|
||||
amountMl: manualForm.recordType === 'feeding' && manualForm.feedingMethod !== 'breastfeed' ? manualForm.amountMl : null,
|
||||
excretionType: manualForm.recordType === 'excretion' ? manualForm.excretionType : null,
|
||||
operatorName: manualForm.operatorName || store.operatorName,
|
||||
note: finalNote
|
||||
})
|
||||
emit('update:show', false)
|
||||
emit('success')
|
||||
showToast({ message: '补录成功', type: 'success' })
|
||||
} catch (err: any) {
|
||||
showToast(err.message || '补录失败')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="props.show" class="modal-backdrop" @click.self="emit('update:show', false)">
|
||||
<div class="modal-sheet">
|
||||
<div class="modal-header">
|
||||
<h3>补录照护记录</h3>
|
||||
<button class="close-btn" @click="emit('update:show', false)">×</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-form">
|
||||
<!-- 记录类型选择 -->
|
||||
<label>
|
||||
记录类型
|
||||
<div class="chip-group">
|
||||
<button
|
||||
type="button"
|
||||
class="chip"
|
||||
:class="{ active: manualForm.recordType === 'feeding' }"
|
||||
@click="manualForm.recordType = 'feeding'"
|
||||
>
|
||||
🍼 喂奶
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="chip"
|
||||
:class="{ active: manualForm.recordType === 'sleep' }"
|
||||
@click="manualForm.recordType = 'sleep'"
|
||||
>
|
||||
🌙 睡眠
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="chip"
|
||||
:class="{ active: manualForm.recordType === 'excretion' }"
|
||||
@click="manualForm.recordType = 'excretion'"
|
||||
>
|
||||
🧷 尿布排泄
|
||||
</button>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<!-- 发生时间 -->
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px;">
|
||||
<label>
|
||||
开始日期
|
||||
<input v-model="manualForm.startDate" type="date" />
|
||||
</label>
|
||||
<label>
|
||||
开始时间
|
||||
<input v-model="manualForm.startTimeStr" type="time" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- 喂奶特定字段 -->
|
||||
<template v-if="manualForm.recordType === 'feeding'">
|
||||
<label>
|
||||
喂养方式
|
||||
<select v-model="manualForm.feedingMethod">
|
||||
<option value="breastfeed">亲喂 (母乳)</option>
|
||||
<option value="bottle">瓶喂 (母乳)</option>
|
||||
<option value="formula">配方奶</option>
|
||||
<option value="mixed">混合喂养</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<div v-if="manualForm.feedingMethod === 'breastfeed'">
|
||||
<label>
|
||||
亲喂侧
|
||||
<div class="chip-group">
|
||||
<button
|
||||
type="button"
|
||||
class="chip sm"
|
||||
:class="{ active: manualForm.breastSide === 'left' }"
|
||||
@click="manualForm.breastSide = 'left'"
|
||||
>
|
||||
左侧
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="chip sm"
|
||||
:class="{ active: manualForm.breastSide === 'right' }"
|
||||
@click="manualForm.breastSide = '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>
|
||||
|
||||
<!-- 睡眠特定字段 -->
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<label v-if="!manualForm.hasEndTime">
|
||||
睡眠持续时间 (分钟,可选)
|
||||
<input v-model.number="manualForm.durationMinutes" type="number" placeholder="例如:45" />
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<!-- 排泄特定字段 -->
|
||||
<template v-if="manualForm.recordType === 'excretion'">
|
||||
<label>
|
||||
排泄类型
|
||||
<div class="chip-group">
|
||||
<button
|
||||
type="button"
|
||||
class="chip"
|
||||
:class="{ active: manualForm.excretionType === 'pee' }"
|
||||
@click="manualForm.excretionType = 'pee'"
|
||||
>
|
||||
💧 嘘嘘 (尿尿)
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="chip"
|
||||
:class="{ active: manualForm.excretionType === 'poop' }"
|
||||
@click="manualForm.excretionType = 'poop'"
|
||||
>
|
||||
💩 便便 (大便)
|
||||
</button>
|
||||
</div>
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<!-- 记录人选择 -->
|
||||
<label>
|
||||
记录人称谓
|
||||
<div style="display: flex; gap: 8px;">
|
||||
<input v-model="manualForm.operatorName" placeholder="例如:宝妈、宝爸" />
|
||||
</div>
|
||||
<div class="chip-group">
|
||||
<button
|
||||
v-for="m in store.members"
|
||||
:key="m.memberId"
|
||||
type="button"
|
||||
class="chip sm"
|
||||
:class="{ active: manualForm.operatorName === m.roleName }"
|
||||
@click="manualForm.operatorName = m.roleName"
|
||||
>
|
||||
{{ m.roleName }}
|
||||
</button>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<!-- 备注与快捷标签 -->
|
||||
<label>
|
||||
备注说明
|
||||
<input v-model="manualForm.note" placeholder="例如:拍嗝顺利、状态好" />
|
||||
<div class="chip-group">
|
||||
<button
|
||||
v-for="tag in quickNotes"
|
||||
:key="tag"
|
||||
type="button"
|
||||
class="chip sm"
|
||||
@click="appendNote(tag)"
|
||||
>
|
||||
+ {{ tag }}
|
||||
</button>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button class="secondary-button" @click="emit('update:show', false)">取消</button>
|
||||
<button class="save-button" @click="submitManual">确认补录</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user