feat(uiMode): 添加UI模式手动切换功能

This commit is contained in:
PKC278
2025-12-30 01:42:43 +08:00
parent 6b8ed8d527
commit b98512789f
6 changed files with 102 additions and 8 deletions

View File

@@ -12,6 +12,16 @@ const globalPwaStatus = ref<{
const globalLoading = ref(false)
let initPromise: Promise<void> | null = null
// UI模式设置
export type UIMode = 'auto' | 'desktop' | 'app'
const uiMode = ref<UIMode>((localStorage.getItem('ui-mode') as UIMode) || 'auto')
// 设置UI模式
function setUIMode(mode: UIMode) {
uiMode.value = mode
localStorage.setItem('ui-mode', mode)
}
// 全局初始化函数
async function initializePWAGlobally() {
if (initPromise) return initPromise
@@ -50,6 +60,8 @@ export function usePWA() {
})
const appMode = computed(() => {
if (uiMode.value === 'app') return true
if (uiMode.value === 'desktop') return false
return pwaMode.value && display.mdAndDown.value
})
@@ -70,6 +82,8 @@ export function usePWA() {
pwaMode,
appMode,
pwaStatus,
uiMode,
setUIMode,
loading: globalLoading,
initializePWA: initializePWAGlobally,
}

View File

@@ -236,16 +236,15 @@ export function usePullDownGesture(options: PullDownOptions = {}) {
}
}
// PWA状态确定后一次性决定是否添加事件监听器
// 监听 appMode 变化动态添加/移除事件监听器
onMounted(() => {
// 等待PWA检测完成后添加事件监听器
const stopWatcher = watch(
watch(
appMode,
newValue => {
if (newValue) {
addEventListeners()
// PWA状态确定后停止监听
stopWatcher()
} else {
removeEventListeners()
}
},
{ immediate: true },