From 50ac79d055d0d51271b8ae306fb00e4f91928258 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com>
Date: Mon, 9 Feb 2026 17:28:00 +0800
Subject: [PATCH] =?UTF-8?q?feat(user):=20=E4=BC=98=E5=8C=96=E5=9C=B0?=
=?UTF-8?q?=E5=9D=80=E6=B7=BB=E5=8A=A0=E9=A1=B5=E9=9D=A2=E7=9A=84=E5=9C=B0?=
=?UTF-8?q?=E5=9B=BE=E5=AE=9A=E4=BD=8D=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 移除地图选点地址与收货地址的自动同步逻辑
- 改进地图选点地址解析,避免省市区字段重复显示
- 添加经纬度有效性校验,防止无效数值传递给位置选择器
- 将选择定位组件移至表单下方并重新排列布局
- 为收货人和手机号字段添加更严格的验证规则
- 保留地图定位功能的完整交互界面和错误处理
---
src/user/address/add.tsx | 101 +++++++++++++++++++++++++--------------
1 file changed, 64 insertions(+), 37 deletions(-)
diff --git a/src/user/address/add.tsx b/src/user/address/add.tsx
index 2b5234a..3554724 100644
--- a/src/user/address/add.tsx
+++ b/src/user/address/add.tsx
@@ -250,16 +250,6 @@ const AddUserAddress = () => {
}
setSelectedLocation(next)
- // 将地图选点的地址同步到“收货地址”,减少用户重复输入
- const nextDetailAddress = (() => {
- const addr = String(res.address || '').trim()
- const name = String(res.name || '').trim()
- if (!addr && !name) return ''
- if (!addr) return name
- if (!name) return addr
- return addr.includes(name) ? addr : `${addr} ${name}`
- })()
-
// 尝试从地图返回的 address 文本解析省市区(best-effort)
const regionResult = res?.provinceName || res?.cityName || res?.adName
? {
@@ -269,6 +259,29 @@ const AddUserAddress = () => {
}
: parseRegion(String(res.address || ''))
+ // 将地图选点的地址同步到“收货地址”(不额外拼接省市区字段,省市区由独立字段保存)
+ const nextDetailAddress = (() => {
+ const rawAddr = String(res.address || '').trim()
+ const name = String(res.name || '').trim()
+
+ const province = String(regionResult?.province || '').trim()
+ const city = String(regionResult?.city || '').trim()
+ const region = String(regionResult?.region || '').trim()
+
+ // 选择定位返回的 address 往往包含省市区,这里尽量剥离掉,避免和表单的省市区字段重复
+ let detail = rawAddr
+ for (const part of [province, city, region]) {
+ if (part) detail = detail.replace(part, '')
+ }
+ detail = detail.replace(/[,,]+/g, ' ').replace(/\s+/g, ' ').trim()
+
+ const base = detail || rawAddr
+ if (!base && !name) return ''
+ if (!base) return name
+ if (!name) return base
+ return base.includes(name) ? base : `${base} ${name}`
+ })()
+
setFormData(prev => ({
...prev,
lng: next.lng,
@@ -295,9 +308,11 @@ const AddUserAddress = () => {
try {
const initLat = selectedLocation?.lat ? Number(selectedLocation.lat) : undefined
const initLng = selectedLocation?.lng ? Number(selectedLocation.lng) : undefined
+ const latitude = typeof initLat === 'number' && Number.isFinite(initLat) ? initLat : undefined
+ const longitude = typeof initLng === 'number' && Number.isFinite(initLng) ? initLng : undefined
const res = await Taro.chooseLocation({
- latitude: Number.isFinite(initLat as number) ? (initLat as number) : undefined,
- longitude: Number.isFinite(initLng as number) ? (initLng as number) : undefined
+ latitude,
+ longitude
})
applyChosenLocation(res)
} catch (e: any) {
@@ -452,7 +467,43 @@ const AddUserAddress = () => {
-
+
+
+
+
+
+
+
+
+
+
+
+
+
| {
onClick={chooseGeoLocation}
/>
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-