|
@@ -145,31 +145,31 @@ const onLoad = e => {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
-const down = () => {
|
|
|
+const down = item => {
|
|
|
if (isWechat) return showToast('请使用浏览器打开本页面');
|
|
|
-// fetch(item.downUrl)
|
|
|
-// .then(response => {
|
|
|
-// // 确保服务器返回的是blob类型的数据
|
|
|
-// if (!response.ok) {
|
|
|
-// throw new Error('Network response was not ok');
|
|
|
-// }
|
|
|
-// return response.blob();
|
|
|
-// })
|
|
|
-// .then(blob => {
|
|
|
-// // 创建一个可下载的链接
|
|
|
-// const url = URL.createObjectURL(blob);
|
|
|
-// const a = document.createElement('a');
|
|
|
-// a.href = url;
|
|
|
-// a.download = item.title || 'download.docx'; // 如果未指定文件名,则默认为'download.docx'
|
|
|
-// a.style.display = 'none';
|
|
|
-// document.body.appendChild(a);
|
|
|
-// a.click();
|
|
|
-// window.URL.revokeObjectURL(url); // 释放URL对象
|
|
|
-// document.body.removeChild(a);
|
|
|
-// })
|
|
|
-// .catch(error => {
|
|
|
-// console.error('Error downloading file:', error);
|
|
|
-// });
|
|
|
+ window.fetch(item.downUrl)
|
|
|
+ .then(response => {
|
|
|
+ // 确保服务器返回的是blob类型的数据
|
|
|
+ if (!response.ok) {
|
|
|
+ throw new Error('Network response was not ok');
|
|
|
+ }
|
|
|
+ return response.blob();
|
|
|
+ })
|
|
|
+ .then(blob => {
|
|
|
+ // 创建一个可下载的链接
|
|
|
+ const url = URL.createObjectURL(blob);
|
|
|
+ const a = document.createElement('a');
|
|
|
+ a.href = url;
|
|
|
+ a.download = item.title || 'download.docx'; // 如果未指定文件名,则默认为'download.docx'
|
|
|
+ a.style.display = 'none';
|
|
|
+ document.body.appendChild(a);
|
|
|
+ a.click();
|
|
|
+ window.URL.revokeObjectURL(url); // 释放URL对象
|
|
|
+ document.body.removeChild(a);
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.error('Error downloading file:', error);
|
|
|
+ });
|
|
|
};
|
|
|
</script>
|
|
|
<style>
|