perf: 优化项目列表

This commit is contained in:
kuaifan 2024-11-19 19:36:30 +08:00
parent a2ee1135dd
commit 91533c5cac
5 changed files with 82 additions and 45 deletions

View File

@ -324,7 +324,7 @@ class ProjectController extends AbstractController
}
$project->save();
});
$project->pushMsg('update', $project);
$project->pushMsg('update');
//
return Base::retSuccess('修改成功', $project);
}
@ -2592,6 +2592,10 @@ class ProjectController extends AbstractController
}
$projectUser->top_at = $projectUser->top_at ? null : Carbon::now();
$projectUser->save();
if ($projectUser->project) {
$projectUser->project->updated_at = Carbon::now();
$projectUser->project->save();
}
return Base::retSuccess("success", [
'id' => $projectUser->project_id,
'top_at' => $projectUser->top_at?->toDateTimeString(),

View File

@ -325,44 +325,65 @@ class Project extends AbstractModel
/**
* 推送消息
* @param string $action
* @param array|self $data 发送内容,默认为[id=>项目ID]
* @param array|self $data 推送内容
* @param array $userid 指定会员,默认为项目所有成员
*/
public function pushMsg($action, $data = null, $userid = null)
{
if ($data === null) {
$data = ['id' => $this->id];
} elseif ($data instanceof self) {
// 处理数据
if ($data instanceof self) {
$data = $data->toArray();
}
//
$array = [$userid, []];
$data = is_array($data) ? $data : [];
$data['id'] = $this->id;
$data['name'] = $this->name;
$data['desc'] = $this->desc;
// 处理接收用户
$recipients = [$userid, []];
if ($userid === null) {
$array[0] = $this->relationUserids();
$recipients[0] = $this->relationUserids();
} elseif (!is_array($userid)) {
$array[0] = [$userid];
$recipients[0] = [$userid];
}
//
// 移除不需要的字段
unset($data['top_at']);
// 处理所有者权限
if (isset($data['owner'])) {
$owners = ProjectUser::whereProjectId($data['id'])->whereOwner(1)->pluck('userid')->toArray();
$array = [array_intersect($array[0], $owners), array_diff($array[0], $owners)];
$owners = ProjectUser::whereProjectId($data['id'])
->whereOwner(1)
->pluck('userid')
->toArray();
$recipients = [
array_intersect($recipients[0], $owners),
array_diff($recipients[0], $owners)
];
}
//
foreach ($array as $index => $item) {
// 发送推送
foreach ($recipients as $index => $userids) {
if (empty($userids)) {
continue;
}
if ($index > 0) {
$data['owner'] = 0;
}
$params = [
'ignoreFd' => Request::header('fd'),
'userid' => array_values($item),
'userid' => array_values($userids),
'msg' => [
'type' => 'project',
'action' => $action,
'data' => $data,
]
];
$task = new PushTask($params, false);
Task::deliver($task);
Task::deliver(new PushTask($params, false));
}
}

View File

@ -161,26 +161,23 @@ export default {
},
windowActive(active) {
if (active) {
this.autoTheme()
$A.updateTimezone()
this.__windowTimer && clearTimeout(this.__windowTimer)
this.__windowTimer = setTimeout(_ => {
this.$store.dispatch("call", {
url: "users/socket/status",
}).then(_ => {
this.$store.dispatch("websocketSend", {
type: 'handshake',
}).catch(_ => {
this.$store.dispatch("websocketConnection")
})
}).catch(_ => {
this.$store.dispatch("websocketConnection")
})
}, 600)
} else {
if (!active) {
this.$store.dispatch("audioStop", true)
return
}
this.autoTheme()
$A.updateTimezone()
this.__windowTimer && clearTimeout(this.__windowTimer)
this.__windowTimer = setTimeout(async () => {
try {
await this.$store.dispatch("call", {url: "users/socket/status"})
await this.$store.dispatch("websocketSend", {type: 'handshake'})
} catch {
await this.$store.dispatch("websocketConnection")
}
}, 600)
},
},

View File

@ -729,9 +729,13 @@ export default {
},
workReportShow(show) {
if (show) {
this.$store.dispatch("getReportUnread", 0)
}
if (!show) return
this.$store.dispatch("getReportUnread", 0)
},
windowActive(active) {
if (!active) return
this.$store.dispatch("getProjectByQueue", 600);
},
'cacheProjects.length': {

View File

@ -496,11 +496,11 @@ export default {
}
window.__getBasicDataKey = tmpKey
//
dispatch("getProjects").catch(() => {});
dispatch("getDialogAuto").catch(() => {});
dispatch("getDialogTodo", 0).catch(() => {});
dispatch("getReportUnread", 1000);
dispatch("getApproveUnread", 1000);
dispatch("getProjectByQueue");
dispatch("getTaskForDashboard");
dispatch("dialogMsgRead");
//
@ -1249,11 +1249,10 @@ export default {
* 获取项目
* @param state
* @param dispatch
* @param getters
* @param requestData
* @returns {Promise<unknown>}
*/
getProjects({state, dispatch, getters}, requestData) {
getProjects({state, dispatch}, requestData) {
return new Promise(function (resolve, reject) {
if (state.userId === 0) {
state.cacheProjects = [];
@ -1283,6 +1282,20 @@ export default {
});
},
/**
* 获取项目队列
* @param dispatch
* @param timeout
*/
getProjectByQueue({dispatch}, timeout = null) {
window.__getProjectByQueueTimer && clearTimeout(window.__getProjectByQueueTimer)
if (typeof timeout === "number") {
window.__getProjectByQueueTimer = setTimeout(_ => dispatch("getProjectByQueue", null), timeout)
return
}
dispatch("getProjects").catch(() => {});
},
/**
* 获取单个项目
* @param state
@ -1836,10 +1849,9 @@ export default {
* 获取Dashboard相关任务
* @param state
* @param dispatch
* @param getters
* @param timeout
*/
getTaskForDashboard({state, dispatch, getters}, timeout) {
getTaskForDashboard({state, dispatch}, timeout) {
window.__getTaskForDashboard && clearTimeout(window.__getTaskForDashboard)
if (typeof timeout === "number") {
if (timeout > -1) {
@ -2609,11 +2621,10 @@ export default {
* 获取会话列表
* @param state
* @param dispatch
* @param getters
* @param requestData
* @returns {Promise<unknown>}
*/
getDialogs({state, dispatch, getters}, requestData) {
getDialogs({state, dispatch}, requestData) {
return new Promise(function (resolve, reject) {
if (state.userId === 0) {
state.cacheDialogs = [];