优化:文件操作精确更新,避免占用问题
后端改进:
- API 返回 FileOperationResult 结构体(类型安全)
- 所有操作返回文件信息,支持精确更新
- 删除过度抽象的接口和全局函数包装器(桌面程序不需要)
前端改进:
- 精确更新文件列表(避免整目录刷新)
- 分离 add/remove/update 三个独立函数
- 重命名前智能关闭文件/文件夹,解决占用问题
- 优化错误提示,用户友好提示
技术细节:
- 定义 FileOperationResult 结构体替代 map[string]interface{}
- 前端 API 返回类型从 void 改为 any
- 保留运行时状态(如 is_favorite)
- 智能识别文件占用错误并给出解决建议
This commit is contained in:
@@ -81,41 +81,41 @@ export async function writeFile(path: string, content: string): Promise<void> {
|
||||
/**
|
||||
* 删除文件或目录
|
||||
*/
|
||||
export async function deletePath(path: string): Promise<void> {
|
||||
export async function deletePath(path: string): Promise<any> {
|
||||
if (!window.go?.main?.App?.DeletePath) {
|
||||
throw new Error('DeletePath API 不可用')
|
||||
}
|
||||
await window.go.main.App.DeletePath(path)
|
||||
return await window.go.main.App.DeletePath(path)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建目录
|
||||
*/
|
||||
export async function createDir(path: string): Promise<void> {
|
||||
export async function createDir(path: string): Promise<any> {
|
||||
if (!window.go?.main?.App?.CreateDir) {
|
||||
throw new Error('CreateDir API 不可用')
|
||||
}
|
||||
await window.go.main.App.CreateDir(path)
|
||||
return await window.go.main.App.CreateDir(path)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
*/
|
||||
export async function createFile(path: string): Promise<void> {
|
||||
export async function createFile(path: string): Promise<any> {
|
||||
if (!window.go?.main?.App?.CreateFile) {
|
||||
throw new Error('CreateFile API 不可用')
|
||||
}
|
||||
await window.go.main.App.CreateFile(path)
|
||||
return await window.go.main.App.CreateFile(path)
|
||||
}
|
||||
|
||||
/**
|
||||
* 重命名文件或目录
|
||||
*/
|
||||
export async function renamePath(oldPath: string, newPath: string): Promise<void> {
|
||||
export async function renamePath(oldPath: string, newPath: string): Promise<any> {
|
||||
if (!window.go?.main?.App?.RenamePath) {
|
||||
throw new Error('RenamePath API 不可用')
|
||||
}
|
||||
await window.go.main.App.RenamePath({
|
||||
return await window.go.main.App.RenamePath({
|
||||
oldPath: String(oldPath),
|
||||
newPath: String(newPath)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user