1
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -40,10 +40,22 @@ const LocationConfirmDialog: React.FC<LocationConfirmDialogProps> = ({
|
||||
<View className="locationDialogContent">
|
||||
<Text className="locationDialogTitle">定位显示您在{detectedCity}</Text>
|
||||
<View className="locationDialogButtons">
|
||||
<View className="locationDialogButton primary" onClick={onConfirm}>
|
||||
<View
|
||||
className="locationDialogButton primary"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onConfirm();
|
||||
}}
|
||||
>
|
||||
<Text className="locationDialogButtonText primary">切换到{detectedCity}</Text>
|
||||
</View>
|
||||
<View className="locationDialogButton secondary" onClick={onCancel}>
|
||||
<View
|
||||
className="locationDialogButton secondary"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onCancel();
|
||||
}}
|
||||
>
|
||||
<Text className="locationDialogButtonText secondary">继续浏览{currentCity}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user