当前位置: 首页 > news >正文

制定网站分工任务网站的建设规划/百度指数查询入口

制定网站分工任务网站的建设规划,百度指数查询入口,wordpress引用js插件,施工企业总工程师述职报告实现目标 将所有订单信息导出到excel表格中 思路 1、在页面中bindtap绑定一个导出点击事件daochu() 2、先获取所有订单信息,并将数据添加到List数组中 3、传入以List数组作为参数,调用get_excel云函数 4、get_excel云函数利用node-xlsx第三方库&#…

实现目标

将所有订单信息导出到excel表格中

 思路

1、在页面中bindtap绑定一个导出点击事件daochu()

2、先获取所有订单信息,并将数据添加到List数组中

3、传入以List数组作为参数,调用get_excel云函数

4、get_excel云函数利用node-xlsx第三方库,在云函数所在目录npm install安装node-xlsx

5、在云函数导入const xlsx = require('node-xlsx'),并设置表格第一行的列数据

6、循环List数组将数据依次添加到第二行、第三行、第四行等等。

7、云函数返回生成excel的临时地址

8、在页面js获取到该临时地址并预览excel表格

完整代码

saveexcel.js

const app = getApp()
Page({/*** 页面的初始数据*/data: {},daochu() {var that = thiswx.showLoading({title: '正在加载',})var List = []wx.cloud.database().collection('yxb_nmkq_order').count().then(async function name(res) {console.log(res.total)var batchTimes = Math.ceil(res.total / 20)for (let index = 0; index < batchTimes; index++) {console.log("第" + index + "次循环");//异步转同步var itemlist = await that.getitemlist(index)List = List.concat(itemlist)}that.setData({List: List})console.log("处理完毕", List);wx.cloud.callFunction({// 要调用的云函数名称name: 'nmkq_get_excel',// 传递给云函数的event参数data: {List: that.data.List}}).then(res => {console.log("云函数结束");console.log(res);that.saveExcel(res.result.fileID)}).catch(err => {// handle errorwx.hideLoading({success: (res) => {wx.showToast({title: '下载失败!',icon: 'none'})},})})})},getitemlist(index) {return new Promise((rev, rej) => {wx.cloud.database().collection('yxb_nmkq_order').skip(index * 20).limit(20).get({success: function (res) {// res.data 包含该记录的数据console.log(res.data)rev(res.data)}})})},saveExcel(fileID) {var that = thiswx.cloud.getTempFileURL({fileList: [fileID],success: res => {that.setData({fileUrl: res.fileList[0].tempFileURL})console.log("最后的地址" + that.data.fileUrl);wx.downloadFile({url: that.data.fileUrl,success: (res) => {that.setData({httpfile: res.tempFilePath})console.log("找不到这个地址?" + that.data.httpfile);//预览文件wx.openDocument({filePath: that.data.httpfile,showMenu: true,success: res => {console.log("预览成功");wx.hideLoading({success: (res) => {},})},fail: err => {console.log(err);}})},fail: (err) => {console.log('读取失败', err)wx.showToast({title: '读取失败!',})}})},fail: err => {console.log(err);wx.showToast({title: '下载失败2!',icon: 'none'})}})},})

 saveexcel.json

{"usingComponents": {},"navigationBarTitleText": "数据导出excel"
}

  saveexcel.wxml


<view style="width: 100%;display: flex;justify-content: center;">
<button style="width: 80%;margin: 20rpx 0;" bindtap="daochu">导出</button>
</view>

云函数写法:

云函数目录/index.js

// 云函数入口文件
const cloud = require('wx-server-sdk')
const xlsx = require('node-xlsx')cloud.init()// 云函数入口函数
exports.main = async (event, context) => {console.log(event);try {let List = event.List//2,定义存储数据的let alldata = [];let row = ['记录号', '订单号', '用户id', '商品名称', '付款价格', '手机号', '姓名', '数量', '备注', '创建时间', '状态值']; //表属性alldata.push(row);for (var i = 0; i < List.length; i++) {let arr = [];arr.push(List[i]._id);arr.push(List[i].orderId);arr.push(List[i].user._id);arr.push(List[i].shop.title);arr.push(List[i].fkprice);arr.push(List[i].phone);arr.push(List[i].username);arr.push(List[i].number);arr.push(List[i].bz);arr.push(List[i].time));arr.push(List[i].status);alldata.push(arr)}console.log(alldata);//3,把数据保存到excel里var buffer = await xlsx.build([{name: "mySheetName",data: alldata}]);console.log(buffer);//4,把excel文件保存到云存储里return await cloud.uploadFile({cloudPath: Date.now() + 'shuju.xlsx',fileContent: buffer, //excel二进制文件})} catch (e) {console.error(e)return e}
}

如果这篇文章对您有所帮助,给个小赞赞吧🌹

http://www.fp688.cn/news/24.html

相关文章:

  • python 做办公网站/域名收录查询
  • 做网站不错的公司/郑州网站seo顾问
  • 自己做网站不推广/南京市网站
  • 最好的网站建设公司哪家好/aso优化平台有哪些
  • 泉州市住房和城乡建设部网站/免费制作个人网站
  • 哪个网站找做软件/关键词首页排名优化平台
  • js效果网站/seo教程视频论坛
  • 婚纱摄影网站应该如何做优化/自己怎么做百度推广
  • 找产品做代理都有哪个网站/企业网站seo多少钱
  • 云南网站建设公司/seo搜索排名影响因素主要有
  • 有些网站域名解析错误/亚马逊seo是什么意思
  • jsp做门户网站/企业类网站有哪些例子
  • 辽宁省人民政府大楼/牛排seo系统
  • wordpress主题仿/seo网站优化培
  • 网络托管公司/短视频seo是什么
  • 网络营销收获与体会/点金推广优化公司
  • 网站自己怎么做优化/2022年适合小学生的新闻
  • 访问网站出现目录/谷歌浏览器安卓下载
  • 小江高端企业网站建设/查询seo