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 {listShopUserAddress, removeShopUserAddress, updateShopUserAddress} from "@/api/shop/shopUserAddress";
|
||||||
import FixedButton from "@/components/FixedButton";
|
import FixedButton from "@/components/FixedButton";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { getCurrentLngLat } from "@/utils/location";
|
|
||||||
|
|
||||||
const Address = () => {
|
const Address = () => {
|
||||||
const [list, setList] = useState<ShopUserAddress[]>([])
|
const [list, setList] = useState<ShopUserAddress[]>([])
|
||||||
@@ -72,8 +71,7 @@ const Address = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onDefault = async (item: ShopUserAddress) => {
|
const onDefault = async (item: ShopUserAddress) => {
|
||||||
const loc = await getCurrentLngLat()
|
if (item.isDefault) return
|
||||||
if (!loc) return
|
|
||||||
|
|
||||||
if (address) {
|
if (address) {
|
||||||
await updateShopUserAddress({
|
await updateShopUserAddress({
|
||||||
@@ -84,8 +82,6 @@ const Address = () => {
|
|||||||
await updateShopUserAddress({
|
await updateShopUserAddress({
|
||||||
...item,
|
...item,
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
lng: loc.lng,
|
|
||||||
lat: loc.lat,
|
|
||||||
})
|
})
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
title: '设置成功',
|
title: '设置成功',
|
||||||
@@ -108,8 +104,11 @@ const Address = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const selectAddress = async (item: ShopUserAddress) => {
|
const selectAddress = async (item: ShopUserAddress) => {
|
||||||
const loc = await getCurrentLngLat()
|
if (item.isDefault) {
|
||||||
if (!loc) return
|
const backed = await safeNavigateBack()
|
||||||
|
if (!backed) reload()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (address) {
|
if (address) {
|
||||||
await updateShopUserAddress({
|
await updateShopUserAddress({
|
||||||
@@ -120,11 +119,10 @@ const Address = () => {
|
|||||||
await updateShopUserAddress({
|
await updateShopUserAddress({
|
||||||
...item,
|
...item,
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
lng: loc.lng,
|
|
||||||
lat: loc.lat,
|
|
||||||
})
|
})
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
Taro.navigateBack()
|
const backed = await safeNavigateBack()
|
||||||
|
if (!backed) reload()
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user