1 Star 0 Fork 2

wxf/wxshop

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 3.21 KB
一键复制 编辑 原始数据 按行查看 历史
wxf 提交于 2020-09-26 14:51 . Initial Commit
//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:''
},
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wxfwpl/wxshop.git
git@gitee.com:wxfwpl/wxshop.git
wxfwpl
wxshop
wxshop
shop

搜索帮助