From 76eac54165798a79ba279774633c2f3a09f7b185 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Mon, 14 Jun 2021 00:10:45 +0800 Subject: [PATCH] no message --- .../Controllers/Api/ProjectController.php | 58 ++++++++++++++++++- app/Models/ProjectTask.php | 43 +++++++------- .../pages/manage/components/ProjectList.vue | 10 +++- .../js/pages/manage/components/TaskDetail.vue | 58 ++++++++++++++++++- .../js/pages/manage/components/TaskRow.vue | 12 +++- resources/assets/js/store/actions.js | 24 ++++++++ .../sass/pages/components/task-detail.scss | 13 ++++- 7 files changed, 187 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index 654af2b5..e78c54c6 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -790,16 +790,68 @@ class ProjectController extends AbstractController return $result; } + /** + * 添加子任务 + * + * @apiParam {Number} task_id 任务ID + * @apiParam {String} name 任务描述 + */ + public function task__addsub() + { + $user = User::authE(); + if (Base::isError($user)) { + return $user; + } else { + $user = User::IDE($user['data']); + } + // + $task_id = intval(Request::input('task_id')); + $name = Request::input('name'); + // 任务 + $task = ProjectTask::whereId($task_id)->first(); + if (empty($task)) { + return Base::retError('任务不存在'); + } + // 项目 + $project = Project::select($this->projectSelect) + ->join('project_users', 'projects.id', '=', 'project_users.project_id') + ->where('projects.id', $task->project_id) + ->where('project_users.userid', $user->userid) + ->first(); + if (empty($project)) { + return Base::retError('项目不存在或不在成员列表内'); + } + // + $result = ProjectTask::addTask([ + 'name' => $name, + 'parent_id' => $task->id, + 'project_id' => $task->project_id, + 'column_id' => $task->column_id, + ]); + if (Base::isSuccess($result)) { + $result['data'] = [ + 'new_column' => null, + 'in_top' => 0, + 'task' => ProjectTask::with(['taskUser', 'taskTag'])->find($result['data']['id']), + ]; + } + return $result; + } + /** * {post} 修改任务、子任务 * * @apiParam {Number} task_id 任务ID * @apiParam {String} [name] 任务描述 - * @apiParam {String} [color] 任务描述(子任务不支持) - * @apiParam {String} [content] 任务详情(子任务不支持) * @apiParam {Array} [times] 计划时间(格式:开始时间,结束时间;如:2020-01-01 00:00,2020-01-01 23:59) * @apiParam {Number} [owner] 修改负责人 - * @apiParam {Array} [assist] 修改协助人员 + * @apiParam {String} [content] 任务详情(子任务不支持) + * @apiParam {String} [color] 背景色(子任务不支持) + * @apiParam {Array} [assist] 修改协助人员(子任务不支持) + * + * @apiParam {Number} [p_level] 优先级相关(子任务不支持) + * @apiParam {String} [p_name] 优先级相关(子任务不支持) + * @apiParam {String} [p_color] 优先级相关(子任务不支持) * * @apiParam {String|false} [complete_at] 完成时间(如:2020-01-01 00:00,false表示未完成) */ diff --git a/app/Models/ProjectTask.php b/app/Models/ProjectTask.php index 642a3907..64a308ef 100644 --- a/app/Models/ProjectTask.php +++ b/app/Models/ProjectTask.php @@ -334,9 +334,6 @@ class ProjectTask extends AbstractModel $subtask['parent_id'] = $task->id; $subtask['project_id'] = $task->project_id; $subtask['column_id'] = $task->column_id; - $subtask['p_level'] = $task->p_level; - $subtask['p_name'] = $task->p_name; - $subtask['p_color'] = $task->p_color; $result = self::addTask($subtask); if (Base::isError($result)) { return $result; @@ -384,26 +381,6 @@ class ProjectTask extends AbstractModel ]); } } - // 协助人员 - if (Arr::exists($data, 'assist')) { - $array = []; - $assist = is_array($data['assist']) ? $data['assist'] : [$data['assist']]; - foreach ($assist as $uid) { - if (intval($uid) == 0) continue; - if (ProjectTaskUser::whereTaskId($this->id)->whereUserid($uid)->whereOwner(1)->exists()) continue; - // - if (!ProjectTaskUser::whereTaskId($this->id)->whereUserid($uid)->where('owner', '!=', 1)->exists()) { - ProjectTaskUser::createInstance([ - 'project_id' => $this->parent_id, - 'task_id' => $this->id, - 'userid' => $uid, - 'owner' => 0, - ])->save(); - } - $array[] = $uid; - } - ProjectTaskUser::whereTaskId($this->id)->where('owner', '!=', 1)->whereNotIn('userid', $array)->delete(); - } // 计划时间 if (Arr::exists($data, 'times')) { $this->start_at = null; @@ -419,6 +396,26 @@ class ProjectTask extends AbstractModel } // 以下紧顶级任务可修改 if ($this->parent_id === 0) { + // 协助人员 + if (Arr::exists($data, 'assist')) { + $array = []; + $assist = is_array($data['assist']) ? $data['assist'] : [$data['assist']]; + foreach ($assist as $uid) { + if (intval($uid) == 0) continue; + if (ProjectTaskUser::whereTaskId($this->id)->whereUserid($uid)->whereOwner(1)->exists()) continue; + // + if (!ProjectTaskUser::whereTaskId($this->id)->whereUserid($uid)->where('owner', '!=', 1)->exists()) { + ProjectTaskUser::createInstance([ + 'project_id' => $this->parent_id, + 'task_id' => $this->id, + 'userid' => $uid, + 'owner' => 0, + ])->save(); + } + $array[] = $uid; + } + ProjectTaskUser::whereTaskId($this->id)->where('owner', '!=', 1)->whereNotIn('userid', $array)->delete(); + } // 背景色 if (Arr::exists($data, 'color')) { $this->color = $data['color']; diff --git a/resources/assets/js/pages/manage/components/ProjectList.vue b/resources/assets/js/pages/manage/components/ProjectList.vue index 13014971..a98eabb4 100644 --- a/resources/assets/js/pages/manage/components/ProjectList.vue +++ b/resources/assets/js/pages/manage/components/ProjectList.vue @@ -122,7 +122,7 @@ v-for="item in panelTask(column.project_task)" :class="['task-item task-draggable', item.complete_at ? 'complete' : '']" :style="item.color ? {backgroundColor: item.color} : {}" - @click="$store.dispatch('openTask', item.id)"> + @click="openTask(item)">
{{item.name}}
@@ -961,6 +961,14 @@ export default { } }, + openTask(task) { + if (task.parent_id > 0) { + this.$store.dispatch('openTask', task.parent_id) + } else { + this.$store.dispatch('openTask', task.id) + } + }, + toggleBoolean(type) { this.$store.dispatch('toggleBoolean', type); }, diff --git a/resources/assets/js/pages/manage/components/TaskDetail.vue b/resources/assets/js/pages/manage/components/TaskDetail.vue index b051c6a4..1f21312e 100644 --- a/resources/assets/js/pages/manage/components/TaskDetail.vue +++ b/resources/assets/js/pages/manage/components/TaskDetail.vue @@ -252,7 +252,16 @@
  • -
    + +
    {{$L('添加子任务')}}
  • @@ -337,6 +346,10 @@ export default { assistData: {}, assistLoad: 0, + addsubShow: false, + addsubName: "", + addsubLoad: 0, + nowTime: Math.round(new Date().getTime() / 1000), nowInterval: null, @@ -812,6 +825,49 @@ export default { }); this.timeOpen = false; }, + + addsubOpen() { + this.addsubShow = true; + this.$nextTick(() => { + this.$refs.addsub.focus() + }); + }, + + addsubChackClose() { + if (this.addsubName == '') { + this.addsubShow = false; + } + }, + + addsubKeydown(e) { + if (e.keyCode === 13) { + if (e.shiftKey) { + return; + } + e.preventDefault(); + this.onAddsub(); + + } + }, + + onAddsub() { + if (this.addsubName == '') { + $A.messageSuccess('任务描述不能为空'); + return; + } + this.addsubLoad++; + this.$store.dispatch("taskAddSub", { + task_id: this.taskDetail.id, + name: this.addsubName, + }).then(({msg}) => { + this.addsubLoad--; + this.addsubName = ""; + $A.messageSuccess(msg); + }).catch(({msg}) => { + this.addsubLoad--; + $A.modalError(msg); + }); + } } } diff --git a/resources/assets/js/pages/manage/components/TaskRow.vue b/resources/assets/js/pages/manage/components/TaskRow.vue index 70eec4ed..721f12ac 100644 --- a/resources/assets/js/pages/manage/components/TaskRow.vue +++ b/resources/assets/js/pages/manage/components/TaskRow.vue @@ -50,7 +50,7 @@ -
    {{item.name}}
    +
    {{item.name}}
    {{item.sub_complete}}/{{item.sub_num}} @@ -168,6 +168,14 @@ export default { }); }, + openTask(task) { + if (task.parent_id > 0) { + this.$store.dispatch('openTask', task.parent_id) + } else { + this.$store.dispatch('openTask', task.id) + } + }, + formatTime(date) { let time = Math.round(new Date(date).getTime() / 1000), string = ''; @@ -202,7 +210,7 @@ export default { else if (minutes > 0) duration = this.formatBit(minutes) + ":" + this.formatBit(seconds); else if (seconds > 0) duration = this.formatBit(seconds) + "s"; return duration; - }, + } } } diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 6ec86655..adfb27c4 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -570,6 +570,30 @@ export default { }); }, + /** + * 添加子任务 + * @param state + * @param dispatch + * @param data {task_id, name} + * @returns {Promise} + */ + taskAddSub({state, dispatch}, data) { + return new Promise(function (resolve, reject) { + dispatch("call", { + url: 'project/task/addsub', + data: data, + }).then(result => { + if (data.task_id == state.projectOpenTask.id) { + state.projectOpenTask.sub_task.push(result.data.task); + } + dispatch('taskOne', data.task_id); + resolve(result) + }).catch(result => { + reject(result) + }); + }); + }, + /** * 更新任务 * @param state diff --git a/resources/assets/sass/pages/components/task-detail.scss b/resources/assets/sass/pages/components/task-detail.scss index 5e843545..d48ba699 100644 --- a/resources/assets/sass/pages/components/task-detail.scss +++ b/resources/assets/sass/pages/components/task-detail.scss @@ -170,6 +170,9 @@ > li { align-items: flex-start; margin-bottom: 4px; + &:last-child { + margin-bottom: -6px; + } .subtask-icon { width: 16px; height: 26px; @@ -241,12 +244,19 @@ height: 26px; cursor: pointer; } + .ivu-icon-ios-loading { + animation: icon-loading-load 0.6s infinite linear; + } } } } } .add { margin-top: 12px; + margin-bottom: 10px; + } + .add-input { + margin-top: 6px; } .add-button { cursor: pointer; @@ -254,6 +264,7 @@ display: flex; align-items: center; margin-top: 6px; + height: 32px; > i { font-size: 14px; padding-right: 8px; @@ -284,7 +295,7 @@ flex: 1; display: flex; flex-direction: column; - margin-top: 32px; + margin-top: 22px; position: relative; .head { display: flex;