1
0
tangning 7 ماه پیش
والد
کامیت
1aa958d8d8
1فایلهای تغییر یافته به همراه15 افزوده شده و 1 حذف شده
  1. 15 1
      src/view/material/index.vue

+ 15 - 1
src/view/material/index.vue

@@ -245,11 +245,25 @@ const handleCommand = (command: string | number | object, item) => {
       handleDel(item)
       break;
     default:
-      window.open(item.filesUrl)
+      // window.open(item.filesUrl)
+      downloadFile(item.filesUrl, item.fileName+'.'+item.fileFormat)
       console.log("other", command);
   }
   // ElMessage(`click on item ${command}`)
 }
+// 下载文件
+function downloadFile(sourceUrl, fileName,) {
+  const link = document.createElement('a');
+  link.style.display = 'none';
+  // 设置下载地址
+  link.setAttribute('href', sourceUrl);
+  // 设置文件名
+  link.setAttribute('download', fileName);
+  document.body.appendChild(link);
+  link.click();
+  document.body.removeChild(link);
+}
+
 function handleClose(e) {
   console.log("handleClose", e);
 }