// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database();
const _ = db.command;
// 云函数入口函数
exports.main = async (event, context) => {
const {
pageIndex,
pageSize
} = event;
const wxContext = cloud.getWXContext();
const openid = wxContext.OPENID;
const countResult = await db.collection('takePhoto').where({
openid: openid
}).count(); //获取集合的总计录数
const total = countResult.total; //得到总记录数
const totalPage = total / 10; //计算需要多少页
let hasMore = pageIndex >= totalPage ? false : true; //提示前端是否还有数据
console.log('云相册',total,totalPage,hasMore);
return db.collection('takePhoto')
.where({
openid: openid
})
.orderBy('photoTime','asc')
.skip((pageIndex - 1) * pageSize)
.limit(pageSize)
.get()
.then(res => {
res.hasMore = hasMore
return res;
});
}
网友评论