|
|
|
@ -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 { |
|
|
|
|