8 changed files with 173 additions and 191 deletions
@ -1,123 +1,118 @@ |
|||
<script setup lang="ts"> |
|||
import { debounce } from 'feng-uniapp-exploit/utils/index' |
|||
import { getMobile, getSign } from '@/api/login' |
|||
|
|||
import useUserStore from '@/store/user' |
|||
const userStore = useUserStore() |
|||
|
|||
const loginCode = ref('') |
|||
|
|||
// 获取微信登录 code |
|||
const getLoginCode = async (): Promise<string> => { |
|||
try { |
|||
const res = await uni.login({ provider: 'weixin' }) |
|||
loginCode.value = res.code |
|||
return res.code |
|||
} catch (error) { |
|||
console.error('获取登录code失败:', error) |
|||
throw error |
|||
} |
|||
} |
|||
|
|||
// 处理获取手机号 |
|||
|
|||
interface phoneEvent { |
|||
detail: { errMsg: string; iv: string; encryptedData: string; code: string } |
|||
} |
|||
const onGetPhoneNumber = debounce(async (e: phoneEvent) => { |
|||
if (e.detail.errMsg.includes('fail')) { |
|||
uni.showToast({ title: '用户拒绝授权', icon: 'none' }) |
|||
return |
|||
} |
|||
|
|||
try { |
|||
if (!loginCode.value) { |
|||
await getLoginCode() |
|||
} |
|||
|
|||
if (!userStore.openId) { |
|||
await userStore.getopenid({ code: loginCode.value }) |
|||
} |
|||
|
|||
getMobile({ openid: userStore.openId, code: e.detail.code }) |
|||
.then((res) => { |
|||
const { data: phone } = res as { data: string } |
|||
|
|||
userStore.mobile = phone |
|||
|
|||
userStore.getUserInfo() |
|||
|
|||
onLoginSuccess() |
|||
}) |
|||
.catch(() => { |
|||
uni.showToast({ title: '登录失败!', icon: 'none' }) |
|||
}) |
|||
} catch (error) { |
|||
uni.showToast({ title: '登录失败', icon: 'none' }) |
|||
} |
|||
}) |
|||
|
|||
const meetid = ref('') |
|||
|
|||
const onLoginSuccess = () => { |
|||
import { debounce } from 'feng-uniapp-exploit/utils/index' |
|||
import { getMobile, getSign} from '@/api/login' |
|||
|
|||
import useUserStore from '@/store/user' |
|||
const userStore = useUserStore() |
|||
|
|||
const loginCode = ref('') |
|||
|
|||
// 获取微信登录 code |
|||
const getLoginCode = async () : Promise<string> => { |
|||
try { |
|||
const res = await uni.login({ provider: 'weixin' }) |
|||
loginCode.value = res.code |
|||
return res.code |
|||
} catch (error) { |
|||
console.error('获取登录code失败:', error) |
|||
throw error |
|||
} |
|||
} |
|||
|
|||
// 处理获取手机号 |
|||
|
|||
interface phoneEvent { |
|||
detail : { errMsg : string; iv : string; encryptedData : string; code : string } |
|||
} |
|||
const onGetPhoneNumber = debounce(async (e : phoneEvent) => { |
|||
if (e.detail.errMsg.includes('fail')) { |
|||
uni.showToast({ title: '用户拒绝授权', icon: 'none' }) |
|||
return |
|||
} |
|||
|
|||
try { |
|||
if (!loginCode.value) { |
|||
await getLoginCode() |
|||
} |
|||
|
|||
if (!userStore.openId) { |
|||
await userStore.getopenid({ code: loginCode.value }) |
|||
} |
|||
|
|||
getMobile({ openid: userStore.openId, code: e.detail.code }) |
|||
.then((res) => { |
|||
const { data: phone } = res as { data : string } |
|||
|
|||
userStore.mobile = phone |
|||
|
|||
userStore.getUserInfo() |
|||
|
|||
onLoginSuccess() |
|||
}) |
|||
.catch(() => { |
|||
uni.showToast({ title: '登录失败!', icon: 'none' }) |
|||
}) |
|||
} catch (error) { |
|||
uni.showToast({ title: '登录失败', icon: 'none' }) |
|||
} |
|||
}) |
|||
|
|||
const onLoginSuccess = () => { |
|||
uni.showToast({ |
|||
title: '登录成功', |
|||
icon: 'none', |
|||
success: () => { |
|||
setTimeout(() => { |
|||
userStore.showtoast = false |
|||
uni.reLaunch({ url: '/pages/votingElection/index?meetId='+ meetid.value }) |
|||
|
|||
uni.reLaunch({ url: '/pages/votingElection/index?meetId=' + userStore.meetId }) |
|||
}, 1000) |
|||
} |
|||
}) |
|||
getSign({openid: userStore.openId, meetId: meetid.value}) |
|||
|
|||
} |
|||
onLoad((options: any) => { |
|||
console.log('扫码参数1:', options); |
|||
if(options.scene){ |
|||
meetid.value = options.scene |
|||
|
|||
} |
|||
|
|||
}) |
|||
|
|||
onShow(() => { |
|||
if (userStore.mobile) { |
|||
onLoginSuccess() |
|||
} |
|||
}) |
|||
onLoad((options : any) => { |
|||
console.log('扫码参数1:', options); |
|||
if (options.scene) { |
|||
userStore.meetId = options.scene |
|||
uni.setStorageSync('meetstorage', { |
|||
meetid: options.scene |
|||
}); |
|||
} |
|||
|
|||
}) |
|||
|
|||
onShow(() => { |
|||
// if (userStore.mobile) { |
|||
// onLoginSuccess() |
|||
// } |
|||
}) |
|||
</script> |
|||
<template> |
|||
<view class="login"> |
|||
<image class="logo-img" src="@/static/logo.png" mode="widthFix" /> |
|||
|
|||
<view class="btn_box"> |
|||
<u-button |
|||
@getphonenumber="onGetPhoneNumber" |
|||
text="请签到后进行投票" |
|||
icon-color="#fff" |
|||
open-type="getPhoneNumber" |
|||
color="linear-gradient(270deg, rgba(232, 123, 7, 1) 0%, rgba(247, 205, 77, 1) 100%)" |
|||
shape="circle" |
|||
/> |
|||
</view> |
|||
</view> |
|||
<view class="login"> |
|||
<image class="logo-img" src="@/static/logo.png" mode="widthFix" /> |
|||
|
|||
<view class="btn_box"> |
|||
<u-button @getphonenumber="onGetPhoneNumber" text="请签到后进行投票" icon-color="#fff" open-type="getPhoneNumber" |
|||
color="linear-gradient(270deg, rgba(232, 123, 7, 1) 0%, rgba(247, 205, 77, 1) 100%)" shape="circle" /> |
|||
</view> |
|||
</view> |
|||
</template> |
|||
|
|||
<style scoped lang="scss"> |
|||
.login { |
|||
width: 100%; |
|||
height: 100vh; |
|||
overflow: hidden; |
|||
position: relative; |
|||
text-align: center; |
|||
box-sizing: border-box; |
|||
padding: 500rpx 30rpx 0; |
|||
background-color: #fff; |
|||
|
|||
.logo-img { |
|||
width: 220rpx; |
|||
margin-bottom: 60rpx; |
|||
} |
|||
} |
|||
</style> |
|||
.login { |
|||
width: 100%; |
|||
height: 100vh; |
|||
overflow: hidden; |
|||
position: relative; |
|||
text-align: center; |
|||
box-sizing: border-box; |
|||
padding: 500rpx 30rpx 0; |
|||
background-color: #fff; |
|||
|
|||
.logo-img { |
|||
width: 220rpx; |
|||
margin-bottom: 60rpx; |
|||
} |
|||
} |
|||
</style> |
|||
Loading…
Reference in new issue