83 lines
2.0 KiB
Vue
83 lines
2.0 KiB
Vue
![]() |
<template>
|
||
|
<view class="container" style="padding-top:250rpx">
|
||
|
<view>{{tel}}</view>
|
||
|
<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机获取</button>
|
||
|
</view>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
export default {
|
||
|
data() {
|
||
|
return {}
|
||
|
},
|
||
|
computed: {
|
||
|
tel() {
|
||
|
return this.$store.state.userInfo.tel
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
//手机获取
|
||
|
getPhoneNumber(e) {
|
||
|
if (e.detail.errMsg === "getPhoneNumber:ok") {
|
||
|
uni.$u.http.post('/Api/Check/getPhoneNumber', {
|
||
|
iv: e.detail.iv, //解密偏移向量
|
||
|
encryptedData: e.detail.encryptedData //手机加密信息
|
||
|
}, {
|
||
|
header: {
|
||
|
'Token': this.$store.state.userInfo.token,
|
||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||
|
}
|
||
|
}).then(res => {
|
||
|
// 处理成功获取手机号后的逻辑
|
||
|
if (res.data.status === 1) {
|
||
|
let userInfo
|
||
|
//把电话写入 用户信息缓存
|
||
|
uni.getStorage({
|
||
|
key: 'userInfo',
|
||
|
success: (resU) => {
|
||
|
userInfo = resU.data
|
||
|
userInfo.tel = res.data.phoneNumber
|
||
|
uni.setStorage({
|
||
|
key: 'userInfo',
|
||
|
data: userInfo,
|
||
|
success: () => {
|
||
|
//登录成功后 把用户信息提取到内存
|
||
|
this.$store.commit('setUserInfo', userInfo)
|
||
|
uni.showToast({
|
||
|
title: '获取手机号成功',
|
||
|
duration: 2000
|
||
|
})
|
||
|
setTimeout(() => {
|
||
|
uni.navigateBack()
|
||
|
}, 2000) // 与 showToast 的 duration 保持一致
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
} else {
|
||
|
console.log(res)
|
||
|
// uni.showToast({
|
||
|
// title: res.data.msg,
|
||
|
// icon: 'error',
|
||
|
// duration: 2000
|
||
|
// })
|
||
|
}
|
||
|
}).catch(err => {
|
||
|
uni.showToast({
|
||
|
title: '获取手机号失败',
|
||
|
icon: 'error',
|
||
|
duration: 2000
|
||
|
})
|
||
|
})
|
||
|
} else {
|
||
|
// 用户拒绝获取手机号
|
||
|
console.log('用户拒绝获取手机号')
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style>
|
||
|
|
||
|
</style>
|