108 lines
1.9 KiB
Vue
108 lines
1.9 KiB
Vue
<template>
|
|
<!-- <view class="content">
|
|
<view class="avatar">
|
|
<nut-avatar size="80">
|
|
<nut-icon size="30" name="my" />
|
|
</nut-avatar>
|
|
</view>
|
|
<view class="divider">
|
|
</view>
|
|
</view> -->
|
|
|
|
<view class="tip-infos">
|
|
<text>申请获取以下权限</text>
|
|
<text>获得你的手机号信息</text>
|
|
</view>
|
|
<view class="authorize-btn-inner">
|
|
<nut-button type="success" size="large" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">授权手机号</nut-button>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import {
|
|
onMounted,
|
|
ref
|
|
} from 'vue';
|
|
import {
|
|
login,
|
|
fetchUserPhone
|
|
} from '../../api/user';
|
|
import {
|
|
onLoad
|
|
} from '@dcloudio/uni-app'
|
|
import {
|
|
navigateTo
|
|
} from '../../utils/helper';
|
|
const code = ref('')
|
|
const redirect_url = ref('')
|
|
onLoad((options) => {
|
|
redirect_url.value = options.redirect_url
|
|
})
|
|
onMounted(() => {
|
|
uni.login({
|
|
provider: "weixin",
|
|
success(res) {
|
|
if (res.errMsg === 'login:ok') {
|
|
code.value = res.code
|
|
}
|
|
}
|
|
})
|
|
})
|
|
const getPhoneNumber = (res) => {
|
|
if(res.detail.code){
|
|
fetchUserPhone(res.detail.code).then(res=>{
|
|
console.log(res);
|
|
if(res.msg==='success' && res.code ===1){
|
|
uni.showToast({
|
|
title: '授权成功',
|
|
icon: 'none'
|
|
})
|
|
console.log("code");
|
|
uni.switchTab({
|
|
url: '/pages/mine/index'
|
|
})
|
|
// uni.navigateBack()
|
|
}else{
|
|
uni.switchTab({
|
|
url: '/pages/mine/index'
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
}
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.divider {
|
|
height: 1px;
|
|
background: #eee;
|
|
width: 100%;
|
|
}
|
|
|
|
.content {
|
|
display: flex;
|
|
justify-content: center;
|
|
flex-direction: column;
|
|
padding: 25px 15px;
|
|
align-items: center;
|
|
gap: 20px;
|
|
}
|
|
|
|
.tip-infos {
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: flex-start;
|
|
padding: 10px 25px;
|
|
gap: 10px;
|
|
|
|
text:nth-child(2) {
|
|
font-size: 15px;
|
|
color: #666;
|
|
}
|
|
}
|
|
|
|
.authorize-btn-inner {
|
|
padding: 15px;
|
|
}
|
|
</style> |