perf: 优化提示此文件夹内已有共享文件夹

This commit is contained in:
kuaifan 2022-03-30 08:20:24 +08:00
parent fe82c44687
commit cf6b4f5432
4 changed files with 38 additions and 9 deletions

View File

@ -811,6 +811,9 @@ class FileController extends AbstractController
* - 0:只读
* - 1:读写
* - -1: 删除
* @apiParam {Number} [force] 设置共享时是否忽略提醒
* - 0如果子文件夹已存在共享则ret返回-3001(默认)
* - 1:忽略提醒
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
@ -823,6 +826,7 @@ class FileController extends AbstractController
$id = intval(Request::input('id'));
$userids = Request::input('userids');
$permission = intval(Request::input('permission'));
$force = intval(Request::input('force'));
//
if (!in_array($permission, [-1, 0, 1])) {
return Base::retError('参数错误');
@ -859,6 +863,11 @@ class FileController extends AbstractController
} else {
// 设置共享
$action = "update";
if ($force === 0) {
if (File::where('pids', 'like', ",{$file->id},")->whereShare(1)->exists()) {
return Base::retError('此文件夹内已有共享文件夹', [], -3001);
}
}
if (FileUser::whereFileId($file->id)->count() + count($userids) > 100) {
return Base::retError('共享人数上限100个成员');
}
@ -874,7 +883,7 @@ class FileController extends AbstractController
}
}
//
$file->setShare();
$file->updataShare();
$file->pushMsg($action, $action == "delete" ? null : $file, $array);
return Base::retSuccess($action == "delete" ? "删除成功" : "设置成功", $file);
}
@ -915,7 +924,7 @@ class FileController extends AbstractController
'userid' => $user->userid,
])->delete();
//
$file->setShare();
$file->updataShare();
return Base::retSuccess("退出成功");
}

View File

@ -158,7 +158,7 @@ class File extends AbstractModel
* @param $share
* @return bool
*/
public function setShare($share = null)
public function updataShare($share = null)
{
if ($share === null) {
$share = FileUser::whereFileId($this->id)->count() == 0 ? 0 : 1;
@ -167,10 +167,13 @@ class File extends AbstractModel
AbstractModel::transaction(function () use ($share) {
$this->share = $share;
$this->save();
if ($share === 0) {
FileUser::whereFileId($this->id)->delete();
}
$list = self::wherePid($this->id)->get();
if ($list->isNotEmpty()) {
foreach ($list as $item) {
$item->setShare(0);
$item->updataShare(0);
}
}
});

View File

@ -17,7 +17,7 @@ class AddFilesPids extends Migration
Schema::table('files', function (Blueprint $table) use (&$isAdd) {
if (!Schema::hasColumn('files', 'pids')) {
$isAdd = true;
$table->string('pids', 255)->nullable()->default('')->after('id')->comment('上级ID递归');
$table->string('pids', 255)->nullable()->default('')->after('pid')->comment('上级ID递归');
}
});
if ($isAdd) {
@ -28,6 +28,12 @@ class AddFilesPids extends Migration
$item->saveBeforePids();
}
});
\App\Models\File::whereShare(0)->chunkById(100, function ($lists) {
/** @var \App\Models\File $item */
foreach ($lists as $item) {
\App\Models\FileUser::whereFileId($item->id)->delete();
}
});
}
}

View File

@ -1272,7 +1272,7 @@ export default {
})
},
onShare() {
onShare(force = false) {
if (this.shareInfo.userids.length == 0) {
$A.messageWarning("请选择共享成员")
return;
@ -1280,16 +1280,27 @@ export default {
this.shareLoad++;
this.$store.dispatch("call", {
url: 'file/share/update',
data: this.shareInfo,
data: Object.assign(this.shareInfo, {
force: force === true ? 1 : 0
}),
}).then(({data, msg}) => {
this.shareLoad--;
$A.messageSuccess(msg)
this.$store.dispatch("saveFile", data);
this.$set(this.shareInfo, 'userids', []);
this.getShare();
}).catch(({msg}) => {
}).catch(({ret, msg}) => {
this.shareLoad--;
$A.modalError(msg)
if (ret === -3001) {
$A.modalConfirm({
content: '此文件夹内已有共享文件夹,子文件的共享状态将被取消,是否继续?',
onOk: () => {
this.onShare(true)
}
})
} else {
$A.modalError(msg, force === true ? 301 : 0)
}
})
},