feat: 小程序手机号登录获取openid逻辑
This commit is contained in:
@ -15,6 +15,7 @@ import { useInterface } from "@/hooks/useInterface";
|
|||||||
import { privacyAgreementUrl, sendSmsCode as sendSmsCodeRequest, smsLogin, userAgreementUrl } from '@/api/auth'
|
import { privacyAgreementUrl, sendSmsCode as sendSmsCodeRequest, smsLogin, userAgreementUrl } from '@/api/auth'
|
||||||
import { useMainStore } from "@/store/modules/useMainStore";
|
import { useMainStore } from "@/store/modules/useMainStore";
|
||||||
import { afterLogin } from "@/utils";
|
import { afterLogin } from "@/utils";
|
||||||
|
import { wxLogin } from "@/utils/wechatUtils";
|
||||||
|
|
||||||
const {getParams, goBack, push, pushToTab} = useRouter()
|
const {getParams, goBack, push, pushToTab} = useRouter()
|
||||||
const {toast} = useInterface();
|
const {toast} = useInterface();
|
||||||
@ -30,6 +31,7 @@ const codeFocus = ref(false)
|
|||||||
const form = ref({
|
const form = ref({
|
||||||
mobile: '',
|
mobile: '',
|
||||||
code: '',
|
code: '',
|
||||||
|
loginCode: undefined,// 微信环境的CODE
|
||||||
invitationCode: undefined
|
invitationCode: undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -146,6 +148,10 @@ async function doLogin() {
|
|||||||
if (!(unref(form).code)) return toast({title: '请输入正确的验证码'})
|
if (!(unref(form).code)) return toast({title: '请输入正确的验证码'})
|
||||||
try {
|
try {
|
||||||
loginLoading.value = true
|
loginLoading.value = true
|
||||||
|
// 如果是微信小程序环境,获取wx.login的code给后端去获取openid
|
||||||
|
// #ifdef MP-WEIXIN
|
||||||
|
form.value.loginCode = await wxLogin();
|
||||||
|
// #endif
|
||||||
const res = await smsLogin(form.value);
|
const res = await smsLogin(form.value);
|
||||||
if (res) {
|
if (res) {
|
||||||
await mainStore.setAccessToken(res)
|
await mainStore.setAccessToken(res)
|
||||||
|
Reference in New Issue
Block a user