微信小程序预览文件 兼容性苹果

javascript 复制代码
uni.request({
					url: url,
					method: 'GET',
					header: {
						'Authorization': token,
						responseType: 'blob',
					},
					responseType: "arraybuffer",
					success: (res) => {
						uni.hideLoading()
						const fs = wx.getFileSystemManager(); //获取全局唯一的文件管理器
						let index = url.lastIndexOf(".");
						const typeRp = url.slice(index, url.length);
						let fileType = url.slice(index + 1, url.length);
						var platform = wx.getSystemInfoSync();
						if (platform.platform === "ios") {
							if (fileType == 'xls') {
								fileType = fileType + 'x'
							}
						}
						const filePath = `${wx.env.USER_DATA_PATH}/preview${typeRp}`;
						fs.writeFile({
							filePath,
							data: res.data,
							encoding: "binary", //二进制流文件必须是 binary
							success(res) {
								uni.hideLoading()
								// console.log(res, '写入成功', typeRp, fileType);
								fs.access({
									path: filePath,
									success: () => {
										wx.openDocument({
											filePath,
											fileType,
											showMenu: true,
											success: function(res) {
												setTimeout(() => {
													wx.hideLoading();
												}, 500);
											},
										});
									},
									fail: (err) => {
										uni.hideLoading()
									},
								});
							},
						});
					},
					fail: (err) => {
						uni.hideLoading()
					},
				})

如果是苹果系统就需要修改一下后缀

javascript 复制代码
var platform = wx.getSystemInfoSync();
						if (platform.platform === "ios") {
							if(fileType == 'xls') {
								fileType = fileType + 'x'
							}
						}
相关推荐
换日线°6 小时前
NFC标签打开微信小程序
前端·微信小程序
光影少年10 小时前
AIGC + Taro / 小程序
小程序·aigc·taro
2501_9159184111 小时前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074712 小时前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
天空属于哈夫克312 小时前
Go 语言实战:构建一个企微外部群“技术贴收藏夹”小程序后端
小程序·golang·企业微信
菜鸟una13 小时前
【微信小程序+Taro 3+NutUI 3】input (nut-input) 、 textarea (nut-texteare)类型使用避坑
前端·vue.js·微信小程序·小程序·taro
计算机毕设指导613 小时前
基于微信小程序的校园二手交易系统【源码文末联系】
java·spring boot·spring·微信小程序·小程序·tomcat·maven
Jiaberrr13 小时前
小程序setData性能优化指南:避开坑点,让页面丝滑如飞
前端·javascript·vue.js·性能优化·小程序
Code王13 小时前
【课程设计/毕业设计】基于springboot +微信小程序的家政服务平台系统基于小程序的家政服务系统安全开发【附源码、数据库、万字文档】
spring boot·小程序·课程设计
CHU72903513 小时前
旧物回收小程序前端功能版块解析:便捷赋能闲置循环
小程序