115 lines
2.2 KiB
Vue
115 lines
2.2 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="getUserInfo" @getuserinfo="getUserInfo">授权登录</nut-button>
|
||
</view>
|
||
<view class="authorize-btn-inner">
|
||
<nut-button type="danger" size="large" @click="switchTab('/pages/index/index')">暂不登录</nut-button>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import {
|
||
onMounted,
|
||
ref
|
||
} from 'vue';
|
||
import {
|
||
login
|
||
} from '@/api/user';
|
||
import {
|
||
onLoad
|
||
} from '@dcloudio/uni-app'
|
||
import {
|
||
navigateTo,
|
||
switchTab
|
||
} 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 getUserInfo = (res) => {
|
||
if (code.value === '') {
|
||
uni.showToast({
|
||
icon: 'none',
|
||
title: '请稍后再试'
|
||
})
|
||
return;
|
||
}
|
||
login(code.value, JSON.stringify(res.detail.userInfo)).then(res => {
|
||
console.log(res);
|
||
uni.setStorageSync('token', res.token)
|
||
uni.setStorageSync('uid', res.user_id)
|
||
if(res.is_bind_phone){
|
||
navigateTo('/pages/login/phoneAuthorization');
|
||
return
|
||
}
|
||
uni.showToast({
|
||
title: '授权成功',
|
||
icon: 'none'
|
||
})
|
||
if (redirect_url.value !== 'undefined') {
|
||
navigateTo(redirect_url.value)
|
||
} else {
|
||
uni.navigateBack()
|
||
}
|
||
})
|
||
}
|
||
</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> |