uni-app微信小程序分享与下载pdf文件

文章讲述了在uni-app开发的微信小程序中,分享功能可能导致数据传输过程中的丢失。作者分析了问题并提供了检查分享路径进入和下载PDF文件的解决方案,以确保分享后的数据完整无误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目场景:

提示:这里简述项目相关背景:
uni-app微信小程序分享
分享使用制定图片
onShareAppMessage() {
let materialUrl = this.oss + this.materialList.materialUrl;
let share = “share”;
return {
title: this.materialList.materialTitle,
imageUrl: this.oss + this.materialList.materialShareThumbnail,
path: “/edrpages/pages/manual/manual?from=” + share + “&materialUrl=” + materialUrl,
};
},

问题描述

分享成功后,点击

例如:数据传输过程中数据不时出现丢失的情况,偶尔会丢失一部分数据
APP 中接收数据代码:

@Override
	public void run() {
		bytes = mmInStream.read(buffer);
		mHandler.obtainMessage(READ_DATA, bytes, -1, buffer).sendToTarget();
	}

原因分析:

解决方案:

首先判断是否为分享路径进入
onLoad(opetion) {
if (opetion && opetion.from === “share”) {
this.openFile(opetion.materialUrl);
this.shareBg = true;
} else {
// 非分享进入,执行其他逻辑
this.shareBg = false;
}
this.typeId = opetion.type;
this.getFileList(opetion.type);
this.getProductList();
},
分享之后下载PDF文件
openFile(materialUrl) {
wx.showLoading({
title: “正在打开文档,请等待…”,
});
wx.downloadFile({
url: materialUrl,
// filePath: wx.env.USER_DATA_PATH + “/” + material.materialTitle + “.pdf”,
success: (res) => {
const filePath = res.tempFilePath
wx.openDocument({
filePath,
showMenu: true,
success: (res) => {
wx.hideLoading();
this.shareBg = false;
},
fail: function (err) {
wx.hideLoading();
wx.showToast({
title: “打开文档失败”,
icon: “none”,
});
},
});
},
fail: function (err) {
wx.hideLoading();
wx.showToast({
title: “打开文档失败”,
icon: “none”,
});
},
});
},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值