refactor(模板管理): 移除未保存更改检测并提取模板卡片组件

移除CreateTemplateScreen中的未保存更改检测逻辑,简化保存和返回操作
将TemplateListScreen中的模板卡片提取为独立的TemplateCard组件
This commit is contained in:
zhanggy committed 2025-10-31 16:37:06 +08:00
1 parent f3e909923a
commit 35a0821153
3 files changed
+109 -103

No files matched your search

+8 -77
View File
@@ -28,62 +28,13 @@
<div v-else>
<v-row>
<v-col v-for="template in templates" :key="template.id" cols="12" sm="6" md="4" lg="3">
<v-card class="d-flex flex-column" height="100%">
<v-card-item>
<v-card-title>{{ template.name }}</v-card-title>
<v-card-subtitle>{{ template.description }}</v-card-subtitle>
</v-card-item>
<v-card-text class="flex-grow-1 py-2">
<v-chip-group column>
<v-chip size="small" color="primary" variant="tonal">
节点: {{ countTreeNodes(template.treeStructure).files }}
</v-chip>
<v-chip size="small" color="success" variant="tonal">
目录: {{ countTreeNodes(template.treeStructure).directories }}
</v-chip>
</v-chip-group>
</v-card-text>
<v-divider class="mt-auto"></v-divider>
<v-card-actions class="pa-2 justify-space-between">
<div>
<v-btn color="primary" variant="text" size="small" @click="viewTemplate(template)">
查看
</v-btn>
<v-btn color="success" variant="text" size="small" @click="executeTemplate(template)">
执行
</v-btn>
</div>
<v-menu location="bottom end">
<template v-slot:activator="{ props }">
<v-btn v-bind="props" icon variant="text" size="small" density="comfortable">
<v-icon>mdi-dots-vertical</v-icon>
</v-btn>
</template>
<v-list density="compact">
<v-list-item @click="editTemplate(template)">
<template v-slot:prepend>
<v-icon>mdi-pencil</v-icon>
</template>
<v-list-item-title>修改</v-list-item-title>
</v-list-item>
<v-divider></v-divider>
<v-list-item @click="deleteTemplate(template)">
<template v-slot:prepend>
<v-icon color="error">mdi-delete</v-icon>
</template>
<v-list-item-title class="text-error">删除</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-card-actions>
</v-card>
<TemplateCard
:template="template"
@view="viewTemplate"
@execute="executeTemplate"
@edit="editTemplate"
@delete="deleteTemplate"
/>
</v-col>
</v-row>
</div>
@@ -141,6 +92,7 @@ import { useRouter } from 'vue-router'
import { useTemplateStore, TreeNode } from '@/renderer/store/template'
import { Template } from '@/renderer/store/template'
import TemplateTree from '@/renderer/components/TemplateTree.vue'
import TemplateCard from '@/renderer/components/TemplateCard.vue'
import { ConfirmDialogService } from '@/renderer/utils/confirm-dialog-service'
const router = useRouter()
@@ -166,28 +118,7 @@ const executePath = ref('')
const baseDirNames = ref('')
const executeFormValid = ref(false)
// 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 []