refactor(模板创建): 重构模板树结构处理逻辑

- 将 parentDirectory 类型从 string 改为 TreeNode 以直接引用节点
- 移除冗余的 TreeItem 接口和转换逻辑
- 简化文件/目录添加和更新逻辑,直接操作 TreeNode
- 使用新的 generateUniqueId 工具函数生成唯一ID
- 移除不必要的路径拼接和重复检查逻辑
This commit is contained in:
zhanggy committed 2025-10-31 13:41:45 +08:00
1 parent d3f4242445
commit 47fb017e21
4 files changed
+78 -207

No files matched your search

+11
View File
@@ -9,3 +9,14 @@ export async function openExternal(url: string): Promise<void> {
export async function openFile(type: string): Promise<any> {
return window.mainApi.invoke('msgOpenFile', type)
}
/**
* 生成唯一ID
* @param prefix ID前缀,默认为空
* @returns 唯一ID字符串
*/
export function generateUniqueId(prefix: string = ''): string {
const timestamp = Date.now().toString(36) // 转换为36进制,更短
const randomStr = Math.random().toString(36).substring(2, 9) // 7位随机字符
return prefix ? `${prefix}-${timestamp}-${randomStr}` : `${timestamp}-${randomStr}`
}