Browse Source

去掉弹窗、去掉定位请求,改为门店页面请求

master
DU 3 weeks ago
parent
commit
19fb43cf3f
  1. 6
      src/pageScan/selfStart/index.tsx
  2. 10
      src/pages/index/index.tsx
  3. 47
      src/pages/store/index.tsx

6
src/pageScan/selfStart/index.tsx

@ -35,9 +35,9 @@ const SelfStart = observer(() => {
if (grpSn) { if (grpSn) {
tableStore.setCurrentGrpSn(grpSn) tableStore.setCurrentGrpSn(grpSn)
} }
setTimeout(() => { // setTimeout(() => {
Taro.showToast({ title: '开台后需要手动进行关台哦!', icon: 'none', duration: 2000 }) // Taro.showToast({ title: '开台后需要手动进行关台哦!', icon: 'none', duration: 2000 })
}, 300) // }, 300)
}) })
// 拨打电话 // 拨打电话

10
src/pages/index/index.tsx

@ -130,11 +130,11 @@ const Index = observer(() => {
setCurrentDistance('--') setCurrentDistance('--')
} }
} }
// 暂时注释,不要删除这段代码
useEffect(() => { // useEffect(() => {
// 页面加载时请求定位权限 // // 页面加载时请求定位权限
requestLocationPermission() // requestLocationPermission()
}, []) // }, [])
// 处理扫码开台点击 - 跳转到独立扫码页面(无tabbar) // 处理扫码开台点击 - 跳转到独立扫码页面(无tabbar)
const handleScanClick = () => { const handleScanClick = () => {

47
src/pages/store/index.tsx

@ -2,9 +2,9 @@
* *
*/ */
import { View, Text, Image, Input, ScrollView } from '@tarojs/components' 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 { observer } from 'mobx-react'
import { useState, useEffect } from 'react' import { useState, useEffect, useRef } from 'react'
import { Popup, Toast, Tabs } from '@taroify/core' import { Popup, Toast, Tabs } from '@taroify/core'
import { useCascader } from '@taroify/hooks' import { useCascader } from '@taroify/hooks'
import { Arrow, Cross, Search } from '@taroify/icons' import { Arrow, Cross, Search } from '@taroify/icons'
@ -71,6 +71,7 @@ const StoreIndex = observer(() => {
const [isSearched, setIsSearched] = useState(false) const [isSearched, setIsSearched] = useState(false)
const [cityValue, setCityValue] = useState<string[]>([]) const [cityValue, setCityValue] = useState<string[]>([])
const [tabIndex, setTabIndex] = useState(0) const [tabIndex, setTabIndex] = useState(0)
const requestingLocationRef = useRef(false)
// 使用 useCascader hook // 使用 useCascader hook
const { columns } = useCascader({ const { columns } = useCascader({
@ -84,6 +85,48 @@ const StoreIndex = observer(() => {
loadStores() 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 () => { const loadStores = async () => {
setLoading(true) setLoading(true)
try { try {

Loading…
Cancel
Save