diff --git a/src/pageScan/selfStart/index.tsx b/src/pageScan/selfStart/index.tsx index dad6524..7e0781b 100644 --- a/src/pageScan/selfStart/index.tsx +++ b/src/pageScan/selfStart/index.tsx @@ -35,9 +35,9 @@ const SelfStart = observer(() => { if (grpSn) { tableStore.setCurrentGrpSn(grpSn) } - setTimeout(() => { - Taro.showToast({ title: '开台后需要手动进行关台哦!', icon: 'none', duration: 2000 }) - }, 300) + // setTimeout(() => { + // Taro.showToast({ title: '开台后需要手动进行关台哦!', icon: 'none', duration: 2000 }) + // }, 300) }) // 拨打电话 diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 27ec383..312db9a 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -130,11 +130,11 @@ const Index = observer(() => { setCurrentDistance('--') } } - - useEffect(() => { - // 页面加载时请求定位权限 - requestLocationPermission() - }, []) + // 暂时注释,不要删除这段代码 + // useEffect(() => { + // // 页面加载时请求定位权限 + // requestLocationPermission() + // }, []) // 处理扫码开台点击 - 跳转到独立扫码页面(无tabbar) const handleScanClick = () => { diff --git a/src/pages/store/index.tsx b/src/pages/store/index.tsx index bc42e14..859ea11 100644 --- a/src/pages/store/index.tsx +++ b/src/pages/store/index.tsx @@ -2,9 +2,9 @@ * 门店列表页 */ import { View, Text, Image, Input, ScrollView } from '@tarojs/components' -import Taro, { useLoad } from '@tarojs/taro' +import Taro, { useDidShow, useLoad } from '@tarojs/taro' import { observer } from 'mobx-react' -import { useState, useEffect } from 'react' +import { useState, useEffect, useRef } from 'react' import { Popup, Toast, Tabs } from '@taroify/core' import { useCascader } from '@taroify/hooks' import { Arrow, Cross, Search } from '@taroify/icons' @@ -71,6 +71,7 @@ const StoreIndex = observer(() => { const [isSearched, setIsSearched] = useState(false) const [cityValue, setCityValue] = useState([]) const [tabIndex, setTabIndex] = useState(0) + const requestingLocationRef = useRef(false) // 使用 useCascader hook const { columns } = useCascader({ @@ -84,6 +85,48 @@ const StoreIndex = observer(() => { loadStores() }) + useDidShow(() => { + requestLocationWhenShow() + }) + + // 切换到门店 Tab 时再按需请求定位权限,避免首页进入即弹授权 + const requestLocationWhenShow = async () => { + if (requestingLocationRef.current) return + + requestingLocationRef.current = true + try { + const setting = await Taro.getSetting() + + if (!setting.authSetting['scope.userLocation']) { + await Taro.authorize({ scope: 'scope.userLocation' }) + } + + const location = await Taro.getLocation({ + type: 'gcj02', + isHighAccuracy: true, + }) + + console.log('门店页当前位置:', location) + } catch (error: any) { + console.warn('门店页获取位置失败:', error) + + if (error?.errMsg?.includes('auth')) { + Taro.showModal({ + title: '定位权限', + content: '需要获取您的位置信息以显示附近门店,请在设置中开启定位权限', + confirmText: '去设置', + success: (res) => { + if (res.confirm) { + Taro.openSetting() + } + } + }) + } + } finally { + requestingLocationRef.current = false + } + } + const loadStores = async () => { setLoading(true) try {