uniapp to WeChat applet to preview and download files

	// 预览
			openPDF() {
				uni.showLoading({
					title: '加载中',
				})
				switch (uni.getSystemInfoSync().platform) {
					case "android":
						console.log("安卓");
						// 这里直接调用原生的方法,我们上面定义的
						this.androidOpenPdf(这里放下载资源的url);
						break;
					case "ios":
						console.log("IOS");
						this.androidOpenPdf(这里放下载资源的url);
						//这里跳转web-view页面
						// uni.navigateTo({
						// 	url: "./webView?contractUrl=" + this.OrderInfoList.report,
						// });
						break;
					default:
						console.log('其他')
						this.androidOpenPdf(这里放下载资源的url);
						break;
				}
			},
androidOpenPdf(url) {
				uni.downloadFile({
					url: url,
					success: function(res) {
						var filePath = res.tempFilePath;
						console.log(filePath)
						uni.openDocument({
							showMenu: true,
							filePath: filePath,
							success: function(res) {
								uni.hideLoading();
								console.log("打开文档成功");
							},
						});
					},
				});
			},

Download all depends on it→→→showMenu: true

The pro-test is effective! ! !

There are some differences between ios system and android system:

If ios needs to be downloaded, the file needs to be shared to download the file

Android system does not need to download files directly

Guess you like

Origin blog.csdn.net/maowencai/article/details/128019366