From f4eead9cc201254f97361b54b53135d96a0583ea Mon Sep 17 00:00:00 2001 From: zhengkunwang223 <31820853+zhengkunwang223@users.noreply.github.com> Date: Tue, 6 Sep 2022 10:35:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/file.go | 13 +++ backend/app/dto/file.go | 6 + backend/app/service/file.go | 8 ++ backend/router/ro_file.go | 1 + backend/utils/files/file_op.go | 11 ++ backend/utils/files/fileinfo.go | 13 ++- frontend/src/api/interface/file.ts | 7 ++ frontend/src/api/modules/files.ts | 4 + frontend/src/components/file-list/index.vue | 5 + frontend/src/lang/modules/zh.ts | 3 + .../{file-down => download}/index.vue | 0 frontend/src/views/file-management/index.vue | 29 ++++- .../src/views/file-management/move/index.vue | 107 ++++++++++++++++++ .../{file-rename => rename}/index.vue | 0 14 files changed, 201 insertions(+), 6 deletions(-) rename frontend/src/views/file-management/{file-down => download}/index.vue (100%) create mode 100644 frontend/src/views/file-management/move/index.vue rename frontend/src/views/file-management/{file-rename => rename}/index.vue (100%) diff --git a/backend/app/api/v1/file.go b/backend/app/api/v1/file.go index f82d774da..2f9ffa9f1 100644 --- a/backend/app/api/v1/file.go +++ b/backend/app/api/v1/file.go @@ -180,3 +180,16 @@ func (b *BaseApi) Download(c *gin.Context) { } helper.SuccessWithData(c, nil) } + +func (b *BaseApi) Move(c *gin.Context) { + var req dto.FileMove + if err := c.ShouldBindJSON(&req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err) + return + } + if err := fileService.MvFile(req); err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + helper.SuccessWithData(c, nil) +} diff --git a/backend/app/dto/file.go b/backend/app/dto/file.go index 32b8a8eb5..a72414e28 100644 --- a/backend/app/dto/file.go +++ b/backend/app/dto/file.go @@ -63,3 +63,9 @@ type FileDownload struct { Path string `json:"path" validate:"required"` Name string `json:"name" validate:"required"` } + +type FileMove struct { + Type string `json:"type" validate:"required"` + OldPaths []string `json:"oldPaths" validate:"required"` + NewPath string `json:"newPath" validate:"required"` +} diff --git a/backend/app/service/file.go b/backend/app/service/file.go index 27333d070..cb4c4ae35 100644 --- a/backend/app/service/file.go +++ b/backend/app/service/file.go @@ -125,6 +125,14 @@ func (f FileService) Download(c dto.FileDownload) error { return fo.DownloadFile(c.Url, filepath.Join(c.Path, c.Name)) } +func (f FileService) MvFile(c dto.FileMove) error { + fo := files.NewFileOp() + if c.Type == "cut" { + return fo.Cut(c.OldPaths, c.NewPath) + } + return nil +} + func getUuid() string { b := make([]byte, 16) io.ReadFull(rand.Reader, b) diff --git a/backend/router/ro_file.go b/backend/router/ro_file.go index 64dd592ab..e7a0f5adf 100644 --- a/backend/router/ro_file.go +++ b/backend/router/ro_file.go @@ -27,6 +27,7 @@ func (f *FileRouter) InitFileRouter(Router *gin.RouterGroup) { fileRouter.POST("/upload", baseApi.UploadFiles) fileRouter.POST("/rename", baseApi.ChangeName) fileRouter.POST("/download", baseApi.Download) + fileRouter.POST("/move", baseApi.Move) } } diff --git a/backend/utils/files/file_op.go b/backend/utils/files/file_op.go index 3a88c3dca..cf96d52a4 100644 --- a/backend/utils/files/file_op.go +++ b/backend/utils/files/file_op.go @@ -105,6 +105,17 @@ func (f FileOp) DownloadFile(url, dst string) error { return nil } +func (f FileOp) Cut(oldPaths []string, dst string) error { + for _, p := range oldPaths { + base := filepath.Base(p) + dstPath := filepath.Join(dst, base) + if err := f.Fs.Rename(p, dstPath); err != nil { + return err + } + } + return nil +} + type CompressType string const ( diff --git a/backend/utils/files/fileinfo.go b/backend/utils/files/fileinfo.go index 6f5739c60..591113ab4 100644 --- a/backend/utils/files/fileinfo.go +++ b/backend/utils/files/fileinfo.go @@ -36,6 +36,7 @@ type FileOption struct { Path string `json:"path"` Search string `json:"search"` Expand bool `json:"expand"` + Dir bool `json:"dir"` } func NewFileInfo(op FileOption) (*FileInfo, error) { @@ -69,7 +70,7 @@ func NewFileInfo(op FileOption) (*FileInfo, error) { } if op.Expand { if file.IsDir { - if err := file.listChildren(); err != nil { + if err := file.listChildren(op.Dir); err != nil { return nil, err } return file, nil @@ -82,14 +83,18 @@ func NewFileInfo(op FileOption) (*FileInfo, error) { return file, nil } -func (f *FileInfo) listChildren() error { +func (f *FileInfo) listChildren(dir bool) error { afs := &afero.Afero{Fs: f.Fs} - dir, err := afs.ReadDir(f.Path) + files, err := afs.ReadDir(f.Path) if err != nil { return err } var items []*FileInfo - for _, df := range dir { + for _, df := range files { + if dir && !df.IsDir() { + continue + } + name := df.Name() fPath := path.Join(f.Path, df.Name()) diff --git a/frontend/src/api/interface/file.ts b/frontend/src/api/interface/file.ts index 28e860123..fc7c5545b 100644 --- a/frontend/src/api/interface/file.ts +++ b/frontend/src/api/interface/file.ts @@ -22,6 +22,7 @@ export namespace File { path: string; search?: string; expand: boolean; + dir?: boolean; } export interface FileTree { @@ -75,4 +76,10 @@ export namespace File { name: string; url: string; } + + export interface FileMove { + oldPaths: string[]; + newPath: string; + type: string; + } } diff --git a/frontend/src/api/modules/files.ts b/frontend/src/api/modules/files.ts index 39360d613..1cffa8e8f 100644 --- a/frontend/src/api/modules/files.ts +++ b/frontend/src/api/modules/files.ts @@ -48,3 +48,7 @@ export const RenameRile = (params: File.FileRename) => { export const DownloadFile = (params: File.FileDownload) => { return http.post('files/download', params); }; + +export const MoveFile = (params: File.FileMove) => { + return http.post('files/move', params); +}; diff --git a/frontend/src/components/file-list/index.vue b/frontend/src/components/file-list/index.vue index b5222bc81..052586926 100644 --- a/frontend/src/components/file-list/index.vue +++ b/frontend/src/components/file-list/index.vue @@ -54,6 +54,10 @@ const props = defineProps({ type: String, default: '/', }, + dir: { + type: Boolean, + default: false, + }, }); const em = defineEmits(['choose']); @@ -89,6 +93,7 @@ const jump = async (index: number) => { }; const search = async (req: File.ReqFile) => { + req.dir = props.dir; loading.value = true; await GetFilesList(req) .then((res) => { diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 026084cd7..a4d59cf9f 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -200,5 +200,8 @@ export default { downloadSuccess: '下载成功', downloadUrl: '下载地址', downloadStart: '下载开始!', + moveStart: '移动成功', + move: '移动', + copy: '复制', }, }; diff --git a/frontend/src/views/file-management/file-down/index.vue b/frontend/src/views/file-management/download/index.vue similarity index 100% rename from frontend/src/views/file-management/file-down/index.vue rename to frontend/src/views/file-management/download/index.vue diff --git a/frontend/src/views/file-management/index.vue b/frontend/src/views/file-management/index.vue index 5e48132cc..777d26a01 100644 --- a/frontend/src/views/file-management/index.vue +++ b/frontend/src/views/file-management/index.vue @@ -60,10 +60,17 @@ {{ $t('file.upload') }} {{ $t('file.remoteFile') }} + + {{ $t('file.copy') }} + + {{ $t('file.move') }} + @@ -151,11 +159,12 @@ import ChangeRole from './change-role/index.vue'; import Compress from './compress/index.vue'; import Decompress from './decompress/index.vue'; import Upload from './upload/index.vue'; -import FileRename from './file-rename/index.vue'; +import FileRename from './rename/index.vue'; import { useDeleteData } from '@/hooks/use-delete-data'; import CodeEditor from './code-editor/index.vue'; import { ElMessage } from 'element-plus'; -import FileDown from './file-down/index.vue'; +import FileDown from './download/index.vue'; +import Move from './move/index.vue'; let data = ref(); let selects = ref([]); @@ -175,6 +184,7 @@ const codeReq = reactive({ path: '', expand: false }); const uploadPage = reactive({ open: false, path: '' }); const renamePage = reactive({ open: false, path: '', oldName: '' }); const downloadPage = reactive({ open: false, path: '' }); +const movePage = reactive({ open: false, oldPaths: [''], type: '' }); const defaultProps = { children: 'children', @@ -370,6 +380,21 @@ const closeRename = () => { search(req); }; +const openMove = (type: string) => { + movePage.type = type; + movePage.open = true; + const oldpaths = []; + for (const s of selects.value) { + oldpaths.push(s['path']); + } + movePage.oldPaths = oldpaths; +}; + +const clodeMove = () => { + movePage.open = false; + search(req); +}; + const saveContent = (content: string) => { editorPage.loading = true; SaveFileContent({ path: codeReq.path, content: content }).finally(() => { diff --git a/frontend/src/views/file-management/move/index.vue b/frontend/src/views/file-management/move/index.vue new file mode 100644 index 000000000..e1f19ab15 --- /dev/null +++ b/frontend/src/views/file-management/move/index.vue @@ -0,0 +1,107 @@ + + + diff --git a/frontend/src/views/file-management/file-rename/index.vue b/frontend/src/views/file-management/rename/index.vue similarity index 100% rename from frontend/src/views/file-management/file-rename/index.vue rename to frontend/src/views/file-management/rename/index.vue