任务列表增删通知

This commit is contained in:
Pang 2021-06-18 00:29:44 +08:00
parent a97b7f158a
commit c3fe7c1f7e
6 changed files with 87 additions and 15 deletions

View File

@ -392,6 +392,7 @@ class ProjectController extends AbstractController
//
$data = $column->find($column->id);
$data->project_task = [];
$data->pushMsg("add", $data->toArray());
return Base::retSuccess('添加成功', $data);
}
@ -461,7 +462,9 @@ class ProjectController extends AbstractController
}
//
if ($column->deleteColumn()) {
return Base::retSuccess('删除成功');
$data = ['id' => $column->id];
$column->pushMsg("delete", $data);
return Base::retSuccess('删除成功', $data);
}
return Base::retError('删除失败');
}

View File

@ -3,6 +3,8 @@
namespace App\Models;
use App\Module\Base;
use App\Tasks\PushTask;
use Hhxsv5\LaravelS\Swoole\Task\Task;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
@ -17,6 +19,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property-read \App\Models\Project|null $project
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProjectTask[] $projectTask
* @property-read int|null $project_task_count
* @method static \Illuminate\Database\Eloquent\Builder|ProjectColumn newModelQuery()
@ -39,6 +42,14 @@ class ProjectColumn extends AbstractModel
{
use SoftDeletes;
/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function project(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(Project::class, 'id', 'project_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
@ -86,4 +97,26 @@ class ProjectColumn extends AbstractModel
$log->save();
return $log;
}
/**
* 推送消息
* @param string $action
* @param array $data
*/
public function pushMsg($action, $data)
{
if (!$this->project) {
return;
}
$lists = [
'userid' => $this->project->relationUserids(),
'msg' => [
'type' => 'projectColumn',
'action' => $action,
'data' => $data,
]
];
$task = new PushTask($lists, false);
Task::deliver($task);
}
}

View File

@ -76,9 +76,10 @@
<EDropdown
v-else
trigger="click"
size="small"
@command="dropColumn(column, $event)">
<Icon type="ios-more" />
<EDropdownMenu slot="dropdown" class="project-list-more-dropdown-menu column-more">
<EDropdownMenu slot="dropdown" class="project-list-more-dropdown-menu">
<EDropdownItem command="title">
<div class="item">
<Icon type="md-create" />{{$L('修改')}}
@ -701,7 +702,7 @@ export default {
}).then(({data, msg}) => {
$A.messageSuccess(msg);
this.addColumnName = '';
this.projectDetail.project_column.push(data)
this.$store.commit("columnAddSuccess", data);
}).catch(({msg}) => {
$A.modalError(msg);
});
@ -777,15 +778,11 @@ export default {
data: {
column_id: column.id,
},
}).then(({msg}) => {
}).then(({data, msg}) => {
$A.messageSuccess(msg);
this.$set(column, 'loading', false);
this.$Modal.remove();
let index = this.projectDetail.project_column.findIndex(({id}) => id === column.id);
if (index > -1) {
this.projectDetail.project_column.splice(index, 1);
}
this.$store.dispatch("getProjectBasic", column.project_id);
this.$store.commit("columnRemoveSuccess", data);
}).catch(({msg}) => {
$A.modalError(msg, 301);
this.$set(column, 'loading', false);

View File

@ -1064,7 +1064,7 @@ export default {
});
switch (type) {
/**
* 会话消息
* 聊天会话消息
*/
case "dialog": // 更新会话
(function (msg) {
@ -1110,6 +1110,23 @@ export default {
})(msgDetail);
break;
/**
* 任务列表消息
*/
case "projectColumn":
(function (msg) {
const {action, data} = msg;
switch (action) {
case 'add':
commit("columnAddSuccess", data)
break;
case 'delete':
commit("columnRemoveSuccess", data)
break;
}
})(msgDetail);
break;
/**
* 任务消息
*/

View File

@ -1,4 +1,31 @@
export default {
/**
* 添加列表成功
* @param state
* @param data
*/
columnAddSuccess(state, data) {
if (state.projectDetail.id == data.project_id) {
let index = state.projectDetail.project_column.findIndex(({id}) => id === data.id);
if (index === -1) {
state.projectDetail.project_column.push(data);
}
}
},
/**
* 删除列表成功
* @param state
* @param data
*/
columnRemoveSuccess(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);
},
/**
* 添加任务成功
* @param state

View File

@ -757,9 +757,4 @@
}
}
}
&.column-more {
> li {
min-width: 130px;
}
}
}