- 将 parentDirectory 类型从 string 改为 TreeNode 以直接引用节点 - 移除冗余的 TreeItem 接口和转换逻辑 - 简化文件/目录添加和更新逻辑,直接操作 TreeNode - 使用新的 generateUniqueId 工具函数生成唯一ID - 移除不必要的路径拼接和重复检查逻辑
23 lines
746 B
TypeScript
23 lines
746 B
TypeScript
export function getCurrentLocale(): string {
|
|
return navigator?.language?.split('-')[0] || 'en'
|
|
}
|
|
|
|
export async function openExternal(url: string): Promise<void> {
|
|
await window.mainApi.send('msgOpenExternalLink', url)
|
|
}
|
|
|
|
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}`
|
|
}
|