feat: 微信小程序登录改造(手机号授权 + API前缀改为/mp-api + 隐私协议检查)

This commit is contained in:
jacobxu666
2026-06-14 21:54:08 +08:00
parent 6ee484d8a3
commit 3af5f2850d
6 changed files with 60 additions and 29 deletions
+3 -16
View File
@@ -12,27 +12,14 @@ export const useUserStore = defineStore('user', () => {
const isLogin = computed(() => !!token.value)
/** 微信授权登录 */
async function wxLogin() {
// #ifdef MP-WEIXIN
const loginRes = await new Promise<UniApp.LoginRes>((resolve, reject) => {
uni.login({
provider: 'weixin',
success: resolve,
fail: reject
})
})
const result = await apiWxLogin(loginRes.code)
/** 微信授权登录(接收 loginCode + phoneCode) */
async function wxLogin(params: { loginCode: string; phoneCode: string }) {
const result = await apiWxLogin(params)
token.value = result.accessToken
refreshToken.value = result.refreshToken
setToken(result.accessToken)
uni.setStorageSync(REFRESH_TOKEN_KEY, result.refreshToken)
return result
// #endif
// #ifdef H5
throw new Error('H5 登录暂未开放,请在微信小程序中使用')
// #endif
}
/** 账号密码登录(降级方案) */