From a10fd29440eab3b431c7da022c7b7d8c03d29e56 Mon Sep 17 00:00:00 2001 From: Apcallover <1503963513@qq.com> Date: Wed, 17 Dec 2025 19:48:45 +0800 Subject: [PATCH] =?UTF-8?q?flat:=20bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 35 +- config.js | 4 +- pages/login/login.vue | 6 +- pages/nearby/components/one.vue | 7 +- stores/useScreenStore.js | 610 +++++++++++++++++--------------- vite-inject-popup.js | 2 +- 6 files changed, 359 insertions(+), 305 deletions(-) diff --git a/App.vue b/App.vue index 5b064aa..7601e92 100644 --- a/App.vue +++ b/App.vue @@ -25,7 +25,7 @@ onLaunch((options) => { useUserStore().changMachineEnv(false); return; } - if (!isY9MachineType()) { + if (isY9MachineType()) { console.warn('求职一体机环境'); baseDB.resetAndReinit(); // 清空indexdb useUserStore().logOutApp(); @@ -63,15 +63,16 @@ onHide(() => { console.log('App Hide'); }); -async function handleInactivity() { +function handleInactivity() { console.log('【全局】60秒无操作,执行安全逻辑'); if (inactivityModalTimer) { clearTimeout(inactivityModalTimer); inactivityModalTimer = null; } + if (useUserStore().hasLogin) { - // 示例:弹窗确认 - await $confirm({ + // 1. 正常弹出确认框 + $confirm({ title: '会话即将过期', content: '长时间无操作,是否继续使用?', success: (res) => { @@ -80,25 +81,33 @@ async function handleInactivity() { inactivityModalTimer = null; } if (res.confirm) { - inactivityManager?.resume(); // 恢复监听 + inactivityManager?.resume(); } else { performLogout(); } }, fail: () => { - if (inactivityModalTimer) clearTimeout(inactivityModalTimer); + if (inactivityModalTimer) { + clearTimeout(inactivityModalTimer); + inactivityModalTimer = null; + } performLogout(); }, }); + + // 2. 启动 10 秒倒计时 + inactivityModalTimer = setTimeout(() => { + inactivityModalTimer = null; + console.log('【自动登出】10秒无响应,强制清理状态'); + + // 【关键改进】:通知全局组件强制关闭弹窗,防止用户点击陈旧弹窗 + uni.$emit('hide-global-popup'); + + performLogout(); + }, 10000); } else { - inactivityManager?.resume(); // 恢复监听 + inactivityManager?.resume(); } - // 启动 10 秒自动登出定时器 - inactivityModalTimer = setTimeout(() => { - inactivityModalTimer = null; - console.log('【自动登出】用户10秒未操作'); - performLogout(); - }, 10000); // 10秒 } function performLogout() { diff --git a/config.js b/config.js index b005721..502066f 100644 --- a/config.js +++ b/config.js @@ -1,6 +1,6 @@ export default { - // baseUrl: 'https://fw.rc.qingdao.gov.cn/rgpp-api/api', // 内网 - baseUrl: 'https://qd.zhaopinzao8dian.com/api', // 测试 + baseUrl: 'https://fw.rc.qingdao.gov.cn/rgpp-api/api', // 内网 + // baseUrl: 'https://qd.zhaopinzao8dian.com/api', // 测试 // baseUrl: 'http://192.168.3.29:8081', // baseUrl: 'http://10.213.6.207:19010/api', // 语音转文字 diff --git a/pages/login/login.vue b/pages/login/login.vue index c3d88d9..7eb0670 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -182,7 +182,7 @@ - + @@ -276,9 +276,7 @@ const resetCountdown = () => { const returnToHome = () => { stopCountdown(); stopScanAnimation(); - uni.switchTab({ - url: '/pages/index/index', - }); + useUserStore().logOutApp(); }; // 取消登录 diff --git a/pages/nearby/components/one.vue b/pages/nearby/components/one.vue index 942282c..7bfa61f 100644 --- a/pages/nearby/components/one.vue +++ b/pages/nearby/components/one.vue @@ -2,7 +2,7 @@ - + {{ item }}km @@ -147,6 +147,7 @@ function changeRangeShow() { } function changeRadius(item) { + console.log(item); pageState.search.radius = item; rangeShow.value = false; progressChange(item); @@ -244,7 +245,7 @@ function getInit() { } function progressChange(value) { - const range = 1 + value; + const range = value < 1 ? 1 : value; pageState.search.radius = range; mapCircles.value = [ { diff --git a/stores/useScreenStore.js b/stores/useScreenStore.js index b14e946..4dd4e6c 100644 --- a/stores/useScreenStore.js +++ b/stores/useScreenStore.js @@ -1,283 +1,329 @@ -import { defineStore } from 'pinia'; -import { ref, computed } from 'vue'; - -// 屏幕检测管理器类 -class ScreenDetectionManager { - constructor() { - this.WIDE_SCREEN_CSS_ID = 'wide-screen-css'; - this.WIDE_SCREEN_CSS_PATH = '../common/wide-screen.css'; - this.resizeTimer = null; - this.resizeListeners = []; - this.cssLink = null; - } - - // 获取屏幕宽度 - getScreenWidth() { - if (typeof window === 'undefined') return 0; - - // 优先使用 uni.getSystemInfo - if (typeof uni !== 'undefined' && uni.getSystemInfo) { - return new Promise((resolve) => { - uni.getSystemInfo({ - success: (res) => { - const width = res.screenWidth || res.windowWidth || window.innerWidth; - resolve(width); - }, - fail: () => { - resolve(this.getWindowWidth()); - } - }); - }); - } - - return Promise.resolve(this.getWindowWidth()); - } - - // 备用方案:使用 window 对象 - getWindowWidth() { - if (typeof window === 'undefined') return 0; - return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; - } - - // 检测折叠屏 - checkVisualViewport() { - if (window.visualViewport?.segments?.length > 1) { - return { - foldable: true, - count: window.visualViewport.segments.length - 1 - } - } - else { - return { - foldable: false, - count: 1 - } - } - } - - // 动态加载 CSS - loadWideScreenCSS() { - if (typeof window === 'undefined' || this.cssLink) return null; - - try { - this.cssLink = document.createElement('link'); - this.cssLink.id = this.WIDE_SCREEN_CSS_ID; - this.cssLink.rel = 'stylesheet'; - this.cssLink.href = this.WIDE_SCREEN_CSS_PATH; - - // 添加加载成功/失败监听 - this.cssLink.onload = () => { - console.log('🎨 宽屏 CSS 文件加载成功'); - }; - - this.cssLink.onerror = () => { - console.error('❌ 宽屏 CSS 文件加载失败'); - this.cssLink = null; - }; - - document.head.appendChild(this.cssLink); - return this.cssLink; - } catch (error) { - console.error('加载 CSS 失败:', error); - this.cssLink = null; - return null; - } - } - - // 移除 CSS - removeWideScreenCSS() { - if (this.cssLink && this.cssLink.parentNode) { - try { - this.cssLink.parentNode.removeChild(this.cssLink); - this.cssLink = null; - console.log('🗑️ 宽屏 CSS 文件已移除'); - return true; - } catch (error) { - console.error('移除 CSS 失败:', error); - return false; - } - } - return false; - } - - // 更新 CSS 状态 - updateWideScreenCSS(isWideScreen) { - if (isWideScreen) { - return this.loadWideScreenCSS(); - } else { - return this.removeWideScreenCSS(); - } - } - //显示/隐藏默认tabbar - updateTabbar(isWideScreen){ - if(isWideScreen) uni.hideTabBar() - else uni.showTabBar() - } - - // 添加 resize 监听器 - addResizeListener(callback, delay = 250) { - if (typeof window === 'undefined') return () => {}; - - const handler = () => { - clearTimeout(this.resizeTimer); - this.resizeTimer = setTimeout(() => { - callback(); - }, delay); - }; - - window.addEventListener('resize', handler); - this.resizeListeners.push({ callback, handler }); - - // 返回清理函数 - return () => this.removeResizeListener(callback); - } - - // 移除 resize 监听器 - removeResizeListener(callback) { - const index = this.resizeListeners.findIndex(item => item.callback === callback); - if (index > -1) { - const { handler } = this.resizeListeners[index]; - window.removeEventListener('resize', handler); - this.resizeListeners.splice(index, 1); - } - } - - -} - -// 创建屏幕状态 store -const useScreenStore = defineStore('screen', () => { - // 状态 - const screenWidth = ref(0); - const isInitialized = ref(false); - const isLoading = ref(false); - const foldFeature = ref(false); - const foldCount = ref(0); - - - const isWideScreen = computed(() => { - return screenWidth.value >= 900; - }); - - - - - - // 管理器实例 - const manager = new ScreenDetectionManager(); - - // 初始化屏幕检测 - const initScreenDetection = async () => { - if (isLoading.value || isInitialized.value) return; - isLoading.value = true; - try { - // 检测屏幕状态 - const width = await manager.getScreenWidth(); - const { foldable, count } = manager.checkVisualViewport(); - - foldFeature.value = foldable; - foldCount.value = count; - screenWidth.value = width; - isInitialized.value = true; - - console.log(`📱 屏幕检测完成: ${width}px, 宽屏: ${isWideScreen.value}`); - console.log(`是否为折叠屏: ${foldFeature.value},折叠屏数量:${foldCount.value}`); - - // 根据状态加载或移除 CSS - manager.updateWideScreenCSS(isWideScreen.value); - manager.updateTabbar(isWideScreen.value); - - // 设置 resize 监听 - setupResizeListener(); - return { - screenWidth: width, - isWideScreen: isWideScreen.value, - foldable, - count - }; - } catch (error) { - console.error('初始化屏幕检测失败:', error); - return null; - } finally { - isLoading.value = false; - } - }; - - // 手动更新屏幕状态 - const updateScreenStatus = async () => { - try { - const width = await manager.getScreenWidth(); - const { foldable, count } = manager.checkVisualViewport(); - - // 保存旧状态 - const oldWidth = screenWidth.value; - const oldIsWideScreen = isWideScreen.value; - const oldFoldable = foldFeature.value; - const oldFoldCount = foldCount.value; - - // 更新状态 - screenWidth.value = width; - foldFeature.value = foldable; - foldCount.value = count; - - // 检查宽屏状态是否发生变化 - if (oldIsWideScreen !== isWideScreen.value) { - console.log(`🔄 屏幕状态变化: ${oldIsWideScreen ? '宽屏' : '非宽屏'} -> ${isWideScreen.value ? '宽屏' : '非宽屏'}`); - console.log(`屏幕宽度变化: ${oldWidth}px -> ${width}px`); - manager.updateWideScreenCSS(isWideScreen.value); - manager.updateTabbar(isWideScreen.value); - } - - // 检查折叠屏状态是否发生变化 - if (oldFoldable !== foldable || oldFoldCount !== count) { - console.log(`折叠屏状态变化: ${oldFoldable ? '是' : '否'}->${foldable ? '是' : '否'}, 折叠数: ${oldFoldCount}->${count}`); - } - - return { - screenWidth: width, - isWideScreen: isWideScreen.value, - foldable, - count - }; - } catch (error) { - console.error('更新屏幕状态失败:', error); - return null; - } - }; - - // 设置 resize 监听 - let cleanupResizeListener = () => {}; - const setupResizeListener = () => { - if (typeof window === 'undefined') return; - - cleanupResizeListener = manager.addResizeListener(async () => { - await updateScreenStatus(); - }, 300); - }; - - // 手动触发屏幕检测 - const detectScreen = () => { - return updateScreenStatus(); - }; - - - - return { - // 状态 - foldFeature, - foldCount, - screenWidth, - isInitialized, - isLoading, - - // 响应式计算属性 - isWideScreen, - - // 方法 - initScreenDetection, - updateScreenStatus, - detectScreen, - }; -}); - +import { + defineStore +} from 'pinia'; +import { + ref, + computed +} from 'vue'; +import wideScreenStyles from '../common/wide-screen.css?inline'; + +// 屏幕检测管理器类 +class ScreenDetectionManager { + constructor() { + this.WIDE_SCREEN_CSS_ID = 'wide-screen-css'; + this.WIDE_SCREEN_CSS_PATH = '../common/wide-screen.css'; + this.resizeTimer = null; + this.resizeListeners = []; + this.cssLink = null; + this.STYLE_ID = 'wide-screen-style-tag'; + this.styleTag = null; + } + + // 获取屏幕宽度 + getScreenWidth() { + if (typeof window === 'undefined') return 0; + + // 优先使用 uni.getSystemInfo + if (typeof uni !== 'undefined' && uni.getSystemInfo) { + return new Promise((resolve) => { + uni.getSystemInfo({ + success: (res) => { + const width = res.screenWidth || res.windowWidth || window.innerWidth; + resolve(width); + }, + fail: () => { + resolve(this.getWindowWidth()); + } + }); + }); + } + + return Promise.resolve(this.getWindowWidth()); + } + + // 备用方案:使用 window 对象 + getWindowWidth() { + if (typeof window === 'undefined') return 0; + return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; + } + + // 检测折叠屏 + checkVisualViewport() { + if (window.visualViewport?.segments?.length > 1) { + return { + foldable: true, + count: window.visualViewport.segments.length - 1 + } + } else { + return { + foldable: false, + count: 1 + } + } + } + + // 动态加载 CSS + loadWideScreenCSS() { + if (typeof window === 'undefined' || this.cssLink) return null; + + try { + this.cssLink = document.createElement('link'); + this.cssLink.id = this.WIDE_SCREEN_CSS_ID; + this.cssLink.rel = 'stylesheet'; + this.cssLink.href = this.WIDE_SCREEN_CSS_PATH; + + // 添加加载成功/失败监听 + this.cssLink.onload = () => { + console.log('🎨 宽屏 CSS 文件加载成功'); + }; + + this.cssLink.onerror = () => { + console.error('❌ 宽屏 CSS 文件加载失败'); + this.cssLink = null; + }; + + document.head.appendChild(this.cssLink); + return this.cssLink; + } catch (error) { + console.error('加载 CSS 失败:', error); + this.cssLink = null; + return null; + } + } + + // 移除 CSS + removeWideScreenCSS() { + if (this.cssLink && this.cssLink.parentNode) { + try { + this.cssLink.parentNode.removeChild(this.cssLink); + this.cssLink = null; + console.log('🗑️ 宽屏 CSS 文件已移除'); + return true; + } catch (error) { + console.error('移除 CSS 失败:', error); + return false; + } + } + return false; + } + + // 更新 CSS 状态 + // updateWideScreenCSS(isWideScreen) { + // if (isWideScreen) { + // return this.loadWideScreenCSS(); + // } else { + // return this.removeWideScreenCSS(); + // } + // } + + updateWideScreenCSS(isWideScreen) { + if (typeof document === 'undefined') return; + + if (isWideScreen) { + // 如果已经是宽屏且标签已存在,则不重复创建 + if (document.getElementById(this.STYLE_ID)) return; + + this.styleTag = document.createElement('style'); + this.styleTag.id = this.STYLE_ID; + this.styleTag.innerHTML = wideScreenStyles; // 将 CSS 文本注入 + document.head.appendChild(this.styleTag); + console.log('宽屏样式已通过内联方式注入'); + } else { + // 非宽屏时移除标签 + const existingTag = document.getElementById(this.STYLE_ID); + if (existingTag) { + existingTag.remove(); + this.styleTag = null; + console.log('宽屏样式已移除'); + } + } + } + + //显示/隐藏默认tabbar + updateTabbar(isWideScreen) { + if (isWideScreen) uni.hideTabBar() + else uni.showTabBar() + } + + // 添加 resize 监听器 + addResizeListener(callback, delay = 250) { + if (typeof window === 'undefined') return () => {}; + + const handler = () => { + clearTimeout(this.resizeTimer); + this.resizeTimer = setTimeout(() => { + callback(); + }, delay); + }; + + window.addEventListener('resize', handler); + this.resizeListeners.push({ + callback, + handler + }); + + // 返回清理函数 + return () => this.removeResizeListener(callback); + } + + // 移除 resize 监听器 + removeResizeListener(callback) { + const index = this.resizeListeners.findIndex(item => item.callback === callback); + if (index > -1) { + const { + handler + } = this.resizeListeners[index]; + window.removeEventListener('resize', handler); + this.resizeListeners.splice(index, 1); + } + } + + +} + +// 创建屏幕状态 store +const useScreenStore = defineStore('screen', () => { + // 状态 + const screenWidth = ref(0); + const isInitialized = ref(false); + const isLoading = ref(false); + const foldFeature = ref(false); + const foldCount = ref(0); + + + const isWideScreen = computed(() => { + return screenWidth.value >= 900; + }); + + + + + + // 管理器实例 + const manager = new ScreenDetectionManager(); + + // 初始化屏幕检测 + const initScreenDetection = async () => { + if (isLoading.value || isInitialized.value) return; + isLoading.value = true; + try { + // 检测屏幕状态 + const width = await manager.getScreenWidth(); + const { + foldable, + count + } = manager.checkVisualViewport(); + + foldFeature.value = foldable; + foldCount.value = count; + screenWidth.value = width; + isInitialized.value = true; + + console.log(`📱 屏幕检测完成: ${width}px, 宽屏: ${isWideScreen.value}`); + console.log(`是否为折叠屏: ${foldFeature.value},折叠屏数量:${foldCount.value}`); + + // 根据状态加载或移除 CSS + manager.updateWideScreenCSS(isWideScreen.value); + manager.updateTabbar(isWideScreen.value); + + // 设置 resize 监听 + setupResizeListener(); + return { + screenWidth: width, + isWideScreen: isWideScreen.value, + foldable, + count + }; + } catch (error) { + console.error('初始化屏幕检测失败:', error); + return null; + } finally { + isLoading.value = false; + } + }; + + // 手动更新屏幕状态 + const updateScreenStatus = async () => { + try { + const width = await manager.getScreenWidth(); + const { + foldable, + count + } = manager.checkVisualViewport(); + + // 保存旧状态 + const oldWidth = screenWidth.value; + const oldIsWideScreen = isWideScreen.value; + const oldFoldable = foldFeature.value; + const oldFoldCount = foldCount.value; + + // 更新状态 + screenWidth.value = width; + foldFeature.value = foldable; + foldCount.value = count; + + // 检查宽屏状态是否发生变化 + if (oldIsWideScreen !== isWideScreen.value) { + console.log( + `🔄 屏幕状态变化: ${oldIsWideScreen ? '宽屏' : '非宽屏'} -> ${isWideScreen.value ? '宽屏' : '非宽屏'}` + ); + console.log(`屏幕宽度变化: ${oldWidth}px -> ${width}px`); + manager.updateWideScreenCSS(isWideScreen.value); + manager.updateTabbar(isWideScreen.value); + } + + // 检查折叠屏状态是否发生变化 + if (oldFoldable !== foldable || oldFoldCount !== count) { + console.log( + `折叠屏状态变化: ${oldFoldable ? '是' : '否'}->${foldable ? '是' : '否'}, 折叠数: ${oldFoldCount}->${count}` + ); + } + + return { + screenWidth: width, + isWideScreen: isWideScreen.value, + foldable, + count + }; + } catch (error) { + console.error('更新屏幕状态失败:', error); + return null; + } + }; + + // 设置 resize 监听 + let cleanupResizeListener = () => {}; + const setupResizeListener = () => { + if (typeof window === 'undefined') return; + + cleanupResizeListener = manager.addResizeListener(async () => { + await updateScreenStatus(); + }, 300); + }; + + // 手动触发屏幕检测 + const detectScreen = () => { + return updateScreenStatus(); + }; + + + + return { + // 状态 + foldFeature, + foldCount, + screenWidth, + isInitialized, + isLoading, + + // 响应式计算属性 + isWideScreen, + + // 方法 + initScreenDetection, + updateScreenStatus, + detectScreen, + }; +}); + export default useScreenStore; \ No newline at end of file diff --git a/vite-inject-popup.js b/vite-inject-popup.js index 5eacd4a..6300e7d 100644 --- a/vite-inject-popup.js +++ b/vite-inject-popup.js @@ -53,7 +53,7 @@ export default function viteInjectPopup() { '\n \n' + code.slice(lastTemplateEndIndex); - console.log(`🎯 [精准注入]: ${relativePath}`); + console.log(`[精准注入]: ${relativePath}`); return { code: newCode, map: null