From 5452327e71aa86a7db07fc2d5de1b7791cbc472a Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Wed, 15 Dec 2021 14:04:04 +0800 Subject: [PATCH] 1. 秒杀,只有会员重新登陆之后,才重新调用,优化速度 2. 底部导航使用缓存技术,不实时调用接口 3. 首页再使用自定义模板的时候,就不能调用默认的接口 4. 判断要不要弹出全屏广告 --- components/diy_seckill/diy_seckill.js | 9 ++++++++- custom-tab-bar/index.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------- pages/index/index/full_screen.js | 49 ++++++++++++++++++++++++++++++------------------- pages/index/index/index.js | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------- 4 files changed, 182 insertions(+), 132 deletions(-) diff --git a/components/diy_seckill/diy_seckill.js b/components/diy_seckill/diy_seckill.js index 5b73ec6..fdd208d 100644 --- a/components/diy_seckill/diy_seckill.js +++ b/components/diy_seckill/diy_seckill.js @@ -35,6 +35,7 @@ Component({ ylp_img: "https://mshopimg.yolipai.net/", imghost: os.imghost, timer: null, + user_id:0 }, pageLifetimes: { @@ -43,7 +44,12 @@ Component({ //会员身份变化 var th = this; var g_id = this.data.object; - this.init(g_id); + //只有再会员登陆之后,才重新调用接口 + + if(this.data.user_id!=getApp().globalData.user_id){ + this.data.user_id=getApp().globalData.user_id + this.init(g_id); + } setTimeout(function () { if (th.data.goods_array && th.data.goods_array.length > 0) { th.data.timer = setInterval(function () { @@ -62,6 +68,7 @@ Component({ ready: function () { var g_id = this.data.object; this.init(g_id); + this.data.user_id=getApp().globalData.user_id; }, detached() { // 页面被被销毁的时候,清除定时器 diff --git a/custom-tab-bar/index.js b/custom-tab-bar/index.js index 2cf2e5b..e229a34 100644 --- a/custom-tab-bar/index.js +++ b/custom-tab-bar/index.js @@ -9,33 +9,43 @@ Component({ list:app.def_list, cartGoodsNum:0, }, - lifetimes: { attached: function() { var th=this; - getApp().promiseGet("/api/weshop/storeDistribut/get/"+os.stoid,{}).then(rs=>{ var dis=rs.data.data; if( dis && dis.switch==0){ th.setData({is_no_distri:1}) } - }) - - getApp().promiseGet("/store/storemoduleendtime/page?store_id=" +os.stoid + "&type=5",{}).then(res=>{ - if(res.data.code==0){ - var arr = res.data.data.pageData; - if (arr.length > 0) { - var item=arr[0]; - if(item.is_sy==0){ - var now = Date.parse(new Date());now = now / 1000; - if(item.end_time 0) { + var item=arr[0]; + if(item.is_sy==0){ + var now = Date.parse(new Date());now = now / 1000; + if(item.end_time{ + if(res.data.code==0){ + var arr = res.data.data.pageData; + getApp().globalData.dis_buy_obj=arr; + if (arr.length > 0) { + var item=arr[0]; + if(item.is_sy==0){ + var now = Date.parse(new Date());now = now / 1000; + if(item.end_time { - getApp().globalData.is_read=true; - var e = res; - if(e.data.code != -1 && e.data.data && e.data.data.data){ - var itemList = e.data.data.data; - itemList = JSON.parse(itemList) - //如果是有定义自定义导航的小程序链接 - if(itemList[0].weappurl && itemList[0].weappurl!=""){ - getApp().globalData.custum_data=e.data.data; - var custum_data=e.data.data; - th.set_list(custum_data); - } - - } - - }) + + //全局缓存 + if(getApp().globalData.storeFooter) { + var itemList = getApp().globalData.storeFooter; + itemList = JSON.parse(itemList) + //-- 如果是有定义自定义导航的小程序链接 -- + if (itemList[0].weappurl && itemList[0].weappurl != "") { + getApp().globalData.custum_data = e.data.data; + var custum_data = e.data.data; + th.set_list(custum_data); + } + + }else{ + var stoid = os.stoid; + getApp().request.promiseGet("/api/weshop/storeFooter/get/" + stoid, {}).then(res => { + getApp().globalData.is_read = true; + var e = res; + if (e.data.code != -1 && e.data.data && e.data.data.data) { + var itemList = e.data.data.data; + getApp().globalData.storeFooter=itemList; + itemList = JSON.parse(itemList) + //-- 如果是有定义自定义导航的小程序链接 -- + if (itemList[0].weappurl && itemList[0].weappurl != "") { + getApp().globalData.custum_data = e.data.data; + var custum_data = e.data.data; + th.set_list(custum_data); + } + } + + }) + } } }, }, diff --git a/pages/index/index/full_screen.js b/pages/index/index/full_screen.js index 16cf312..8b7d8aa 100644 --- a/pages/index/index/full_screen.js +++ b/pages/index/index/full_screen.js @@ -1,31 +1,42 @@ module.exports = { //判断要不要显示全屏广告 get_the_full_screen(th){ - var stoid=getApp().globalData.setting.stoid; - if(th.data.full_ad) { + var stoid=getApp().globalData.setting.stoid; + if(getApp().globalData.full_screen) { + return false; + } + if(th.data.full_ad) { return false; } + //获取全屏的广告 getApp().promiseGet("/api/weshop/ad/page?pid=1001&store_id=" + stoid,{ data: { enabled: 1 } }).then(res=>{ - //判断是不是有全屏广告 - if(res.data.code==0 && res.data.data.pageData && res.data.data.pageData.length>0){ - th.setData({ - is_full_screen_show:1, - full_ad:res.data.data.pageData[0], - }) - //--定时关闭-- - th.data.full_screen=setInterval(function(){ - if(!th.data.sec_show) { - clearInterval(th.data.full_screen); - th.close_full_screen(); - return false; - } - th.data.sec_show--; - th.setData({sec_show:th.data.sec_show}); - },1000) - } + //判断是不是有全屏广告 + if(res.data.code==0 && res.data.data.pageData && res.data.data.pageData.length>0){ + getApp().globalData.full_screen=res.data.data.pageData[0]; + th.setData({ + is_full_screen_show:1, + full_ad:res.data.data.pageData[0], + }) + //--定时关闭-- + th.data.full_screen=setInterval(function(){ + if(!th.data.sec_show) { + clearInterval(th.data.full_screen); + th.close_full_screen(); + return false; + } + th.data.sec_show--; + th.setData({sec_show:th.data.sec_show}); + },1000) + }else{ + getApp().globalData.full_screen=true; + } }) + + + + } } \ No newline at end of file diff --git a/pages/index/index/index.js b/pages/index/index/index.js index b30c650..a5bb279 100644 --- a/pages/index/index/index.js +++ b/pages/index/index/index.js @@ -318,74 +318,99 @@ Page({ } } - var pre_data={store_id:os.stoid,is_end:0,timetype:1,isuse:1}; - if(user_id){ - pre_data.user_id= user_id; - } + console.log(this.data.isTemplate,'首页'); - getApp().request.get("/api/weshop/marketing/marketingPresellList/page",{ - data:pre_data, - success:function (e) { - if(e.data.code==0 && e.data.data.pageData && e.data.data.pageData.length>0 ){ - var pre_data=e.data.data.pageData; - var arr = new Array(); - //--三个三个一组--- - for (var i = 0; i < pre_data.length; i += 3) { - arr.push(pre_data.slice(i, i + 3)); + if(!this.data.isTemplate){ + var pre_data={store_id:os.stoid,is_end:0,timetype:1,isuse:1}; + if(user_id){ + pre_data.user_id= user_id; + } + + getApp().request.get("/api/weshop/marketing/marketingPresellList/page",{ + data:pre_data, + success:function (e) { + if(e.data.code==0 && e.data.data.pageData && e.data.data.pageData.length>0 ){ + var pre_data=e.data.data.pageData; + var arr = new Array(); + //--三个三个一组--- + for (var i = 0; i < pre_data.length; i += 3) { + arr.push(pre_data.slice(i, i + 3)); + } + th.setData({ + preGoods: arr + }); + }else{ + th.setData({ + preGoods: null + }); } + } + }) + + // 获取幸运购活动列表 + getApp().request.promiseGet('/api/weshop/prom/luckyActivity/page', { + data: { + store_id: getApp().globalData.setting.stoid, + is_end: 0, + timetype: 1, + } + }).then(res => { + if(res.data.code == 0) { th.setData({ - preGoods: arr + luckGo_list: res.data.data.pageData.slice(0,3), + }); + } + }); + + //-----秒杀----- + var flash_data = null; + var f_req={ + store_id: os.stoid, + timetype: 2, + is_end: 0, + is_show: 1, + pageSize: 9, + user_id:0 + }; + if(user_id) f_req.user_id=user_id; + //--获取活动-- + await getApp().request.promiseGet("/api/ms/flash_sale/spikepage", { + data:f_req , + }).then(res => { + var e = res; + if (e.data.code == 0) { + flash_data = e.data.data.pageData; + if (flash_data == null || flash_data.length <= 0) return false; + + //当前时间戳 + var nt = ut.gettimestamp(); + + flash_data.forEach(function (val, ind) { + + if(val.user_price) val.price=val.user_price; + if (val.start_time > nt) flash_data[ind].status = 0; + else if (val.end_time > nt) flash_data[ind].status = 1; + if (val.buy_num >= val.goods_num) flash_data[ind].status = 2; }); - }else{ + + var arr = new Array(); + //--三个三个一组--- + for (var i = 0; i < flash_data.length; i += 3) { + arr.push(flash_data.slice(i, i + 3)); + } th.setData({ - preGoods: null + saleGoods: arr }); } - } - }) + }); + + } + + + + - //-----秒杀----- - var flash_data = null; - var f_req={ - store_id: os.stoid, - timetype: 2, - is_end: 0, - is_show: 1, - pageSize: 9, - user_id:0 - }; - if(user_id) f_req.user_id=user_id; - //--获取活动-- - await getApp().request.promiseGet("/api/ms/flash_sale/spikepage", { - data:f_req , - }).then(res => { - var e = res; - if (e.data.code == 0) { - flash_data = e.data.data.pageData; - if (flash_data == null || flash_data.length <= 0) return false; - - //当前时间戳 - var nt = ut.gettimestamp(); - - flash_data.forEach(function (val, ind) { - - if(val.user_price) val.price=val.user_price; - if (val.start_time > nt) flash_data[ind].status = 0; - else if (val.end_time > nt) flash_data[ind].status = 1; - if (val.buy_num >= val.goods_num) flash_data[ind].status = 2; - }); - - var arr = new Array(); - //--三个三个一组--- - for (var i = 0; i < flash_data.length; i += 3) { - arr.push(flash_data.slice(i, i + 3)); - } - th.setData({ - saleGoods: arr - }); - } - }); @@ -394,7 +419,7 @@ Page({ var json_d = JSON.parse(e.switch_list); th.setData({ is_closecoupon: json_d.is_closecoupon }) th.setData({ is_topstore: json_d.is_show_storeselect }) - th.setData({is_gz_h5:json_d.is_gz_h5}) + if(json_d.is_gz_h5) th.setData({is_gz_h5:json_d.is_gz_h5}) }, 1) if (typeof this.getTabBar === 'function' && this.getTabBar()) { @@ -403,7 +428,7 @@ Page({ active: index //数字是当前页面在tabbar的索引 }) - //sty + getApp().requestCardNum(this); } @@ -434,22 +459,6 @@ Page({ } }, 1500) - - // 获取幸运购活动列表 - getApp().request.promiseGet('/api/weshop/prom/luckyActivity/page', { - data: { - store_id: getApp().globalData.setting.stoid, - is_end: 0, - timetype: 1, - } - }).then(res => { - if(res.data.code == 0) { - th.setData({ - luckGo_list: res.data.data.pageData.slice(0,3), - }); - } - }); - }, //当隐藏的时候就关闭计时器 -- libgit2 0.21.4