|
@@ -14,8 +14,8 @@
|
|
|
</u-cell-group>
|
|
|
<u-button type="warning" :ripple="true" :custom-style="{...customStyle, margin: '10px 0'}" @click="login()">登录</u-button>
|
|
|
<u-button type="warning" :ripple="true" :custom-style="{...customStyle, margin: '10px 0'}" @click="login1()">app微信授权登录</u-button>
|
|
|
- <u-button type="warning" :ripple="true" :custom-style="{...customStyle, backgroundColor: '#07c160'}" open-type="getUserInfo"
|
|
|
- @getuserinfo="getUserinfoWechat" withCredentials="true">微信一键登录</u-button>
|
|
|
+ <u-button type="warning" :ripple="true" :custom-style="{...customStyle, backgroundColor: '#07c160'}" open-type="getPhoneNumber"
|
|
|
+ @getphonenumber="getUserinfoWechat" withCredentials="true">微信一键登录</u-button>
|
|
|
</view>
|
|
|
</u-card>
|
|
|
<u-top-tips ref="uTips"></u-top-tips>
|
|
@@ -83,54 +83,40 @@
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
- login1() {
|
|
|
+ loginApp() {
|
|
|
let that = this
|
|
|
uni.login({
|
|
|
provider: 'weixin',
|
|
|
- success: function(loginRes) {
|
|
|
+ success: (loginRes) => {
|
|
|
uni.getUserInfo({
|
|
|
provider: 'weixin',
|
|
|
- success: function(infoRes) {
|
|
|
- }
|
|
|
+ success: (infoRes) => {}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
getUserinfoWechat(data) {
|
|
|
- uni.getProvider({
|
|
|
- service: 'oauth',
|
|
|
+ uni.login({
|
|
|
+ provider: 'weixin',
|
|
|
success: (res) => {
|
|
|
- if (~res.provider.indexOf('weixin')) {
|
|
|
- uni.login({
|
|
|
- provider: 'weixin',
|
|
|
- success: (res2) => {
|
|
|
- let wxLoginData = {
|
|
|
- code: res2.code,
|
|
|
- encryptedData: data.detail.encryptedData,
|
|
|
- iv: data.detail.iv,
|
|
|
- shareParams: uni.getStorageSync('shareParams')
|
|
|
- }
|
|
|
- uni.setStorage({
|
|
|
- key: 'wxLoginData',
|
|
|
- data: wxLoginData
|
|
|
- })
|
|
|
- this.getUserInfo(wxLoginData)
|
|
|
- },
|
|
|
- fail: () => {
|
|
|
- this.$refs.uTips.show({
|
|
|
- title: '微信登录授权失败',
|
|
|
- type: 'warning',
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.$refs.uTips.show({
|
|
|
- title: '请先安装微信或升级版本',
|
|
|
- type: 'warning',
|
|
|
- })
|
|
|
+ let wxLoginData = {
|
|
|
+ code: res.code,
|
|
|
+ encryptedData: data.target.encryptedData,
|
|
|
+ iv: data.target.iv,
|
|
|
}
|
|
|
+ uni.setStorage({
|
|
|
+ key: 'wxLoginData',
|
|
|
+ data: wxLoginData
|
|
|
+ })
|
|
|
+ this.getUserInfo(wxLoginData)
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ this.$refs.uTips.show({
|
|
|
+ title: '微信登录授权失败',
|
|
|
+ type: 'warning',
|
|
|
+ })
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
},
|
|
|
// 发请求获取个人数据
|
|
|
getUserInfo(wxLoginData) {
|