update
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
2025-10-08 22:28:15 +08:00
parent 010beaaafb
commit bf745be372
3 changed files with 11 additions and 3 deletions

View File

@@ -6,8 +6,9 @@ import { ref, provide, inject } from "vue"
*/ */
export interface SyncStatusState { export interface SyncStatusState {
otherUser?: { name: string; isSuperAdmin: boolean }
hadConnection: boolean hadConnection: boolean
otherUser?: { name: string; isSuperAdmin: boolean }
lastLeftUser?: { name: string; isSuperAdmin: boolean } // 保存离开之人的信息
} }
// 提供/注入的 key // 提供/注入的 key
@@ -20,8 +21,13 @@ export const SYNC_STATUS_KEY = Symbol("syncStatus")
export function createSyncStatus() { export function createSyncStatus() {
const otherUser = ref<{ name: string; isSuperAdmin: boolean }>() const otherUser = ref<{ name: string; isSuperAdmin: boolean }>()
const hadConnection = ref(false) const hadConnection = ref(false)
const lastLeftUser = ref<{ name: string; isSuperAdmin: boolean }>()
const setOtherUser = (user?: { name: string; isSuperAdmin: boolean }) => { const setOtherUser = (user?: { name: string; isSuperAdmin: boolean }) => {
// 如果之前有其他用户,现在没有了,说明用户离开了
if (otherUser.value && !user) {
lastLeftUser.value = otherUser.value
}
otherUser.value = user otherUser.value = user
if (user) { if (user) {
hadConnection.value = true hadConnection.value = true
@@ -31,11 +37,13 @@ export function createSyncStatus() {
const reset = () => { const reset = () => {
otherUser.value = undefined otherUser.value = undefined
hadConnection.value = false hadConnection.value = false
lastLeftUser.value = undefined
} }
return { return {
otherUser, otherUser,
hadConnection, hadConnection,
lastLeftUser,
setOtherUser, setOtherUser,
reset, reset,
} }

View File

@@ -194,7 +194,7 @@ defineExpose({
" "
type="warning" type="warning"
> >
{{ SYNC_MESSAGES.STUDENT_LEFT }} {{ SYNC_MESSAGES.STUDENT_LEFT(syncStatus.lastLeftUser.value?.name) }}
</n-tag> </n-tag>
</template> </template>
</template> </template>

View File

@@ -42,7 +42,7 @@ export const SYNC_MESSAGES = {
SYNC_ON: "断开同步", SYNC_ON: "断开同步",
SYNC_OFF: "开启同步", SYNC_OFF: "开启同步",
SYNCING_WITH: (name: string) => `🔗 与 ${name} 同步中`, SYNCING_WITH: (name: string) => `🔗 与 ${name} 同步中`,
STUDENT_LEFT: "💡 可以关闭同步", STUDENT_LEFT: (name?: string) => name ? `💡 ${name} 已离开,可以关闭同步` : "💡 可以关闭同步",
} as const } as const
// 类型定义 // 类型定义