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

建设电影网站的目的购物网站制作

建设电影网站的目的,购物网站制作,软件开发需要什么学历,网站托管做的好的公司微信小程序中pdf的上传、下载及excel导出 pdf上传上传1&#xff1a;上传2&#xff1a; pdf下载导出excel pdf上传 上传两种方法&#xff1a; 上传1&#xff1a; 1.用vant weapp组件&#xff1a; //pdf上传--vant weapp组件 <view class"content"><van-u…

微信小程序中pdf的上传、下载及excel导出

  • pdf上传
    • 上传1:
    • 上传2:
  • pdf下载
  • 导出excel

pdf上传

上传两种方法:

上传1:

1.用vant weapp组件:

//pdf上传--vant weapp组件
<view class="content"><van-uploaderfile-list="{{ fileList }}"  bind:after-read="afterReadFile" accept="file"  upload-icon="plus"preview-size="30px"max-count="1"deletable="{{deletableFile}}"></van-uploader>
</view> page({data:{fileList:[],//pdf上传}
})afterReadFile: function (e) {let that = this;const { file } = e.detail;let myId = that.data.myId; //console.log(file,1000);wx.uploadFile({url: api.hhh+'?file='+file.url+'&schedulingId='+myId,//服务器上的pdf地址filePath: file.url,name: 'file',// formData: { //     file: file.url,//     schedulingId:myId// },success(res) {// 上传完成需要更新 fileListconst { fileList = [] } = that.data;fileList.push({ ...file });that.setData({ fileList });},});
},

上传2:

<view class="content" bindtap="uploadFileTap">上传
</view>//pdf上传--原生组件
uploadFileTap:function(e){let that = this;let myId = that.data.myId; wx.chooseMessageFile({count: 1,type: 'file',success (res) {// tempFilePath可以作为img标签的src属性显示图片const tempFilePaths = res.tempFileswx.uploadFile({url: url,//服务器上的pdf地址 filePath: tempFilePaths[0].path,name: 'file',formData: {file: tempFilePaths[0].path,schedulingId:myId},success (res){const data = res.data//do somethingwx.showToast({title: '数据上传成功!',icon: 'none',duration: 3000})}})}})
},

pdf下载

参考:https://blog.csdn.net/weixin_38566069/article/details/110229404

//下载pdf
downloadPDF:function(e){let that = this;let myId = that.data.myId; wx.showLoading({title: '加载中...',mask: true});//获取pdf地址app.get(api.xxxx, {schedulingId: myId, //}).then(res => {if (res.code == 200) {wx.hideLoading()let pdfUrl=res.data ? (res.data.pdfUrl ? res.data.pdfUrl : null) : nullif(pdfUrl){const fileExtName = ".pdf";const randfile = new Date().getTime() + fileExtName;const newPath = `${wx.env.USER_DATA_PATH}/${randfile}`;that.deletContract();//下载wx.downloadFile({url: pdfUrl,filePath: newPath,success: function (res) {const filePath = res.tempFilePath;wx.openDocument({filePath: newPath,showMenu: true,fileType: 'pdf',success: function (res) {}})},fail: function (res) {wx.hideLoading();}})}else{wx.showToast({title: '请先上传pdf数据!',icon: 'none',duration: 3000})}} else {wx.hideLoading()wx.showToast({title: '获取数据失败!',icon: 'none',duration: 3000})}}).catch((err) => {wx.hideLoading()wx.showToast({title: 'err',icon: 'none',duration: 3000})});
},// 删除本地文件
deletContract() {try {let file = wx.getFileSystemManager();file.readdir({dirPath: `${wx.env.USER_DATA_PATH}`,success: res => {console.log(res);if (res.files.length > 2) {file.unlink({filePath: `${wx.env.USER_DATA_PATH}/${res.files[0]}`,complete: res => {}})}}})} catch (error) {}
},

导出excel

//导出ExceldownloadExcel:function(e){let that = this;let myId = that.data.myId; wx.showLoading({title: '加载中...',mask: true});app.get(api.xxxExcel, {schedulingId: myId, }).then(res => {if (res.code == 200) {let excelUrl=res.data ? res.data : nullif(excelUrl){let type=excelUrl.split('.').pop();let fileExtName = "";if(type==''){//空wx.showToast({title: '导入的非Excel文件!',icon: 'none',duration: 3000})return false}else if(type=='xls'){fileExtName=".xls"}else if(type=='xlsx'){fileExtName=".xlsx"}const randfile = new Date().getTime() + fileExtName;const newPath = `${wx.env.USER_DATA_PATH}/${randfile}`;that.deletContract();wx.downloadFile({url: excelUrl,filePath: newPath,success: function (res) {wx.hideLoading()const filePath = res.filePath;wx.openDocument({filePath: newPath,showMenu: true,fileType: type,success: function (res) {}})},fail: function (res) {wx.hideLoading();}})}else{wx.showToast({title: '请先上导入Excel数据!',icon: 'none',duration: 3000})}} else {wx.hideLoading()wx.showToast({title: '获取Excel数据失败!',icon: 'none',duration: 3000})}}).catch((err) => {wx.hideLoading()wx.showToast({title: 'err',icon: 'none',duration: 3000})});},

提示:突然冒出一个报错:wx.chooseMessageFile点击很多次后就突然无效了
昨天上传功能在【微信开发工具和移动端】都可以用,早上突然实现了。
查了下是官方给出的解释是:
2023年9月15日之前,此功能逻辑只对开发版/体验版生效,开发者请尽快进行隐私弹窗适配、发版。2023年9月15日之后,将对正式版生效,详情可见《关于小程序隐私保护指引设置的公告》。

具体见:
https://developers.weixin.qq.com/community/develop/doc/0002aa86b6ccb056ff20a04e96bc00?jumpto=comment

https://developers.weixin.qq.com/community/develop/doc/00042e3ef54940ce8520e38db61801

http://www.hkea.cn/news/99623/

相关文章:

  • 如何做b2c网站下列关于友情链接说法正确的是
  • 网站开发中网页上传seo在线网站推广
  • 网站建设报价流程免费培训网站
  • 聊城网站建设服务好最新网域查询入口
  • 一般网站建设流程有哪些步骤官方百度app下载安装
  • 档案网站建设的步骤八大营销方式有哪几种
  • 手机网站免费制作平台semseo
  • 周口市做网站小红书seo排名
  • 网站开始怎么做的ps培训
  • 去哪个网站找题目给孩子做保定百度首页优化
  • 五道口网站建设惠州seo外包服务
  • 如何查看网站是否备案企业宣传册
  • 好的网站建设公司排名互联网宣传推广
  • 上海买二手房做哪个网站好seo快速排名优化
  • 十大中国网站制作免费广告
  • wordpress 文章主题关键词推广seo
  • 佛山网站建设佛山网络推广代运营公司靠谱吗
  • 贵阳疫情最新消息站内seo优化
  • wordpress相关问题深圳百度关键字优化
  • 做国珍新时代 网站陕西seo顾问服务
  • 建立网站怎么做关键字搜索引擎营销的作用
  • 广州手机网站建设宁波seo优化费用
  • 怎么设置网站服务器宁德市教育局官网
  • 查看网站源代码建站可以牛排seo系统
  • 政府网站建设的基本原则百度网盘电脑版
  • 张家港网站建设福州百度快速优化
  • 兼职做网站编辑百度搜索推广开户
  • 谁告诉你j2ee是做网站的宁波网站推广找哪家公司
  • 谷歌外贸建站多少钱搭建网站教程
  • 赚钱靠普的网站关键字搜索软件