refactor(对话框组件): 重构文件及目录对话框的关闭逻辑
将重置表单的逻辑从close方法移到after-leave事件处理中 简化目录对话框的confirm事件参数,移除fullPath字段 清理CreateTemplateScreen中未使用的导入和状态
This commit is contained in:
1 parent
7f77c7f6f3
commit
d3f4242445
3 files changed
+22
-48
No files matched your search
@@ -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>
|
||||
</script>
|
||||
@@ -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>
|
||||
@@ -107,7 +107,7 @@
|
||||
添加根文件
|
||||
</v-tooltip>
|
||||
</v-btn>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<TemplateTree
|
||||
@@ -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)
|
||||
@@ -260,7 +251,7 @@ onMounted(async () => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
@@ -375,7 +366,7 @@ const handleDirectoryDialogConfirm = (data: { path: string; fullPath: string })
|
||||
parentDirectoryForNewItems.value = null // Clear parent context after creation
|
||||
currentEditingItem.value = null
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 在树状结构中更新节点的辅助函数
|
||||
@@ -427,9 +418,6 @@ const addChildToNode = (
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const handleFileDialogConfirm = (data: { path: string; fullPath: string; sourceFilePath?: string }) => {
|
||||
const { path, fullPath, sourceFilePath } = data
|
||||
|
||||
@@ -518,7 +506,7 @@ const handleFileDialogConfirm = (data: { path: string; fullPath: string; sourceF
|
||||
parentDirectoryForNewItems.value = null // Clear parent context after creation
|
||||
currentEditingItem.value = null
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 检查树中是否有重复路径的辅助函数
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user