diff --git a/src/App.vue b/src/App.vue index 50e327f..d41ca20 100644 --- a/src/App.vue +++ b/src/App.vue @@ -29,6 +29,12 @@ const isSettingsOpen = ref(false); const isTagManagerOpen = ref(false); const isEventModalOpen = ref(false); +const toast = ref({ message: "", type: "success", visible: false }); +const showToast = (message: string, type = "success") => { + toast.value = { message, type, visible: true }; + setTimeout(() => { toast.value.visible = false; }, 3000); +}; + const mergeScreens = ref(false); const retainDays = ref(30); const captureInterval = ref(30); @@ -95,24 +101,48 @@ const loadTags = async () => { tags.value = await invoke("get_tags"); }; const loadEvents = async () => { dayEvents.value = await invoke("get_events", { date: currentDate.value }); }; const handleAddTag = async (name: string, parentId: number | null, color: string) => { - await invoke("add_tag", { name, parentId, color }); - await loadTags(); + try { + await invoke("add_tag", { name, parentId, color }); + await loadTags(); + showToast("标签添加成功"); + } catch (e) { + showToast("添加失败: " + e, "error"); + } }; const handleDeleteTag = async (id: number) => { - await invoke("delete_tag", { id }); - await loadTags(); + try { + await invoke("delete_tag", { id }); + await loadTags(); + showToast("标签已删除"); + } catch (e: any) { + if (e.toString().includes("FOREIGN KEY")) { + showToast("该标签正在被使用,无法删除", "error"); + } else { + showToast("删除失败: " + e, "error"); + } + } }; const saveEvent = async () => { - await invoke("save_event", { event: editingEvent.value }); - isEventModalOpen.value = false; - await loadEvents(); + try { + await invoke("save_event", { event: editingEvent.value }); + isEventModalOpen.value = false; + await loadEvents(); + showToast("事件已保存"); + } catch (e) { + showToast("保存失败: " + e, "error"); + } }; const deleteEvent = async (id: number) => { - await invoke("delete_event", { id }); - await loadEvents(); + try { + await invoke("delete_event", { id }); + await loadEvents(); + showToast("事件已删除"); + } catch (e) { + showToast("删除失败: " + e, "error"); + } }; const timeToLogicalMinutes = (timeStr: string, isNextDay = false) => { @@ -336,6 +366,15 @@ const resetTagForm = () => { newTagName.value = ""; newTagParent.value = null; n