feat(miniprogram): add wechatLogin API client on user store.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
wuzilongandCursor committed 2026-09-18 11:14:59 +08:00
1 parent 713aa700ae
commit 6f39801c63
3 files changed
+34 -1

No files matched your search

+32
View File
@@ -130,6 +130,37 @@ export const useUserStore = defineStore('user', () => {
}
}
async function wechatLogin(params) {
isLoading.value = true
try {
const res = await request({
url: AUTH_API.WECHAT_LOGIN,
method: 'POST',
data: {
loginCode: params.loginCode,
phoneCode: params.phoneCode
}
})
const result = parseResponseJson(res)
if (result && result.code === 200 && result.data) {
setLoginInfo({
token: result.data.token,
refreshToken: result.data.refreshToken,
userInfo: result.data.userInfo
})
await fetchMenuCodes()
return true
}
uni.showToast({ title: (result && result.message) || '登录失败', icon: 'none' })
return false
} catch (e) {
uni.showToast({ title: (e && e.message) || '登录失败', icon: 'none' })
return false
} finally {
isLoading.value = false
}
}
function clearLoginInfo() {
token.value = ''
refreshToken.value = ''
@@ -193,6 +224,7 @@ export const useUserStore = defineStore('user', () => {
homePath,
checkLoginStatus,
login,
wechatLogin,
logout,
clearLoginInfo,
navigateToHome,