From d82bd93033f9abfb134d92beaee706134ec7ccdf Mon Sep 17 00:00:00 2001 From: GaoHao <1210693421@qq.com> Date: Thu, 8 Aug 2024 16:02:54 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=85=85=E5=80=BC=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=85=85=E5=80=BC?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=A2=9E=E5=8A=A0=E5=BC=80=E9=80=9A=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/indexs.vue | 5 +- pages/member/activatedmemberone.vue | 3 +- pages/member/index.vue | 157 ++++++++++++++++++++++++++-- 3 files changed, 154 insertions(+), 11 deletions(-) diff --git a/pages/index/indexs.vue b/pages/index/indexs.vue index 0dba44e..25d6b33 100644 --- a/pages/index/indexs.vue +++ b/pages/index/indexs.vue @@ -87,8 +87,9 @@ url: '/pages/member/activatedmemberone?shopId=' + uni.cache.get('shopUser') }) } else { - uni.pro.navigateTo('member/memberdetails', { - shopId_id: uni.cache.get('shopUser'), + uni.pro.navigateTo('member/index', { + shopId: uni.cache.get('shopUser'), + type: 'index', }) } } else { diff --git a/pages/member/activatedmemberone.vue b/pages/member/activatedmemberone.vue index 66539e9..838cec3 100644 --- a/pages/member/activatedmemberone.vue +++ b/pages/member/activatedmemberone.vue @@ -41,7 +41,8 @@ this.switchdata = false uni.cache.set('userInfo', resdata .data); uni.pro.redirectTo('/pages/member/index', { - shopId: uni.cache.get('shopUser') + shopId: this.shopId, + type: 'index' }) } diff --git a/pages/member/index.vue b/pages/member/index.vue index c159a44..afa681d 100644 --- a/pages/member/index.vue +++ b/pages/member/index.vue @@ -16,6 +16,15 @@ 立即充值 + + + + + + + + + @@ -31,20 +40,121 @@ listdata: [], amount: '', userInfo: {}, - shopId: '' + shopId: '', + tokenShow: true, + memberOpen: false, + usershopUserinfo: null, } }, onLoad(e) { - this.shopId = e.shopId - if (e.type == 'list') { //从列表进来的 - this.paygetShopByMember(e.shopId) - } else { - this.paygetShopByMember(e.shopId) + console.log(e) + if ( e.type == 'list' || e.type == 'index') { + this.shopId = e.shopId; + this.init(); } - this.paygetActive(e.shopId) //列表 - + if (e.q) { + this.shopId = this.getQueryString(decodeURIComponent(e.q), 'shopId') + if (!uni.cache.get('token')) { + 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); + this.tokenShow = false; + this.init(); + } + }, + fail: (err) => {} + }); + } catch (e) {} + } + }); + } else { + this.init(); + } + } + console.log(this.shopId) }, methods: { + async init() { + let res = await this.api.shopUserInfo({ + "shopId": this.shopId, + "userId": uni.cache.get('userInfo').id, + }) + if (res.code == 0) { + this.usershopUserinfo = res.data + } + if ( this.usershopUserinfo.isVip == 0 ) { + this.memberOpen = true; + return; + } + this.paygetShopByMember(this.shopId) + this.paygetActive() + }, + memberCancel () { + let pages = getCurrentPages() + if ( pages.length > 1) { + uni.navigateBack() + } else { + uni.exitMiniProgram({ + success: function () { + console.log('退出成功'); + }, + fail: function () { + console.log('退出失败'); + } + }); + } + + }, + sumbit(d) { + if (d.detail.iv) { + uni.login({ + provider: 'weixin', + success: async (data) => { + let res = await this.api.userwxlogins({ + code: data.code, + encryptedData: d.detail.encryptedData, + iv: d.detail.iv, + shopId: this.shopId + }) + if (res.code == 0) { + let resdata = await this.api.loginwxuserInfo({ + userId: uni.cache.get('userInfo').id + }) + if (resdata.code == 0) { + uni.cache.set('userInfo', resdata .data); + this.memberOpen = false + this.paygetShopByMember(this.shopId) + this.paygetActive() + } + + + } + } + }) + } + }, + getQueryString(url, name) { //解码 + var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i') + var r = url.substr(1).match(reg) + if (r != null) { + return r[2] + } + return null; + }, async paygetShopByMember(w) { let res = await this.api.paygetShopByMember({ page: 1, @@ -60,6 +170,7 @@ page: 1, pageSize: 10 }) + try { this.listdata = res.data.list this.amount = res.data.list[0].minNum @@ -328,5 +439,35 @@ border-radius: 8rpx; background: #F1CB66; } + .imgstyle { + width: 694rpx; + height: 414rpx; + margin: 70rpx auto; + } + + .btnclass { + width: 694rpx; + height: 90rpx; + line-height: 90rpx; + background: #6D89A4; + border-radius: 12rpx 12rpx 12rpx 12rpx; + text-align: center; + margin: auto; + font-family: PingFang SC, PingFang SC; + font-weight: bold; + font-size: 36rpx; + color: #FFFFFF; + bottom: 50rpx; + position: absolute; + left: 0; + right: 0; + margin: auto; + + } + .u-popup-content { + height: 80vh; /* 设置高度为视口高度的50% */ + width: 100%; + /* 其他样式 */ + } } \ No newline at end of file From b67f1381ca2ab3e609c9c2eeabd45cce5cb0ff44 Mon Sep 17 00:00:00 2001 From: GaoHao <1210693421@qq.com> Date: Thu, 8 Aug 2024 17:06:26 +0800 Subject: [PATCH 2/5] *** --- common/js/api.js | 2 +- framework/0-conf.js | 8 ++-- pages/member/index.vue | 19 ++++++-- pages/order_food/order_food.vue | 82 ++++++++++++--------------------- 4 files changed, 51 insertions(+), 60 deletions(-) diff --git a/common/js/api.js b/common/js/api.js index 05e8744..8d7b8a6 100644 --- a/common/js/api.js +++ b/common/js/api.js @@ -166,7 +166,7 @@ export default { return uni.api.get("/product/queryShopIdByTableCode", data); }, geocodelocation(data) { //根据经纬度获取信息 - return uni.api.get("/location/geocode", data); + return uni.api.get("/location/geocode", data, false); }, // 修改头像和昵称 upUserInfo(data) { diff --git a/framework/0-conf.js b/framework/0-conf.js index a9b4c7d..ab5aecc 100644 --- a/framework/0-conf.js +++ b/framework/0-conf.js @@ -16,11 +16,11 @@ const baseUrlwws = 'ws://cashier.sxczgkj.cn/cashierService' // #endif // #ifdef APP || MP-WEIXIN -const baseUrl = debug ? proxyApi : 'https://cashier.sxczgkj.cn/cashierService' // 线上 -const baseUrlwws = debug ? proxyApiwws : 'wss://cashier.sxczgkj.cn/netty' // 线上 +// const baseUrl = debug ? proxyApi : 'https://cashier.sxczgkj.cn/cashierService' // 线上 +// const baseUrlwws = debug ? proxyApiwws : 'wss://cashier.sxczgkj.cn/netty' // 线上 -// const baseUrl = 'https://cashier.sxczgkj.cn/cashierService' // 线上 -// const baseUrlwws = 'wss://cashier.sxczgkj.cn/netty' // 线上/ +const baseUrl = 'https://cashier.sxczgkj.cn/cashierService' // 线上 +const baseUrlwws = 'wss://cashier.sxczgkj.cn/netty' // 线上/ // #endif // import VConsole from "./vConsole.js" diff --git a/pages/member/index.vue b/pages/member/index.vue index afa681d..605f666 100644 --- a/pages/member/index.vue +++ b/pages/member/index.vue @@ -216,9 +216,22 @@ title: "支付成功" }) uni.hideLoading() - setTimeout(res => { - uni.navigateBack() - }, 500) + let pages = getCurrentPages() + if ( pages.length > 1) { + setTimeout(res => { + uni.navigateBack() + }, 500) + } else { + uni.exitMiniProgram({ + success: function () { + console.log('退出成功'); + }, + fail: function () { + console.log('退出失败'); + } + }); + } + }, fail: (res) => { uni.hideLoading() diff --git a/pages/order_food/order_food.vue b/pages/order_food/order_food.vue index 1c9115d..d294b50 100644 --- a/pages/order_food/order_food.vue +++ b/pages/order_food/order_food.vue @@ -424,38 +424,33 @@ scrollTop: 0, duration: 0 }); - if (!uni.cache.get('token')) { - 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.getLocation() - } - }, - fail: (err) => {} - }); - } catch (e) {} - } - }); - } else { - uni.$on('message', this.getMessage) - _this.getLocation() - } + 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.getLocation() + } + }, + fail: (err) => {} + }); + } catch (e) {} + } + }); }, methods: { navigateBacknav() { @@ -508,24 +503,7 @@ }, fail: async (err) => { console.log(err, '获取错误') //测试用于app - let successres = await this.api.geocodelocation({ - lng: '', - lat: '', - }) - if (successres.code == 0) { - console.log(successres.data.addressComponent.streetNumber.location.split(',')) - let res = successres.data.addressComponent.streetNumber.location.split(',') - let datastorage = { - country: successres.data.addressComponent.country, // "中国" - province: successres.data.addressComponent.province, //province: "陕西省" - address: successres.data.addressComponent.city, //district: "西安市" - district: successres.data.addressComponent.district, //district: "未央区" - lng: res[0], - lat: res[1], - } - uni.cache.set('getLocationstorage', datastorage); - this.productqueryShop(); - } + this.productqueryShop(); } }); }, @@ -536,8 +514,8 @@ async productqueryShop() { let res = await this.api.productqueryShop({ code: uni.cache.get('tableCode'), - lng: uni.cache.get('getLocationstorage').lng, - lat: uni.cache.get('getLocationstorage').lat, + lng: uni.cache.get('getLocationstorage').lng?uni.cache.get('getLocationstorage').lng:'', + lat: uni.cache.get('getLocationstorage').lat? uni.cache.get('getLocationstorage').lat:'', }) if (res.code == 0) { uni.cache.set('shopUser', res.data.storeInfo.id) From c00e084a09f59e2f7c0cedf6553efbad03b6d835 Mon Sep 17 00:00:00 2001 From: GaoHao <1210693421@qq.com> Date: Thu, 8 Aug 2024 18:07:55 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=94=AF=E4=BB=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/member/index.vue | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pages/member/index.vue b/pages/member/index.vue index 605f666..8911881 100644 --- a/pages/member/index.vue +++ b/pages/member/index.vue @@ -222,14 +222,11 @@ uni.navigateBack() }, 500) } else { - uni.exitMiniProgram({ - success: function () { - console.log('退出成功'); - }, - fail: function () { - console.log('退出失败'); - } - }); + setTimeout(res => { + uni.switchTab({ + url: '/pages/index/index' + }) + }, 500) } }, From 8ca9a7377550f714cfabf3f6a0a5aa653e66ccf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=95=BE?= <1144797966@qq.com> Date: Thu, 8 Aug 2024 18:18:22 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E7=99=BB=E5=BD=95=20=20=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=20=20=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 41 ++++++++--- framework/11-api.js | 25 ++++--- pages/order_food/order_food.vue | 122 ++++++++++++++++---------------- 3 files changed, 104 insertions(+), 84 deletions(-) diff --git a/App.vue b/App.vue index 6b41c6c..1cdc5c0 100644 --- a/App.vue +++ b/App.vue @@ -1,5 +1,4 @@ diff --git a/framework/11-api.js b/framework/11-api.js index 489545c..e3ffbba 100644 --- a/framework/11-api.js +++ b/framework/11-api.js @@ -104,19 +104,18 @@ async function request(options) { if (res.code != 0) { console.log(options) if (res.code == -4) { - // uni.showToast({ - // title: '', - // // title: res.message || res.msg, - // icon: "none", - // success: () => { - // setTimeout(res => { - // store.dispatch("loginEvent"); //获取shapid - // }, 1000) - // } - // }) - setTimeout(res => { - store.dispatch("loginEvent"); //获取shapid - }, 1000) + uni.showToast({ + title: res.message || res.msg, + icon: "none", + success: () => { + // setTimeout(res => { + // store.dispatch("loginEvent"); //获取shapid + // }, 1000) + } + }) + // setTimeout(res => { + // store.dispatch("loginEvent"); //获取shapid + // }, 1000) } else if (res.code == 482) { let nowTime = new Date() / 1000 | 0 let offset = parseInt(res.data.message) - parseInt(nowTime); diff --git a/pages/order_food/order_food.vue b/pages/order_food/order_food.vue index d294b50..6766b67 100644 --- a/pages/order_food/order_food.vue +++ b/pages/order_food/order_food.vue @@ -110,10 +110,11 @@ - - TOP{{index1+1}} @@ -277,7 +278,7 @@ {{item.name}} - + @@ -389,15 +390,6 @@ this.$store.getters.is_BarHeight.customBar) } }, - onReady() { - // setTimeout(() => { - // uni.getSystemInfo({ - // success: (data) => { - // this.scrollHeight = data.windowHeight - // } - // }) - // }, 100); - }, onLoad(e) { if (e.q) { this.tableCode = this.getQueryString(decodeURIComponent(e.q), 'code') @@ -442,7 +434,7 @@ .miniAppOpenId) uni.cache.set('userInfo', res.data.userInfo); uni.$on('message', this.getMessage) - + _this.getLocation() } }, @@ -476,36 +468,40 @@ "type": "connect", }) }, - + /** * 获取定位 */ - getLocation () { - uni.getLocation({ - type: 'wgs84', - success: async (res) => { - let successres = await this.api.geocodelocation({ - lng: res.longitude, - lat: res.latitude, - }) - if (successres.code == 0) { - let datastorage = { - country: successres.data.addressComponent.country, // "中国" - province: successres.data.addressComponent.province, //province: "陕西省" - address: successres.data.addressComponent.city, //district: "西安市" - district: successres.data.addressComponent.district, //district: "未央区" + getLocation() { + try { + uni.getLocation({ + type: 'wgs84', + success: async (res) => { + let successres = await this.api.geocodelocation({ lng: res.longitude, lat: res.latitude, + }) + if (successres.code == 0) { + let datastorage = { + country: successres.data.addressComponent.country, // "中国" + province: successres.data.addressComponent.province, //province: "陕西省" + address: successres.data.addressComponent.city, //district: "西安市" + district: successres.data.addressComponent.district, //district: "未央区" + lng: res.longitude, + lat: res.latitude, + } + uni.cache.set('getLocationstorage', datastorage); + this.productqueryShop(); } - uni.cache.set('getLocationstorage', datastorage); + }, + fail: async (err) => { this.productqueryShop(); } - }, - fail: async (err) => { - console.log(err, '获取错误') //测试用于app - this.productqueryShop(); - } - }); + }); + } catch (e) { + this.productqueryShop(); + //TODO handle the exception + } }, /** @@ -514,8 +510,10 @@ async productqueryShop() { let res = await this.api.productqueryShop({ code: uni.cache.get('tableCode'), - lng: uni.cache.get('getLocationstorage').lng?uni.cache.get('getLocationstorage').lng:'', - lat: uni.cache.get('getLocationstorage').lat? uni.cache.get('getLocationstorage').lat:'', + lng: uni.cache.get('getLocationstorage').lng ? uni.cache.get('getLocationstorage').lng : + '', + lat: uni.cache.get('getLocationstorage').lat ? uni.cache.get('getLocationstorage').lat : + '', }) if (res.code == 0) { uni.cache.set('shopUser', res.data.storeInfo.id) @@ -529,18 +527,18 @@ } }, - + /** * 图片加载 */ - imageLoaded (item,index,index1) { + imageLoaded(item, index, index1) { console.log(index) console.log(index1) console.log(this.shopProductList.productInfo[index]) this.shopProductList.productInfo[index].products[index1]['imgLoad'] = true; // e.currentTarget.src }, - + /** * 商品数量增加/减少 * @param {Object} item @@ -735,7 +733,7 @@ start: -1, children: [] } - item.value.split(",").forEach((v,e)=>{ + item.value.split(",").forEach((v, e) => { res.children.push({ name: v, isGrounding: false @@ -743,7 +741,7 @@ }) return res }) - + //初始化第一列规格可编辑 let filteredJson; let isSkuidname = []; @@ -756,14 +754,14 @@ console.log(filteredJson); for (let i = 0; i < filteredJson.length; i++) { console.log(filteredJson[i].isGrounding) - if ( filteredJson[i].isGrounding ) { + if (filteredJson[i].isGrounding) { this.specifications.tagSnap[0].children[o].isGrounding = true break; // 终止循环 } } - + } - + this.skuBtnText = `您还没选择${this.specifications.tagSnap[0].name}哦` // this.specifications.tagSnap.forEach((val, index, arr) => { //初始化skuidname的数据 选择第一个 @@ -787,7 +785,7 @@ * @param {Object} item */ async morloe(e, index, index1, item) { - if ( !e.isGrounding ) { + if (!e.isGrounding) { return; } @@ -801,18 +799,18 @@ } this.skuidname = []; this.specifications.tagSnap.forEach((val, i, arr) => { //初始化skuidname的数据 选择第一个 - if ( i > index ) { - val.children.forEach(( v1,e1)=>{ + if (i > index) { + val.children.forEach((v1, e1) => { v1.isGrounding = false; }) val.start = -1; } - if ( val.start >= 0 ) { + if (val.start >= 0) { this.skuidname.push(val.children[val.start].name) } }) // this.skuidname.splice(index, 1, e.info); //替换skuidname的数据 - + for (let i = 0; i < this.specifications.tagSnap.length; i++) { if (this.specifications.tagSnap[i].start < 0) { this.isSpec = false; @@ -820,36 +818,36 @@ break; // 终止循环 } } - - + + let filteredJson; let isSkuidname = []; //提前下一列规格循环,查看是否有下架规格 - if ( this.specifications.tagSnap[index+1] ) { - for (let o = 0; o < this.specifications.tagSnap[index+1].children.length; o++) { + if (this.specifications.tagSnap[index + 1]) { + for (let o = 0; o < this.specifications.tagSnap[index + 1].children.length; o++) { isSkuidname = JSON.parse(JSON.stringify(this.skuidname)); - isSkuidname.push(this.specifications.tagSnap[index+1].children[o].name) + isSkuidname.push(this.specifications.tagSnap[index + 1].children[o].name) //筛选符合条件的规格列表 console.log(isSkuidname); filteredJson = this.querySpecList.filter(obj => obj.specSnap.indexOf(isSkuidname) == 0); console.log(filteredJson); for (let i = 0; i < filteredJson.length; i++) { console.log(filteredJson[i].isGrounding) - if ( filteredJson[i].isGrounding ) { - this.specifications.tagSnap[index+1].children[o].isGrounding = true + if (filteredJson[i].isGrounding) { + this.specifications.tagSnap[index + 1].children[o].isGrounding = true break; // 终止循环 } } - + } } - - + + // res.data.forEach((v,e)=>{ // // this.$set(this.specifications.tagSnap[e], 'children', v.value) // }) console.log(this.specifications.tagSnap) - + this.$forceUpdate(); this.hodgepodge(item, 2) }, From bf5460c304889f4a5f6e72ba728b3d6ef751b1fd Mon Sep 17 00:00:00 2001 From: GaoHao <1210693421@qq.com> Date: Fri, 9 Aug 2024 10:31:45 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E8=B0=83=E6=95=B4=EF=BC=8C=E4=BC=9A=E5=91=98=E5=85=85=E5=80=BC?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 34 ++++++++++++++++++++++++- framework/0-conf.js | 8 +++--- main.js | 4 +++ pages/member/index.vue | 45 +++++++++------------------------ pages/order_food/order_food.vue | 34 +++++-------------------- store/index.js | 1 + 6 files changed, 60 insertions(+), 66 deletions(-) diff --git a/App.vue b/App.vue index 1cdc5c0..262edcc 100644 --- a/App.vue +++ b/App.vue @@ -1,14 +1,17 @@ diff --git a/framework/0-conf.js b/framework/0-conf.js index ab5aecc..a9b4c7d 100644 --- a/framework/0-conf.js +++ b/framework/0-conf.js @@ -16,11 +16,11 @@ const baseUrlwws = 'ws://cashier.sxczgkj.cn/cashierService' // #endif // #ifdef APP || MP-WEIXIN -// const baseUrl = debug ? proxyApi : 'https://cashier.sxczgkj.cn/cashierService' // 线上 -// const baseUrlwws = debug ? proxyApiwws : 'wss://cashier.sxczgkj.cn/netty' // 线上 +const baseUrl = debug ? proxyApi : 'https://cashier.sxczgkj.cn/cashierService' // 线上 +const baseUrlwws = debug ? proxyApiwws : 'wss://cashier.sxczgkj.cn/netty' // 线上 -const baseUrl = 'https://cashier.sxczgkj.cn/cashierService' // 线上 -const baseUrlwws = 'wss://cashier.sxczgkj.cn/netty' // 线上/ +// const baseUrl = 'https://cashier.sxczgkj.cn/cashierService' // 线上 +// const baseUrlwws = 'wss://cashier.sxczgkj.cn/netty' // 线上/ // #endif // import VConsole from "./vConsole.js" diff --git a/main.js b/main.js index 1774450..2b0ca78 100644 --- a/main.js +++ b/main.js @@ -23,6 +23,10 @@ uni.$u.config.unit = 'rpx' Vue.prototype.useStorage = useStorage Vue.prototype.api = Api; Vue.prototype.shop = Shop; +Vue.prototype.$onLaunched = new Promise(resolve => { + Vue.prototype.$isResolve = resolve +}) + // #ifdef VUE3 import { createSSRApp diff --git a/pages/member/index.vue b/pages/member/index.vue index 8911881..329b6cc 100644 --- a/pages/member/index.vue +++ b/pages/member/index.vue @@ -46,44 +46,23 @@ usershopUserinfo: null, } }, - onLoad(e) { + async onLoad(e) { console.log(e) - if ( e.type == 'list' || e.type == 'index') { - this.shopId = e.shopId; - this.init(); - } + // if ( e.type == 'list' || e.type == 'index') { + // this.shopId = e.shopId; + // this.init(); + // } if (e.q) { this.shopId = this.getQueryString(decodeURIComponent(e.q), 'shopId') + this.tokenShow = false; + // 等待登录结果返回 if (!uni.cache.get('token')) { - 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); - this.tokenShow = false; - this.init(); - } - }, - fail: (err) => {} - }); - } catch (e) {} - } - }); - } else { - this.init(); + await this.$onLaunched; } + this.init(); + } else{ + this.shopId = e.shopId; + this.init(); } console.log(this.shopId) }, diff --git a/pages/order_food/order_food.vue b/pages/order_food/order_food.vue index 6766b67..614616f 100644 --- a/pages/order_food/order_food.vue +++ b/pages/order_food/order_food.vue @@ -409,40 +409,18 @@ uni.$off('message') this.fixedtrue = true }, - onShow() { + async onShow() { let _this = this; this.orderdetailFlag = true; uni.pageScrollTo({ scrollTop: 0, duration: 0 }); - 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.getLocation() - } - }, - fail: (err) => {} - }); - } catch (e) {} - } - }); + if (!uni.cache.get('token')) { + await this.$onLaunched; + } + uni.$on('message', this.getMessage) + _this.getLocation() }, methods: { navigateBacknav() { diff --git a/store/index.js b/store/index.js index d61ce3f..8277552 100644 --- a/store/index.js +++ b/store/index.js @@ -78,6 +78,7 @@ const store = new Vuex.Store({ uni.cache.set('miniAppOpenId', res.data.userInfo .miniAppOpenId) uni.cache.set('userInfo', res.data.userInfo); + this.$isResolve() } }, fail: (err) => {}