添加任务推送消息
This commit is contained in:
parent
c74fdb18e6
commit
3da0a41155
@ -628,11 +628,13 @@ class ProjectController extends AbstractController
|
|||||||
'project_id' => $project->id,
|
'project_id' => $project->id,
|
||||||
'column_id' => $column->id,
|
'column_id' => $column->id,
|
||||||
]));
|
]));
|
||||||
return Base::retSuccess('添加成功', [
|
$data = [
|
||||||
'new_column' => $newColumn,
|
'new_column' => $newColumn,
|
||||||
'in_top' => intval($data['top']),
|
'in_top' => intval($data['top']),
|
||||||
'task' => ProjectTask::with(['taskUser', 'taskTag'])->find($task->id),
|
'task' => ProjectTask::with(['taskUser', 'taskTag'])->find($task->id),
|
||||||
]);
|
];
|
||||||
|
$task->pushMsg('add', $data);
|
||||||
|
return Base::retSuccess('添加成功', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -656,11 +658,13 @@ class ProjectController extends AbstractController
|
|||||||
'project_id' => $task->project_id,
|
'project_id' => $task->project_id,
|
||||||
'column_id' => $task->column_id,
|
'column_id' => $task->column_id,
|
||||||
]);
|
]);
|
||||||
return Base::retSuccess('添加成功', [
|
$data = [
|
||||||
'new_column' => null,
|
'new_column' => null,
|
||||||
'in_top' => 0,
|
'in_top' => 0,
|
||||||
'task' => ProjectTask::with(['taskUser', 'taskTag'])->find($task->id),
|
'task' => ProjectTask::with(['taskUser', 'taskTag'])->find($task->id),
|
||||||
]);
|
];
|
||||||
|
$task->pushMsg('add', $data);
|
||||||
|
return Base::retSuccess('添加成功', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,8 +4,10 @@ namespace App\Models;
|
|||||||
|
|
||||||
use App\Exceptions\ApiException;
|
use App\Exceptions\ApiException;
|
||||||
use App\Module\Base;
|
use App\Module\Base;
|
||||||
|
use App\Tasks\PushTask;
|
||||||
use Arr;
|
use Arr;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Hhxsv5\LaravelS\Swoole\Task\Task;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -616,6 +618,28 @@ class ProjectTask extends AbstractModel
|
|||||||
return $log;
|
return $log;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送消息
|
||||||
|
* @param string $action
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
public function pushMsg($action, $data)
|
||||||
|
{
|
||||||
|
if (!$this->project) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$lists = [
|
||||||
|
'userid' => $this->project->relationUserids(),
|
||||||
|
'msg' => [
|
||||||
|
'type' => 'projectTask',
|
||||||
|
'action' => $action,
|
||||||
|
'data' => $data,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$task = new PushTask($lists, false);
|
||||||
|
Task::deliver($task);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据会员ID获取任务、项目信息(用于判断会员是否存在项目内)
|
* 根据会员ID获取任务、项目信息(用于判断会员是否存在项目内)
|
||||||
* @param int $task_id
|
* @param int $task_id
|
||||||
|
@ -18,14 +18,16 @@ use Hhxsv5\LaravelS\Swoole\Task\Task;
|
|||||||
class PushTask extends AbstractTask
|
class PushTask extends AbstractTask
|
||||||
{
|
{
|
||||||
protected $params;
|
protected $params;
|
||||||
|
protected $retryOffline = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PushTask constructor.
|
* PushTask constructor.
|
||||||
* @param array|string $params
|
* @param array|string $params
|
||||||
*/
|
*/
|
||||||
public function __construct($params = [])
|
public function __construct($params = [], $retryOffline = true)
|
||||||
{
|
{
|
||||||
$this->params = $params;
|
$this->params = $params;
|
||||||
|
$this->retryOffline = $retryOffline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function start()
|
public function start()
|
||||||
@ -43,7 +45,7 @@ class PushTask extends AbstractTask
|
|||||||
self::sendTmpMsgForUserid(intval(Base::leftDelete($this->params, "RETRY::")));
|
self::sendTmpMsgForUserid(intval(Base::leftDelete($this->params, "RETRY::")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is_array($this->params) && self::push($this->params);
|
is_array($this->params) && self::push($this->params, '', 1, $this->retryOffline);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -162,7 +164,7 @@ class PushTask extends AbstractTask
|
|||||||
'fd' => $fid,
|
'fd' => $fid,
|
||||||
'msg' => $msg,
|
'msg' => $msg,
|
||||||
]);
|
]);
|
||||||
$task = new PushTask($key);
|
$task = new PushTask($key, $retryOffline);
|
||||||
$task->delay($delay);
|
$task->delay($delay);
|
||||||
Task::deliver($task);
|
Task::deliver($task);
|
||||||
}
|
}
|
||||||
@ -174,13 +176,4 @@ class PushTask extends AbstractTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 推送消息(仅推送当前在线的)
|
|
||||||
* @param array $lists 消息列表
|
|
||||||
*/
|
|
||||||
public static function pushO(array $lists, $key = '', $delay = 1)
|
|
||||||
{
|
|
||||||
self::push($lists, $key, $delay, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
158
resources/assets/js/store/actions.js
vendored
158
resources/assets/js/store/actions.js
vendored
@ -419,6 +419,9 @@ export default {
|
|||||||
if (!data.start_at || !data.end_at) {
|
if (!data.start_at || !data.end_at) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!data.userid != state.userId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let task = {
|
let task = {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
calendarId: String(data.project_id),
|
calendarId: String(data.project_id),
|
||||||
@ -612,40 +615,22 @@ export default {
|
|||||||
* 添加任务
|
* 添加任务
|
||||||
* @param state
|
* @param state
|
||||||
* @param dispatch
|
* @param dispatch
|
||||||
|
* @param commit
|
||||||
* @param data
|
* @param data
|
||||||
* @returns {Promise<unknown>}
|
* @returns {Promise<unknown>}
|
||||||
*/
|
*/
|
||||||
taskAdd({state, dispatch}, data) {
|
taskAdd({state, dispatch, commit}, data) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
const post = state.method.cloneJSON(state.method.date2string(data));
|
const post = state.method.cloneJSON(state.method.date2string(data));
|
||||||
if (state.method.isArray(post.column_id)) {
|
if (state.method.isArray(post.column_id)) post.column_id = post.column_id.find((val) => val)
|
||||||
post.column_id = post.column_id.find((val) => val)
|
if (state.method.isArray(post.owner)) post.owner = post.owner.find((val) => val)
|
||||||
}
|
|
||||||
if (state.method.isArray(post.owner)) {
|
|
||||||
post.owner = post.owner.find((val) => val)
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
dispatch("call", {
|
dispatch("call", {
|
||||||
url: 'project/task/add',
|
url: 'project/task/add',
|
||||||
data: post,
|
data: post,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
const {task, in_top, new_column} = result.data;
|
commit("taskAddSuccess", result.data)
|
||||||
if (state.projectDetail.id == task.project_id) {
|
|
||||||
if (new_column) {
|
|
||||||
state.projectDetail.project_column.push(new_column);
|
|
||||||
}
|
|
||||||
const column = state.projectDetail.project_column.find(({id}) => id === task.column_id);
|
|
||||||
if (column) {
|
|
||||||
if (in_top) {
|
|
||||||
column.project_task.unshift(task);
|
|
||||||
} else {
|
|
||||||
column.project_task.push(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dispatch("saveTask", task);
|
|
||||||
dispatch("getProjectOne", task.project_id);
|
|
||||||
resolve(result)
|
resolve(result)
|
||||||
}).catch(result => {
|
}).catch(result => {
|
||||||
reject(result)
|
reject(result)
|
||||||
@ -655,38 +640,18 @@ export default {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加子任务
|
* 添加子任务
|
||||||
* @param state
|
|
||||||
* @param dispatch
|
* @param dispatch
|
||||||
|
* @param commit
|
||||||
* @param data {task_id, name}
|
* @param data {task_id, name}
|
||||||
* @returns {Promise<unknown>}
|
* @returns {Promise<unknown>}
|
||||||
*/
|
*/
|
||||||
taskAddSub({state, dispatch}, data) {
|
taskAddSub({dispatch, commit}, data) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
dispatch("call", {
|
dispatch("call", {
|
||||||
url: 'project/task/addsub',
|
url: 'project/task/addsub',
|
||||||
data: data,
|
data: data,
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
const {task} = result.data;
|
commit("taskAddSuccess", result.data)
|
||||||
if (state.projectDetail.id == task.project_id) {
|
|
||||||
const column = state.projectDetail.project_column.find(({id}) => id === task.column_id);
|
|
||||||
if (column) {
|
|
||||||
const project_task = column.project_task.find(({id}) => id === task.parent_id)
|
|
||||||
if (project_task && project_task.sub_task) {
|
|
||||||
let index = project_task.sub_task.findIndex(({id}) => id === task.id)
|
|
||||||
if (index === -1) {
|
|
||||||
project_task.sub_task.push(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (task.parent_id == state.projectOpenTask.id) {
|
|
||||||
let index = state.projectOpenTask.sub_task.findIndex(({id}) => id === task.id)
|
|
||||||
if (index === -1) {
|
|
||||||
state.projectOpenTask.sub_task.push(task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dispatch("saveTask", task);
|
|
||||||
dispatch("getTaskOne", task.parent_id);
|
|
||||||
resolve(result)
|
resolve(result)
|
||||||
}).catch(result => {
|
}).catch(result => {
|
||||||
reject(result)
|
reject(result)
|
||||||
@ -1045,8 +1010,9 @@ export default {
|
|||||||
* 初始化 websocket
|
* 初始化 websocket
|
||||||
* @param state
|
* @param state
|
||||||
* @param dispatch
|
* @param dispatch
|
||||||
|
* @param commit
|
||||||
*/
|
*/
|
||||||
websocketConnection({state, dispatch}) {
|
websocketConnection({state, dispatch, commit}) {
|
||||||
clearTimeout(state.wsTimeout);
|
clearTimeout(state.wsTimeout);
|
||||||
if (state.userId === 0) {
|
if (state.userId === 0) {
|
||||||
if (state.ws) {
|
if (state.ws) {
|
||||||
@ -1116,49 +1082,65 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (type === "dialog") {
|
switch (type) {
|
||||||
// 更新会话
|
/**
|
||||||
(function (msg) {
|
* 会话消息
|
||||||
const {mode, data} = msg;
|
*/
|
||||||
const {dialog_id} = data;
|
case "dialog": // 更新会话
|
||||||
// 更新消息列表
|
(function (msg) {
|
||||||
if (dialog_id == state.dialogId) {
|
const {mode, data} = msg;
|
||||||
let index = state.dialogMsgList.findIndex(({id}) => id == data.id);
|
const {dialog_id} = data;
|
||||||
if (index === -1) {
|
// 更新消息列表
|
||||||
state.dialogMsgList.push(data);
|
if (dialog_id == state.dialogId) {
|
||||||
} else {
|
let index = state.dialogMsgList.findIndex(({id}) => id == data.id);
|
||||||
state.dialogMsgList.splice(index, 1, data);
|
if (index === -1) {
|
||||||
}
|
state.dialogMsgList.push(data);
|
||||||
}
|
} else {
|
||||||
// 更新最后消息
|
state.dialogMsgList.splice(index, 1, data);
|
||||||
let dialog = state.dialogList.find(({id}) => id == dialog_id);
|
|
||||||
if (dialog) {
|
|
||||||
dialog.last_msg = data;
|
|
||||||
} else {
|
|
||||||
dispatch("getDialogOne", dialog_id);
|
|
||||||
}
|
|
||||||
if (mode === "add") {
|
|
||||||
// 更新对话列表
|
|
||||||
if (dialog) {
|
|
||||||
// 新增未读数
|
|
||||||
if (data.userid !== state.userId) dialog.unread++;
|
|
||||||
// 移动到首位
|
|
||||||
const index = state.dialogList.findIndex(({id}) => id == dialog_id);
|
|
||||||
if (index > -1) {
|
|
||||||
const tmp = state.dialogList[index];
|
|
||||||
state.dialogList.splice(index, 1);
|
|
||||||
state.dialogList.unshift(tmp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 新增任务消息数量
|
// 更新最后消息
|
||||||
state.projectDetail.project_column.some(({project_task}) => {
|
let dialog = state.dialogList.find(({id}) => id == dialog_id);
|
||||||
const task = project_task.find(({dialog_id}) => dialog_id === data.dialog_id);
|
if (dialog) {
|
||||||
if (task) task.msg_num++;
|
dialog.last_msg = data;
|
||||||
});
|
} else {
|
||||||
// 新增总未读数
|
dispatch("getDialogOne", dialog_id);
|
||||||
if (data.userid !== state.userId) state.dialogMsgUnread++;
|
}
|
||||||
}
|
if (mode === "add") {
|
||||||
})(msgDetail);
|
// 更新对话列表
|
||||||
|
if (dialog) {
|
||||||
|
// 新增未读数
|
||||||
|
if (data.userid !== state.userId) dialog.unread++;
|
||||||
|
// 移动到首位
|
||||||
|
const index = state.dialogList.findIndex(({id}) => id == dialog_id);
|
||||||
|
if (index > -1) {
|
||||||
|
const tmp = state.dialogList[index];
|
||||||
|
state.dialogList.splice(index, 1);
|
||||||
|
state.dialogList.unshift(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 新增任务消息数量
|
||||||
|
state.projectDetail.project_column.some(({project_task}) => {
|
||||||
|
const task = project_task.find(({dialog_id}) => dialog_id === data.dialog_id);
|
||||||
|
if (task) task.msg_num++;
|
||||||
|
});
|
||||||
|
// 新增总未读数
|
||||||
|
if (data.userid !== state.userId) state.dialogMsgUnread++;
|
||||||
|
}
|
||||||
|
})(msgDetail);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 任务消息
|
||||||
|
*/
|
||||||
|
case "projectTask":
|
||||||
|
(function (msg) {
|
||||||
|
const {action, data} = msg;
|
||||||
|
if (action == 'add') {
|
||||||
|
commit("taskAddSuccess", data)
|
||||||
|
}
|
||||||
|
})(msgDetail);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
48
resources/assets/js/store/mutations.js
vendored
48
resources/assets/js/store/mutations.js
vendored
@ -1,3 +1,49 @@
|
|||||||
export default {
|
export default {
|
||||||
|
/**
|
||||||
|
* 添加任务完成
|
||||||
|
* @param state
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
taskAddSuccess(state, data) {
|
||||||
|
const {task, in_top, new_column} = data;
|
||||||
|
if (task.parent_id == 0) {
|
||||||
|
// 添加任务
|
||||||
|
if (state.projectDetail.id == task.project_id) {
|
||||||
|
if (new_column) {
|
||||||
|
state.projectDetail.project_column.push(new_column);
|
||||||
|
}
|
||||||
|
const column = state.projectDetail.project_column.find(({id}) => id === task.column_id);
|
||||||
|
if (column) {
|
||||||
|
if (in_top) {
|
||||||
|
column.project_task.unshift(task);
|
||||||
|
} else {
|
||||||
|
column.project_task.push(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.dispatch("getProjectOne", task.project_id);
|
||||||
|
} else {
|
||||||
|
// 添加子任务
|
||||||
|
if (state.projectDetail.id == task.project_id) {
|
||||||
|
const column = state.projectDetail.project_column.find(({id}) => id === task.column_id);
|
||||||
|
if (column) {
|
||||||
|
const project_task = column.project_task.find(({id}) => id === task.parent_id)
|
||||||
|
if (project_task && project_task.sub_task) {
|
||||||
|
let index = project_task.sub_task.findIndex(({id}) => id === task.id)
|
||||||
|
if (index === -1) {
|
||||||
|
project_task.sub_task.push(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (task.parent_id == state.projectOpenTask.id) {
|
||||||
|
let index = state.projectOpenTask.sub_task.findIndex(({id}) => id === task.id)
|
||||||
|
if (index === -1) {
|
||||||
|
state.projectOpenTask.sub_task.push(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.dispatch("getTaskOne", task.parent_id);
|
||||||
|
}
|
||||||
|
this.dispatch("saveTask", task);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user