Explorar o código

Merge branch 'master' of http://8.152.4.3:3000/yp_web/yoe-shop-web

weixin_52219567 hai 1 día
pai
achega
54c1db9eff
Modificáronse 1 ficheiros con 37 adicións e 0 borrados
  1. 37 0
      src/views/reconciliation/billManage/detail.vue

+ 37 - 0
src/views/reconciliation/billManage/detail.vue

@@ -65,6 +65,7 @@
           <el-table-column label="操作" width="150" align="center">
             <template #default="{ row }">
               <el-button type="primary" link @click="handlePreview(row.url)">预览</el-button>
+              <el-button type="primary" link @click="handleDownload(row)">下载</el-button>
             </template>
           </el-table-column>
         </el-table>
@@ -123,6 +124,42 @@ const handleBack = () => {
   router.back();
 };
 
+// 下载发票附件
+const handleDownload = async (row: any) => {
+  if (!row.url) {
+    ElMessage.warning('附件不存在');
+    return;
+  }
+  const url = row.url;
+  const fileName = url.split('/').pop() || '附件';
+
+  try {
+    // 使用 fetch 获取文件内容
+    const response = await fetch(url);
+    if (!response.ok) {
+      throw new Error('下载失败');
+    }
+    const blob = await response.blob();
+    const blobUrl = window.URL.createObjectURL(blob);
+
+    // 创建下载链接
+    const link = document.createElement('a');
+    link.href = blobUrl;
+    link.download = decodeURIComponent(fileName);
+    document.body.appendChild(link);
+    link.click();
+    document.body.removeChild(link);
+
+    // 释放 blob URL
+    window.URL.revokeObjectURL(blobUrl);
+    ElMessage.success('下载成功');
+  } catch (error) {
+    console.error('下载失败:', error);
+    // 降级方案:直接打开链接让用户手动保存
+    window.open(url, '_blank');
+  }
+};
+
 const loadDetail = async (id: number | string) => {
   loading.value = true;
   try {