From 092506e9ab3c3f4eaba71693d4d6462258e9cefd Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 27 Apr 2022 15:47:53 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=85=B1=E4=BA=AB=E7=9A=84=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=A6=81=E6=AD=A2=E7=A7=BB=E5=8A=A8=E5=88=B0=E5=8F=A6?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=85=B1=E4=BA=AB=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/FileController.php | 16 ++++++++++------ app/Models/File.php | 9 +++++++++ resources/assets/js/pages/manage/file.vue | 18 +++++++----------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index 4d473d331..3290bbaf2 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -363,6 +363,15 @@ class FileController extends AbstractController $file = File::permissionFind($id, 1000); // if ($pid > 0) { + if ($toShareFile) { + if ($file->share) { + throw new ApiException("{$file->name} 当前正在共享,无法移动到另一个共享文件夹内"); + } + if ($file->isSubShare()) { + throw new ApiException("{$file->name} 内含有共享文件,无法移动到另一个共享文件夹内"); + } + } + // $tmpId = $pid; while ($tmpId > 0) { if ($id == $tmpId) { @@ -370,11 +379,6 @@ class FileController extends AbstractController } $tmpId = intval(File::whereId($tmpId)->value('pid')); } - if ($file->share && $toShareFile) { - $file->share = 0; - $file->save(); - FileUser::deleteFileAll($file->id, $file->userid); - } } // $file->pid = $pid; @@ -951,7 +955,7 @@ class FileController extends AbstractController // 设置共享 $action = "update"; if ($force === 0) { - if (File::where("pids", "like", "%,{$file->id},%")->whereShare(1)->exists()) { + if ($file->isSubShare()) { return Base::retError('此文件夹内已有共享文件夹', [], -3001); } } diff --git a/app/Models/File.php b/app/Models/File.php index 7af8549bd..39134b5b4 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -160,6 +160,15 @@ class File extends AbstractModel return false; } + /** + * 目录内是否存在共享文件或文件夹 + * @return bool + */ + public function isSubShare() + { + return $this->type == 'folder' && File::where("pids", "like", "%,{$this->id},%")->whereShare(1)->exists(); + } + /** * 设置/关闭 共享(同时遍历取消里面的共享) * @param $share diff --git a/resources/assets/js/pages/manage/file.vue b/resources/assets/js/pages/manage/file.vue index c9604f562..f45a1f779 100644 --- a/resources/assets/js/pages/manage/file.vue +++ b/resources/assets/js/pages/manage/file.vue @@ -1164,20 +1164,16 @@ export default { this.$refs.linkInput.focus({cursor:'all'}); }, - shearTo(force = false) { + shearTo() { if (this.shearIds.length == 0) { return; } - if (force !== true - && this.isParentShare - && this.files.findIndex(({id, share}) => share && this.shearIds.includes(id)) > -1) { - $A.modalConfirm({ - content: '剪切板含有共享文件,粘贴到共享文件夹中原共享属性将失效。', - onOk: () => { - this.shearTo(true) - } - }); - return; + if (this.isParentShare) { + const tmpFile = this.files.find(({id, share}) => share && this.shearIds.includes(id)); + if (tmpFile) { + $A.modalError(`${tmpFile.name} 当前正在共享,无法移动到另一个共享文件夹内`) + return; + } } this.$store.dispatch("call", { url: 'file/move',