From e0757f4d657c932d0b5d598bc77e36b6d44d6657 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 24 Aug 2022 17:58:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=87=E4=BB=B6=E5=A4=B9=E6=A0=91?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=B1=95=E5=BC=80=E6=A0=B9=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/dto/file.go | 1 + backend/app/service/file.go | 13 ++++ frontend/src/api/interface/file.ts | 1 + frontend/src/views/file-management/index.vue | 68 +++++++++++--------- 4 files changed, 53 insertions(+), 30 deletions(-) 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" >