您当前的位置: 首页 >  cmmboy1990

uniapp H5预览excle、pdf、word等文件

cmmboy1990 发布时间:2022-01-27 09:56:38 ,浏览量:4

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"
						})
					}
				})

			}
关注
打赏
1688896170
查看更多评论

cmmboy1990

暂无认证

  • 4浏览

    0关注

    131博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.1308s