优化页面展示
This commit is contained in:
1 parent
cbcd6b4c7f
commit
1ed38c6648
67 files changed
+4484
-370
No files matched your search
@@ -1,9 +1,68 @@
|
||||
export function formatDate(value?: string | null) {
|
||||
if (!value) return ''
|
||||
const date = new Date(value)
|
||||
return getLocalDateStr(date)
|
||||
}
|
||||
|
||||
export function getLocalDateStr(date: Date = new Date()): string {
|
||||
const y = date.getFullYear()
|
||||
const m = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const d = String(date.getDate()).padStart(2, '0')
|
||||
return `${y}-${m}-${d}`
|
||||
}
|
||||
|
||||
export function getLocalTimeStr(date: Date = new Date()): string {
|
||||
const h = String(date.getHours()).padStart(2, '0')
|
||||
const min = String(date.getMinutes()).padStart(2, '0')
|
||||
return `${h}:${min}`
|
||||
}
|
||||
|
||||
export function formatTime(value?: string | null) {
|
||||
if (!value) return '--'
|
||||
const date = new Date(value)
|
||||
return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
export function getFriendlyDayLabel(dateStr: string): string {
|
||||
if (!dateStr) return ''
|
||||
const today = getLocalDateStr(new Date())
|
||||
const yesterday = getLocalDateStr(new Date(Date.now() - 86400000))
|
||||
if (dateStr === today) return `${dateStr} · 今天`
|
||||
if (dateStr === yesterday) return `${dateStr} · 昨天`
|
||||
|
||||
const parts = dateStr.split('-')
|
||||
if (parts.length === 3) {
|
||||
const d = new Date(Number(parts[0]), Number(parts[1]) - 1, Number(parts[2]))
|
||||
const days = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
||||
const weekday = days[d.getDay()] || ''
|
||||
return `${dateStr} · ${weekday}`
|
||||
}
|
||||
return dateStr
|
||||
}
|
||||
|
||||
export function formatRecordTimeRange(startTime?: string | null, endTime?: string | null) {
|
||||
if (!startTime) return '--'
|
||||
const startDate = formatDate(startTime)
|
||||
const startT = formatTime(startTime)
|
||||
if (!endTime) {
|
||||
return `${startDate} ${startT}`
|
||||
}
|
||||
const endDate = formatDate(endTime)
|
||||
const endT = formatTime(endTime)
|
||||
if (startDate === endDate) {
|
||||
return `${startDate} ${startT} ~ ${endT}`
|
||||
}
|
||||
return `${startDate} ${startT} ~ ${endDate} ${endT}`
|
||||
}
|
||||
|
||||
export function formatCleanNote(noteOrRemark?: string | null): string {
|
||||
if (!noteOrRemark) return ''
|
||||
const cleaned = noteOrRemark
|
||||
.replace(/亲喂侧\s*:\s*[^;;\n]+([;;]\s*)?/g, '')
|
||||
.trim()
|
||||
return cleaned
|
||||
}
|
||||
|
||||
export function formatMinutes(minutes: number) {
|
||||
const h = Math.floor(minutes / 60)
|
||||
const m = minutes % 60
|
||||
@@ -12,16 +71,22 @@ export function formatMinutes(minutes: number) {
|
||||
return `${h} 小时 ${m} 分钟`
|
||||
}
|
||||
|
||||
export const FEEDING_METHOD_MAP: Record<string, string> = {
|
||||
breastfeed: '亲喂',
|
||||
bottle: '瓶喂',
|
||||
formula: '配方奶',
|
||||
mixed: '混合喂养',
|
||||
other: '其他'
|
||||
}
|
||||
|
||||
export function formatFeedingMethod(method?: string | null): string {
|
||||
if (!method) return '其他'
|
||||
return FEEDING_METHOD_MAP[method] || method
|
||||
}
|
||||
|
||||
export function recordLabel(type: string, sub?: string | null) {
|
||||
if (type === 'feeding') {
|
||||
const map: Record<string, string> = {
|
||||
breastfeed: '亲喂',
|
||||
bottle: '瓶喂',
|
||||
formula: '配方奶',
|
||||
mixed: '混合',
|
||||
other: '其他'
|
||||
}
|
||||
return `喂奶 · ${map[sub || 'other'] || '其他'}`
|
||||
return `喂奶 · ${formatFeedingMethod(sub)}`
|
||||
}
|
||||
if (type === 'sleep') return '睡眠'
|
||||
if (type === 'excretion' && sub === 'pee') return '小便'
|
||||
@@ -29,3 +94,47 @@ export function recordLabel(type: string, sub?: string | null) {
|
||||
return '记录'
|
||||
}
|
||||
|
||||
export interface FeedingSplitInfo {
|
||||
leftMinutes?: number
|
||||
rightMinutes?: number
|
||||
}
|
||||
|
||||
export function parseFeedingSplitInfo(noteOrRemark?: string | null, durationMinutes?: number | null): FeedingSplitInfo | null {
|
||||
if (!noteOrRemark) return null
|
||||
const leftMatch = noteOrRemark.match(/左侧\s*(\d+)\s*分钟/)
|
||||
const rightMatch = noteOrRemark.match(/右侧\s*(\d+)\s*分钟/)
|
||||
|
||||
if (leftMatch || rightMatch) {
|
||||
return {
|
||||
leftMinutes: leftMatch ? Number(leftMatch[1]) : undefined,
|
||||
rightMinutes: rightMatch ? Number(rightMatch[1]) : undefined
|
||||
}
|
||||
}
|
||||
|
||||
if (noteOrRemark.includes('亲喂侧: 左侧') && durationMinutes) {
|
||||
return { leftMinutes: durationMinutes }
|
||||
}
|
||||
if (noteOrRemark.includes('亲喂侧: 右侧') && durationMinutes) {
|
||||
return { rightMinutes: durationMinutes }
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function getFeedingSplitInfo(record?: {
|
||||
leftDurationMinutes?: number | null
|
||||
rightDurationMinutes?: number | null
|
||||
remark?: string | null
|
||||
note?: string | null
|
||||
durationMinutes?: number | null
|
||||
} | null): FeedingSplitInfo | null {
|
||||
if (!record) return null
|
||||
if ((record.leftDurationMinutes != null && record.leftDurationMinutes > 0) ||
|
||||
(record.rightDurationMinutes != null && record.rightDurationMinutes > 0)) {
|
||||
return {
|
||||
leftMinutes: record.leftDurationMinutes ?? undefined,
|
||||
rightMinutes: record.rightDurationMinutes ?? undefined
|
||||
}
|
||||
}
|
||||
return parseFeedingSplitInfo(record.remark || record.note, record.durationMinutes)
|
||||
}
|
||||
Reference in new issue
Block a user