mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 23:56:42 +08:00
Deduplicate offline connection prompts by status
This commit is contained in:
@@ -5,7 +5,7 @@ import { useToast } from 'vue-toastification'
|
|||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { connectionStatus, connectionReason } = useGlobalOfflineStatus()
|
const { connectionStatus, connectionReason } = useGlobalOfflineStatus()
|
||||||
const lastConnectionPromptKey = ref('')
|
const shownConnectionPromptKeys = new Set<string>()
|
||||||
|
|
||||||
const isChecking = computed(() => connectionStatus.value === 'checking')
|
const isChecking = computed(() => connectionStatus.value === 'checking')
|
||||||
const statusTitle = computed(() => (isChecking.value ? t('app.connectionChecking') : t('app.serviceUnavailable')))
|
const statusTitle = computed(() => (isChecking.value ? t('app.connectionChecking') : t('app.serviceUnavailable')))
|
||||||
@@ -36,17 +36,21 @@ function showConnectionPrompt() {
|
|||||||
toast.error(message, options)
|
toast.error(message, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 在连接状态变化时发出一次离线提示,并在恢复在线后允许下一轮提示重新出现。 */
|
/** 在同一轮连接异常内按状态去重提示,并在恢复在线后允许下一轮提示重新出现。 */
|
||||||
function handleConnectionStatusChange() {
|
function handleConnectionStatusChange() {
|
||||||
if (connectionStatus.value === 'online') {
|
if (connectionStatus.value === 'online') {
|
||||||
lastConnectionPromptKey.value = ''
|
shownConnectionPromptKeys.clear()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const promptKey = `${connectionStatus.value}:${connectionReason.value || 'unknown'}`
|
const promptKey =
|
||||||
if (promptKey === lastConnectionPromptKey.value) return
|
connectionStatus.value === 'checking'
|
||||||
|
? connectionStatus.value
|
||||||
|
: `${connectionStatus.value}:${connectionReason.value || 'unknown'}`
|
||||||
|
|
||||||
lastConnectionPromptKey.value = promptKey
|
if (shownConnectionPromptKeys.has(promptKey)) return
|
||||||
|
|
||||||
|
shownConnectionPromptKeys.add(promptKey)
|
||||||
showConnectionPrompt()
|
showConnectionPrompt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user