From 95b18ebc894589ead0be0d5738efa9bd6a9caf9b Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Thu, 15 Sep 2022 10:44:43 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E5=A2=9E=E5=8A=A0=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/utils/files/fileinfo.go | 21 ++++++++++++++++--- frontend/src/api/interface/file.ts | 5 +++-- frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + .../src/views/host/file-management/index.vue | 10 ++++++--- .../host/file-management/process/index.vue | 9 ++++++-- .../views/host/file-management/wget/index.vue | 7 ++++++- 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/backend/utils/files/fileinfo.go b/backend/utils/files/fileinfo.go index 84455994c..0ddcf8ff1 100644 --- a/backend/utils/files/fileinfo.go +++ b/backend/utils/files/fileinfo.go @@ -31,6 +31,7 @@ type FileInfo struct { ModTime time.Time `json:"modTime"` FileMode os.FileMode `json:"-"` Items []*FileInfo `json:"items"` + ItemTotal int `json:"itemTotal"` } type FileOption struct { @@ -39,6 +40,8 @@ type FileOption struct { Expand bool `json:"expand"` Dir bool `json:"dir"` ShowHidden bool `json:"showHidden"` + Page int `json:"page"` + PageSize int `json:"pageSize"` } func NewFileInfo(op FileOption) (*FileInfo, error) { @@ -70,7 +73,7 @@ func NewFileInfo(op FileOption) (*FileInfo, error) { } if op.Expand { if file.IsDir { - if err := file.listChildren(op.Dir, op.ShowHidden); err != nil { + if err := file.listChildren(op.Dir, op.ShowHidden, op.Page, op.PageSize); err != nil { return nil, err } return file, nil @@ -83,12 +86,14 @@ func NewFileInfo(op FileOption) (*FileInfo, error) { return file, nil } -func (f *FileInfo) listChildren(dir, showHidden bool) error { +func (f *FileInfo) listChildren(dir, showHidden bool, page, pageSize int) error { afs := &afero.Afero{Fs: f.Fs} files, err := afs.ReadDir(f.Path) if err != nil { return err } + f.ItemTotal = len(files) + var items []*FileInfo for _, df := range files { if dir && !df.IsDir() { @@ -138,7 +143,17 @@ func (f *FileInfo) listChildren(dir, showHidden bool) error { } items = append(items, file) } - f.Items = items + + start := (page - 1) * pageSize + end := pageSize + start + var result []*FileInfo + if start < 0 || start > f.ItemTotal || end < 0 || start > end || end > f.ItemTotal { + result = items + } else { + result = items[start:end] + } + + f.Items = result return nil } diff --git a/frontend/src/api/interface/file.ts b/frontend/src/api/interface/file.ts index 9a727d475..9964badea 100644 --- a/frontend/src/api/interface/file.ts +++ b/frontend/src/api/interface/file.ts @@ -1,4 +1,4 @@ -import { CommonModel } from '.'; +import { CommonModel, ReqPage } from '.'; export namespace File { export interface File extends CommonModel { path: string; @@ -18,9 +18,10 @@ export namespace File { dirSize: number; items: File[]; extension: string; + itemTotal: number; } - export interface ReqFile { + export interface ReqFile extends ReqPage { path: string; search?: string; expand: boolean; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 0ed93e50a..3cd847b34 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -246,5 +246,6 @@ export default { canNotDeCompress: 'Can not DeCompress this File', uploadSuccess: 'Upload Success!', downloadProcess: 'Download Process', + downloading: 'Downloading...', }, }; diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index b055c1fd9..8b0769ed7 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -246,5 +246,6 @@ export default { canNotDeCompress: '无法解压此文件', uploadSuccess: '上传成功!', downloadProcess: '下载进度', + downloading: '正在下载...', }, }; diff --git a/frontend/src/views/host/file-management/index.vue b/frontend/src/views/host/file-management/index.vue index fd6c0cd49..a1f061e9f 100644 --- a/frontend/src/views/host/file-management/index.vue +++ b/frontend/src/views/host/file-management/index.vue @@ -43,6 +43,7 @@ v-model:selects="selects" :data="data" v-loading="loading" + @search="search(req)" >