This commit is contained in:
魏啾
2024-07-19 13:42:14 +08:00
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> <script>
export default { export default {
onLaunch: function() { onLaunch: function() {
@@ -5,6 +8,9 @@
uni.cache.set('menuInfo', uni.getMenuButtonBoundingClientRect()); uni.cache.set('menuInfo', uni.getMenuButtonBoundingClientRect());
// #endif // #endif
uni.cache.set('NAME', '零点八零'); uni.cache.set('NAME', '零点八零');
this.userlogin()
},
onLoad(){
}, },
onShow: function() { onShow: function() {
this.$store.dispatch("HeightActions"); //获取随时获取页面的高度 this.$store.dispatch("HeightActions"); //获取随时获取页面的高度
@@ -12,6 +18,48 @@
}, },
onHide: function() { onHide: function() {
// console.log('App Hide'); // 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> </script>

View File

@@ -103,19 +103,19 @@ async function request(options) {
// #endif // #endif
if (res.code != 0) { if (res.code != 0) {
if (res.code == -4) { if (res.code == -4) {
uni.showToast({ // uni.showToast({
title: res.message || res.msg, // title: res.message || res.msg,
icon: "none", // icon: "none",
success: () => { // success: () => {
setTimeout(res => { // setTimeout(res => {
uni.cache.set('token', ''); // uni.cache.set('token', '');
uni.redirectTo({ // uni.redirectTo({
url: '/pages/login/login' // url: '/pages/login/login'
}); // });
}, 1000) // }, 1000)
} // }
}) // })
} else if (res.code == 482) { } else if (res.code == 482) {
let nowTime = new Date() / 1000 | 0 let nowTime = new Date() / 1000 | 0
let offset = parseInt(res.data.message) - parseInt(nowTime); let offset = parseInt(res.data.message) - parseInt(nowTime);