From f3225f83ea1f7e11437c9b77ac133f1dd717fb78 Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Mon, 29 Jan 2024 17:52:03 +0800 Subject: [PATCH] 首页分享的优化~~ --- app.js | 28 ++++++++++++++++++++++++++-- pages/index/index/index.js | 9 ++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index bca94af..e056c46 100644 --- a/app.js +++ b/app.js @@ -75,7 +75,8 @@ App({ sp_scene: null, navBarHeight:44, //默认高度44 - is_pc:0, //是不是在pc端打开小程序 + is_pc:0, //是不是在pc端打开小程序 + is_get_login:0 }, auth: o, request: a, @@ -139,7 +140,7 @@ App({ } }) } - else if(app.globalData.user_id){ //-- 启用默认的user_id -- + else if(app.globalData.user_id){ //-- 启用默认的user_id -- app.promiseGet("/api/weshop/users/get/" + app.globalData.setting.stoid + "/" + app.globalData.user_id,{}).then(res=>{ if(res.data.code==0){ app.globalData.userInfo = res.data.data; @@ -165,6 +166,9 @@ App({ app.request.get("/api/weshop/users/openidandkey", { data: dd, success: function (e) { + //说明会员是有wx.login运行拿了一下是不是会员 + app.globalData.is_get_login=1; + if (e.data.code == 0) { //如果有会员的话,没有sessionKey if (!e.data.data.sessionKey) { @@ -796,6 +800,26 @@ App({ }); }, + + //--- 最多十秒 --- + waitfor_login(func){ + var n = 0; + var that=this; + if (!this.globalData.is_get_login) { + var inter = setInterval(function () { + n++; + if (that.globalData.is_get_login) { + clearInterval(inter); + func(); + } + if (n > 20) { + clearInterval(inter); + func(); + } + }, 500); + } + }, + //------定时等待某个值,有值才进行运算-------- waitfor: function (page, key, pop_value, func) { var n = 0; diff --git a/pages/index/index/index.js b/pages/index/index/index.js index ec17090..16239c7 100644 --- a/pages/index/index/index.js +++ b/pages/index/index/index.js @@ -216,9 +216,12 @@ Page({ } }) - if (!getApp().globalData.user_id) { - ut.new_user_go(os.stoid, first_leader); - } + //先查看一下是不是系统会员 + getApp().waitfor_login(()=> { + if (!getApp().globalData.user_id) { + ut.new_user_go(os.stoid, first_leader); + } + }) } -- libgit2 0.21.4