1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713 | <!DOCTYPE html>
<html lang="zh-CN" data-theme="">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<meta id="theme-color-meta" name="theme-color" content="#D4896A">
<meta name="color-scheme" content="light dark">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="apple-mobile-web-app-title" content="宝宝日记">
<meta name="mobile-web-app-capable" content="yes">
<meta name="description" content="记录宝宝喝奶、辅食、便便与生长的温暖日记">
<title>宝宝日记 - 记录成长每一天</title>
<link rel="manifest" href="./manifest.webmanifest">
<link rel="icon" href="./icons/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="./icons/apple-touch-icon.svg">
<link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin>
<link rel="preconnect" href="https://cdn.tailwindcss.com" crossorigin>
<script src="https://cdn.tailwindcss.com"></script>
<!-- ECharts 延迟加载:切换到"生长"Tab 时动态引入 -->
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.14.8/dist/cdn.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<link rel="stylesheet" href="./src/styles/main.css">
<style>
/* Early theme paint — avoid flash before Alpine init */
html { color-scheme: light dark; background: #FAF7F2; }
html[data-theme="dark"] { background: #1A1816; }
@media (prefers-color-scheme: dark) {
html:not([data-theme="light"]) { background: #1A1816; }
}
</style>
<script>
// Apply stored / system theme before first paint
(function () {
try {
var stored = localStorage.getItem('baby_theme');
var theme = (stored === 'dark' || stored === 'light')
? stored
: (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
document.documentElement.dataset.theme = theme;
var meta = document.getElementById('theme-color-meta');
if (meta) meta.content = theme === 'dark' ? '#1A1816' : '#D4896A';
} catch (e) { /* ignore */ }
})();
</script>
</head>
<body x-data="app" x-cloak>
<!-- Boot splash -->
<div x-show="!ready" class="boot-splash">
<div class="boot-mark" aria-hidden="true">🍼</div>
<div class="boot-brand">宝宝日记</div>
<div class="boot-text">加载中</div>
</div>
<div class="main-container" x-show="ready" x-transition.opacity>
<header class="modern-header">
<div class="flex justify-between items-center">
<h1 class="header-title">
<a href="https://zelinlife2025.888653.xyz" target="_blank" rel="noopener noreferrer"
title="进入相册" class="avatar-ring" aria-label="进入相册">
<img src="https://ii99photoshow.888653.xyz/file/1764031994825_Generated_Image_November_25__2025_-_8_52AM.png"
class="w-10 h-10 object-cover"
alt="宝宝头像"
width="40" height="40">
</a>
<span class="flex flex-col">
<span>宝宝日记</span>
<span class="subtitle">记录成长的每一天</span>
</span>
</h1>
<button type="button" class="theme-toggle"
@click="toggleTheme()"
:aria-label="theme === 'dark' ? '切换到浅色模式' : '切换到深色模式'"
x-text="theme === 'dark' ? '☀️' : '🌙'"></button>
</div>
<div class="tab-bar flex" role="tablist" aria-label="主导航">
<button type="button" role="tab" id="tab-record"
@click="switchToRecord()"
:class="{ 'active': view === 'record' }"
:aria-selected="view === 'record'"
aria-controls="panel-record"
class="tab-button">
记录
</button>
<button type="button" role="tab" id="tab-history"
@click="switchToHistory()"
:class="{ 'active': view === 'history' }"
:aria-selected="view === 'history'"
aria-controls="panel-history"
class="tab-button">
历史
</button>
<button type="button" role="tab" id="tab-growth"
@click="switchToGrowth()"
:class="{ 'active': view === 'growth' }"
:aria-selected="view === 'growth'"
aria-controls="panel-growth"
class="tab-button">
生长
</button>
<button type="button" role="tab" id="tab-report"
@click="switchToReport()"
:class="{ 'active': view === 'report' }"
:aria-selected="view === 'report'"
aria-controls="panel-report"
class="tab-button">
报告
</button>
</div>
</header>
<div class="content-pad">
<!-- ================= 记录 ================= -->
<div x-show="view === 'record'"
x-transition:enter="transition ease-out duration-150"
x-transition:enter-start="opacity-0"
role="tabpanel" id="panel-record" aria-labelledby="tab-record">
<!-- 编辑模式横幅 -->
<div x-show="isEditing" x-transition class="edit-banner">
<div class="flex items-center justify-between gap-3">
<div class="text-sm font-semibold" style="color: var(--accent-ink)">
正在编辑记录
</div>
<button type="button" @click="cancelEdit()" class="edit-cancel-btn">取消</button>
</div>
</div>
<!-- 今日摘要(非编辑时显示) -->
<div x-show="!isEditing" class="today-summary mb-3">
<div class="today-summary-head">
<span class="today-summary-title">今日</span>
<span class="today-summary-feed" x-show="todaySummary.lastMilkAt">
距上次喝奶 <strong x-text="getLastFeedLabel()"></strong>
</span>
<span class="today-summary-feed muted" x-show="!todaySummary.lastMilkAt && !todaySummary.loading">
今天还没记喝奶
</span>
</div>
<div class="today-summary-grid">
<div class="today-stat milk">
<div class="today-stat-val"><span x-text="todaySummary.milk"></span><small>ml</small></div>
<div class="today-stat-lbl">奶量</div>
</div>
<div class="today-stat food">
<div class="today-stat-val"><span x-text="todaySummary.food"></span><small>顿</small></div>
<div class="today-stat-lbl">辅食</div>
</div>
<div class="today-stat poo">
<div class="today-stat-val"><span x-text="todaySummary.poo"></span><small>次</small></div>
<div class="today-stat-lbl">便便</div>
</div>
<div class="today-stat" :class="todaySummary.vitD ? 'vitd' : 'vitd empty'">
<div class="today-stat-val">
<span x-show="todaySummary.vitD">✓</span>
<span x-show="!todaySummary.vitD">—</span>
</div>
<div class="today-stat-lbl">维D</div>
</div>
</div>
</div>
<!-- 维D提醒 -->
<div x-show="vitamindReminder.show && !isEditing" x-transition class="vitamind-reminder">
<div class="flex items-start gap-3">
<div class="text-2xl" aria-hidden="true">💊</div>
<div class="flex-1">
<div class="font-bold text-sm" style="color: var(--accent-ink)">温馨提示</div>
<div class="text-sm mt-1" style="color: var(--ink-secondary)">
昨天好像还没记维生素 D,今天记得给宝宝补一下。
</div>
<button type="button"
@click="setType('meds'); vitamindReminder.show = false"
class="mt-2 text-xs font-bold link-today">
现在去打卡 →
</button>
</div>
<button type="button" @click="vitamindReminder.show = false"
class="text-2xl leading-none font-light"
style="color: var(--muted); min-width: 36px; min-height: 36px;"
aria-label="关闭提醒">×</button>
</div>
</div>
<div class="modern-card p-4 mb-3">
<div class="label-title">记录时间</div>
<div class="datetime-split">
<div class="datetime-split-field">
<label class="sr-only" for="record-date">日期</label>
<input id="record-date" type="date"
x-model="form.date"
class="input-field text-base font-semibold">
</div>
<div class="datetime-split-field">
<label class="sr-only" for="record-time">时间</label>
<input id="record-time" type="time"
x-model="form.time"
class="input-field text-base font-semibold">
</div>
</div>
</div>
<div class="type-grid mb-3" role="group" aria-label="记录类型">
<button type="button" @click="setType('milk')"
:class="form.type === 'milk' ? 'milk active' : 'milk'"
:aria-pressed="form.type === 'milk'"
class="type-button">
<span aria-hidden="true">🍼</span>
<span>喝奶</span>
</button>
<button type="button" @click="setType('food')"
:class="form.type === 'food' ? 'food active' : 'food'"
:aria-pressed="form.type === 'food'"
class="type-button">
<span aria-hidden="true">🥣</span>
<span>辅食</span>
</button>
<button type="button" @click="setType('poo')"
:class="form.type === 'poo' ? 'poo active' : 'poo'"
:aria-pressed="form.type === 'poo'"
class="type-button">
<span aria-hidden="true">💩</span>
<span>便便</span>
</button>
<button type="button" @click="setType('meds')"
:class="form.type === 'meds' ? 'meds active' : 'meds'"
:aria-pressed="form.type === 'meds'"
class="type-button">
<span aria-hidden="true">💊</span>
<span>维D</span>
</button>
</div>
<div class="modern-card p-5">
<!-- 喝奶 -->
<div x-show="form.type === 'milk'" class="space-y-4">
<div>
<div class="label-title">奶类</div>
<div class="chip-row">
<template x-for="opt in ['配方奶', '母乳亲喂', '母乳瓶喂']" :key="opt">
<button type="button" @click="form.subType = opt"
class="chip"
:class="form.subType === opt ? 'active' : ''"
x-text="opt"></button>
</template>
</div>
</div>
<div>
<label class="label-title" for="milk-amount">摄入量 (ml)</label>
<div class="amount-presets mb-2">
<template x-for="ml in milkPresets" :key="ml">
<button type="button"
class="amount-chip milk"
:class="{ 'active': String(form.amount) === String(ml) }"
@click="setMilkAmount(ml)"
x-text="ml"></button>
</template>
</div>
<input id="milk-amount" type="number" inputmode="numeric" min="1" max="500" step="1"
x-model="form.amount" placeholder="180"
class="input-field text-xl font-bold"
style="color: var(--milk-ink)">
<div x-show="lastMilkAmount && !isEditing" class="text-xs mt-1.5" style="color: var(--muted)">
默认已填上次奶量 <button type="button" class="link-today"
@click="setMilkAmount(lastMilkAmount)"
x-text="lastMilkAmount + 'ml'"></button>
</div>
</div>
<div>
<label class="label-title" for="milk-notes">备注</label>
<input id="milk-notes" type="text" x-model="form.notes"
class="input-field" placeholder="选填" maxlength="200">
</div>
</div>
<!-- 辅食 -->
<div x-show="form.type === 'food'" class="space-y-4">
<div>
<label class="label-title" for="food-detail">食材详情</label>
<textarea id="food-detail" x-model="form.subType" rows="4" maxlength="500"
placeholder="例如:猪肝菠菜粥(半碗)、苹果泥(几口)"
class="input-field leading-relaxed"></textarea>
</div>
<label class="modern-checkbox">
<input type="checkbox" x-model="form.isNewFood" class="mr-3">
<span class="font-semibold flex-1" style="color: var(--food-ink)">含新食材(观察 3 天)</span>
</label>
<div>
<label class="label-title" for="food-reaction">反应</label>
<select id="food-reaction" x-model="form.tags" class="input-field">
<option value="无异常">无异常 / 喜欢</option>
<option value="拒吃">拒吃 / 没胃口</option>
<option value="过敏/皮疹">过敏 / 皮疹</option>
<option value="呕吐">呕吐</option>
<option value="胀气">胀气 / 哭闹</option>
</select>
</div>
</div>
<!-- 便便 -->
<div x-show="form.type === 'poo'" class="space-y-4">
<div>
<label class="label-title" for="poo-type">性状</label>
<select id="poo-type" x-model="form.subType" class="input-field">
<option value="正常糊状">正常糊状</option>
<option value="干硬球状">干硬(便秘)</option>
<option value="水样稀便">水样(腹泻)</option>
<option value="有奶瓣">有奶瓣</option>
<option value="墨绿色">墨绿色(铁未吸收)</option>
</select>
</div>
<div>
<label class="label-title" for="poo-notes">备注</label>
<input id="poo-notes" type="text" x-model="form.notes"
placeholder="如:带血丝、酸臭" class="input-field" maxlength="200">
</div>
<div>
<div class="label-title">照片记录</div>
<div class="image-upload-area">
<label class="upload-box" aria-label="拍照或从相册选择">
<!-- 不设 capture:手机可在「拍照 / 相册」间选择,电脑直接选本地文件 -->
<input type="file" accept="image/*"
class="file-input" @change="handleFileSelect">
<template x-if="!form.previewUrl">
<span class="text-2xl" style="color: var(--muted)" aria-hidden="true">📷</span>
</template>
<template x-if="form.previewUrl">
<img :src="form.previewUrl" alt="预览">
</template>
</label>
<div class="text-sm flex-1">
<div x-show="!form.previewUrl" style="color: var(--muted)">
拍照或从相册 / 本地选择
</div>
<div x-show="form.previewUrl" class="font-semibold" style="color: var(--success)">已选择图片</div>
<button type="button" x-show="form.previewUrl" @click="clearFile"
class="mt-1 underline cursor-pointer text-sm"
style="color: var(--danger)">
删除 / 重选
</button>
</div>
</div>
</div>
</div>
<!-- 维D -->
<div x-show="form.type === 'meds'" class="space-y-4">
<div class="meds-callout">
<div class="icon" aria-hidden="true">☀️</div>
<div class="title">补充维生素 D</div>
<div class="hint">点下方按钮完成今日打卡</div>
</div>
<div>
<label class="label-title" for="meds-notes">备注</label>
<input id="meds-notes" type="text" x-model="form.notes"
placeholder="可选:AD 滴剂、益生菌" class="input-field" maxlength="200">
</div>
</div>
<button type="button" @click="submit" :disabled="loading" class="submit-button"
:class="{
'milk': form.type === 'milk',
'food': form.type === 'food',
'poo': form.type === 'poo',
'meds': form.type === 'meds'
}">
<span x-show="!loading && !isEditing">保存记录</span>
<span x-show="!loading && isEditing">保存修改</span>
<span x-show="loading && !uploading">保存中…</span>
<span x-show="uploading">正在上传图片…</span>
<span x-show="loading" class="spinner" aria-hidden="true"></span>
</button>
</div>
</div>
<!-- ================= 历史 ================= -->
<div x-show="view === 'history'"
x-transition:enter="transition ease-out duration-150"
x-transition:enter-start="opacity-0"
role="tabpanel" id="panel-history" aria-labelledby="tab-history">
<div class="date-nav-card mb-3">
<div class="flex items-center justify-between">
<button type="button" @click="changeDate(-1)" class="date-nav-btn" aria-label="前一天"><</button>
<div class="flex flex-col items-center relative">
<input type="date" x-model="historyDate" @change="fetchHistory()"
class="date-selector font-bold bg-transparent text-center outline-none appearance-none p-0 border-0 focus:ring-0 w-36 text-base relative z-10"
style="color: var(--ink)"
aria-label="选择日期">
<div class="text-xs -mt-0.5 font-medium flex items-center gap-1" style="color: var(--muted)">
<span x-text="getDayLabel(historyDate)"></span>
<button type="button" x-show="!isToday()" @click="resetToToday()" class="link-today ml-1">回今天</button>
</div>
</div>
<button type="button" @click="changeDate(1)" class="date-nav-btn" aria-label="后一天">></button>
</div>
<div class="flex items-center justify-between mt-3">
<span class="age-pill" x-text="getAgeDisplay()"></span>
<button type="button" @click="exportData()" :disabled="exporting" class="export-btn">
<span x-text="exporting ? '导出中…' : '导出数据'"></span>
</button>
</div>
</div>
<!-- 四格统计:奶 / 辅食 / 便便 / 维D -->
<div class="stats-grid stats-grid-4 mb-3">
<div class="stats-card milk">
<div class="stats-label">总奶量</div>
<div class="stats-value">
<span x-text="stats.milk"></span><span class="text-sm font-normal">ml</span>
</div>
</div>
<div class="stats-card food">
<div class="stats-label">辅食</div>
<div class="stats-value">
<span x-text="stats.food"></span><span class="text-sm font-normal">顿</span>
</div>
</div>
<div class="stats-card poo">
<div class="stats-label">便便</div>
<div class="stats-value">
<span x-text="stats.poo"></span><span class="text-sm font-normal">次</span>
</div>
</div>
<div class="stats-card" :class="stats.vitD ? 'vitd' : 'vitd empty'">
<div class="stats-label">维D</div>
<div class="stats-value">
<span x-show="stats.vitD">✓</span>
<span x-show="!stats.vitD" class="text-sm">—</span>
</div>
</div>
</div>
<div x-show="loading" class="empty-state py-10">
<div class="spinner spinner-dark mx-auto mb-3"></div>
<div class="empty-state-text">加载中…</div>
</div>
<div class="space-y-2.5" x-show="!loading">
<template x-if="logs.length === 0">
<div class="empty-state">
<div class="empty-state-icon" aria-hidden="true">📝</div>
<div class="empty-state-text">这一天还没有记录</div>
<div class="empty-state-hint">记下喝奶、辅食或维D,成长轨迹会更清晰</div>
<button type="button" @click="switchToRecord()" class="empty-action">
去记录一条 →
</button>
</div>
</template>
<template x-for="log in logs" :key="log.id">
<div @click="toggleExpand(log.id)"
@keydown.enter="toggleExpand(log.id)"
@keydown.space.prevent="toggleExpand(log.id)"
tabindex="0"
role="button"
:aria-expanded="expandedId === log.id"
class="log-item"
:class="{
'milk': log.type === 'milk',
'food': log.type === 'food',
'poo': log.type === 'poo',
'meds': log.type === 'meds',
'expanded': expandedId === log.id
}">
<div class="flex-1 pr-2 overflow-hidden">
<div class="flex items-center gap-2 mb-1 flex-wrap">
<div class="font-bold text-sm transition-all"
style="color: var(--ink)"
:class="expandedId === log.id ? 'whitespace-pre-wrap break-words' : 'truncate'"
x-text="log.sub_type || formatType(log.type)">
</div>
<span x-show="log.is_new_food" class="badge new">新</span>
<span x-show="log.tags && log.tags !== '无异常'"
x-text="log.tags" class="badge reaction"></span>
</div>
<div class="text-sm break-words leading-tight" style="color: var(--muted)">
<span x-show="log.type==='milk'" class="font-bold mr-1"
style="color: var(--milk-ink)"
x-text="(log.amount || 0) + 'ml'"></span>
<span x-show="log.notes" x-text="log.notes"></span>
<div x-show="log.image_url"
@click.stop="openImage(log.image_url)"
class="photo-link">
<span>📷 查看照片</span>
</div>
</div>
<div x-show="log.type === 'food' && expandedId !== log.id && log.sub_type && log.sub_type.length > 15"
class="text-xs mt-1" style="color: var(--muted)">… 点击查看详情</div>
<!-- 展开后的操作 -->
<div x-show="expandedId === log.id" x-transition class="log-actions mt-2">
<button type="button" class="log-action-btn edit"
@click.stop="startEdit(log)">编辑</button>
<button type="button" class="log-action-btn danger"
@click.stop="deleteRecord(log.id)">删除</button>
</div>
</div>
<div class="text-right flex flex-col items-end min-w-[52px]">
<div class="text-sm font-bold font-mono" style="color: var(--ink-secondary)"
x-text="formatTimeCN(log.recorded_at)"></div>
<div class="text-base mt-1" x-text="getIcon(log.type)" aria-hidden="true"></div>
<template x-if="log.id === getLatestMilkId()">
<div class="time-since">
距今 <span x-text="getTimeDiff(log.recorded_at)"></span>
</div>
</template>
</div>
<!-- 右上角快捷编辑 -->
<button type="button" @click.stop="startEdit(log)"
class="log-edit"
aria-label="编辑记录">✎</button>
</div>
</template>
</div>
</div>
<!-- ================= 生长 ================= -->
<div x-show="view === 'growth'"
x-transition:enter="transition ease-out duration-150"
x-transition:enter-start="opacity-0"
role="tabpanel" id="panel-growth" aria-labelledby="tab-growth">
<div class="assessment-box" x-show="growth.aiVisible" x-transition>
<h3>智能发育评估</h3>
<div class="assessment-body whitespace-pre-wrap"
:class="{ 'assessment-loading': growth.aiText.includes('正在分析') }"
x-text="growth.aiText"></div>
</div>
<div x-show="growth.loading" class="empty-state">
<div class="spinner spinner-dark mx-auto mb-4"></div>
<div class="empty-state-text">正在获取最新数据…</div>
</div>
<div x-show="growth.error" class="empty-state">
<div class="empty-state-icon" aria-hidden="true">⚠️</div>
<div class="font-semibold mb-1" style="color: var(--danger)" x-text="growth.errorMessage"></div>
<div class="empty-state-hint">检查网络或生长数据 API 配置后重试</div>
<button type="button" @click="retryGrowth()" class="empty-action">重试</button>
</div>
<div id="charts" x-show="!growth.loading && !growth.error">
<div class="chart-container">
<div id="bmiChart" class="chart-box"></div>
</div>
<div class="chart-container">
<div id="weightChart" class="chart-box"></div>
</div>
<div class="chart-container">
<div id="heightChart" class="chart-box"></div>
</div>
<div class="chart-container">
<div id="headChart" class="chart-box"></div>
</div>
</div>
</div>
<!-- ================= 报告 ================= -->
<div x-show="view === 'report'"
x-transition:enter="transition ease-out duration-150"
x-transition:enter-start="opacity-0"
role="tabpanel" id="panel-report" aria-labelledby="tab-report">
<!-- 周报/月报切换 -->
<div class="report-range-bar" role="group" aria-label="报告周期">
<button type="button" @click="report.range = 7; loadReportData()"
:class="{ 'active': report.range === 7 }"
class="report-range-btn">周报 (7天)</button>
<button type="button" @click="report.range = 30; loadReportData()"
:class="{ 'active': report.range === 30 }"
class="report-range-btn">月报 (30天)</button>
</div>
<!-- Loading -->
<div x-show="report.loading" class="empty-state">
<div class="spinner spinner-dark mx-auto mb-3"></div>
<div class="empty-state-text">正在生成报告…</div>
</div>
<!-- Empty -->
<div x-show="!report.loading && report.summary.activeDays === 0">
<div class="empty-state">
<div class="empty-state-icon" aria-hidden="true">📊</div>
<div class="empty-state-text">
<span x-text="report.range === 7 ? '本周暂无记录' : '本月暂无记录'"></span>
</div>
<div class="empty-state-hint">多记几天后,这里会汇总奶量与辅食趋势</div>
<button type="button" @click="switchToRecord()" class="empty-action">
去记录一条 →
</button>
</div>
</div>
<!-- Report content -->
<div x-show="!report.loading && report.summary.activeDays > 0">
<!-- Summary cards -->
<div class="report-summary-grid">
<div class="report-summary-card milk">
<div class="rsc-label">日均奶量</div>
<div class="rsc-value" x-text="report.summary.avgDailyMilk + 'ml'"></div>
</div>
<div class="report-summary-card milk">
<div class="rsc-label">总奶量</div>
<div class="rsc-value" x-text="report.summary.totalMilk + 'ml'"></div>
</div>
<div class="report-summary-card food">
<div class="rsc-label">辅食种类</div>
<div class="rsc-value" x-text="report.summary.foodVariety + '种'"></div>
</div>
<div class="report-summary-card poo">
<div class="rsc-label">便便次数</div>
<div class="rsc-value" x-text="report.summary.poopCount + '次'"></div>
</div>
<div class="report-summary-card" style="grid-column: span 2;">
<div class="rsc-label">记录天数</div>
<div class="rsc-value" x-text="report.summary.activeDays + '天'"></div>
</div>
</div>
<!-- Bar chart: daily milk -->
<div class="chart-container">
<div id="reportMilkBar" class="chart-box" style="height: 260px;"></div>
</div>
<!-- Donut chart: milk type -->
<div class="chart-container">
<div id="reportMilkDonut" class="chart-box" style="height: 260px;"></div>
</div>
<!-- Food log -->
<div class="modern-card p-4 mb-3" x-show="report.foodLog.length > 0">
<div class="report-section-title">🥣 尝试过的食物</div>
<div class="report-food-list">
<template x-for="food in report.foodLog" :key="food">
<span class="report-food-tag" x-text="food"></span>
</template>
</div>
</div>
<!-- Poo pattern -->
<div class="modern-card p-4 mb-3">
<div class="report-section-title">💩 便便情况</div>
<div class="report-poo-row">
<span>正常</span>
<span class="report-poo-count normal" x-text="report.pooSummary.normal + '次'"></span>
<span style="margin-left: 8px;">异常</span>
<span class="report-poo-count abnormal" x-text="report.pooSummary.abnormal + '次'"></span>
</div>
<div x-show="report.pooSummary.total === 0" class="text-sm mt-2" style="color: var(--muted)">
本周期暂无便便记录
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 图片查看器 -->
<div x-show="showModal" x-transition.opacity
class="fixed inset-0 z-50 lightbox flex items-center justify-center"
@click.self="closeModal()"
@keydown.escape.window="showModal && closeModal()"
role="dialog" aria-modal="true" aria-label="图片预览">
<div class="relative max-w-full max-h-full">
<img :src="modalImage" alt="记录照片"
class="max-w-full max-h-[80vh] rounded-2xl shadow-2xl object-contain">
<button type="button" @click="closeModal()"
class="lightbox-close"
aria-label="关闭">
×
</button>
</div>
</div>
<!-- Toast -->
<div x-data class="fixed top-4 left-1/2 transform -translate-x-1/2 z-50 flex flex-col gap-2 pointer-events-none"
style="max-width: 90vw; top: max(1rem, env(safe-area-inset-top, 0px));" aria-live="polite">
<template x-for="msg in $store.toast.messages" :key="msg.id">
<div x-show="msg.visible"
x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="opacity-0 -translate-y-3"
x-transition:leave="transition ease-in duration-150"
x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0"
@click="$store.toast.dismiss(msg.id)"
class="pointer-events-auto px-4 py-3 text-sm cursor-pointer text-white toast-kid"
:class="{
'toast-success': msg.type === 'success',
'toast-error': msg.type === 'error',
'toast-warning': msg.type === 'warning',
'toast-info': msg.type === 'info'
}"
role="status">
<span x-text="msg.message"></span>
</div>
</template>
</div>
<script src="./src/js/config.js"></script>
<script src="./src/js/utils.js"></script>
<script src="./src/js/db.js"></script>
<script src="./src/js/charts.js"></script>
<script src="./src/js/toast.js"></script>
<script src="./src/js/app.js"></script>
</body>
</html>
|