1.代码

previewFile() {
				uni.showLoading({
					title: '加载中'
				})

				uni.downloadFile({
					url: "https://..../gwy.xls", //后端返回的文件地址
					// filePath: wx.env.USER_DATA_PATH + '/gwy.xls',
					// filePath: wx.env.USER_DATA_PATH + '/' + item.name + '.' + item.value.split('.')[item.value.split('.').length - 1],
					success: function(res) {
						if (res.statusCode === 200) {
							uni.openDocument({
								showMenu: true,
								filePath: res.tempFilePath,
								success: function(res) {
									console.log(res, '打开文件成功')
								},
								fail: (err) => {
									uni.showToast({
										title: '打开文件失败请重试',
										icon: 'none'
									})
								}
							})
						} else {
							uni.showToast({
								title: '打开文件失败请重试',
								icon: 'none'
							})
						}
						uni.hideLoading()
					},
					fail: (err) => {
						uni.hideLoading()
						uni.showToast({
							title: '加载失败请重试',
							icon: "none"
						})
					}
				})

			}
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐