静默登录二次修改

This commit is contained in:
duan
2024-07-19 11:11:59 +08:00
parent 0faa782b00
commit 0d0d0d26ae
2 changed files with 60 additions and 12 deletions

48
App.vue
View File

@@ -1,3 +1,6 @@
<template>
<button v-show="false" open-type="getPhoneNumber" @getphonenumber="userlogin"> </button>
</template>
<script>
export default {
onLaunch: function() {
@@ -5,6 +8,9 @@
uni.cache.set('menuInfo', uni.getMenuButtonBoundingClientRect());
// #endif
uni.cache.set('NAME', '零点八零');
this.userlogin()
},
onLoad(){
},
onShow: function() {
this.$store.dispatch("HeightActions"); //获取随时获取页面的高度
@@ -12,6 +18,48 @@
},
onHide: function() {
// console.log('App Hide');
},
methods:{
async userlogin(reslange) {
var resdataa = reslange
uni.login({
provider: 'weixin',
success: async (data) => {
try {
uni.getUserInfo({
provider: 'weixin',
success: async (infoRes) => {
uni.cache.set('weixincode', data.code);
let res = await this.api.userwxlogin({
code: uni.cache.get('weixincode'), //临时登录凭证
rawData: infoRes.rawData,
// signature: infoRes.signature,
// iv: infoRes.detail.iv,
// encryptedData: infoRes.detail
// .encryptedData
})
if (res.code == 0) {
uni.cache.set('token', res.data.token);
uni.cache.set('miniAppOpenId', res.data.userInfo
.miniAppOpenId)
uni.cache.set('userInfo', res.data.userInfo);
if (uni.cache.get('types') == 'types') {
uni.reLaunch({
url: '/pages/order_food/order_food'
});
} else {
uni.pro.switchTab('index/index')
}
}
},
fail: (err) => {}
});
} catch (e) {}
}
});
},
}
};
</script>