|
|
@@ -97,6 +97,7 @@ import uCharts from '@qiun/ucharts'
|
|
|
import CustomNav from '@/components/custom-nav.vue'
|
|
|
import TabBar from '@/components/tab-bar.vue'
|
|
|
import ScaleRuler from '@/components/scale-ruler.vue'
|
|
|
+import { getWeekStart, getWeekEnd, getWeekNumber, formatDisplayDate, formatPickerDate, daysInMonth, weekDayIndex } from '@/utils/date'
|
|
|
|
|
|
type RecordItem = { id: string; date: string; value: number; type: string }
|
|
|
|
|
|
@@ -129,12 +130,7 @@ function getCanvasSize(): Promise<{ width: number; height: number }> {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-function formatPickerDate(d: Date) {
|
|
|
- const y = d.getFullYear()
|
|
|
- const m = String(d.getMonth() + 1).padStart(2, '0')
|
|
|
- const day = String(d.getDate()).padStart(2, '0')
|
|
|
- return `${y}-${m}-${day}`
|
|
|
-}
|
|
|
+// 使用共享日期工具 (src/utils/date.ts)
|
|
|
|
|
|
const displayYear = computed(() => current.value.getFullYear())
|
|
|
const displayMonth = computed(() => current.value.getMonth() + 1)
|
|
|
@@ -186,32 +182,7 @@ function generateMockRecords(d: Date): RecordItem[] {
|
|
|
}
|
|
|
|
|
|
// 获取指定日期所在周的开始日期(星期一)
|
|
|
-function getWeekStart(date: Date): Date {
|
|
|
- const d = new Date(date)
|
|
|
- d.setHours(0, 0, 0, 0)
|
|
|
- const day = d.getDay()
|
|
|
- const diff = day === 0 ? -6 : 1 - day
|
|
|
- d.setDate(d.getDate() + diff)
|
|
|
- d.setHours(0, 0, 0, 0)
|
|
|
- return d
|
|
|
-}
|
|
|
-
|
|
|
-// 获取指定日期所在周的结束日期(星期日)
|
|
|
-function getWeekEnd(date: Date): Date {
|
|
|
- const d = getWeekStart(date)
|
|
|
- d.setDate(d.getDate() + 6)
|
|
|
- d.setHours(0, 0, 0, 0)
|
|
|
- return d
|
|
|
-}
|
|
|
-
|
|
|
-// 获取指定日期所在周的周数(一年中的第几周)
|
|
|
-function getWeekNumber(date: Date): number {
|
|
|
- const d = new Date(date)
|
|
|
- d.setHours(0, 0, 0, 0)
|
|
|
- d.setDate(d.getDate() + 4 - (d.getDay() || 7))
|
|
|
- const yearStart = new Date(d.getFullYear(), 0, 1)
|
|
|
- return Math.ceil(((d.getTime() - yearStart.getTime()) / 86400000 + 1) / 7)
|
|
|
-}
|
|
|
+// 使用共享日期工具 (src/utils/date.ts)
|
|
|
|
|
|
// 将 records 聚合为每天一个点(取最新记录)
|
|
|
function aggregateDaily(recordsArr: RecordItem[], year: number, month: number) {
|
|
|
@@ -232,9 +203,7 @@ function aggregateDaily(recordsArr: RecordItem[], year: number, month: number) {
|
|
|
return map
|
|
|
}
|
|
|
|
|
|
-function formatDisplayDate(d: Date) {
|
|
|
- return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
|
|
-}
|
|
|
+// 使用 formatDisplayDate 从 src/utils/date.ts
|
|
|
|
|
|
const averageGlucose = computed(() => {
|
|
|
if (records.value.length === 0) return '--'
|
|
|
@@ -242,9 +211,7 @@ const averageGlucose = computed(() => {
|
|
|
return (sum / records.value.length).toFixed(1)
|
|
|
})
|
|
|
|
|
|
-function daysInMonth(year: number, month: number) {
|
|
|
- return new Date(year, month + 1, 0).getDate()
|
|
|
-}
|
|
|
+// 使用 daysInMonth 从 src/utils/date.ts
|
|
|
|
|
|
// Canvas / uCharts 绘图 - 修复版本
|
|
|
const chartInstance = ref<any>(null)
|