From e496aa59f48ac59a995464a5e6501efcb073d8a5 Mon Sep 17 00:00:00 2001 From: Jasery Date: Fri, 31 Oct 2025 17:20:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor(types):=20=E5=B0=86=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E7=A7=BB=E5=8A=A8=E5=88=B0=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E7=9A=84types=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将原本分散在多个文件中的TreeNode和Template类型定义集中到src/types模块中,并更新所有相关引用 修改tsconfig配置以包含新的types目录 优化IPCs中模板处理逻辑,改进文件复制和路径处理 --- src/main/IPCs.ts | 31 ++++++++++++------- src/renderer/components/DirectoryDialog.vue | 2 +- src/renderer/components/FileDialog.vue | 10 ++---- src/renderer/components/TemplateCard.vue | 2 +- src/renderer/screens/CreateTemplateScreen.vue | 3 +- src/renderer/screens/TemplateListScreen.vue | 4 +-- src/renderer/store/template.ts | 20 +----------- src/types/index.ts | 18 +++++++++++ tsconfig.json | 2 +- tsconfig.node.json | 1 + 10 files changed, 49 insertions(+), 44 deletions(-) create mode 100644 src/types/index.ts diff --git a/src/main/IPCs.ts b/src/main/IPCs.ts index 70f8fa4..f2a28e4 100644 --- a/src/main/IPCs.ts +++ b/src/main/IPCs.ts @@ -6,9 +6,11 @@ import { readFileSync, existsSync, ensureDirSync, - copyFileSync + copyFileSync, + readdirSync } from 'fs-extra' import { autoUpdater } from 'electron-updater' +import { Template, TreeNode } from '../types' /* * IPC Communications @@ -182,7 +184,7 @@ export default class IPCs { const userDataPath = join(Constants.APP_DATA_PATH, 'data') const filePath = join(userDataPath, 'templates.json') - let templates = [] + let templates: Template[] = [] if (existsSync(filePath)) { const templatesData = readFileSync(filePath, 'utf-8') templates = JSON.parse(templatesData) @@ -203,11 +205,14 @@ export default class IPCs { ensureDirSync(baseDirPath) // Helper function to traverse the tree and collect all nodes - const collectAllNodes = (nodes, allNodes = []) => { + const collectAllNodes = (nodes: TreeNode[], allNodes: TreeNode[] = [], parent?: TreeNode) => { for (const node of nodes) { - allNodes.push(node); + allNodes.push({ + ...node, + path: join(parent?.path || '', node.path) + }); if (node.children) { - collectAllNodes(node.children, allNodes); + collectAllNodes(node.children, allNodes, node); } } return allNodes; @@ -227,13 +232,17 @@ export default class IPCs { const fileDir = dirname(nodePath); ensureDirSync(fileDir); - if (node.sourceFilePath) { - // Copy from source file - const sourceContent = readFileSync(node.sourceFilePath); - writeFileSync(nodePath, sourceContent); - } else if (node.content) { + if (node.sourceType === 'file') { + copyFileSync(node.sourcePath, nodePath); + } else { // Write content directly - writeFileSync(nodePath, node.content, 'utf-8'); + const files = readdirSync(node.sourcePath, { withFileTypes: true }) + for (const file of files) { + if (file.isFile() && file.name.startsWith(baseDirName)) { + const filePath = join(node.sourcePath, file.name); + copyFileSync(filePath, nodePath); + } + } } } } diff --git a/src/renderer/components/DirectoryDialog.vue b/src/renderer/components/DirectoryDialog.vue index 6bdd79a..a6e49a0 100644 --- a/src/renderer/components/DirectoryDialog.vue +++ b/src/renderer/components/DirectoryDialog.vue @@ -39,7 +39,7 @@