Commit 22ff0f92 authored by Junling Bu's avatar Junling Bu
Browse files

update[litemall-wx, litemall-wx-api, litemall-db]: 用户收藏支分页显示。

parent b7a2a1e6
...@@ -21,9 +21,11 @@ public class LitemallCollectService { ...@@ -21,9 +21,11 @@ public class LitemallCollectService {
return (int)collectMapper.countByExample(example); return (int)collectMapper.countByExample(example);
} }
public List<LitemallCollect> queryByType(Integer userId, Integer typeId) { public List<LitemallCollect> queryByType(Integer userId, Integer typeId, Integer page, Integer size) {
LitemallCollectExample example = new LitemallCollectExample(); LitemallCollectExample example = new LitemallCollectExample();
example.or().andUserIdEqualTo(userId).andTypeIdEqualTo(typeId); example.or().andUserIdEqualTo(userId).andTypeIdEqualTo(typeId);
example.setOrderByClause(LitemallCollect.Column.addTime.desc());
PageHelper.startPage(page, size);
return collectMapper.selectByExample(example); return collectMapper.selectByExample(example);
} }
......
...@@ -10,6 +10,7 @@ import org.linlinjava.litemall.wx.annotation.LoginUser; ...@@ -10,6 +10,7 @@ import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate; import java.time.LocalDate;
...@@ -30,7 +31,9 @@ public class WxCollectController { ...@@ -30,7 +31,9 @@ public class WxCollectController {
* 获取用户收藏 * 获取用户收藏
*/ */
@RequestMapping("list") @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){ if(userId == null){
return ResponseUtil.fail401(); return ResponseUtil.fail401();
} }
...@@ -39,8 +42,9 @@ public class WxCollectController { ...@@ -39,8 +42,9 @@ public class WxCollectController {
} }
List<LitemallCollect> collectList = collectService.queryByType(userId, typeId); List<LitemallCollect> collectList = collectService.queryByType(userId, typeId, page, size);
int count = collectService.countByType(userId, typeId); int count = collectService.countByType(userId, typeId);
int totalPages = (int) Math.ceil((double) count / size);
List<Object> collects = new ArrayList<>(collectList.size()); List<Object> collects = new ArrayList<>(collectList.size());
for(LitemallCollect collect : collectList){ for(LitemallCollect collect : collectList){
...@@ -59,8 +63,8 @@ public class WxCollectController { ...@@ -59,8 +63,8 @@ public class WxCollectController {
} }
Map<String, Object> result = new HashMap(); Map<String, Object> result = new HashMap();
result.put("count", count); result.put("collectList", collects);
result.put("data", collects); result.put("totalPages", totalPages);
return ResponseUtil.ok(result); return ResponseUtil.ok(result);
} }
......
...@@ -29,7 +29,7 @@ Page({ ...@@ -29,7 +29,7 @@ Page({
// 页面关闭 // 页面关闭
}, },
wxLogin() { wxLogin: function () {
user.checkLogin().catch(() => { user.checkLogin().catch(() => {
user.loginByWeixin().then(res => { user.loginByWeixin().then(res => {
......
...@@ -6,22 +6,44 @@ var app = getApp(); ...@@ -6,22 +6,44 @@ var app = getApp();
Page({ Page({
data: { data: {
typeId: 0, typeId: 0,
collectList: [] collectList: [],
page: 1,
size: 10,
totalPages: 1
}, },
getCollectList() { getCollectList() {
wx.showLoading({
title: '加载中...',
});
let that = this; 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) { if (res.errno === 0) {
console.log(res.data);
that.setData({ that.setData({
collectList: res.data.data collectList: that.data.collectList.concat(res.data.collectList),
totalPages: res.data.totalPages
}); });
} }
wx.hideLoading();
}); });
}, },
onLoad: function (options) { onLoad: function (options) {
this.getCollectList(); 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 () { onReady: function () {
}, },
...@@ -78,7 +100,6 @@ Page({ ...@@ -78,7 +100,6 @@ Page({
that.setData({ that.setData({
touchStart: e.timeStamp touchStart: e.timeStamp
}) })
console.log(e.timeStamp + '- touch-start')
}, },
//按下事件结束 //按下事件结束
touchEnd: function (e) { touchEnd: function (e) {
...@@ -86,6 +107,5 @@ Page({ ...@@ -86,6 +107,5 @@ Page({
that.setData({ that.setData({
touchEnd: e.timeStamp touchEnd: e.timeStamp
}) })
console.log(e.timeStamp + '- touch-end')
}, },
}) })
\ No newline at end of file
...@@ -6,6 +6,9 @@ page{ ...@@ -6,6 +6,9 @@ page{
.container{ .container{
background: #f4f4f4; background: #f4f4f4;
min-height: 100%; min-height: 100%;
width: 100%;
height: auto;
overflow: hidden;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment