收藏
回答

小程序初始加载获取权限和数据

大家帮我看下 ,小程序初始加载的数据,感觉这样写老是不妥,初始加载有获取权限的操作,有时候怎么会无法获取权限,请教下大神有没有什么可以优化的。


,onLaunch: function () {

that = this;

console.log("onLaunch: function ()");


try{

var houseCount = wx.getStorageSync('houseCount');

console.log("===============缓存houseCount=" + houseCount);

if (houseCount) {

that.globalData.houseCount = houseCount;

}


var houseXyzCount = wx.getStorageSync('houseXyzCount');

console.log("===============缓存houseXyzCount=" + houseXyzCount);

if (houseXyzCount) {

that.globalData.houseXyzCount = houseXyzCount;

}


var houseTgCount = wx.getStorageSync('houseTgCount');

console.log("===============houseTgCount=" + houseTgCount);

if (houseTgCount) {

that.globalData.houseTgCount = houseTgCount;

}


var houseGsCount = wx.getStorageSync('houseGsCount');

console.log("===============houseGsCount=" + houseGsCount);

if (houseGsCount) {

that.globalData.houseGsCount = houseGsCount;

}

var houseShopCount = wx.getStorageSync('houseShopCount');

console.log("===============houseShopCount=" + houseShopCount);

if (houseShopCount) {

that.globalData.houseShopCount = houseShopCount;

}


var houseDelCount = wx.getStorageSync('houseDelCount');

console.log("===============houseDelCount=" + houseDelCount);

if (houseDelCount) {

that.globalData.houseDelCount = houseDelCount;

}

} catch(e) {

wx.showModal({

title: '提示', showCancel: false,

content: '获取微信房源数量缓存失败,请与管理员联系' + e

})


}


wx.getSystemInfo({

success: function (res) {

console.info("app获取高度返回=" + res.windowHeight);

that.globalData.height=res.windowHeight

}

})


var admin ="";

var adminTime = "";


try {

var wxUserInfo = wx.getStorageSync('wxUserInfo')

var wxUserInfoTime = wx.getStorageSync('wxUserInfoTime')



console.log("当前时间Time=" + new Date().getTime()+" wxUserInfoTime ="+wxUserInfoTime);

console.log("缓存wxUserInfo的天数 =" + (new Date().getTime() - wxUserInfoTime) / (24 * 3600 * 1000));


if (wxUserInfo == "") {

console.log("wxUserInfo 等于空");

that.getWxUserInfo();

//如果缓存wxUserInfoTime 大于三天就同步

} else if (wxUserInfoTime != "" && (new Date().getTime() - wxUserInfoTime) / (24 * 3600 * 1000)>3){

console.log("缓存wxUserInfo的天数 =" + (new Date().getTime() - wxUserInfoTime) / (24 * 3600 * 1000));

that.getWxUserInfo();

}else{

console.log("wxUserInfo缓存小于三天");

that.globalData.wxUserInfo = wxUserInfo;

//临时认为也要更新

that.getWxUserInfo();

}


} catch (e) {

wx.hideLoading()

wx.showModal({

title: '提示', showCancel: false,

content: '获取微信wxUserInfo缓存失败,请与管理员联系'+e

})


}


最后一次编辑于  2018-09-07
回答关注问题邀请回答
收藏