diff --git a/src/views/work/NegativeTask.vue b/src/views/work/NegativeTask.vue index 00c5da9..6bb1abb 100644 --- a/src/views/work/NegativeTask.vue +++ b/src/views/work/NegativeTask.vue @@ -110,28 +110,32 @@ onMounted(() => { }); function handleDownload(row) { - if (row.status !== '1') { - } - fetch(`${BASE_PATH}/file/stream${row.filePath}`) - .then((response) => { - console.log(response); - return response.blob(); - }) - .then((res) => { - console.log(res); - const blob = new Blob([res], { - type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - }); - const url = window.URL.createObjectURL(blob); - const link = document.createElement("a"); - link.href = url; - link.setAttribute("download", row.taskName + ".xlsx"); - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - window.URL.revokeObjectURL(url); - }); + fetch(`${BASE_PATH}/file/stream${row.filePath}`) + .then((response) => response.blob()) + .then((blob) => { + + const url = window.URL.createObjectURL(blob); + + const link = document.createElement("a"); + link.href = url; + + let fileName = row.taskName; + + if (row.filePath.endsWith(".docx")) { + fileName += ".docx"; + } else { + fileName += ".xlsx"; + } + + link.download = fileName; + + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + window.URL.revokeObjectURL(url); + }); }