feat: 重构模板管理,采用树状结构存储文件和目录,优化模板创建和编辑流程

This commit is contained in:
zhanggy committed 2025-10-28 18:34:31 +08:00
1 parent f8890ff1e9
commit 5ca31a5348
4 files changed
+351 -246

No files matched your search

+26 -34
View File
@@ -37,10 +37,10 @@
<v-card-text class="flex-grow-1 py-2">
<v-chip-group column>
<v-chip size="small" color="primary" variant="tonal">
文件: {{ template.files.length }}
节点: {{ countTreeNodes(template.treeStructure).files }}
</v-chip>
<v-chip size="small" color="success" variant="tonal">
目录: {{ template.directories.length }}
目录: {{ countTreeNodes(template.treeStructure).directories }}
</v-chip>
</v-chip-group>
</v-card-text>
@@ -138,7 +138,7 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useTemplateStore } from '@/renderer/store/template'
import { useTemplateStore, TreeNode } from '@/renderer/store/template'
import { Template } from '@/renderer/store/template'
import TemplateTree from '@/renderer/components/TemplateTree.vue'
import { ConfirmDialogService } from '@/renderer/utils/confirm-dialog-service'
@@ -166,42 +166,34 @@ const executePath = ref('')
const baseDirNames = ref('')
const executeFormValid = ref(false)
// Define item type for the tree view
interface TreeNode {
id: string
name: string
type: 'directory' | 'file'
children?: TreeNode[]
// Count files and directories in tree structure
const countTreeNodes = (nodes: TreeNode[]) => {
let files = 0;
let directories = 0;
const count = (nodeList: TreeNode[]) => {
nodeList.forEach(node => {
if (node.type === 'file') {
files++;
} else if (node.type === 'directory') {
directories++;
if (node.children) {
count(node.children);
}
}
});
};
count(nodes || []);
return { files, directories };
}
const templateTree = computed<TreeNode[]>(() => {
if (!selectedTemplate.value) return []
const items: TreeNode[] = []
// Add directories
selectedTemplate.value.directories.forEach((dir) => {
items.push({
id: `dir-${dir.path}`,
name: dir.path.split('/').pop() || dir.path, // Show just the directory name, not full path
type: 'directory',
children: []
})
})
// Add files
selectedTemplate.value.files.forEach((file) => {
items.push({
id: `file-${file.path}`,
name: file.path.split('/').pop() || file.path, // Show just the file name, not full path
type: 'file'
})
})
// Auto-expand all nodes when showing template details
expandedTreeNodes.value = items.map(item => item.id)
return items
// 直接返回模板的树状结构
return selectedTemplate.value.treeStructure || []
})
const navigateToCreateTemplate = () => {