diff --git a/src/oj/composables/syncStatus.ts b/src/oj/composables/syncStatus.ts index 2dbf150..fcddcb2 100644 --- a/src/oj/composables/syncStatus.ts +++ b/src/oj/composables/syncStatus.ts @@ -6,8 +6,9 @@ import { ref, provide, inject } from "vue" */ export interface SyncStatusState { - otherUser?: { name: string; isSuperAdmin: boolean } hadConnection: boolean + otherUser?: { name: string; isSuperAdmin: boolean } + lastLeftUser?: { name: string; isSuperAdmin: boolean } // 保存离开之人的信息 } // 提供/注入的 key @@ -20,8 +21,13 @@ export const SYNC_STATUS_KEY = Symbol("syncStatus") export function createSyncStatus() { const otherUser = ref<{ name: string; isSuperAdmin: boolean }>() const hadConnection = ref(false) + const lastLeftUser = ref<{ name: string; isSuperAdmin: boolean }>() const setOtherUser = (user?: { name: string; isSuperAdmin: boolean }) => { + // 如果之前有其他用户,现在没有了,说明用户离开了 + if (otherUser.value && !user) { + lastLeftUser.value = otherUser.value + } otherUser.value = user if (user) { hadConnection.value = true @@ -31,11 +37,13 @@ export function createSyncStatus() { const reset = () => { otherUser.value = undefined hadConnection.value = false + lastLeftUser.value = undefined } return { otherUser, hadConnection, + lastLeftUser, setOtherUser, reset, } diff --git a/src/oj/problem/components/Form.vue b/src/oj/problem/components/Form.vue index f248fd5..4e7efd0 100644 --- a/src/oj/problem/components/Form.vue +++ b/src/oj/problem/components/Form.vue @@ -194,7 +194,7 @@ defineExpose({ " type="warning" > - {{ SYNC_MESSAGES.STUDENT_LEFT }} + {{ SYNC_MESSAGES.STUDENT_LEFT(syncStatus.lastLeftUser.value?.name) }} diff --git a/src/shared/composables/sync.ts b/src/shared/composables/sync.ts index ef81600..92144b2 100644 --- a/src/shared/composables/sync.ts +++ b/src/shared/composables/sync.ts @@ -42,7 +42,7 @@ export const SYNC_MESSAGES = { SYNC_ON: "断开同步", SYNC_OFF: "开启同步", SYNCING_WITH: (name: string) => `🔗 与 ${name} 同步中`, - STUDENT_LEFT: "💡 可以关闭同步", + STUDENT_LEFT: (name?: string) => name ? `💡 ${name} 已离开,可以关闭同步` : "💡 可以关闭同步", } as const // 类型定义