From 293b9e6ebad5d6500e20e742b3b6c9bdd73f0242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Thu, 11 Dec 2025 15:56:22 +0800 Subject: [PATCH] 1 --- src/components/HomeNavbar/index.tsx | 50 ++++++++++++++++++- .../LocationConfirmDialog/index.scss | 6 +++ .../LocationConfirmDialog/index.tsx | 16 +++++- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/components/HomeNavbar/index.tsx b/src/components/HomeNavbar/index.tsx index 3929053..bde384a 100644 --- a/src/components/HomeNavbar/index.tsx +++ b/src/components/HomeNavbar/index.tsx @@ -13,6 +13,10 @@ import LocationConfirmDialog from "@/components/LocationConfirmDialog"; // 城市缓存 key const CITY_CACHE_KEY = "USER_SELECTED_CITY"; +// 定位弹窗关闭时间缓存 key(用户选择"继续浏览"时记录) +const LOCATION_DIALOG_DISMISS_TIME_KEY = "LOCATION_DIALOG_DISMISS_TIME"; +// 2小时的毫秒数 +const TWO_HOURS_MS = 2 * 60 * 60 * 1000; interface IProps { config?: { @@ -130,8 +134,41 @@ const HomeNavbar = (props: IProps) => { } }, [detectedLocation]); + // 检查是否在2小时内已选择"继续浏览" + const should_show_location_dialog = (): boolean => { + try { + const dismiss_time = (Taro as any).getStorageSync(LOCATION_DIALOG_DISMISS_TIME_KEY); + if (!dismiss_time) { + return true; // 没有记录,可以显示 + } + + const current_time = Date.now(); + const time_diff = current_time - dismiss_time; + + // 如果距离上次选择"继续浏览"已超过2小时,可以再次显示 + if (time_diff >= TWO_HOURS_MS) { + // 清除过期记录 + (Taro as any).removeStorageSync(LOCATION_DIALOG_DISMISS_TIME_KEY); + return true; + } + + // 在2小时内,不显示弹窗 + console.log(`距离上次选择"继续浏览"还不到2小时,剩余时间: ${Math.ceil((TWO_HOURS_MS - time_diff) / 1000 / 60)}分钟`); + return false; + } catch (error) { + console.error('检查定位弹窗显示条件失败:', error); + return true; // 出错时默认显示 + } + }; + // 显示定位确认弹窗 const showLocationConfirmDialog = (detectedLocation: string, cachedCity: [string, string]) => { + // 检查是否在2小时内已选择"继续浏览" + if (!should_show_location_dialog()) { + console.log('[LocationDialog] 用户在2小时内已选择"继续浏览",不显示弹窗'); + return; + } + console.log('[LocationDialog] 准备显示定位确认弹窗,隐藏 GuideBar'); setLocationDialogData({ detectedProvince: detectedLocation, cachedCity }); setLocationDialogVisible(true); @@ -162,14 +199,23 @@ const HomeNavbar = (props: IProps) => { handleCityChangeWithoutCache(); }; - // 处理定位弹窗取消 + // 处理定位弹窗取消(用户选择"继续浏览") const handleLocationDialogCancel = () => { if (!locationDialogData) return; const { cachedCity } = locationDialogData; - // 用户选择"否",保持缓存的定位城市 + // 用户选择"继续浏览",保持缓存的定位城市 console.log("保持缓存的定位城市:", cachedCity[1]); + // 记录用户选择"继续浏览"的时间戳,2小时内不再提示 + try { + const current_time = Date.now(); + (Taro as any).setStorageSync(LOCATION_DIALOG_DISMISS_TIME_KEY, current_time); + console.log(`[LocationDialog] 已记录用户选择"继续浏览"的时间,2小时内不再提示`); + } catch (error) { + console.error('保存定位弹窗关闭时间失败:', error); + } + // 关闭弹窗 setLocationDialogVisible(false); setLocationDialogData(null); diff --git a/src/components/LocationConfirmDialog/index.scss b/src/components/LocationConfirmDialog/index.scss index 2b91270..d2db227 100644 --- a/src/components/LocationConfirmDialog/index.scss +++ b/src/components/LocationConfirmDialog/index.scss @@ -79,6 +79,10 @@ cursor: pointer; transition: opacity 0.2s; margin-top: 20px; + position: relative; + z-index: 1; + user-select: none; + -webkit-tap-highlight-color: transparent; &:first-child { margin-top: 0; @@ -111,6 +115,8 @@ font-size: 16px; line-height: 22px; text-align: center; + pointer-events: none; + user-select: none; &.primary { color: #ffffff; diff --git a/src/components/LocationConfirmDialog/index.tsx b/src/components/LocationConfirmDialog/index.tsx index 09424a8..7501b73 100644 --- a/src/components/LocationConfirmDialog/index.tsx +++ b/src/components/LocationConfirmDialog/index.tsx @@ -40,10 +40,22 @@ const LocationConfirmDialog: React.FC = ({ 定位显示您在{detectedCity} - + { + e.stopPropagation(); + onConfirm(); + }} + > 切换到{detectedCity} - + { + e.stopPropagation(); + onCancel(); + }} + > 继续浏览{currentCity}