From 305af935a7e0ccd9fdda04052006e8b48409424e Mon Sep 17 00:00:00 2001 From: "Mr.Huan" Date: Thu, 27 Jan 2022 14:24:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=87=E4=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E7=A7=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/FileController.php | 44 +++++++++++++-- resources/assets/js/pages/manage/file.vue | 60 ++++++++++++++++++++- 2 files changed, 99 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index baddbb17..a2b04315 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -317,11 +317,11 @@ class FileController extends AbstractController * @apiSuccess {String} msg 返回信息(错误描述) * @apiSuccess {Object} data 返回数据 */ - public function move() + public function move($id = 0) { $user = User::auth(); // - $id = intval(Request::input('id')); + $id = empty($id) ? intval(Request::input('id')) : $id; $pid = intval(Request::input('pid')); // $file = File::permissionFind($id, 1000); @@ -347,6 +347,44 @@ class FileController extends AbstractController return Base::retSuccess('操作成功', $file); } + /** + * @api {get} api/file/batch/move 批量移动文件 + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup file + * @apiName batch__move + * + * @apiParam {Array} ids 文件ID + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + * + * @return array + */ + public function batch__move(): array + { + $ids = Request::input('ids'); + if ( empty($ids) || !is_array($ids) ) { + return Base::retError("请选择要移动的文件"); + } + // 去重 + $ids = array_unique($ids); + $data = []; + // 暂时不考虑异步 + AbstractModel::transaction( function () use ($ids, &$data) { + foreach ($ids as $id) { + $res = $this->move($id); + if ( Base::isError($res) ) + throw new ApiException($res["msg"]); + + $data[] = $res["data"]; + } + } ); + return Base::retSuccess('操作成功', $data); + } + /** * @api {get} api/file/remove 07. 删除文件(夹) * @@ -397,7 +435,7 @@ class FileController extends AbstractController } $task = new BatchRemoveFileTask($ids, User::userid()); Task::deliver($task); - return Base::retSuccess('success'); + return Base::retSuccess('操作成功'); } /** diff --git a/resources/assets/js/pages/manage/file.vue b/resources/assets/js/pages/manage/file.vue index e77a2ef8..a9b8a059 100644 --- a/resources/assets/js/pages/manage/file.vue +++ b/resources/assets/js/pages/manage/file.vue @@ -37,7 +37,25 @@ "{{shearFile.name}}" - + +
@@ -439,6 +457,7 @@ export default { selectFile: [], fileChecked: [], + shearFiles: [], } }, @@ -906,6 +925,14 @@ export default { this.shearId = item.id; break; + case 'batchShear': + // 排除目录 + for (const item of this.selectFile) { + if (item.type !== 'folder') + this.shearFiles.push(item); + } + break; + case 'share': this.shareInfo = { id: item.id, @@ -1279,6 +1306,8 @@ export default { handleTableSelect(selection, row) { this.selectFile = selection; + // 需要清空剪切的文件 + this.shearFiles = []; }, deleteSelectFile() { @@ -1302,6 +1331,7 @@ export default { }).then(() => { this.$Modal.remove(); this.selectFile = []; + this.fileChecked = []; $A.messageSuccess("已提交至后台处理,请稍后再回来查看结果吧"); }).catch(({msg}) => { $A.modalError(msg, 301); @@ -1326,7 +1356,33 @@ export default { if (index >= 0) this.selectFile.splice(index, 1); } - } + // 需要清空剪切的文件 + this.shearFiles = []; + }, + batchShearTo() { + if (!this.shearFiles) { + return; + } + this.$store.dispatch("call", { + url: 'file/batch/move', + data: { + ids: this.shearFiles.map( (item,index) => item.id ), + pid: this.pid, + }, + }).then(({data, msg}) => { + $A.messageSuccess(msg); + // 清空数据 + this.shearId = 0; + this.shearFiles = []; + this.selectFile = []; + this.fileChecked = []; + for (const item of data) { + this.$store.dispatch("saveFile", item); + } + }).catch(({msg}) => { + $A.modalError(msg); + }); + }, } }