diff --git a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCollectService.java b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCollectService.java index eaa68884..a0ca1576 100644 --- a/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCollectService.java +++ b/litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCollectService.java @@ -21,9 +21,11 @@ public class LitemallCollectService { return (int)collectMapper.countByExample(example); } - public List queryByType(Integer userId, Integer typeId) { + public List queryByType(Integer userId, Integer typeId, Integer page, Integer size) { LitemallCollectExample example = new LitemallCollectExample(); example.or().andUserIdEqualTo(userId).andTypeIdEqualTo(typeId); + example.setOrderByClause(LitemallCollect.Column.addTime.desc()); + PageHelper.startPage(page, size); return collectMapper.selectByExample(example); } diff --git a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCollectController.java b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCollectController.java index 687556b5..68e11850 100644 --- a/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCollectController.java +++ b/litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCollectController.java @@ -10,6 +10,7 @@ import org.linlinjava.litemall.wx.annotation.LoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.time.LocalDate; @@ -30,7 +31,9 @@ public class WxCollectController { * 获取用户收藏 */ @RequestMapping("list") - public Object list(@LoginUser Integer userId, Integer typeId) { + public Object list(@LoginUser Integer userId, Integer typeId, + @RequestParam(value = "page", defaultValue = "1") Integer page, + @RequestParam(value = "size", defaultValue = "10") Integer size) { if(userId == null){ return ResponseUtil.fail401(); } @@ -39,8 +42,9 @@ public class WxCollectController { } - List collectList = collectService.queryByType(userId, typeId); + List collectList = collectService.queryByType(userId, typeId, page, size); int count = collectService.countByType(userId, typeId); + int totalPages = (int) Math.ceil((double) count / size); List collects = new ArrayList<>(collectList.size()); for(LitemallCollect collect : collectList){ @@ -59,8 +63,8 @@ public class WxCollectController { } Map result = new HashMap(); - result.put("count", count); - result.put("data", collects); + result.put("collectList", collects); + result.put("totalPages", totalPages); return ResponseUtil.ok(result); } diff --git a/litemall-wx/pages/auth/login/login.js b/litemall-wx/pages/auth/login/login.js index ad0cc244..2a93b152 100644 --- a/litemall-wx/pages/auth/login/login.js +++ b/litemall-wx/pages/auth/login/login.js @@ -29,7 +29,7 @@ Page({ // 页面关闭 }, - wxLogin() { + wxLogin: function () { user.checkLogin().catch(() => { user.loginByWeixin().then(res => { diff --git a/litemall-wx/pages/ucenter/collect/collect.js b/litemall-wx/pages/ucenter/collect/collect.js index 466475f9..e1df447c 100644 --- a/litemall-wx/pages/ucenter/collect/collect.js +++ b/litemall-wx/pages/ucenter/collect/collect.js @@ -6,22 +6,44 @@ var app = getApp(); Page({ data: { typeId: 0, - collectList: [] + collectList: [], + page: 1, + size: 10, + totalPages: 1 }, getCollectList() { + wx.showLoading({ + title: '加载中...', + }); let that = this; - util.request(api.CollectList, { typeId: that.data.typeId}).then(function (res) { + util.request(api.CollectList, { typeId: that.data.typeId, page: that.data.page, size: that.data.size }).then(function (res) { if (res.errno === 0) { - console.log(res.data); that.setData({ - collectList: res.data.data + collectList: that.data.collectList.concat(res.data.collectList), + totalPages: res.data.totalPages }); } + wx.hideLoading(); }); }, onLoad: function (options) { this.getCollectList(); }, + onReachBottom() { + if (this.data.totalPages > this.data.page) { + this.setData({ + page: this.data.page + 1 + }); + this.getCollectList(); + } else { + wx.showToast({ + title: '没有更多用户收藏了', + icon: 'none', + duration: 2000 + }); + return false; + } + }, onReady: function () { }, @@ -78,7 +100,6 @@ Page({ that.setData({ touchStart: e.timeStamp }) - console.log(e.timeStamp + '- touch-start') }, //按下事件结束 touchEnd: function (e) { @@ -86,6 +107,5 @@ Page({ that.setData({ touchEnd: e.timeStamp }) - console.log(e.timeStamp + '- touch-end') }, }) \ No newline at end of file diff --git a/litemall-wx/pages/ucenter/collect/collect.wxss b/litemall-wx/pages/ucenter/collect/collect.wxss index ce1f13c4..43996184 100644 --- a/litemall-wx/pages/ucenter/collect/collect.wxss +++ b/litemall-wx/pages/ucenter/collect/collect.wxss @@ -6,6 +6,9 @@ page{ .container{ background: #f4f4f4; min-height: 100%; + width: 100%; + height: auto; + overflow: hidden; }