|
@@ -96,7 +96,7 @@ import { createUChart } from '@/composables/useUChart'
|
|
|
import CustomNav from '@/components/custom-nav.vue'
|
|
import CustomNav from '@/components/custom-nav.vue'
|
|
|
|
|
|
|
|
import ScaleRuler from '@/components/scale-ruler.vue'
|
|
import ScaleRuler from '@/components/scale-ruler.vue'
|
|
|
-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'
|
|
import { getWindowWidth } from '@/utils/platform'
|
|
|
|
|
|
|
|
type RecordItem = { id: string; date: string; s: number; d: number }
|
|
type RecordItem = { id: string; date: string; s: number; d: number }
|
|
@@ -265,6 +265,8 @@ async function rebuildChart() {
|
|
|
try { await bpChart.rebuild(records, current, viewMode) } catch (e) { console.warn('rebuildChart failed', e) }
|
|
try { await bpChart.rebuild(records, current, viewMode) } catch (e) { console.warn('rebuildChart failed', e) }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 使用共享日期工具(在 src/utils/date.ts 中定义)
|
|
|
|
|
+
|
|
|
// 周/月周期导航与 Picker 处理
|
|
// 周/月周期导航与 Picker 处理
|
|
|
async function prevPeriod() {
|
|
async function prevPeriod() {
|
|
|
const d = new Date(current.value)
|
|
const d = new Date(current.value)
|
|
@@ -283,8 +285,16 @@ async function nextPeriod() {
|
|
|
const d = new Date(current.value)
|
|
const d = new Date(current.value)
|
|
|
if (viewMode.value === 'month') {
|
|
if (viewMode.value === 'month') {
|
|
|
d.setMonth(d.getMonth() + 1)
|
|
d.setMonth(d.getMonth() + 1)
|
|
|
|
|
+ if (isMonthAfterToday(d)) {
|
|
|
|
|
+ uni.showToast && uni.showToast({ title: '不能查看未来的日期', icon: 'none' })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
d.setDate(d.getDate() + 7)
|
|
d.setDate(d.getDate() + 7)
|
|
|
|
|
+ if (isWeekAfterToday(d)) {
|
|
|
|
|
+ uni.showToast && uni.showToast({ title: '不能查看未来的日期', icon: 'none' })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
current.value = d
|
|
current.value = d
|
|
|
pickerValue.value = [d.getFullYear() - 2000, d.getMonth()]
|
|
pickerValue.value = [d.getFullYear() - 2000, d.getMonth()]
|
|
@@ -305,9 +315,17 @@ async function onPickerChange(e: any) {
|
|
|
if (Array.isArray(val) && val.length >= 2) {
|
|
if (Array.isArray(val) && val.length >= 2) {
|
|
|
const y = 2000 + val[0]
|
|
const y = 2000 + val[0]
|
|
|
const m = val[1]
|
|
const m = val[1]
|
|
|
- const d = new Date(y, m, 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 = [val[0], val[1]]
|
|
|
|
|
+ }
|
|
|
current.value = d
|
|
current.value = d
|
|
|
- pickerValue.value = [val[0], val[1]]
|
|
|
|
|
records.value = generateMockRecords(d)
|
|
records.value = generateMockRecords(d)
|
|
|
await rebuildChart()
|
|
await rebuildChart()
|
|
|
}
|
|
}
|
|
@@ -338,6 +356,19 @@ function closeAdd() {
|
|
|
|
|
|
|
|
function onAddDateChange(e: any) {
|
|
function onAddDateChange(e: any) {
|
|
|
const val = e?.detail?.value || e;
|
|
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;
|
|
addDate.value = val;
|
|
|
addDateLabel.value = val.replace(/^(.{10}).*$/, '$1')
|
|
addDateLabel.value = val.replace(/^(.{10}).*$/, '$1')
|
|
|
}
|
|
}
|
|
@@ -367,12 +398,18 @@ async function confirmAdd() {
|
|
|
const parts = addDate.value.split('-')
|
|
const parts = addDate.value.split('-')
|
|
|
const addY = parseInt(parts[0], 10)
|
|
const addY = parseInt(parts[0], 10)
|
|
|
const addM = parseInt(parts[1], 10) - 1
|
|
const addM = parseInt(parts[1], 10) - 1
|
|
|
|
|
+ const addD = parseInt(parts[2] || '1', 10)
|
|
|
|
|
+ const addDateObj = new Date(addY, addM, addD)
|
|
|
|
|
+ if (isAfterTodayDate(addDateObj)) {
|
|
|
|
|
+ uni.showToast && uni.showToast({ title: '不能添加未来日期的数据', icon: 'none' })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
if (viewMode.value === 'month') {
|
|
if (viewMode.value === 'month') {
|
|
|
if (addY === current.value.getFullYear() && addM === current.value.getMonth()) {
|
|
if (addY === current.value.getFullYear() && addM === current.value.getMonth()) {
|
|
|
records.value = [item, ...records.value]
|
|
records.value = [item, ...records.value]
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- const addDateObj = new Date(addY, addM, parseInt(parts[2] || '1', 10))
|
|
|
|
|
|
|
+ // addDateObj already computed above
|
|
|
const addWeekStart = getWeekStart(addDateObj)
|
|
const addWeekStart = getWeekStart(addDateObj)
|
|
|
const curWeekStart = getWeekStart(current.value)
|
|
const curWeekStart = getWeekStart(current.value)
|
|
|
if (addWeekStart.getTime() === curWeekStart.getTime()) {
|
|
if (addWeekStart.getTime() === curWeekStart.getTime()) {
|