现在是云函数只能查询到100条,小程序js查询20条,如何修改超100条数据以上???急!
云函数:
const cloud = require('wx-server-sdk')
//这里最好也初始化一下你的云开发环境
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV,
})
//操作excel用的类库
const xlsx = require('node-xlsx');
// 云函数入口函数
exports.main = async(event, context) => {
try {
let applydata = getdata.data;
//1,定义excel表格名
let dataCVS = event.fileName;
//2,定义存储数据的
let alldata = [];
let row = ['时间', '当前状态', '姓名', '性别', '手机号', '身份证', '是否开车入厂', '车牌号','确认配合完成以下工作','体温','来源地区','来源地详细','来访事宜','健康码和行程码','入厂时间','入厂放行值班人','离厂时间','离厂校验值班人']; //表属性
alldata.push(row);
for (let key in applydata) {
let arr = [];
arr.push(applydata[key].createTime);
arr.push(applydata[key].xm_zt);
arr.push(applydata[key].name);
arr.push(applydata[key].xm_xb);
arr.push(applydata[key].phone);
arr.push(applydata[key].xm_sfz);
arr.push(applydata[key].sfkcrc);
arr.push(applydata[key].cph);
arr.push(applydata[key].wcgzph);
arr.push(applydata[key].xm_tw);
arr.push(applydata[key].xm_lyd);
arr.push(applydata[key].xm_lydxx);
arr.push(applydata[key].xm_lfsy);
arr.push(applydata[key].scjkm);
arr.push(applydata[key].RCcreateTime);
arr.push(applydata[key].RCname);
arr.push(applydata[key].LCcreateTime);
arr.push(applydata[key].LCname);
alldata.push(arr)
}
//3,把数据保存到excel里
var buffer = await xlsx.build([{
name: "mySheetName",
data: alldata
}]);
//4,把excel文件保存到云存储里
return await cloud.uploadFile({
cloudPath: dataCVS,
fileContent: buffer, //excel二进制文件
})
} catch (e) {
console.error(e)
return e
}
}
JS:
const db = wx.cloud.database()
const _ = db.command
import {
moment
} from '../../utils/moment';
Page({
/**
* 页面的初始数据
*/
data: {
index: "0",
picker: ['全部', '近三天', '近七天', '近十五天'],
isSelect: false,
exportData:"",
fileName:"来访登记统计表"
},
PickerChange(e) {
console.log(e);
this.setData({
index: e.detail.value
})
},
one(e) {
let repTime = e.detail.value.replace(/-/g, '/');
console.log("返回时间:" + repTime); //转换格式
let timeTamp = Date.parse(repTime); //转时间戳
let one = timeTamp
this.setData({
repTime,
one
})
},
two(e) {
let repTime2 = e.detail.value.replace(/-/g, '/');
console.log("返回时间:" + repTime2); //转换格式
let timeTamp = Date.parse(repTime2); //转时间戳
let two = parseInt(timeTamp + 86400000)
this.setData({
repTime2,
two
})
},
changeSelect(e) {
this.setData({
isSelect: e.detail.value
})
},
buttonClick() {
let that = this;
//判断开关是否打开
if (this.data.isSelect) {
//将选择的时间转为时间戳
let one = parseInt(that.data.one)
let two = parseInt(that.data.two)
console.log(one, two)
//判断是否选中时间,没有选中转为时间戳是NaN
if (isNaN(one) || isNaN(two)) {
wx.showToast({
title: '起始时间或终止时间不能为空',
icon: "none"
})
} else {
db.collection('seamild_lfdj').where({
timestamp: _.and(_.gte(one), _.lte(two))
}).get().then(res => {
console.log(res)
this.setData({
exportData:res.data
})
this.exportData();
})
}
} else {
//如果没有打开开关,那么就按条件选择筛选
//当前选中的下标
let selectValue = this.data.index;
console.log(selectValue)
//获取当前时间并转为时间戳
let nowDate = Date.parse(moment("YYYY-MM-DD").replace(/-/g, '/'))+86400000;
//声明起始时间,最近几天就用当前时间减去天数
let pastDate = "";
console.log(nowDate,"nowDate")
//判断选中的条件
switch (selectValue) {
case "0":
//查询全部的查询语句
db.collection('seamild_lfdj').get().then(res => {
console.log(res)
this.setData({
exportData:res.data
})
this.exportData();
})
break;
case "1":
pastDate = nowDate - (86400000*3);
console.log(pastDate,"pastDate");
break;
case "2":
pastDate = nowDate - (86400000*7);
console.log(pastDate,"pastDate");
break;
case "3":
pastDate = nowDate - (86400000*15);
console.log(pastDate,"pastDate");
break;
}
//近三天、近七天、近十五天的查询语句
if(pastDate != ""){
db.collection('seamild_lfdj').where({
timestamp: _.and(_.gte(pastDate), _.lte(nowDate))
}).get().then(res => {
console.log(res)
this.setData({
exportData:res.data
})
this.exportData();
})
}
}
},
//导出方法,单独拿出来,放一起并发执行,获取不到数据
exportData(){
console.log(this.data.exportData,"exportData")
let that = this;
if(this.data.exportData != null && this.data.exportData.length > 0){
if(this.data.fileName != "" && this.data.fileName.length > 0){
wx.showLoading({
title: '正在导出'
})
wx.cloud.callFunction({
name: "exportExcel",
data:{
exportData:this.data.exportData,
fileName:this.data.fileName+".xls"
},
success(res) {
console.log("读取成功", res.result.fileID)
wx.hideLoading();
wx.showToast({
title: '导出成功,粘贴到浏览器下载',
icon:"none"
})
that.setData({
exportDateTime:moment("YYYY-MM-DD hh:mm:ss")
})
that.getFileUrl(res.result.fileID);
// that.copyFileUrl()
},
fail(res) {
console.log("读取失败", res)
}
})
// 刷新当前页面
that.onLoad();
console.log("页面重载")
}else{
wx.showToast({
title: '文件名不能为空',
icon:"none"
})
}
}else{
wx.showToast({
title: '当前选择无数据,无法导出',
icon:"none"
})
}
},
//获取云存储文件下载地址,这个地址有效期一天
getFileUrl(fileID) {
let that = this;
wx.cloud.getTempFileURL({
fileList: [fileID],
success: res => {
// get temp file URL
console.log("文件下载链接", res.fileList[0].tempFileURL)
that.setData({
fileUrl: res.fileList[0].tempFileURL
})
},
fail: err => {
// handle error
}
})
},
//复制excel文件下载链接
copyFileUrl() {
let that = this
wx.setClipboardData({
data: that.data.fileUrl,
success(res) {
wx.getClipboardData({
success(res) {
console.log("复制成功", res.data) // data
}
})
}
})
},
inputFileName(e){
this.setData({
fileName:e.detail.value
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
//todo 当前的年月日 存入appdata wxml {{nowdata}}
let enddate = moment('YYYY-MM-DD');
this.setData({
enddate: enddate
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
})
导出的excel只有100条数据?
async DataCue(){
let count = await db.collection('seamild_lfdj').count()
count = count.total
let all = []
for (let i = 0; i < count; i += 20){
let list = await db.collection('seamild_lfdj').skip(i).get()
all = all.concat(list.data)
}
this.setData({
all:all
})
this.exportData()
console.log('返回结果',this.data.all)
},