fix: 全局只显示一个useTips弹框,不会有多个叠在一起

This commit is contained in:
shawko 2026-05-12 14:19:55 +08:00
parent d1f364e230
commit d066302c31
2 changed files with 15 additions and 8 deletions

View File

@ -10,6 +10,7 @@ let monitorTimer: ReturnType<typeof setInterval> | null = null
let monitorSessionId = ''
let isUploadingMonitorSnapshot = false
let monitorState: 0 | 1 = 0
let closeMonitorTip: (() => void) | null = null
const MONITOR_SNAPSHOT_INTERVAL = 10000
const MONITOR_MSG_TYPE = 'monitorStart'
@ -23,6 +24,14 @@ const monitorLog = (...args: unknown[]) => console.log(MONITOR_LOG_PREFIX, ...ar
const monitorWarn = (...args: unknown[]) => console.warn(MONITOR_LOG_PREFIX, ...args)
const monitorError = (...args: unknown[]) => console.error(MONITOR_LOG_PREFIX, ...args)
const showMonitorTip = (tips: string) => {
closeMonitorTip?.()
closeMonitorTip = useTips({
tips,
showCancel: false,
})
}
const getServerOrigin = () => {
try {
return new URL(import.meta.env.VITE_SERVER_URL).origin
@ -372,10 +381,7 @@ export const stopClassMonitor = (showTip = false) => {
monitorTimer = null
}
if (showTip && isMonitoring) {
useTips({
tips: '已结束课堂监控',
showCancel: false,
})
showMonitorTip('已结束课堂监控')
}
monitorSessionId = ''
monitorState = 0
@ -396,10 +402,7 @@ const startClassMonitor = (msg: anyObj) => {
stopClassMonitor()
monitorSessionId = sessionId
monitorState = 1
useTips({
tips: '已进入课堂监控状态',
showCancel: false,
})
showMonitorTip('已进入课堂监控状态')
reportMonitorSnapshot(sessionId)
monitorTimer = setInterval(() => reportMonitorSnapshot(sessionId), MONITOR_SNAPSHOT_INTERVAL)
}

View File

@ -15,6 +15,7 @@ interface Tips_Config {
export const useTips = (config: Tips_Config) => {
const container = document.createElement('div')
let closed = false
const dia = createVNode(XDia, {
modelValue: true,
title: config.title || '提示',
@ -31,6 +32,8 @@ export const useTips = (config: Tips_Config) => {
})
const close = () => {
if (closed) return
closed = true
dia.component!.props.modelValue = false
setTimeout(() => {
render(null, container)
@ -39,4 +42,5 @@ export const useTips = (config: Tips_Config) => {
render(dia, container)
document.querySelector('body')?.appendChild(container.firstElementChild!)
return close
}