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

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'
							}
						}
相关推荐
HERR_QQ8 小时前
【unify】unify的微信小程序开发学习 (to be continued)
学习·微信小程序·小程序
racerun16 小时前
小程序导航设置更多内容的实现方法
小程序
说私域16 小时前
基于开源AI智能名片链动2+1模式S2B2C商城小程序的超级文化符号构建路径研究
人工智能·小程序·开源
mg66816 小时前
微信小程序入门实例_____快速搭建一个快递查询小程序
微信小程序·小程序
程序员柳17 小时前
基于微信小程序的校园二手交易平台、微信小程序校园二手商城源代码+数据库+使用说明,layui+微信小程序+Spring Boot
数据库·微信小程序·layui
Jyywww12120 小时前
微信小程序学习笔记
笔记·学习·微信小程序
The_era_achievs_hero21 小时前
微信小程序41~50
微信小程序·小程序
走,带你去玩1 天前
uniapp 微信小程序水印
微信小程序·小程序·uni-app
是一碗螺丝粉1 天前
🔥 微信H5视频自动播放终极秘籍:WeixinJSBridge竟是官方“通行证”?
微信小程序