feat: 重构 TemplateTree 组件的 v-model 绑定,添加 Snackbar 以显示错误消息

This commit is contained in:
zhanggy committed 2025-10-28 11:18:06 +08:00
1 parent 87ce5cb24f
commit 6431049d05
2 files changed
+42 -22

No files matched your search

+33 -10
View File
@@ -141,8 +141,8 @@
<TemplateTree
:items="treeItems"
:height="treeHeight"
:expanded="expandedNodes"
:show-context-menu-var="showContextMenuVar"
v-model:expanded="expandedNodes"
v-model:showContextMenuVar="showContextMenuVar"
:context-menu-x="contextMenuX"
:context-menu-y="contextMenuY"
:current-context-item="currentContextItem"
@@ -154,8 +154,6 @@
@delete-item="deleteItem"
@add-directory="addDirectory"
@add-file="addFile"
@update:showContextMenuVar="handleContextMenuUpdate"
@update:expanded="expandedNodes = $event"
/>
</v-col>
</v-row>
@@ -270,6 +268,24 @@
</v-card-text>
</v-card>
</v-dialog>
<!-- Snackbar for error messages -->
<v-snackbar
v-model="snackbarVisible"
:color="snackbarColor"
:timeout="2000"
location="top"
>
{{ snackbarMessage }}
<template #actions>
<v-btn
icon
@click="snackbarVisible = false"
>
<v-icon>mdi-close</v-icon>
</v-btn>
</template>
</v-snackbar>
</v-container>
</template>
@@ -310,10 +326,10 @@ const contextMenuX = ref(0)
const contextMenuY = ref(0)
const currentContextItem = ref<TreeItem | null>(null)
// Handler for context menu visibility updates from TemplateTree component
const handleContextMenuUpdate = (value: boolean) => {
showContextMenuVar.value = value
}
// Snackbar variables
const snackbarVisible = ref(false)
const snackbarMessage = ref('')
const snackbarColor = ref('error') // Can be 'error', 'success', 'warning', etc.
// New item state
const newDirectoryPath = ref('')
@@ -470,7 +486,7 @@ const confirmAddDirectory = () => {
(d) => d.path === newDirectoryPath.value
)
if (exists) {
alert('该目录路径已存在!')
showSnackbar('该目录路径已存在!')
return
}
@@ -489,7 +505,7 @@ const confirmAddFile = () => {
// Check for duplicates
const exists = files.value.some((f) => f.path === newFilePath.value)
if (exists) {
alert('该文件路径已存在!')
showSnackbar('该文件路径已存在!')
return
}
@@ -563,6 +579,13 @@ const deleteItem = (item: TreeItem) => {
}
}
// Show snackbar message
const showSnackbar = (message: string, color: string = 'error') => {
snackbarMessage.value = message
snackbarColor.value = color
snackbarVisible.value = true
}
// Auto focus methods
const autoFocusDirectoryInput = async () => {
await nextTick()