94 lines
2.4 KiB
Vue
94 lines
2.4 KiB
Vue
<template>
|
||
<view style="width: 100%;position: absolute;bottom: 0; padding-top: 30rpx; background-color: #fff;">
|
||
<view style="padding-left: 30rpx;padding-right: 30rpx;">
|
||
<u-button open-type="getPhoneNumber" size="medium" class="custom-style" @getphonenumber="getphonenumber"
|
||
color='#12CA64'>登录</u-button>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import {
|
||
loginSys
|
||
} from '@/service/request.js'
|
||
export default {
|
||
data() {
|
||
return {}
|
||
},
|
||
methods: {
|
||
getphonenumber(e) {
|
||
var that = this
|
||
console.log(e)
|
||
if (e.detail.errMsg === 'getPhoneNumber:ok') {
|
||
//调用接口利用 e.detail.encryptedData, e.detail.iv 信息来解密手机号
|
||
uni.login({
|
||
"provider": "weixin",
|
||
"onlyAuthorize": true, // 微信登录仅请求授权认证
|
||
success: function(event) {
|
||
const {
|
||
code
|
||
} = event
|
||
that.$apiServe.login({
|
||
code: code
|
||
}).then(res => {
|
||
var data = res.data.data
|
||
// console.log('登录code换取的信息', data);
|
||
uni.setStorageSync('token', data.token);
|
||
that.$toast.success('登录成功')
|
||
that.$emit('success')
|
||
})
|
||
},
|
||
fail: function(err) {
|
||
// 登录授权失败
|
||
// err.code是错误码
|
||
that.$emit('fail')
|
||
}
|
||
})
|
||
} else {
|
||
// 拒绝授权
|
||
that.$emit('fail')
|
||
}
|
||
}
|
||
// getphonenumber(e) {
|
||
// const {
|
||
// phoneCode
|
||
// } = e.detail;
|
||
// console.log("手机code : ", phoneCode);
|
||
// uni.login({
|
||
// "provider": "weixin",
|
||
// "onlyAuthorize": true, // 微信登录仅请求授权认证
|
||
// success: function(event) {
|
||
// const {
|
||
// code
|
||
// } = event
|
||
|
||
// console.log("登录code", code);
|
||
// //客户端成功获取授权临时票据(code),向业务服务器发起登录请求。
|
||
|
||
|
||
// // 调用登录接口 拿到token 传手机code,更新手机号码
|
||
// loginSys(code).then(res => {
|
||
// console.log(res);
|
||
|
||
// //登录完成后使用手机code换取手机号,调用/user/getMobileByMnp接口
|
||
// //接口详细链接 https://docs.apipost.cn/preview/468be606f65cae75/3f2f988ddf82dd8e
|
||
// })
|
||
// },
|
||
// fail: function(err) {
|
||
// // 登录授权失败
|
||
// // err.code是错误码
|
||
// }
|
||
// })
|
||
// },
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="less" scoped>
|
||
.custom-style {
|
||
width: 200rpx;
|
||
padding-left: 30rpx;
|
||
padding-right: 30rpx;
|
||
}
|
||
</style>
|