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

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'
							}
						}
相关推荐
00后程序员张12 分钟前
HTTPS单向认证、双向认证、抓包原理与反抓包策略详解
网络协议·http·ios·小程序·https·uni-app·iphone
梦梦代码精2 小时前
LikeShop按摩到家系统:2026年本地生活创业新风口,上门服务O2O源码私有化部署实战
大数据·docker·小程序·uni-app·生活·高并发·开源软件
leduo668899o3 小时前
商城小程序自由容器支持图片自适应详解:从入门到实战全攻略
小程序
这是个栗子4 小时前
【uni-app微信小程序问题解决】Uni-app 微信小程序组件不渲染
微信小程序·小程序·uni-app
倒流时光三十年5 小时前
第四章 WXSS 样式系统与布局
spring boot·微信小程序
万岳科技系统开发5 小时前
外卖跑腿配送开发搭建指南:从用户下单到配送完成全流程解析
大数据·前端·小程序
靠谱品牌推荐官5 小时前
【高性能工程】每秒万次物联网数据高频握手:如何设计一套抗丢包的工业级小程序后端微服务架构?
物联网·小程序·架构
靠谱品牌推荐官5 小时前
【高并发实战】如何基于缓存穿透治理机制设计一套高可用的小程序本地缓存中台架构?
缓存·小程序·架构
小羊Yveesss5 小时前
商家小程序外卖订单打印方案:云打印机对接、分单逻辑与模板配置实战
小程序·apache
爱学习 爱分享1 天前
微信小程序html 在 webview 会打开再缩放一下
微信小程序·小程序·html