代码拉取完成,页面将自动刷新
//app.js
App({
onLaunch: function(options) {
var that = this
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
if (res.code) {
console.log("code==>", res.code)
wx.request({
url: this.globalData.url + "/auth/wxlogin?code=" + res.code,
header: {
'content-type': 'application/json'
},
method: 'POST',
success(res) {
console.log("wx.login==>", res.data)
console.log("token==>", res.data.data.token);
wx.setStorageSync('token', res.data.data.token);
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
//获取购物车数据求得购物车数量
wx.request({
url: that.globalData.url + '/user/users/cart/list',
header: {
'content-type': 'application/json',
'Authorization': wx.getStorageSync("token"),
},
success: function (res) {
var cartnum = 0
var i = 0
if (res.data.code == 200) {
for (i = 0; i < res.data.data.shoptable.length; i++) //循环店铺id数组
{
const shopId = res.data.data.shoptable[i];
const product = res.data.data.listLinkedHashMap[shopId]; //循环产品信息取出值
cartnum += product.length;
that.globalData.cartNum = cartnum
}
wx.setStorageSync('cartnum', that.globalData.cartNum)
// var cartNum = wx.getStorageSync('cartnum')
// that.SetCartNum(cartNum)
}
},
fail: function (res) {
console.log('submit fail');
}
})
},
onShow:function(options){
var that = this
console.log("进入来源", options)
if (options.scene == 1007) {
// 通过单人聊天会话分享进入
this.globalData.hide = 1
}
},
//加购后改变缓存中的右上角数字
changeCartNum: function () { //定义一个方法b
return new Promise((reslove, reject) => {
var that = this;
//获取购物车数据求得购物车数量
wx.request({
url: that.globalData.url + '/user/users/cart/list',
header: {
'content-type': 'application/json',
'Authorization': wx.getStorageSync("token"),
},
success: function (res) {
var cartnum = 0
var i = 0
if (res.data.code == 200) {
for (i = 0; i < res.data.data.shoptable.length; i++) //循环店铺id数组
{
const shopId = res.data.data.shoptable[i];
const product = res.data.data.listLinkedHashMap[shopId]; //循环产品信息取出值
cartnum += product.length;
}
// console.log('11111111111111111111111111', cartnum)
wx.setStorageSync('cartnum', cartnum)
}
reslove(res.data, res);
},
fail: (msg) => {
reject('请求失败');
}
})
});
},
globalData: {
url: "https://www.njzhny.com:8443",
userInfo: null,
cart: "",
_num: "",
cartNum: '',
humi:'',
temp:'',
time:'',
hide:''
},
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。