From 70f1258bab4dd508ad5d689a23e82b1a5b8a9738 Mon Sep 17 00:00:00 2001 From: "Mr.Huan" Date: Tue, 25 Jan 2022 15:17:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=87=E4=BB=B6=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=89=B9=E9=87=8F=E5=88=A0=E9=99=A4=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/FileController.php | 29 +++++++++++ app/Tasks/BatchRemoveFileTask.php | 55 +++++++++++++++++++++ resources/assets/js/pages/manage/file.vue | 48 ++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 app/Tasks/BatchRemoveFileTask.php diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index f5df5aec..baddbb17 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -12,6 +12,8 @@ use App\Models\FileUser; use App\Models\User; use App\Module\Base; use App\Module\Ihttp; +use App\Tasks\BatchRemoveFileTask; +use Hhxsv5\LaravelS\Swoole\Task\Task; use Illuminate\Support\Facades\DB; use Request; @@ -371,6 +373,33 @@ class FileController extends AbstractController return Base::retSuccess('删除成功', $file); } + /** + * @api {get} api/file/batch/remove 批量删除文件 + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup file + * @apiName batchRemove + * + * @apiParam {Array} ids 文件ID + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + * + * @return array + */ + public function batch__remove(): array + { + $ids = Request::input('ids'); + if ( empty($ids) || !is_array($ids) ) { + return Base::retError("请选择要删除的文件"); + } + $task = new BatchRemoveFileTask($ids, User::userid()); + Task::deliver($task); + return Base::retSuccess('success'); + } + /** * @api {get} api/file/content 08. 获取文件内容 * diff --git a/app/Tasks/BatchRemoveFileTask.php b/app/Tasks/BatchRemoveFileTask.php new file mode 100644 index 00000000..5ef3d711 --- /dev/null +++ b/app/Tasks/BatchRemoveFileTask.php @@ -0,0 +1,55 @@ +_ids = $ids; + $this->_userid = $userid; + } + + public function start() + { + foreach ($this->_ids as $id) { + Log::info("---------- $id ----------"); + Log::info("尝试删除Id为[$id]的文件"); + $file = File::find($id); + if (empty($file)) { + Log::warning("Id为[$id]的文件不存在或已被删除"); + continue; + } + Log::info("获取到文件名为[" . $file->name . "],类型为[" . ( $file->type ?: $file->ext ) . "]"); + $permission = $file->getPermission($this->_userid); + if ($permission < 1000) { + Log::warning("文件[$id][" . $file->name . "]仅限所有者或创建者操作"); + continue; + } + try { + $file->deleteFile(); + Log::info("删除Id为[$id]的文件成功"); + } catch (Throwable $throwable) { + Log::error("删除Id为[$id]的文件失败,原因是:" . $throwable->getMessage()); + } + } + } +} diff --git a/resources/assets/js/pages/manage/file.vue b/resources/assets/js/pages/manage/file.vue index 36eeb1fe..91dbc4c4 100644 --- a/resources/assets/js/pages/manage/file.vue +++ b/resources/assets/js/pages/manage/file.vue @@ -37,6 +37,8 @@ "{{shearFile.name}}" + +
@@ -53,6 +55,10 @@ :no-data-text="$L('没有任何文件')" @on-cell-click="clickRow" @on-contextmenu="handleContextMenu" + @on-select="handleTableSelect" + @on-select-cancel="handleTableSelect" + @on-select-all-cancel="handleTableSelect" + @on-select-all="handleTableSelect" context-menu stripe/>
@@ -428,6 +434,8 @@ export default { top: 0, left: 0 }, + + selectFile: [], } }, @@ -541,6 +549,11 @@ export default { methods: { initLanguage() { this.columns = [ + { + type: 'selection', + width: 60, + align: 'center' + }, { title: this.$L('文件名'), key: 'name', @@ -814,6 +827,8 @@ export default { }, clickRow(row) { + // 清空已选择的行 + this.selectFile = []; this.dropFile(row, 'open'); }, @@ -1239,6 +1254,39 @@ export default { this.uploadShow = true; return true; }, + + handleTableSelect(selection, row) { + this.selectFile = selection; + }, + + deleteSelectFile() { + if ( this.selectFile.length <= 0 ) { + $A.messageError("未选择任何文件或文件夹"); + return false; + } + let s_ids = this.selectFile.map( (item, index) => { + return item.id; + } ); + $A.modalConfirm({ + title: '批量删除', + content: '你确定要删除这些文件吗?', + loading: true, + onOk: () => { + this.$store.dispatch("call", { + url: 'file/batch/remove', + data: { + ids: s_ids, + }, + }).then(({msg}) => { + this.$Modal.remove(); + $A.messageSuccess("已提交至后台处理,请稍后再回来查看结果吧"); + }).catch(({msg}) => { + $A.modalError(msg, 301); + this.$Modal.remove(); + }); + } + }); + } } }