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