|
|
@@ -94,7 +94,7 @@ import CustomNav from '@/components/custom-nav.vue'
|
|
|
|
|
|
import ScaleRuler from '@/components/scale-ruler.vue'
|
|
|
import { createUChart } from '@/composables/useUChart'
|
|
|
-import { getWeekStart, getWeekEnd, formatDisplayDate, formatPickerDate, daysInMonth } from '@/utils/date'
|
|
|
+import { getWeekStart, getWeekEnd, formatDisplayDate, formatPickerDate, daysInMonth, getTodayStart, isAfterTodayDate, isMonthAfterToday, isWeekAfterToday } from '@/utils/date'
|
|
|
import { getWindowWidth } from '@/utils/platform'
|
|
|
|
|
|
type RecordItem = { id: string; date: string; value: number; type: string }
|
|
|
@@ -288,6 +288,8 @@ async function rebuildChart() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 使用共享日期工具(在 src/utils/date.ts 中定义)
|
|
|
+
|
|
|
// 其他函数(含周期切换、picker 处理)
|
|
|
async function prevPeriod() {
|
|
|
const d = new Date(current.value)
|
|
|
@@ -306,8 +308,16 @@ async function nextPeriod() {
|
|
|
const d = new Date(current.value)
|
|
|
if (viewMode.value === 'month') {
|
|
|
d.setMonth(d.getMonth() + 1)
|
|
|
+ if (isMonthAfterToday(d)) {
|
|
|
+ uni.showToast && uni.showToast({ title: '不能查看未来的日期', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
} else {
|
|
|
d.setDate(d.getDate() + 7)
|
|
|
+ if (isWeekAfterToday(d)) {
|
|
|
+ uni.showToast && uni.showToast({ title: '不能查看未来的日期', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
current.value = d
|
|
|
pickerValue.value = [d.getFullYear() - 2000, d.getMonth()]
|
|
|
@@ -327,13 +337,20 @@ async function onPickerChange(e: any) {
|
|
|
// multiSelector 会返回 [yearOffset, monthIndex]
|
|
|
const val = e?.detail?.value || e
|
|
|
if (Array.isArray(val) && val.length >= 2) {
|
|
|
- const y = 2000 + Number(val[0])
|
|
|
- const m = Number(val[1])
|
|
|
- const d = new Date(y, m, 1)
|
|
|
- current.value = d
|
|
|
- pickerValue.value = [Number(val[0]), Number(val[1])]
|
|
|
- records.value = generateMockRecords(d)
|
|
|
- await rebuildChart()
|
|
|
+ const y = 2000 + Number(val[0])
|
|
|
+ const m = Number(val[1])
|
|
|
+ let d = new Date(y, m, 1)
|
|
|
+ if (isMonthAfterToday(d)) {
|
|
|
+ const today = getTodayStart()
|
|
|
+ uni.showToast && uni.showToast({ title: '不能选择未来的月份,已切换到当前月份', icon: 'none' })
|
|
|
+ d = new Date(today.getFullYear(), today.getMonth(), 1)
|
|
|
+ pickerValue.value = [today.getFullYear() - 2000, today.getMonth()]
|
|
|
+ } else {
|
|
|
+ pickerValue.value = [Number(val[0]), Number(val[1])]
|
|
|
+ }
|
|
|
+ current.value = d
|
|
|
+ records.value = generateMockRecords(d)
|
|
|
+ await rebuildChart()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -354,7 +371,23 @@ function onRulerChange(v: number) { addGlucose.value = Number(v.toFixed ? Number
|
|
|
function openAdd() { showAdd.value = true; if (!addGlucose.value) addGlucose.value = 6 }
|
|
|
function closeAdd() { showAdd.value = false; addGlucose.value = null }
|
|
|
|
|
|
-function onAddDateChange(e: any) { const val = e?.detail?.value || e; addDate.value = val; addDateLabel.value = val.replace(/^(.{10}).*$/, '$1') }
|
|
|
+function onAddDateChange(e: any) {
|
|
|
+ const val = e?.detail?.value || e
|
|
|
+ const parts = (val || '').split('-')
|
|
|
+ const y = parseInt(parts[0] || '', 10)
|
|
|
+ const m = parseInt(parts[1] || '1', 10) - 1
|
|
|
+ const d = parseInt(parts[2] || '1', 10)
|
|
|
+ const sel = new Date(y, m, d)
|
|
|
+ if (isAfterTodayDate(sel)) {
|
|
|
+ const today = getTodayStart()
|
|
|
+ uni.showToast && uni.showToast({ title: '不能选择未来的日期,已切换到今天', icon: 'none' })
|
|
|
+ addDate.value = formatPickerDate(today)
|
|
|
+ addDateLabel.value = formatDisplayDate(today)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ addDate.value = val
|
|
|
+ addDateLabel.value = val.replace(/^(.{10}).*$/, '$1')
|
|
|
+}
|
|
|
|
|
|
async function confirmAdd() {
|
|
|
if (!addGlucose.value) {
|
|
|
@@ -383,6 +416,10 @@ async function confirmAdd() {
|
|
|
const addM = parseInt(parts[1], 10) - 1
|
|
|
const addD = parseInt(parts[2], 10)
|
|
|
const addDateObj = new Date(addY, addM, addD)
|
|
|
+ if (isAfterTodayDate(addDateObj)) {
|
|
|
+ uni.showToast && uni.showToast({ title: '不能添加未来日期的数据', icon: 'none' })
|
|
|
+ return
|
|
|
+ }
|
|
|
let isInCurrentPeriod = false
|
|
|
if (viewMode.value === 'month') {
|
|
|
isInCurrentPeriod = addY === current.value.getFullYear() && addM === current.value.getMonth()
|