hookehuyr

文件下载优化微信浏览器判断不同系统处理

1 <!-- 1 <!--
2 * @Date: 2022-08-31 16:16:49 2 * @Date: 2022-08-31 16:16:49
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-07-27 19:30:34 4 + * @LastEditTime: 2024-07-29 14:10:48
5 * @FilePath: /data-table/src/components/FileUploaderField/index.vue 5 * @FilePath: /data-table/src/components/FileUploaderField/index.vue
6 * @Description: 文件上传控件 6 * @Description: 文件上传控件
7 --> 7 -->
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
69 > 69 >
70 {{ item.name }} 70 {{ item.name }}
71 </a> 71 </a>
72 + <a class="app-download-btn" id="BtnClick" href="javascript:;" style="display: none;"> 点此继续访问 </a>
72 </div> 73 </div>
73 </div> 74 </div>
74 75
...@@ -117,8 +118,20 @@ onMounted(() => { ...@@ -117,8 +118,20 @@ onMounted(() => {
117 118
118 const downloadFile = (item) => { 119 const downloadFile = (item) => {
119 if (wxInfo().isWeiXin) { 120 if (wxInfo().isWeiXin) {
120 - // 在微信内置浏览器中,直接跳转到手机自带浏览器中下载文件 121 + // 安卓浏览器
121 - window.location.href = item.url; 122 + if (wxInfo().isAndroid) {
123 + var iframe = document.createElement("iframe");
124 + iframe.style.display = "none";
125 + iframe.src = item.url;
126 + document.body.appendChild(iframe);
127 + iframe.click();
128 + }
129 + // IOS浏览器
130 + else if (wxInfo().isiOS) {
131 + var entityDom = document.getElementById('BtnClick');
132 + entityDom.href = item.url;
133 + entityDom.click();
134 + }
122 } else { 135 } else {
123 // 不在微信内置浏览器中,直接打开下载链接 136 // 不在微信内置浏览器中,直接打开下载链接
124 fileLinkToStreamDownload(item.url, item.name, item.name.split('.').pop()); 137 fileLinkToStreamDownload(item.url, item.name, item.name.split('.').pop());
......