wuyi hai 1 ano
pai
achega
db2b556a56
Modificáronse 2 ficheiros con 23 adicións e 0 borrados
  1. 1 0
      package.json
  2. 22 0
      src/views/TaskView.vue

+ 1 - 0
package.json

@@ -15,6 +15,7 @@
     "axios": "^1.3.6",
     "date-fns": "^2.29.3",
     "element-plus": "^2.3.3",
+    "file-saver": "^2.0.5",
     "pinia": "^2.0.32",
     "qs": "^6.11.1",
     "resolve-url": "^0.2.1",

+ 22 - 0
src/views/TaskView.vue

@@ -40,6 +40,9 @@
                 <ElButton type="primary" size="small" @click="pause(row)" v-if="row.status === 'pending'">
                     暂停
                 </ElButton>
+                <ElButton type="primary" size="small" @click="receipt(row)" v-if="row.status === 'completed'">
+                    回执
+                </ElButton>
                 <ElButton type="danger" size="small" @click="del(row)" v-if="row.status === 'idle'">删除</ElButton>
             </template>
         </ElTableColumn>
@@ -242,6 +245,25 @@ async function pause(row) {
     await http.post(`/task/${row.id}/pause`)
     table.value.refresh()
 }
+
+async function receipt(row) {
+    try {
+        const response =  await http.post(`/task/item/${row.id}/receipt`, {
+            responseType: 'blob', // 重要:指定响应类型为blob,以便处理二进制文件
+        });
+        // 处理成功响应,触发文件下载
+        const url = window.URL.createObjectURL(new Blob([response.data]));
+        const link = document.createElement('a');
+        link.href = url;
+        link.setAttribute('download', `${row.name}_回执.xlsx`);
+        document.body.appendChild(link);
+        link.click();
+        document.body.removeChild(link);
+    } catch (error) {
+        console.error('Error receipt:', error)
+        ElMessage.error('获取回执错误,请稍后再试.')
+    }
+}
 </script>
 <style lang="less" scoped>
 .tip {