feat(miniprogram): add wechatLogin API client on user store.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
713aa700ae
commit
6f39801c63
3 files changed
+34
-1
No files matched your search
@@ -36,6 +36,7 @@ console.log('[ENV]', APP_ENV, CURRENT_ENV.label, resolveApiBase(), resolveWebOri
|
||||
export const AUTH_API = {
|
||||
LOGIN_RSA_PUBLIC_KEY: '/web/auth/login-rsa-public-key',
|
||||
LOGIN: '/web/auth/login',
|
||||
WECHAT_LOGIN: '/mini/auth/wechat-login',
|
||||
LOGOUT: '/web/auth/logout',
|
||||
CURRENT_USER: '/web/auth/current-user',
|
||||
REFRESH_TOKEN: '/web/auth/refresh-token',
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -9,7 +9,7 @@ const API_ENCRYPT_FAIL_OPEN = false
|
||||
const API_ENCRYPT_FIXED_SECRET = 'shanxia-web-api-crypto-fixed-secret'
|
||||
// TODO(config-hardcoded): 排除路径清单后续改为集中配置,避免多端重复维护。
|
||||
const API_ENCRYPT_EXCLUDE_PATHS = String(
|
||||
'/web/auth/login-rsa-public-key,/web/auth/login,/web/auth/refresh-token'
|
||||
'/web/auth/login-rsa-public-key,/web/auth/login,/web/auth/refresh-token,/mini/auth/wechat-login'
|
||||
)
|
||||
.split(',')
|
||||
.map((item) => item.trim())
|
||||
|
||||
Reference in new issue
Block a user