forked from gxwebsoft/mp-10550
refactor(address): 移除地理位置获取逻辑并优化默认地址处理
- 删除 getCurrentLngLat 工具函数的导入和使用 - 简化 onDefault 函数中的默认地址检查逻辑 - 移除地址更新时的经纬度参数传递 - 优化 selectAddress 函数中的导航回退逻辑 - 使用 safeNavigateBack 替代直接的 navigateBack 操作 - 添加回退失败时的页面重载机制
This commit is contained in:
@@ -7,7 +7,6 @@ import {ShopUserAddress} from "@/api/shop/shopUserAddress/model";
|
||||
import {listShopUserAddress, removeShopUserAddress, updateShopUserAddress} from "@/api/shop/shopUserAddress";
|
||||
import FixedButton from "@/components/FixedButton";
|
||||
import dayjs from "dayjs";
|
||||
import { getCurrentLngLat } from "@/utils/location";
|
||||
|
||||
const Address = () => {
|
||||
const [list, setList] = useState<ShopUserAddress[]>([])
|
||||
@@ -72,8 +71,7 @@ const Address = () => {
|
||||
}
|
||||
|
||||
const onDefault = async (item: ShopUserAddress) => {
|
||||
const loc = await getCurrentLngLat()
|
||||
if (!loc) return
|
||||
if (item.isDefault) return
|
||||
|
||||
if (address) {
|
||||
await updateShopUserAddress({
|
||||
@@ -84,8 +82,6 @@ const Address = () => {
|
||||
await updateShopUserAddress({
|
||||
...item,
|
||||
isDefault: true,
|
||||
lng: loc.lng,
|
||||
lat: loc.lat,
|
||||
})
|
||||
Taro.showToast({
|
||||
title: '设置成功',
|
||||
@@ -108,8 +104,11 @@ const Address = () => {
|
||||
}
|
||||
|
||||
const selectAddress = async (item: ShopUserAddress) => {
|
||||
const loc = await getCurrentLngLat()
|
||||
if (!loc) return
|
||||
if (item.isDefault) {
|
||||
const backed = await safeNavigateBack()
|
||||
if (!backed) reload()
|
||||
return
|
||||
}
|
||||
|
||||
if (address) {
|
||||
await updateShopUserAddress({
|
||||
@@ -120,11 +119,10 @@ const Address = () => {
|
||||
await updateShopUserAddress({
|
||||
...item,
|
||||
isDefault: true,
|
||||
lng: loc.lng,
|
||||
lat: loc.lat,
|
||||
})
|
||||
setTimeout(() => {
|
||||
Taro.navigateBack()
|
||||
setTimeout(async () => {
|
||||
const backed = await safeNavigateBack()
|
||||
if (!backed) reload()
|
||||
}, 500)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user