fix(mini-user): locate before store list fetch; prefer masked phone on mine

Resolve city once then fetch stores once; skip refetch when city unchanged. Show masked phone under nickname when available.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-29 11:56:40 +08:00
parent 2ccadce34a
commit e742f1e88b
2 changed files with 64 additions and 48 deletions
+5 -2
View File
@@ -351,11 +351,14 @@ export default function MinePage() {
const needProfileFill = isWeapp && needsWxProfileFill(display);
const avatarProfileReady = isWeapp ? !needProfileFill : hasWechat;
const maskedPhone = profile?.phone ? maskPhone(String(profile.phone)) : '';
const memberLabel = needProfileFill
// 昵称下优先展示脱敏手机号;无手机号时再提示完善资料/授权
const memberLabel =
maskedPhone ||
(needProfileFill
? '点击头像完善资料'
: !isWeapp && !hasWechat && canWxAuth
? '点击头像授权'
: maskedPhone || '未绑定手机';
: '未绑定手机');
const avatarClickable = isWeapp || (!hasWechat && canWxAuth);
const previewAvatar = draftAvatarUrl || display.avatarUrl;
+61 -48
View File
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useEffect, useMemo, useRef, useState } from 'react';
import { View, Text, Image, Input } from '@tarojs/components';
import Taro, { useDidShow, usePullDownRefresh, useShareAppMessage, useShareTimeline } from '@tarojs/taro';
import PageShell from '../../components/PageShell';
@@ -25,7 +25,6 @@ import {
toCityWideRegion,
type UserCoords,
} from '../../lib/user-location';
import { FALLBACK_CITY_CODE } from '../../lib/product-images';
import { formatDistanceMeters } from '../../lib/geo';
import { request, toast } from '../../lib/api';
import {
@@ -55,6 +54,10 @@ type Store = {
distanceMeters?: number | null;
};
function regionEqual(a: RegionSelection, b: RegionSelection): boolean {
return a.province === b.province && a.city === b.city && a.district === b.district;
}
export default function StoresPage() {
const [stores, setStores] = useState<Store[]>([]);
const [loading, setLoading] = useState(true);
@@ -65,8 +68,9 @@ export default function StoresPage() {
const [category, setCategory] = useState<CategorySelection>(EMPTY_CATEGORY);
const [categoryOpen, setCategoryOpen] = useState(false);
const [categoryTree, setCategoryTree] = useState<StoreCategoryNode[]>([]);
const [cityCode, setCityCode] = useState<string>(FALLBACK_CITY_CODE);
const [userCoords, setUserCoords] = useState<UserCoords | null>(() => readCachedUserCoords());
/** 上次已用于请求的城市编码;仅换城才再拉列表 */
const cityCodeRef = useRef<string | null>(null);
const fetchSeqRef = useRef(0);
const regionLabel = formatRegionLabel(region);
const categoryLabel = formatCategoryLabel(category);
@@ -81,50 +85,9 @@ export default function StoresPage() {
return map;
}, [categoryTree]);
useDidShow(() => {
syncTabBarSelected(1);
void resolveUserCity().then((resolved) => {
setRegion(toCityWideRegion(resolved.region));
setCityCode(getCityCodeForCatalog(resolved));
setUserCoords(readCachedUserCoords());
});
});
useEffect(() => {
void request<StoreCategoryNode[]>('/store-categories')
.then((tree) => setCategoryTree(Array.isArray(tree) ? tree : []))
.catch(() => setCategoryTree([]));
}, []);
const loadStores = useCallback(() => {
setLoading(true);
const qs = new URLSearchParams();
if (cityCode) qs.set('cityCode', cityCode);
const coords = userCoords ?? readCachedUserCoords();
if (coords) {
qs.set('lat', String(coords.latitude));
qs.set('lng', String(coords.longitude));
}
const path = qs.toString() ? `/stores?${qs}` : '/stores';
return request<Store[]>(path)
.then((list) => setStores(Array.isArray(list) ? list : []))
.catch((e) => toast(e instanceof Error ? e.message : '加载失败'))
.finally(() => setLoading(false));
}, [cityCode, userCoords]);
useEffect(() => {
void loadStores();
}, [loadStores]);
usePullDownRefresh(() => {
void (async () => {
try {
const resolved = await resolveUserCity(true);
setRegion(toCityWideRegion(resolved.region));
const nextCode = getCityCodeForCatalog(resolved);
setCityCode(nextCode);
const coords = readCachedUserCoords();
setUserCoords(coords);
/** 按城市拉门店;coords 仅用于排序距离,不单独触发二次请求 */
async function fetchStores(nextCode: string, coords: UserCoords | null) {
const seq = ++fetchSeqRef.current;
setLoading(true);
const qs = new URLSearchParams();
if (nextCode) qs.set('cityCode', nextCode);
@@ -133,12 +96,62 @@ export default function StoresPage() {
qs.set('lng', String(coords.longitude));
}
const path = qs.toString() ? `/stores?${qs}` : '/stores';
try {
const list = await request<Store[]>(path);
if (seq !== fetchSeqRef.current) return;
setStores(Array.isArray(list) ? list : []);
} catch (e) {
if (seq !== fetchSeqRef.current) return;
toast(e instanceof Error ? e.message : '加载失败');
} finally {
if (seq === fetchSeqRef.current) setLoading(false);
}
}
/**
* 流程:先定位 → 再请求一次列表(成功用定位城市,失败用默认城市)。
* 再次进入页且城市未变:不重复请求,避免列表闪烁。
*/
useDidShow(() => {
syncTabBarSelected(1);
void (async () => {
const resolved = await resolveUserCity();
const nextCode = getCityCodeForCatalog(resolved);
const nextCoords = readCachedUserCoords();
const nextRegion = toCityWideRegion(resolved.region);
const cityChanged = cityCodeRef.current !== nextCode;
setRegion((prev) => (regionEqual(prev, nextRegion) ? prev : nextRegion));
if (cityCodeRef.current == null || cityChanged) {
cityCodeRef.current = nextCode;
await fetchStores(nextCode, nextCoords);
return;
}
setLoading(false);
})();
});
useEffect(() => {
void request<StoreCategoryNode[]>('/store-categories')
.then((tree) => setCategoryTree(Array.isArray(tree) ? tree : []))
.catch(() => setCategoryTree([]));
}, []);
usePullDownRefresh(() => {
void (async () => {
try {
const resolved = await resolveUserCity(true);
const nextCode = getCityCodeForCatalog(resolved);
const nextRegion = toCityWideRegion(resolved.region);
const coords = readCachedUserCoords();
cityCodeRef.current = nextCode;
setRegion(nextRegion);
await fetchStores(nextCode, coords);
} catch (e) {
toast(e instanceof Error ? e.message : '加载失败');
setLoading(false);
} finally {
Taro.stopPullDownRefresh();
}
})();