refactor(对话框组件): 重构文件及目录对话框的关闭逻辑

将重置表单的逻辑从close方法移到after-leave事件处理中
简化目录对话框的confirm事件参数,移除fullPath字段
清理CreateTemplateScreen中未使用的导入和状态
This commit is contained in:
zhanggy committed 2025-10-31 11:33:29 +08:00
1 parent 7f77c7f6f3
commit d3f4242445
3 files changed
+17 -43

No files matched your search

+6 -11
View File
@@ -2,6 +2,7 @@
<v-dialog
v-model="isVisible"
max-width="500"
@after-leave="reset"
>
<v-card>
<v-card-title>
@@ -49,7 +50,7 @@ interface Props {
interface Emits {
(e: 'update:modelValue', value: boolean): void
(e: 'confirm', data: { path: string; fullPath: string }): void
(e: 'confirm', data: { path: string; }): void
}
const props = withDefaults(defineProps<Props>(), {
@@ -100,25 +101,19 @@ const confirm = () => {
if (!directoryPath.value.trim()) return
// Construct the full path if there's a parent directory
let fullPath = directoryPath.value
if (props.parentDirectory) {
// Make sure parent directory ends with a slash before appending
const parentPath = props.parentDirectory.endsWith('/')
? props.parentDirectory
: props.parentDirectory + '/'
fullPath = parentPath + directoryPath.value
}
emit('confirm', {
path: directoryPath.value,
fullPath
})
close()
}
const reset = () => {
directoryPath.value = ''
formValid.value = false
}
const close = () => {
isVisible.value = false
directoryPath.value = ''
}
</script>
+7 -2
View File
@@ -2,6 +2,7 @@
<v-dialog
v-model="isVisible"
max-width="600"
@after-leave="reset"
>
<v-card>
<v-card-title>
@@ -155,9 +156,13 @@ const confirm = () => {
close()
}
const close = () => {
isVisible.value = false
const reset = () => {
filePath.value = ''
selectedSourcePath.value = ''
formValid.value = false
}
const close = () => {
isVisible.value = false
}
</script>
+4 -30
View File
@@ -142,15 +142,10 @@
@confirm="handleFileDialogConfirm"
/>
</v-container>
</template>
<script setup lang="ts">
import { ref, computed, onMounted, onUnmounted, watch, nextTick } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useTemplateStore, TreeNode } from '@/renderer/store/template'
import { useSnackbarStore } from '@/renderer/store/snackbar'
import TemplateTree from '@/renderer/components/TemplateTree.vue'
@@ -177,14 +172,10 @@ const showFileDialog = ref(false)
// Directory dialog state
const showDirectoryDialog = ref(false)
const directoryFormValid = ref(false)
const parentDirectoryForNewItems = ref<string | null>(null)
const currentEditingItem = ref<TreeNode | null>(null)
// Tree state
const expandedNodes = ref<string[]>([])
const treeHeight = ref(600)
@@ -299,8 +290,8 @@ const addNewItemToCurrentDirectory = (directoryItem: TreeItem) => {
showDirectoryDialog.value = true
}
const handleDirectoryDialogConfirm = (data: { path: string; fullPath: string }) => {
const { path, fullPath } = data
const handleDirectoryDialogConfirm = (data: { path: string }) => {
const { path } = data
// Check for duplicate names in the same parent directory
if (parentDirectoryForNewItems.value) {
@@ -340,7 +331,7 @@ const handleDirectoryDialogConfirm = (data: { path: string; fullPath: string })
const updatedNode: TreeNode = {
id: currentEditingItem.value.id,
name: path,
path: fullPath,
path: path,
type: 'directory'
}
treeStructure.value = updateNodeInTree(
@@ -353,7 +344,7 @@ const handleDirectoryDialogConfirm = (data: { path: string; fullPath: string })
const newNode: TreeNode = {
id: newId,
name: path,
path: fullPath,
path: path,
type: 'directory'
}
@@ -427,9 +418,6 @@ const addChildToNode = (
}
const handleFileDialogConfirm = (data: { path: string; fullPath: string; sourceFilePath?: string }) => {
const { path, fullPath, sourceFilePath } = data
@@ -558,9 +546,6 @@ const goBack = async () => {
}
// Unified method to edit items (both files and directories)
// This function needs to find the actual path of the item in our hierarchical tree
const editItem = (item: TreeItem) => {
@@ -620,7 +605,6 @@ const findNodeInTreeByName = (
}
// Show dialog to edit directory
const showEditDirectoryDialog = (directory: TreeNode) => {
// Set up for editing an existing directory
@@ -637,8 +621,6 @@ const showEditFileDialog = (file: TreeNode) => {
showFileDialog.value = true
}
const deleteItem = async (item: TreeItem) => {
const confirmed = await ConfirmDialogService.confirm({
title: '删除确认',
@@ -669,14 +651,6 @@ const removeItemFromTree = (nodes: TreeNode[], itemId: string): TreeNode[] => {
})
}
const saveTemplate = () => {
if (!formValid.value) return