fix time duration
This commit is contained in:
@@ -4,7 +4,7 @@ import { load as loadStore } from "@tauri-apps/plugin-store";
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import {
|
import {
|
||||||
RefreshCw, Calendar, ChevronLeft, ChevronRight, Play, Pause, SquarePlus, Tag as TagIcon, Download, Settings, Maximize2, X, Image as ImageIcon, BarChart2
|
RefreshCw, Calendar, ChevronLeft, ChevronRight, Play, Pause, SquarePlus, Tag as TagIcon, Download, Settings, Maximize2, X, Image as ImageIcon, BarChart2, Trash2
|
||||||
} from "lucide-vue-next";
|
} from "lucide-vue-next";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -219,6 +219,10 @@ const calendarDays = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const saveEvent = async () => {
|
const saveEvent = async () => {
|
||||||
|
if (editingEvent.value.end_minute <= editingEvent.value.start_minute) {
|
||||||
|
showToast("结束时间必须晚于开始时间", "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await invoke("save_event", { event: editingEvent.value });
|
await invoke("save_event", { event: editingEvent.value });
|
||||||
isEventModalOpen.value = false; await loadEvents(); showToast("事件已保存");
|
isEventModalOpen.value = false; await loadEvents(); showToast("事件已保存");
|
||||||
@@ -231,7 +235,7 @@ const deleteEvent = async (id: number) => {
|
|||||||
|
|
||||||
const handleQuickAddEvent = () => {
|
const handleQuickAddEvent = () => {
|
||||||
let start = dayEvents.value.length ? Math.max(...dayEvents.value.map(e => e.end_minute)) : 0;
|
let start = dayEvents.value.length ? Math.max(...dayEvents.value.map(e => e.end_minute)) : 0;
|
||||||
let end = currentLogicalMinute.value >= 0 ? currentLogicalMinute.value : 1439;
|
let end = currentLogicalMinute.value >= 0 ? currentLogicalMinute.value : Math.min(start + 30, 1439);
|
||||||
editingEvent.value = { id: 0, date: currentDate.value, start_minute: Math.min(start, end), end_minute: end, main_tag_id: mainTags.value[0]?.id || 0, sub_tag_id: null, content: "" };
|
editingEvent.value = { id: 0, date: currentDate.value, start_minute: Math.min(start, end), end_minute: end, main_tag_id: mainTags.value[0]?.id || 0, sub_tag_id: null, content: "" };
|
||||||
isEventModalOpen.value = true;
|
isEventModalOpen.value = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ref, computed, watch } from "vue";
|
import { ref, computed, watch } from "vue";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { DBEvent } from "../types";
|
import { DBEvent } from "../types";
|
||||||
import { currentDate, getTagColor, getTagName, formatMinutes } from "./index";
|
import { currentDate, getTagColor, getTagName, formatMinutes, parseISODate, toISODate } from "./index";
|
||||||
|
|
||||||
// Re-export for easier access in Dashboard component
|
// Re-export for easier access in Dashboard component
|
||||||
export { getTagColor, getTagName, formatMinutes };
|
export { getTagColor, getTagName, formatMinutes };
|
||||||
@@ -17,12 +17,17 @@ export const loadDashboardEvents = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
watch([dashboardRange, currentDate], () => {
|
watch([dashboardRange, currentDate], () => {
|
||||||
const end = new Date(currentDate.value);
|
const end = parseISODate(currentDate.value);
|
||||||
let start = new Date(currentDate.value);
|
let start = parseISODate(currentDate.value);
|
||||||
if (dashboardRange.value === '7days') start.setDate(end.getDate() - 6);
|
|
||||||
else if (dashboardRange.value === '30days') start.setDate(end.getDate() - 29);
|
if (dashboardRange.value === '7days') {
|
||||||
dashboardStartDate.value = start.toLocaleDateString('sv');
|
start.setDate(end.getDate() - 6);
|
||||||
dashboardEndDate.value = end.toLocaleDateString('sv');
|
} else if (dashboardRange.value === '30days') {
|
||||||
|
start.setDate(end.getDate() - 29);
|
||||||
|
}
|
||||||
|
|
||||||
|
dashboardStartDate.value = toISODate(start);
|
||||||
|
dashboardEndDate.value = toISODate(end);
|
||||||
loadDashboardEvents();
|
loadDashboardEvents();
|
||||||
}, { immediate: true });
|
}, { immediate: true });
|
||||||
|
|
||||||
@@ -32,8 +37,7 @@ export const dashboardStats = computed(() => {
|
|||||||
const uniqueDays = new Set<string>();
|
const uniqueDays = new Set<string>();
|
||||||
|
|
||||||
dashboardEvents.value.forEach(ev => {
|
dashboardEvents.value.forEach(ev => {
|
||||||
let diff = ev.end_minute - ev.start_minute;
|
const diff = Math.max(0, ev.end_minute - ev.start_minute);
|
||||||
if (diff < 0) diff += 1440;
|
|
||||||
totalMinutes += diff;
|
totalMinutes += diff;
|
||||||
uniqueDays.add(ev.date);
|
uniqueDays.add(ev.date);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,28 @@ import { Tag, DBEvent, TimelineItem, Toast } from "../types";
|
|||||||
export const TIME_OFFSET_MINUTES = 180;
|
export const TIME_OFFSET_MINUTES = 180;
|
||||||
export const TOTAL_MINUTES = 1440;
|
export const TOTAL_MINUTES = 1440;
|
||||||
|
|
||||||
|
// --- Date Utils (Logical Day Safe) ---
|
||||||
|
export const getLogicDateStr = (date: Date = new Date()) => {
|
||||||
|
// Subtract offset to get logic day
|
||||||
|
const d = new Date(date.getTime() - TIME_OFFSET_MINUTES * 60000);
|
||||||
|
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}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const parseISODate = (dateStr: string) => {
|
||||||
|
const [y, m, d] = dateStr.split('-').map(Number);
|
||||||
|
return new Date(y, m - 1, d, 12, 0, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const toISODate = (date: Date) => {
|
||||||
|
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}`;
|
||||||
|
};
|
||||||
|
|
||||||
// --- Config State ---
|
// --- Config State ---
|
||||||
export const isSetupComplete = ref(false);
|
export const isSetupComplete = ref(false);
|
||||||
export const savePath = ref("");
|
export const savePath = ref("");
|
||||||
@@ -16,7 +38,7 @@ export const theme = ref("system");
|
|||||||
|
|
||||||
// --- Global UI State ---
|
// --- Global UI State ---
|
||||||
export const isPaused = ref(false);
|
export const isPaused = ref(false);
|
||||||
export const currentDate = ref(new Date(Date.now() - TIME_OFFSET_MINUTES * 60000).toLocaleDateString('sv'));
|
export const currentDate = ref(getLogicDateStr()); // Initialize with logic date
|
||||||
export const viewMode = ref<'preview' | 'dashboard'>('preview');
|
export const viewMode = ref<'preview' | 'dashboard'>('preview');
|
||||||
export const isFullscreen = ref(false);
|
export const isFullscreen = ref(false);
|
||||||
export const previewSrc = ref("");
|
export const previewSrc = ref("");
|
||||||
|
|||||||
Reference in New Issue
Block a user