From d660e2f89f45371a6dfd9fe1cd3265f4ffeba36d Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Fri, 12 Mar 2021 09:42:43 +0800 Subject: [PATCH] 小程序过期的程序优化 --- app.js | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------- 1 file changed, 103 insertions(+), 37 deletions(-) diff --git a/app.js b/app.js index 95a978e..a6a3d6b 100644 --- a/app.js +++ b/app.js @@ -101,6 +101,29 @@ App({ }, }) + var th=this; + var pages = getCurrentPages(); //获取加载的页面 + var currentPage = pages[pages.length - 1]; //获取当前页面的对象 + if(!currentPage || currentPage.route.indexOf('error/error')==-1){ + var tt=this.globalData.wxapp_buy_obj; + if (!tt){ + this.get_isbuy(function (){ + tt=th.globalData.wxapp_buy_obj; + if (tt.isout == 1){ + th.promiseGet('/api/weshop/store/get/'+t.stoid,{}).then(res=>{ + wx.reLaunch({ + url: "/pages/error/error?msg=该商城已到期,暂停浏览!\r\n可联系:"+res.data.data.store_tel, + }); + }) + } + else if (tt.isbuy == 0) + wx.reLaunch({ + url: "/pages/error/error?msg=还未购买小程序", + }); + }) + } + } + }, //---初始化第三方---- @@ -287,9 +310,11 @@ App({ }, //同步化,在调用的时候要await - async get_isbuy() { - var th=this; - await api.check_isbuy({ store_id: t.stoid, type: 5 }).then(res=>{ + async get_isbuy(func) { + var th=this + var stoid=os.stoid; + + await this.promiseGet("/store/storemoduleendtime/page?store_id=" +stoid + "&type=5",{}).then(res=>{ var o=res; if (o.data.code == 0) { var ob = { isout: 0, isbuy: 1 }; @@ -308,6 +333,9 @@ App({ } ob.isbuy = isbuy; th.globalData.wxapp_buy_obj=ob; + if(func){ + func(); + } } }) }, @@ -384,44 +412,61 @@ App({ } //---如果会员没有设置默认门店,同时也没有再注册的时候选择门店-- if(pick_id==0) return func(null); - //获取用户注册时候的门店,这个门店不能关闭,同时这个门店的分类不能关闭 - th.request.get("/api/weshop/pickup/get/"+os.stoid+"/"+pick_id,{ - data:{}, - success:function (res) { - th.globalData.pk_store=null; - if(res.data.code==0 && res.data.data && res.data.data.isstop==0){ - if(res.data.data.category_id){ - th.request.get( "/api/weshop/storagecategory/get/"+os.stoid+"/"+res.data.data.category_id, { - data: {}, - success: function (ee) { - if(ee.data.code==0 && ee.data.data ){ - if(ee.data.data.is_show==1){ - th.globalData.pk_store = res.data.data; - func(th.globalData.pk_store); - }else{ - func(null); - } - }else{ - func(null); - } - } - }) - }else{ - th.globalData.pk_store = res.data.data; - func(th.globalData.pk_store); - } - }else{ - func(null); - } - } - }) + + //返回门店的数量 + th.get_pk_num(function(num){ + //获取用户注册时候的门店,这个门店不能关闭,同时这个门店的分类不能关闭 + th.request.get("/api/weshop/pickup/get/"+os.stoid+"/"+pick_id,{ + data:{}, + success:function (res) { + th.globalData.pk_store=null; + if(res.data.code==0 && res.data.data && res.data.data.isstop==0){ + //--门店的数量大于5个才要关心门店的分类有没有关闭-- + if(res.data.data.category_id && num>5){ + th.request.get( "/api/weshop/storagecategory/get/"+os.stoid+"/"+res.data.data.category_id, { + data: {}, + success: function (ee) { + if(ee.data.code==0 && ee.data.data ){ + if(ee.data.data.is_show==1){ + th.globalData.pk_store = res.data.data; + func(th.globalData.pk_store); + }else{ + func(null); + } + }else{ + func(null); + } + } + }) + }else{ + th.globalData.pk_store = res.data.data; + func(th.globalData.pk_store); + } + }else{ + func(null); + } + } + }) + + }) + }else{ func(th.globalData.pk_store); } }) - }, - + + //-- 获取门店的数量 -- + get_pk_num:function(func){ + this.request.get("/api/weshop/pickup/page",{ + data:{page:1,pageSize:1,isstop:0,store_id:os.stoid}, + success:function (res) { + if(res.data.code==0){ + func(res.data.data.total); //门店数量 + } + } + }); + }, //-------获取购物车数量---------- requestCardNum: function(th) { if(!this.globalData.user_id) return false; @@ -538,7 +583,28 @@ App({ } return index; - } + }, + + //---promise的使用get---- + promiseGet:function(url,data){ + if(url.indexOf("http")==-1) url=this.globalData.setting.url +url; + return new Promise((resolve, reject) => { + data.isShowLoading && wx.showLoading(); + wx.request({ + url, + method: 'GET', + header: {"content-type": "application/x-www-form-urlencoded" }, + data:data.data, + success(res) { + data.isShowLoading && wx.hideLoading(); + resolve(res); + }, + fail(err) { data.isShowLoading && wx.hideLoading(); reject(err); } + }) + }) + }, + + }); -- libgit2 0.21.4