This commit is contained in:
魏啾
2024-07-19 17:57:00 +08:00
parent a0baa5b59a
commit 194497eed2
2 changed files with 53 additions and 21 deletions

41
App.vue
View File

@@ -19,29 +19,32 @@
// console.log('App Hide'); // console.log('App Hide');
}, },
methods: { methods: {
userlogin() { async userlogin() {
uni.login({ uni.login({
provider: 'weixin', provider: 'weixin',
success: (data) => { success: async (data) => {
uni.getUserInfo({ try {
provider: 'weixin', uni.getUserInfo({
success: (infoRes) => { provider: 'weixin',
uni.cache.set('weixincode', data.code); success: async (infoRes) => {
let res = this.api.userwxlogin({ uni.cache.set('weixincode', data.code);
code: uni.cache.get('weixincode'), //临时登录凭证 let res = await this.api.userwxlogin({
rawData: infoRes.rawData, code: uni.cache.get('weixincode'), //临时登录凭证
}) rawData: infoRes.rawData
if (res.code == 0) { })
uni.cache.set('token', res.data.token); if (res.code == 0) {
uni.cache.set('miniAppOpenId', res.data.userInfo uni.cache.set('token', res.data.token);
.miniAppOpenId) uni.cache.set('miniAppOpenId', res.data.userInfo
uni.cache.set('userInfo', res.data.userInfo); .miniAppOpenId)
} uni.cache.set('userInfo', res.data.userInfo);
}, }
fail: (err) => {} },
}); fail: (err) => {}
});
} catch (e) {}
} }
}); });
}, },
} }

View File

@@ -322,8 +322,37 @@
this.fixedtrue = true this.fixedtrue = true
}, },
onShow() { onShow() {
uni.$on('message', this.getMessage) if (!uni.cache.get('token')) {
this.productqueryShopIdByTableCode() //获取shop User id 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
})
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);
uni.$on('message', this.getMessage)
this.productqueryShopIdByTableCode() //获取shop User id
}
},
fail: (err) => {}
});
} catch (e) {}
}
});
} else {
uni.$on('message', this.getMessage)
this.productqueryShopIdByTableCode() //获取shop User id
}
}, },
methods: { methods: {
onEnd() { //回调弹幕 onEnd() { //回调弹幕