@@ -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,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
// 类型定义
|
// 类型定义
|
||||||
|
|||||||
Reference in New Issue
Block a user