diff --git a/backend/app/dto/file.go b/backend/app/dto/file.go index 5a3850841..72bc876f1 100644 --- a/backend/app/dto/file.go +++ b/backend/app/dto/file.go @@ -11,6 +11,7 @@ type FileInfo struct { } type FileTree struct { + ID string `json:"id"` Name string `json:"name"` Path string `json:"path"` Children []FileTree `json:"children"` diff --git a/backend/app/service/file.go b/backend/app/service/file.go index ee16acc66..3f850a3e6 100644 --- a/backend/app/service/file.go +++ b/backend/app/service/file.go @@ -1,8 +1,11 @@ package service import ( + "crypto/rand" + "fmt" "github.com/1Panel-dev/1Panel/app/dto" "github.com/1Panel-dev/1Panel/utils/files" + "io" ) type FileService struct { @@ -33,12 +36,14 @@ func (f FileService) GetFileTree(op dto.FileOption) ([]dto.FileTree, error) { return nil, err } node := dto.FileTree{ + ID: getUuid(), Name: info.Name, Path: info.Path, } for _, v := range info.Items { if v.IsDir { node.Children = append(node.Children, dto.FileTree{ + ID: getUuid(), Name: v.Name, Path: v.Path, }) @@ -46,3 +51,11 @@ func (f FileService) GetFileTree(op dto.FileOption) ([]dto.FileTree, error) { } return append(treeArray, node), nil } + +func getUuid() string { + b := make([]byte, 16) + io.ReadFull(rand.Reader, b) + b[6] = (b[6] & 0x0f) | 0x40 + b[8] = (b[8] & 0x3f) | 0x80 + return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:]) +} diff --git a/frontend/src/api/interface/file.ts b/frontend/src/api/interface/file.ts index 292e855e9..012513fa6 100644 --- a/frontend/src/api/interface/file.ts +++ b/frontend/src/api/interface/file.ts @@ -23,6 +23,7 @@ export namespace File { } export interface FileTree { + id: string; name: string; isDir: Boolean; path: string; diff --git a/frontend/src/views/file-management/index.vue b/frontend/src/views/file-management/index.vue index 8a0306462..33de381c7 100644 --- a/frontend/src/views/file-management/index.vue +++ b/frontend/src/views/file-management/index.vue @@ -8,8 +8,9 @@ :props="defaultProps" :load="loadNode" lazy - node-key="id" v-loading="treeLoading" + node-key="id" + :default-expanded-keys="expandKeys" >