提交 9caa7423 authored 作者: 王鹏飞's avatar 王鹏飞

feat: 添加文件下载功能,支持特定类型文件的下载

上级 ff2a2dd8
......@@ -7,6 +7,7 @@ import {
saveExperimentCaseResourceVisibility,
unbindExperimentCaseResource,
} from '../api'
import { saveAs } from 'file-saver'
import Preview from '@/components/Preview.vue'
const BindDialog = defineAsyncComponent(() => import('./ExperimentCaseResourceDialog.vue'))
......@@ -41,6 +42,14 @@ function handleView(file: ExperimentCaseResourceFileItem) {
previewVisible.value = true
}
function isDownloadableFile(file: ExperimentCaseResourceFileItem) {
return ['5', '6'].includes(String(file.type))
}
function handleDownload(file: ExperimentCaseResourceFileItem) {
saveAs(file.url, file.name)
}
async function fetchList() {
if (!props.experimentId) return
loading.value = true
......@@ -136,6 +145,7 @@ watch(
inactive-value="0"
@change="handleVisibilityChange(item)" />
<el-button link type="primary" @click="handleView(file)">查看</el-button>
<el-button v-if="isDownloadableFile(file)" link type="primary" @click="handleDownload(file)">下载</el-button>
</div>
</div>
</div>
......
<script setup lang="ts">
import type { ExperimentCaseResourceFileType, ExperimentCaseResourceType } from '../types'
import { Document } from '@element-plus/icons-vue'
import { saveAs } from 'file-saver'
import { getExperimentCaseResourceList } from '../api'
import Preview from '@/components/Preview.vue'
......@@ -34,6 +35,14 @@ function handleView(file: ExperimentCaseResourceFileType) {
previewVisible.value = true
}
function isDownloadableFile(file: ExperimentCaseResourceFileType) {
return ['5', '6'].includes(String(file.type))
}
function handleDownload(file: ExperimentCaseResourceFileType) {
saveAs(file.url, file.name)
}
async function fetchInfo() {
if (!props.experiment_id) return
loading.value = true
......@@ -78,7 +87,10 @@ watch(
<div class="case-resource-file__name">{{ file.name }}</div>
</div>
</div>
<el-button link type="primary" @click="handleView(file)">查看</el-button>
<div class="case-resource-file__actions">
<el-button link type="primary" @click="handleView(file)">查看</el-button>
<el-button v-if="isDownloadableFile(file)" link type="primary" @click="handleDownload(file)">下载</el-button>
</div>
</div>
</div>
</div>
......@@ -176,6 +188,13 @@ watch(
min-width: 0;
}
.case-resource-file__actions {
display: flex;
align-items: center;
gap: 10px;
flex-shrink: 0;
}
.case-resource-file__name {
font-size: 13px;
color: #303133;
......@@ -191,5 +210,9 @@ watch(
flex-direction: column;
align-items: stretch;
}
.case-resource-file__actions {
justify-content: flex-end;
}
}
</style>
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论