1
This commit is contained in:
@@ -28,7 +28,12 @@
|
||||
>
|
||||
<el-table-column label="所属模块" prop="moduleName" width="120" show-overflow-tooltip />
|
||||
<el-table-column label="任务类型" prop="typeLabel" width="100" show-overflow-tooltip />
|
||||
<el-table-column label="任务名称" prop="detailType" min-width="150" show-overflow-tooltip />
|
||||
<el-table-column label="任务名称" prop="detailType" min-width="150" show-overflow-tooltip >
|
||||
<template #default="{ row }">
|
||||
<el-button v-if="row.type==2" type="text" icon="Download" class="task-name-text" :loading="downloadingId === row.id" @click="handleDownloadFile(row)">{{row.detailType}}</el-button>
|
||||
<span v-else class="task-name-text">{{row.detailType}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="任务状态" align="center" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<el-tag>{{ row.status }}</el-tag>
|
||||
@@ -58,7 +63,8 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, watch, computed } from 'vue'
|
||||
import { fetchList } from '/@/api/basic/basicasynctask'
|
||||
import { fetchList, downloadTaskFile } from '/@/api/basic/basicasynctask'
|
||||
import { useMessage } from '/@/hooks/message'
|
||||
|
||||
type TaskTab = 'upload' | 'download' | 'other'
|
||||
|
||||
@@ -87,6 +93,7 @@ const tableStyle = {
|
||||
}
|
||||
|
||||
const emptyText = computed(() => EMPTY_TEXT_MAP[activeTab.value])
|
||||
const message = useMessage()
|
||||
|
||||
const loadList = async () => {
|
||||
const type = activeTab.value
|
||||
@@ -135,6 +142,34 @@ const open = () => {
|
||||
visible.value = true
|
||||
}
|
||||
|
||||
const downloadingId = ref<string | number | null>(null)
|
||||
const handleDownloadFile = async (row: any) => {
|
||||
if (!row?.id) return
|
||||
downloadingId.value = row.id
|
||||
try {
|
||||
const response: any = await downloadTaskFile({ id: row.id })
|
||||
const blob = (response && response.data instanceof Blob)
|
||||
? response.data
|
||||
: (response instanceof Blob ? response : new Blob([response]))
|
||||
const dateStr = new Date().toISOString().slice(0, 10)
|
||||
const baseName = row.detailType ? String(row.detailType).replace(/\s+/g, '_') : '下载文件'
|
||||
const fileName = `${baseName}_${dateStr}.xls`
|
||||
const elink = document.createElement('a')
|
||||
elink.download = fileName
|
||||
elink.style.display = 'none'
|
||||
elink.href = URL.createObjectURL(blob)
|
||||
document.body.appendChild(elink)
|
||||
elink.click()
|
||||
URL.revokeObjectURL(elink.href)
|
||||
document.body.removeChild(elink)
|
||||
message.success('下载成功')
|
||||
} catch {
|
||||
message.error('下载失败')
|
||||
} finally {
|
||||
downloadingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user