Merge pull request '登录组件封装' (#46) from chenxuelian into dev

Reviewed-on: http://git.hchyun.com/feashow/pupil/pulls/46
This commit is contained in:
1171906056
2023-01-06 14:20:15 +00:00
2 changed files with 108 additions and 35 deletions

View File

@@ -95,11 +95,21 @@
</view> </view>
</view> </view>
</u--form> </u--form>
<view>
<u-overlay :show="!isLoad">
<login @success="reOnLoad()" @fail="failToLoad()"></login>
</u-overlay>
</view>
</view> </view>
</template> </template>
<script> <script>
import login from '../my/login/login.vue'
export default { export default {
components: {
login
},
data() { data() {
return { return {
tabsList: [{ tabsList: [{
@@ -134,7 +144,8 @@
categoryPickerList: [ categoryPickerList: [
['类别1', '类别', '类别'] ['类别1', '类别', '类别']
], ],
fileList1: [] fileList1: [],
isLoad: true
} }
}, },
onLoad(options) { onLoad(options) {
@@ -144,6 +155,15 @@
} else if (options.index == 1) { } else if (options.index == 1) {
this.tabCurrent = 1 this.tabCurrent = 1
} }
if (!uni.getStorageSync('token') || uni.getStorageSync('token').length === 0) {
console.log(uni.getStorageSync('token'))
this.isLoad = false
// uni.navigateTo({
// url: '../../pages/my/login/login'
// })
return
}
this.isLoad = true
}, },
methods: { methods: {
tabChange(data) { tabChange(data) {
@@ -230,6 +250,22 @@
// }); // });
// }) // })
}, },
reOnLoad() {
console.log('----------------true')
if (!uni.getStorageSync('token') || uni.getStorageSync('token').length === 0) {
this.$toast.warn('登录失败请重试')
this.isLoad = false
// uni.navigateTo({
// url: '../../pages/my/login/login'
// })
return
}
this.isLoad = true
},
failToLoad() {
console.log('----------------false')
this.$toast.warn('登录失败请重试')
}
} }
} }
</script> </script>

View File

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