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

View File

@ -325,44 +325,65 @@ class Project extends AbstractModel
/** /**
* 推送消息 * 推送消息
* @param string $action * @param string $action
* @param array|self $data 发送内容,默认为[id=>项目ID] * @param array|self $data 推送内容
* @param array $userid 指定会员,默认为项目所有成员 * @param array $userid 指定会员,默认为项目所有成员
*/ */
public function pushMsg($action, $data = null, $userid = null) public function pushMsg($action, $data = null, $userid = null)
{ {
if ($data === null) { // 处理数据
$data = ['id' => $this->id]; if ($data instanceof self) {
} elseif ($data instanceof self) {
$data = $data->toArray(); $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) { if ($userid === null) {
$array[0] = $this->relationUserids(); $recipients[0] = $this->relationUserids();
} elseif (!is_array($userid)) { } elseif (!is_array($userid)) {
$array[0] = [$userid]; $recipients[0] = [$userid];
} }
//
// 移除不需要的字段
unset($data['top_at']);
// 处理所有者权限
if (isset($data['owner'])) { if (isset($data['owner'])) {
$owners = ProjectUser::whereProjectId($data['id'])->whereOwner(1)->pluck('userid')->toArray(); $owners = ProjectUser::whereProjectId($data['id'])
$array = [array_intersect($array[0], $owners), array_diff($array[0], $owners)]; ->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) { if ($index > 0) {
$data['owner'] = 0; $data['owner'] = 0;
} }
$params = [ $params = [
'ignoreFd' => Request::header('fd'), 'ignoreFd' => Request::header('fd'),
'userid' => array_values($item), 'userid' => array_values($userids),
'msg' => [ 'msg' => [
'type' => 'project', 'type' => 'project',
'action' => $action, 'action' => $action,
'data' => $data, '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) { windowActive(active) {
if (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 {
this.$store.dispatch("audioStop", true) 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) { workReportShow(show) {
if (show) { if (!show) return
this.$store.dispatch("getReportUnread", 0) this.$store.dispatch("getReportUnread", 0)
} },
windowActive(active) {
if (!active) return
this.$store.dispatch("getProjectByQueue", 600);
}, },
'cacheProjects.length': { 'cacheProjects.length': {

View File

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