Browse Source

解决下载重命名文件名问题

gcz 2 weeks ago
parent
commit
2cf1c38745
2 changed files with 6 additions and 10 deletions
  1. 0 1
      src/layout/index.vue
  2. 6 9
      src/utils/index.js

+ 0 - 1
src/layout/index.vue

@@ -146,7 +146,6 @@ const handleHistoryClick = async (item) => {
   // 处理历史记录点击
   console.log('点击历史记录:', item)
   console.log('item.relatedType',item.relatedType);
-  console.log('item.relatedType',item.relatedType=='ai.answer');
   if (!item.relatedType) return;
 
     switch (item.relatedType) {

+ 6 - 9
src/utils/index.js

@@ -16,10 +16,10 @@ export const getUuid = () => {
  * @returns {Promise} - 返回下载Promise
  */
 export const downloadFile = (url, fileName) => {
-    // console.log('url',url);
-    // console.log('fileName',fileName);
-  return new Promise((resolve, reject) => {
-    try {
+  return fetch(url)
+    .then(response => response.blob())
+    .then(blob => {
+      const url = window.URL.createObjectURL(blob)
       const link = document.createElement('a')
       link.href = url
       link.download = fileName
@@ -27,9 +27,6 @@ export const downloadFile = (url, fileName) => {
       document.body.appendChild(link)
       link.click()
       document.body.removeChild(link)
-      resolve()
-    } catch (error) {
-      reject(error)
-    }
-  })
+      window.URL.revokeObjectURL(url)
+    })
 }