mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
perf: 优化提示此文件夹内已有共享文件夹
This commit is contained in:
parent
fe82c44687
commit
cf6b4f5432
@ -811,6 +811,9 @@ class FileController extends AbstractController
|
|||||||
* - 0:只读
|
* - 0:只读
|
||||||
* - 1:读写
|
* - 1:读写
|
||||||
* - -1: 删除
|
* - -1: 删除
|
||||||
|
* @apiParam {Number} [force] 设置共享时是否忽略提醒
|
||||||
|
* - 0:如果子文件夹已存在共享则ret返回-3001(默认)
|
||||||
|
* - 1:忽略提醒
|
||||||
*
|
*
|
||||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
@ -823,6 +826,7 @@ class FileController extends AbstractController
|
|||||||
$id = intval(Request::input('id'));
|
$id = intval(Request::input('id'));
|
||||||
$userids = Request::input('userids');
|
$userids = Request::input('userids');
|
||||||
$permission = intval(Request::input('permission'));
|
$permission = intval(Request::input('permission'));
|
||||||
|
$force = intval(Request::input('force'));
|
||||||
//
|
//
|
||||||
if (!in_array($permission, [-1, 0, 1])) {
|
if (!in_array($permission, [-1, 0, 1])) {
|
||||||
return Base::retError('参数错误');
|
return Base::retError('参数错误');
|
||||||
@ -859,6 +863,11 @@ class FileController extends AbstractController
|
|||||||
} else {
|
} else {
|
||||||
// 设置共享
|
// 设置共享
|
||||||
$action = "update";
|
$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) {
|
if (FileUser::whereFileId($file->id)->count() + count($userids) > 100) {
|
||||||
return Base::retError('共享人数上限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);
|
$file->pushMsg($action, $action == "delete" ? null : $file, $array);
|
||||||
return Base::retSuccess($action == "delete" ? "删除成功" : "设置成功", $file);
|
return Base::retSuccess($action == "delete" ? "删除成功" : "设置成功", $file);
|
||||||
}
|
}
|
||||||
@ -915,7 +924,7 @@ class FileController extends AbstractController
|
|||||||
'userid' => $user->userid,
|
'userid' => $user->userid,
|
||||||
])->delete();
|
])->delete();
|
||||||
//
|
//
|
||||||
$file->setShare();
|
$file->updataShare();
|
||||||
return Base::retSuccess("退出成功");
|
return Base::retSuccess("退出成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -158,7 +158,7 @@ class File extends AbstractModel
|
|||||||
* @param $share
|
* @param $share
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function setShare($share = null)
|
public function updataShare($share = null)
|
||||||
{
|
{
|
||||||
if ($share === null) {
|
if ($share === null) {
|
||||||
$share = FileUser::whereFileId($this->id)->count() == 0 ? 0 : 1;
|
$share = FileUser::whereFileId($this->id)->count() == 0 ? 0 : 1;
|
||||||
@ -167,10 +167,13 @@ class File extends AbstractModel
|
|||||||
AbstractModel::transaction(function () use ($share) {
|
AbstractModel::transaction(function () use ($share) {
|
||||||
$this->share = $share;
|
$this->share = $share;
|
||||||
$this->save();
|
$this->save();
|
||||||
|
if ($share === 0) {
|
||||||
|
FileUser::whereFileId($this->id)->delete();
|
||||||
|
}
|
||||||
$list = self::wherePid($this->id)->get();
|
$list = self::wherePid($this->id)->get();
|
||||||
if ($list->isNotEmpty()) {
|
if ($list->isNotEmpty()) {
|
||||||
foreach ($list as $item) {
|
foreach ($list as $item) {
|
||||||
$item->setShare(0);
|
$item->updataShare(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class AddFilesPids extends Migration
|
|||||||
Schema::table('files', function (Blueprint $table) use (&$isAdd) {
|
Schema::table('files', function (Blueprint $table) use (&$isAdd) {
|
||||||
if (!Schema::hasColumn('files', 'pids')) {
|
if (!Schema::hasColumn('files', 'pids')) {
|
||||||
$isAdd = true;
|
$isAdd = true;
|
||||||
$table->string('pids', 255)->nullable()->default('')->after('id')->comment('上级ID递归');
|
$table->string('pids', 255)->nullable()->default('')->after('pid')->comment('上级ID递归');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if ($isAdd) {
|
if ($isAdd) {
|
||||||
@ -28,6 +28,12 @@ class AddFilesPids extends Migration
|
|||||||
$item->saveBeforePids();
|
$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();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1272,7 +1272,7 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
onShare() {
|
onShare(force = false) {
|
||||||
if (this.shareInfo.userids.length == 0) {
|
if (this.shareInfo.userids.length == 0) {
|
||||||
$A.messageWarning("请选择共享成员")
|
$A.messageWarning("请选择共享成员")
|
||||||
return;
|
return;
|
||||||
@ -1280,16 +1280,27 @@ export default {
|
|||||||
this.shareLoad++;
|
this.shareLoad++;
|
||||||
this.$store.dispatch("call", {
|
this.$store.dispatch("call", {
|
||||||
url: 'file/share/update',
|
url: 'file/share/update',
|
||||||
data: this.shareInfo,
|
data: Object.assign(this.shareInfo, {
|
||||||
|
force: force === true ? 1 : 0
|
||||||
|
}),
|
||||||
}).then(({data, msg}) => {
|
}).then(({data, msg}) => {
|
||||||
this.shareLoad--;
|
this.shareLoad--;
|
||||||
$A.messageSuccess(msg)
|
$A.messageSuccess(msg)
|
||||||
this.$store.dispatch("saveFile", data);
|
this.$store.dispatch("saveFile", data);
|
||||||
this.$set(this.shareInfo, 'userids', []);
|
this.$set(this.shareInfo, 'userids', []);
|
||||||
this.getShare();
|
this.getShare();
|
||||||
}).catch(({msg}) => {
|
}).catch(({ret, msg}) => {
|
||||||
this.shareLoad--;
|
this.shareLoad--;
|
||||||
$A.modalError(msg)
|
if (ret === -3001) {
|
||||||
|
$A.modalConfirm({
|
||||||
|
content: '此文件夹内已有共享文件夹,子文件的共享状态将被取消,是否继续?',
|
||||||
|
onOk: () => {
|
||||||
|
this.onShare(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
$A.modalError(msg, force === true ? 301 : 0)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user