| | |
| | | import { onShow } from '@dcloudio/uni-app' |
| | | import { useGlobal } from '@/composables/useGlobal' |
| | | import { usePlatformLoginType } from '@/composables/usePlatformLoginType' |
| | | import { useUserStore } from '@/store/user' |
| | | |
| | | const { apitype } = usePlatformLoginType() |
| | | const { $http, $message,$store } = useGlobal() |
| | | const { $http, $message, $store } = useGlobal() |
| | | const userStore = useUserStore() |
| | | |
| | | const isChecked = ref(false) |
| | | const toggleCheck = () => { |
| | |
| | | uni.showToast({ title: '请先同意协议', icon: 'none' }); |
| | | return; |
| | | } |
| | | // 微信登录逻辑 |
| | | uni.showToast({ title: '微信登录', icon: 'success' }); |
| | | // 微信登录 |
| | | uni.login({ |
| | | "provider": "weixin", |
| | | "onlyAuthorize": true, // 微信登录仅请求授权认证 |
| | | success: async function (event:any) { |
| | | const { code } = event |
| | | $message.showLoading(); |
| | | const resp = await userStore.loginwx({ code, phoneNumber: wxUser.value.phoneNumber, purePhoneNumber: wxUser.value.purePhoneNumber }) |
| | | if (resp && resp.data) { |
| | | // that.$forceUpdate() |
| | | uni.reLaunch({ |
| | | url: '/pages/home/home' |
| | | }) |
| | | } |
| | | $message.hideLoading(); |
| | | }, |
| | | fail: function (err:any) { |
| | | // 登录授权失败 |
| | | // err.code是错误码 |
| | | } |
| | | }) |
| | | |
| | | |
| | | }; |
| | | |
| | | onShow(() => { |
| | |
| | | "provider": "weixin", |
| | | "onlyAuthorize": true, // 微信登录仅请求授权认证 |
| | | success: async function (event: any) { |
| | | console.log("aaaa") |
| | | console.log(event) |
| | | const { code } = event |
| | | let openIdExistFlag = await getExistUserByOpenId(code); |
| | | console.log(openIdExistFlag) |
| | | console.log(wxUser.value) |
| | | |
| | | }, |
| | | fail: function (err: any) { |
| | | // 登录授权失败 |
| | |
| | | } |
| | | }) |
| | | if (code == 0) { |
| | | console.log("查看当前用户是否已经绑定过") |
| | | console.log(data) |
| | | wxUser.value = data |
| | | if (wxUser && wxUser.user) { |
| | | return true |
| | |
| | | } |
| | | } |
| | | |
| | | const handleGetPhoneNumber = async (e:any) => { |
| | | const handleGetPhoneNumber = async (e: any) => { |
| | | |
| | | if (!isChecked.value) { |
| | | $message.showToast('请同意用户协议') |
| | | return |
| | | } |
| | | debugger; |
| | | console.log(e) |
| | | console.log(e.detail.code) // 动态令牌 |
| | | console.log(e.detail.errMsg) // 回调信息(成功失败都会返回) |
| | | console.log(e.detail.errno) // 错误码(失败时返回) |
| | | |
| | | if (e.detail.errMsg == 'getPhoneNumber:ok') { |
| | | console.log('获取成功') |
| | | const { |
| | |
| | | } |
| | | }) |
| | | if (code == 0) { |
| | | debugger; |
| | | // 获取手机号码后,实现微信登录 |
| | | console.log(data) |
| | | const phoneNumber = data.phone_info.phoneNumber; |
| | | const purePhoneNumber = data.phone_info.purePhoneNumber; |
| | | wxUser.value.phoneNumber = phoneNumber |
| | | wxUser.value.purePhoneNumber = purePhoneNumber |
| | | // that.handleWechatClick() |
| | | handleWechatClick() |
| | | } else { |
| | | |
| | | } |
| | |
| | | uni.login({ |
| | | "provider": "weixin", |
| | | "onlyAuthorize": true, // 微信登录仅请求授权认证 |
| | | success: async function (event) { |
| | | success: async function (event: any) { |
| | | const { code } = event |
| | | $message.showLoading(); |
| | | const resp = await $store.dispatch('loginwx', { code, phoneNumber: wxUser.phoneNumber, purePhoneNumber: wxUser.purePhoneNumber }) |
| | | console.log("获取到的微信用户信息是:", wxUser.value) |
| | | const resp = await userStore.loginwx({ code, phoneNumber: wxUser.value.phoneNumber, purePhoneNumber: wxUser.value.purePhoneNumber }) |
| | | if (resp && resp.data) { |
| | | // $forceUpdate() |
| | | uni.reLaunch({ |
| | |
| | | } |
| | | $message.hideLoading(); |
| | | }, |
| | | fail: function (err) { |
| | | fail: function (err: any) { |
| | | // 登录授权失败 |
| | | // err.code是错误码 |
| | | } |