From 9145d63c7641337eae033c842bcf1ddd01e2198a Mon Sep 17 00:00:00 2001 From: zhangjing1 Date: Fri, 27 Mar 2026 11:25:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(location):=20=E6=97=A0=20GPS=20=E6=97=B6?= =?UTF-8?q?=E6=94=B6=E8=B4=A7=E5=9C=B0=E5=9D=80=E4=B8=8D=E5=86=8D=E5=86=99?= =?UTF-8?q?=E5=85=A5=20location=EF=BC=9B=E5=AF=BC=E8=88=AA=E6=96=87?= =?UTF-8?q?=E6=A1=88=E6=8C=89=20adrdetail=20=E5=88=86=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - useLocation:登录且未拿到定位时仅 updateChooseAddress(默认地址),避免收货地址混入 Redux location - 首页/自定义页 nearbyText:有 adrdetail 优先 address,否则优先 LBS 再退回 address.city - home-header:同上规则展示地区;去掉硬编码昌平默认 - index:移除未使用的 shopInfo、locationKeyRef Made-with: Cursor --- src/hooks/useLocation.js | 7 ++++--- src/pages/custom/custom-page.js | 4 +++- src/pages/home/wgts/home-header.js | 15 +++++++++++++-- src/pages/index.js | 6 +++--- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/hooks/useLocation.js b/src/hooks/useLocation.js index 9c42e782a..9fe4b32f8 100644 --- a/src/hooks/useLocation.js +++ b/src/hooks/useLocation.js @@ -6,7 +6,7 @@ import Taro from '@tarojs/taro' import api from '@/api' import entryLaunch from '@/utils/entryLaunch' import { useSelector, useDispatch } from 'react-redux' -import { updateLocation } from '@/store/slices/user' +import { updateLocation, updateChooseAddress } from '@/store/slices/user' import S from '@/spx' export default (props) => { @@ -146,9 +146,10 @@ export default (props) => { dispatch(updateLocation(res1)) } } else { + // 未拿到 GPS:不要把收货地址写进 location,否则首页「定位」会与收货地址混淆 if (arr.length > 0) { - const arr1 = await processingAddress([list.find((obj) => obj.is_def === true) || list[0]]) - dispatch(updateLocation(arr1[0])) + const defAddr = list.find((obj) => obj.is_def === true) || list[0] + dispatch(updateChooseAddress(defAddr)) } } } diff --git a/src/pages/custom/custom-page.js b/src/pages/custom/custom-page.js index 210e41c18..6ab77ab6b 100644 --- a/src/pages/custom/custom-page.js +++ b/src/pages/custom/custom-page.js @@ -43,7 +43,9 @@ function CustomPage(props) { const loginRef = useRef() const router = useRouter() const { location, address } = useSelector((state) => state.user) - const nearbyText = address?.city || location?.city || '' + const nearbyText = address?.adrdetail + ? address?.city || address?.province || '' + : location?.city || location?.province || address?.city || '' useEffect(() => { fetch() diff --git a/src/pages/home/wgts/home-header.js b/src/pages/home/wgts/home-header.js index b59386cb0..5f64e334c 100644 --- a/src/pages/home/wgts/home-header.js +++ b/src/pages/home/wgts/home-header.js @@ -12,7 +12,7 @@ import './home-header.scss' function WgtHomeHeader(props) { const { children, jump = true, isSetHight } = props - const { location = {} } = useSelector((state) => state.user) + const { location = {}, address } = useSelector((state) => state.user) const { openScanQrcode, entryStoreByLBS, openWechatappLocation } = useSelector( (state) => state.sys ) @@ -46,7 +46,18 @@ function WgtHomeHeader(props) { } }} > - {location?.address || '北京市北京市昌平区'} + + {address?.adrdetail + ? [address.province, address.city, address.county, address.adrdetail] + .filter(Boolean) + .join('') || + address.city || + address.province || + '选择地区' + : location?.address || + [location?.province, location?.city, location?.district].filter(Boolean).join('') || + '选择地区'} + )} diff --git a/src/pages/index.js b/src/pages/index.js index 4c13d983e..2833c645a 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -86,14 +86,14 @@ function Home() { const { openRecommend, appName, openScanQrcode, entryStoreByLBS, openWechatappLocation } = useSelector((state) => state.sys) - const { shopInfo } = useSelector((state) => state.shop) const showAdv = useSelector((member) => member.user.showAdv) const { location, address } = useSelector((state) => state.user) - const nearbyText = address?.city || location?.city || '' + const nearbyText = address?.adrdetail + ? address?.city || address?.province || '' + : location?.city || location?.province || address?.city || '' const { setNavigationBarTitle } = useNavigation() const { updateAddress } = useLocation() - const locationKeyRef = useRef('') const { wgts, pageData,