fix(app): 移除已废弃的 uni.getUserProfile 调用修复首次登录失败

uni.getUserProfile 在微信基础库 2.27.1+ 已被移除,调用时抛出 TypeError
导致整个登录流程中断。新用户昵称由后端默认生成,用户可在资料页修改。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
richarjiang
2026-04-10 09:04:16 +08:00
parent 54104c16d2
commit 57e3227af0

View File

@@ -14,29 +14,11 @@ export async function wxLogin(): Promise<LoginResponse> {
provider: 'weixin',
success: async (loginRes) => {
try {
// Step 2: 获取用户微信头像和昵称
let nickname: string | undefined
let avatarUrl: string | undefined
await new Promise<void>((res) => {
uni.getUserProfile({
desc: '用于完善个人资料',
success: (profileRes) => {
nickname = profileRes.userInfo.nickName
avatarUrl = profileRes.userInfo.avatarUrl
res()
},
fail: () => {
// 用户拒绝授权,仍可继续登录
res()
},
})
})
// Step 3: 发送登录请求
// Step 2: 发送登录请求
// 注uni.getUserProfile 已被微信废弃(基础库 2.27.1+
// 新用户的昵称/头像由后端生成默认值,用户可在个人资料页修改
const result = await post<LoginResponse>('/auth/login', {
code: loginRes.code,
nickname,
avatarUrl,
})
uni.setStorageSync('token', result.token)
resolve(result)