需求:在打开新页面的时候展示pdf或者word文件详情,可以进行购买并下载。(不知道这个需求是否可行)
前置:已经把域名放在了业务域名中配置,现在只是一个静态资源oss的地址,word以及pdf文件地址来模拟实现
现状:我现在实现的,在微信开发者工具中打开页面之后会显示下载按钮,点击会在wps打开。
现状代码如下:
uni.downloadFile({
url,
success: (res) => {
uni.hideLoading();
if (res.statusCode === 200) {
uni.openDocument({
filePath: res.tempFilePath,
fileType: docFileType.value,
showMenu: true,
success: () => {
uni.showToast({ title: '打开后点击右上角菜单保存', icon: 'none' });
},
fail: () => {
uni.showToast({ title: '打开文档失败', icon: 'none' });
},
});
} else {
uni.showToast({ title: '下载失败', icon: 'none' });
}
},
fail: () => {
uni.hideLoading();
uni.showToast({ title: '下载失败,请检查网络', icon: 'none' });
},
complete: () => {
isDownloading.value = false;
},
});
