From 867a46a7919142d7e164ed43cdc7c036d32117c3 Mon Sep 17 00:00:00 2001 From: aipaw Date: Fri, 18 Jun 2021 07:42:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=80=9A=E7=9F=A5=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=AD=A3=E5=88=A0=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/ProjectController.php | 150 +++++++++--------- app/Models/Project.php | 15 +- app/Models/ProjectColumn.php | 17 +- app/Models/ProjectTask.php | 17 +- .../pages/manage/components/ProjectList.vue | 14 +- resources/assets/js/pages/manage/project.vue | 2 +- resources/assets/js/store/actions.js | 34 ++-- resources/assets/js/store/mutations.js | 18 +-- 8 files changed, 150 insertions(+), 117 deletions(-) diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index d5030546..30e0aa75 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -163,7 +163,7 @@ class ProjectController extends AbstractController * @apiParam {String} name 项目名称 * @apiParam {String} [desc] 项目介绍 */ - public function edit() + public function update() { user::auth(); // @@ -193,10 +193,86 @@ class ProjectController extends AbstractController $project->addLog("修改项目介绍"); } $project->save(); + $project->pushMsg('update', $project->toArray()); // return Base::retSuccess('修改成功', $project); } + /** + * 修改项目成员 + * + * @apiParam {Number} project_id 项目ID + * @apiParam {Number} userid 成员ID 或 成员ID组 + */ + public function user() + { + user::auth(); + // + $project_id = intval(Request::input('project_id')); + $userid = Request::input('userid'); + $userid = is_array($userid) ? $userid : [$userid]; + // + $project = Project::userProject($project_id); + if (!$project->owner) { + return Base::retError('你不是项目负责人'); + } + // + return AbstractModel::transaction(function() use ($project, $userid) { + $array = []; + foreach ($userid as $uid) { + if ($project->joinProject($uid)) { + $array[] = $uid; + } + } + $delete = ProjectUser::whereProjectId($project->id)->whereNotIn('userid', $array); + $deleteUser = $delete->pluck('userid'); + $delete->delete(); + $project->syncDialogUser(); + $project->addLog("修改项目成员"); + $project->pushMsg('delete', null, $deleteUser->toArray()); + $project->pushMsg('detail'); + return Base::retSuccess('修改成功', ['id' => $project->id]); + }); + } + + /** + * 移交项目 + * + * @apiParam {Number} project_id 项目ID + * @apiParam {Number} owner_userid 新的项目负责人ID + */ + public function transfer() + { + user::auth(); + // + $project_id = intval(Request::input('project_id')); + $owner_userid = intval(Request::input('owner_userid')); + // + $project = Project::userProject($project_id); + if (!$project->owner) { + return Base::retError('你不是项目负责人'); + } + // + if (!User::whereUserid($owner_userid)->exists()) { + return Base::retError('会员不存在'); + } + // + return AbstractModel::transaction(function() use ($owner_userid, $project) { + ProjectUser::whereProjectId($project->id)->update(['owner' => 0]); + ProjectUser::updateInsert([ + 'project_id' => $project->id, + 'userid' => $owner_userid, + ], [ + 'owner' => 1, + ]); + $project->syncDialogUser(); + $project->addLog("移交项目给会员ID:" . $owner_userid); + $project->pushMsg('detail'); + // + return Base::retSuccess('移交成功', ['id' => $project->id]); + }); + } + /** * 排序任务 * @@ -246,79 +322,10 @@ class ProjectController extends AbstractController } $project->addLog("调整任务排序"); } + $project->pushMsg('detail'); return Base::retSuccess('调整成功'); } - /** - * 修改项目成员 - * - * @apiParam {Number} project_id 项目ID - * @apiParam {Number} userid 成员ID 或 成员ID组 - */ - public function user() - { - user::auth(); - // - $project_id = intval(Request::input('project_id')); - $userid = Request::input('userid'); - $userid = is_array($userid) ? $userid : [$userid]; - // - $project = Project::userProject($project_id); - if (!$project->owner) { - return Base::retError('你不是项目负责人'); - } - // - return AbstractModel::transaction(function() use ($project, $userid) { - $array = []; - foreach ($userid as $uid) { - if ($project->joinProject($uid)) { - $array[] = $uid; - } - } - ProjectUser::whereProjectId($project->id)->whereNotIn('userid', $array)->delete(); - $project->syncDialogUser(); - $project->addLog("修改项目成员"); - return Base::retSuccess('修改成功'); - }); - } - - /** - * 移交项目 - * - * @apiParam {Number} project_id 项目ID - * @apiParam {Number} owner_userid 新的项目负责人ID - */ - public function transfer() - { - user::auth(); - // - $project_id = intval(Request::input('project_id')); - $owner_userid = intval(Request::input('owner_userid')); - // - $project = Project::userProject($project_id); - if (!$project->owner) { - return Base::retError('你不是项目负责人'); - } - // - if (!User::whereUserid($owner_userid)->exists()) { - return Base::retError('会员不存在'); - } - // - return AbstractModel::transaction(function() use ($owner_userid, $project) { - ProjectUser::whereProjectId($project->id)->update(['owner' => 0]); - ProjectUser::updateInsert([ - 'project_id' => $project->id, - 'userid' => $owner_userid, - ], [ - 'owner' => 1, - ]); - $project->syncDialogUser(); - $project->addLog("移交项目给会员ID:" . $owner_userid); - // - return Base::retSuccess('移交成功'); - }); - } - /** * 退出项目 * @@ -340,6 +347,7 @@ class ProjectController extends AbstractController ProjectUser::whereProjectId($project->id)->whereUserid($user->userid)->delete(); $project->syncDialogUser(); $project->addLog("会员ID:" . $user->userid . " 退出项目"); + $project->pushMsg('delete', null, $user->userid); return Base::retSuccess('退出成功', ['id' => $project->id]); }); } diff --git a/app/Models/Project.php b/app/Models/Project.php index f7ee9bb6..bd34c41a 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -266,9 +266,9 @@ class Project extends AbstractModel foreach ($columns as $column) { $column->deleteColumn(false); } - $this->pushMsg('delete', $this->toArray()); $this->delete(); $this->addLog("删除项目"); + $this->pushMsg('delete'); return Base::retSuccess('删除成功', $this->toArray()); }); return Base::isSuccess($result); @@ -296,12 +296,19 @@ class Project extends AbstractModel /** * 推送消息 * @param string $action - * @param array $data + * @param array $data 发送内容,默认为[id=>项目ID] + * @param array $userid 指定会员,默认为项目所有成员 */ - public function pushMsg($action, $data) + public function pushMsg($action, $data = null, $userid = null) { + if ($data === null) { + $data = ['id' => $this->id]; + } + if ($userid === null) { + $userid = $this->relationUserids(); + } $lists = [ - 'userid' => $this->relationUserids(), + 'userid' => $userid, 'msg' => [ 'type' => 'project', 'action' => $action, diff --git a/app/Models/ProjectColumn.php b/app/Models/ProjectColumn.php index a6f6d147..729af433 100644 --- a/app/Models/ProjectColumn.php +++ b/app/Models/ProjectColumn.php @@ -70,11 +70,11 @@ class ProjectColumn extends AbstractModel foreach ($tasks as $task) { $task->deleteTask($pushMsg); } + $this->delete(); + $this->addLog("删除列表:" . $this->name); if ($pushMsg) { $this->pushMsg("delete", $this->toArray()); } - $this->delete(); - $this->addLog("删除列表:" . $this->name); return Base::retSuccess('删除成功', $this->toArray()); }); return Base::isSuccess($result); @@ -102,15 +102,22 @@ class ProjectColumn extends AbstractModel /** * 推送消息 * @param string $action - * @param array $data + * @param array $data 发送内容,默认为[id=>列表ID] + * @param array $userid 指定会员,默认为项目所有成员 */ - public function pushMsg($action, $data) + public function pushMsg($action, $data = null, $userid = null) { if (!$this->project) { return; } + if ($data === null) { + $data = ['id' => $this->id]; + } + if ($userid === null) { + $userid = $this->project->relationUserids(); + } $lists = [ - 'userid' => $this->project->relationUserids(), + 'userid' => $userid, 'msg' => [ 'type' => 'projectColumn', 'action' => $action, diff --git a/app/Models/ProjectTask.php b/app/Models/ProjectTask.php index 73c47100..86b8d3eb 100644 --- a/app/Models/ProjectTask.php +++ b/app/Models/ProjectTask.php @@ -591,11 +591,11 @@ class ProjectTask extends AbstractModel if ($this->dialog_id) { WebSocketDialog::whereId($this->dialog_id)->delete(); } + $this->delete(); + $this->addLog("删除{任务}:" . $this->name); if ($pushMsg) { $this->pushMsg('delete', $this->toArray()); } - $this->delete(); - $this->addLog("删除{任务}:" . $this->name); return Base::retSuccess('删除成功', $this->toArray()); }); } @@ -623,15 +623,22 @@ class ProjectTask extends AbstractModel /** * 推送消息 * @param string $action - * @param array $data + * @param array $data 发送内容,默认为[id=>任务ID] + * @param array $userid 指定会员,默认为项目所有成员 */ - public function pushMsg($action, $data) + public function pushMsg($action, $data = null, $userid = null) { if (!$this->project) { return; } + if ($data === null) { + $data = ['id' => $this->id]; + } + if ($userid === null) { + $userid = $this->project->relationUserids(); + } $lists = [ - 'userid' => $this->project->relationUserids(), + 'userid' => $userid, 'msg' => [ 'type' => 'projectTask', 'action' => $action, diff --git a/resources/assets/js/pages/manage/components/ProjectList.vue b/resources/assets/js/pages/manage/components/ProjectList.vue index 168c3726..f4845ef7 100644 --- a/resources/assets/js/pages/manage/components/ProjectList.vue +++ b/resources/assets/js/pages/manage/components/ProjectList.vue @@ -626,7 +626,7 @@ export default { }).catch(({msg}) => { $A.modalError(msg); this.sortDisabled = false; - this.$store.dispatch("getProjectDetail", this.projectDetail.id); + this.$store.dispatch("getProjectDetail", this.projectDetail); }); }, @@ -782,7 +782,7 @@ export default { $A.messageSuccess(msg); this.$set(column, 'loading', false); this.$Modal.remove(); - this.$store.commit("columnRemoveSuccess", data); + this.$store.commit("columnDeleteSuccess", data); }).catch(({msg}) => { $A.modalError(msg, 301); this.$set(column, 'loading', false); @@ -869,7 +869,7 @@ export default { onSetting() { this.settingLoad++; this.$store.dispatch("call", { - url: 'project/edit', + url: 'project/update', data: this.settingData, }).then(({data, msg}) => { $A.messageSuccess(msg); @@ -890,11 +890,11 @@ export default { project_id: this.userData.project_id, userid: this.userData.userids, }, - }).then(({msg}) => { + }).then(({data, msg}) => { $A.messageSuccess(msg); this.userLoad--; this.userShow = false; - this.$store.dispatch("getProjectDetail", this.userData.project_id); + this.$store.dispatch("getProjectDetail", data); }).catch(({msg}) => { $A.modalError(msg); this.userLoad--; @@ -909,11 +909,11 @@ export default { project_id: this.transferData.project_id, owner_userid: this.transferData.owner_userid[0], }, - }).then(({msg}) => { + }).then(({data, msg}) => { $A.messageSuccess(msg); this.transferLoad--; this.transferShow = false; - this.$store.dispatch("getProjectDetail", this.transferData.project_id); + this.$store.dispatch("getProjectDetail", data); }).catch(({msg}) => { $A.modalError(msg); this.transferLoad--; diff --git a/resources/assets/js/pages/manage/project.vue b/resources/assets/js/pages/manage/project.vue index 61f3e65a..3ba9f91f 100644 --- a/resources/assets/js/pages/manage/project.vue +++ b/resources/assets/js/pages/manage/project.vue @@ -24,7 +24,7 @@ export default { this.project_id = route.params.id; }, project_id(id) { - this.$store.dispatch("getProjectDetail", id); + this.$store.dispatch("getProjectDetail", {id}); } }, } diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 9e3cec3f..b909b014 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -314,16 +314,16 @@ export default { * 获取项目信息 * @param state * @param dispatch - * @param project_id + * @param data {id} */ - getProjectBasic({state, dispatch}, project_id) { - if (state.method.runNum(project_id) === 0) { + getProjectBasic({state, dispatch}, data) { + if (state.method.runNum(data.id) === 0) { return; } dispatch("call", { url: 'project/basic', data: { - project_id: project_id, + project_id: data.id, }, }).then(result => { dispatch("saveProject", result.data); @@ -334,24 +334,24 @@ export default { * 获取项目详情 * @param state * @param dispatch - * @param project_id + * @param data {id} */ - getProjectDetail({state, dispatch}, project_id) { - if (state.method.runNum(project_id) === 0) { + getProjectDetail({state, dispatch}, data) { + if (state.method.runNum(data.id) === 0) { return; } - const project = state.cacheProjectList.find(({id}) => id == project_id); + const project = state.cacheProjectList.find(({id}) => id == data.id); if (project) { state.projectDetail = Object.assign({project_column: [], project_user: []}, project); } else { - state.projectDetail.id = project_id; + state.projectDetail.id = data.id; } // state.projectLoad++; dispatch("call", { url: 'project/detail', data: { - project_id: project_id, + project_id: data.id, }, }).then(result => { state.projectLoad--; @@ -365,7 +365,7 @@ export default { /** * 删除项目信息 * @param state - * @param data + * @param data {id} */ removeProject({state}, data) { let index = state.projectList.findIndex(({id}) => id == data.id); @@ -689,7 +689,7 @@ export default { dispatch("getTaskBasic", result.data.parent_id); } if (typeof post.complete_at !== "undefined") { - dispatch("getProjectBasic", result.data.project_id); + dispatch("getProjectBasic", {id: result.data.project_id}); } dispatch("saveTask", result.data); resolve(result) @@ -716,7 +716,7 @@ export default { task_id, }, }).then(result => { - commit("taskRemoveSuccess", result.data); + commit("taskDeleteSuccess", result.data); resolve(result); }).catch(result => { reject(result) @@ -1126,8 +1126,12 @@ export default { const {action, data} = msg; switch (action) { case 'add': + case 'update': dispatch("saveProject", data) break; + case 'detail': + dispatch("getProjectDetail", data); + break; case 'delete': dispatch("removeProject", data); break; @@ -1146,7 +1150,7 @@ export default { commit("columnAddSuccess", data) break; case 'delete': - commit("columnRemoveSuccess", data) + commit("columnDeleteSuccess", data) break; } })(msgDetail); @@ -1164,7 +1168,7 @@ export default { break; case 'archived': case 'delete': - commit("taskRemoveSuccess", data) + commit("taskDeleteSuccess", data) break; } })(msgDetail); diff --git a/resources/assets/js/store/mutations.js b/resources/assets/js/store/mutations.js index b3e537d6..9a2b99e4 100644 --- a/resources/assets/js/store/mutations.js +++ b/resources/assets/js/store/mutations.js @@ -1,6 +1,6 @@ export default { /** - * 添加列表成功 + * 添加列表 * @param state * @param data */ @@ -14,20 +14,20 @@ export default { }, /** - * 删除列表成功 + * 删除列表 * @param state * @param data */ - columnRemoveSuccess(state, data) { + columnDeleteSuccess(state, data) { let index = state.projectDetail.project_column.findIndex(({id}) => id === data.id); if (index > -1) { state.projectDetail.project_column.splice(index, 1); } - this.dispatch("getProjectBasic", data.project_id); + this.dispatch("getProjectBasic", {id: data.project_id}); }, /** - * 添加任务成功 + * 添加任务 * @param state * @param data */ @@ -51,7 +51,7 @@ export default { } } } - this.dispatch("getProjectBasic", task.project_id); + this.dispatch("getProjectBasic", {id: task.project_id}); } else { // 添加子任务 if (state.projectDetail.id == task.project_id) { @@ -78,11 +78,11 @@ export default { }, /** - * 移除任务成功 + * 删除任务 * @param state * @param data */ - taskRemoveSuccess(state, data) { + taskDeleteSuccess(state, data) { const column = state.projectDetail.project_column.find(({id}) => id === data.column_id); if (column) { let index = column.project_task.findIndex(({id}) => id === data.id); @@ -102,6 +102,6 @@ export default { if (index > -1) { state.calendarTask.splice(index, 1) } - this.dispatch("getProjectBasic", data.project_id); + this.dispatch("getProjectBasic", {id: data.project_id}); } }