feat: Implement template management feature

- Added IPC handlers for selecting directories, loading, saving, and executing templates.
- Created a new TemplateListScreen for displaying and managing templates.
- Developed CreateTemplateScreen for creating and editing templates with file and directory management.
- Updated routing to include new template screens.
- Enhanced MainScreen with navigation to template management.
- Added localization for new template-related strings in English and Chinese.
- Introduced a Pinia store for managing template data.
- Implemented tests for template creation, listing, and detail viewing.
This commit is contained in:
zhangguoyun committed 2025-10-27 15:17:32 +08:00
1 parent 742eb7040f
commit 1aecd5f4b6
15 files changed
+1225 -140

No files matched your search

+107
View File
@@ -0,0 +1,107 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
interface TemplateFile {
path: string
content: string
}
interface TemplateDirectory {
path: string
}
export interface Template {
id: string
name: string
description: string
files: TemplateFile[]
directories: TemplateDirectory[]
}
export const useTemplateStore = defineStore('template', () => {
const templates = ref<Template[]>([])
const dataFile = 'templates.json'
// Load templates from local storage or initialize
async function loadTemplates() {
try {
const stored = await window.mainApi.invoke('msgLoadData', dataFile)
if (stored) {
templates.value = JSON.parse(stored as string) || []
} else {
// Initialize with sample data if no stored data
templates.value = []
}
} catch (error) {
console.error('Failed to load templates:', error)
templates.value = []
}
}
// Save templates to local storage
function saveTemplates() {
try {
window.mainApi.invoke(
'msgSaveData',
dataFile,
JSON.stringify(templates.value)
)
} catch (error) {
console.error('Failed to save templates:', error)
}
}
// Get all templates
function getTemplates() {
return templates.value
}
// Get template by ID
function getTemplateById(id: string) {
return templates.value.find((template) => template.id === id)
}
// Add new template
function addTemplate(template: Omit<Template, 'id'>) {
const newTemplate: Template = {
id: `template_${Date.now()}`,
...template
}
templates.value.push(newTemplate)
saveTemplates()
}
// Update existing template
function updateTemplate(updatedTemplate: Template) {
const index = templates.value.findIndex((t) => t.id === updatedTemplate.id)
if (index !== -1) {
templates.value[index] = updatedTemplate
saveTemplates()
}
}
// Delete template
function deleteTemplate(id: string) {
templates.value = templates.value.filter((template) => template.id !== id)
saveTemplates()
}
// Get template names for dropdowns
function getTemplateNames() {
return templates.value.map((template) => ({
text: template.name,
value: template.id
}))
}
return {
templates,
loadTemplates,
getTemplates,
getTemplateById,
addTemplate,
updateTemplate,
deleteTemplate,
getTemplateNames
}
})