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 {
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();
example.or().andUserIdEqualTo(userId).andTypeIdEqualTo(typeId);
example.setOrderByClause(LitemallCollect.Column.addTime.desc());
PageHelper.startPage(page, size);
return collectMapper.selectByExample(example);
}
......
......@@ -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<LitemallCollect> collectList = collectService.queryByType(userId, typeId);
List<LitemallCollect> collectList = collectService.queryByType(userId, typeId, page, size);
int count = collectService.countByType(userId, typeId);
int totalPages = (int) Math.ceil((double) count / size);
List<Object> collects = new ArrayList<>(collectList.size());
for(LitemallCollect collect : collectList){
......@@ -59,8 +63,8 @@ public class WxCollectController {
}
Map<String, Object> result = new HashMap();
result.put("count", count);
result.put("data", collects);
result.put("collectList", collects);
result.put("totalPages", totalPages);
return ResponseUtil.ok(result);
}
......
......@@ -29,7 +29,7 @@ Page({
// 页面关闭
},
wxLogin() {
wxLogin: function () {
user.checkLogin().catch(() => {
user.loginByWeixin().then(res => {
......
......@@ -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
......@@ -6,6 +6,9 @@ page{
.container{
background: #f4f4f4;
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