feat 下载接口

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Ironsp
2026-05-25 09:14:27 +08:00
parent 466230c2c0
commit fc81616118

View File

@@ -63,7 +63,7 @@
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300">
<template #default="scope"> <template #default="scope">
<el-button type="primary" @click="handlePlay(scope.row)">播放</el-button> <el-button type="primary" @click="handlePlay(scope.row)">播放</el-button>
<el-button type="primary" @click="handleUpload(scope.row)">下载至本地</el-button> <el-button type="primary" @click="handleDown(scope.row)">下载至本地</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@@ -88,6 +88,7 @@
<script setup name="Demo" lang="ts"> <script setup name="Demo" lang="ts">
import { listDemo, getDemo, delDemo, addDemo, updateDemo } from '@/api/fileList/index'; import { listDemo, getDemo, delDemo, addDemo, updateDemo } from '@/api/fileList/index';
import { download } from '@/utils/request';
//import { DemoVO, DemoQuery, DemoForm } from '@/api/demo/demo/types'; //import { DemoVO, DemoQuery, DemoForm } from '@/api/demo/demo/types';
const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { proxy } = getCurrentInstance() as ComponentInternalInstance;
@@ -101,6 +102,7 @@ const single = ref(true);
const multiple = ref(true); const multiple = ref(true);
const total = ref(0); const total = ref(0);
const monitorVideoUrl = ref(); const monitorVideoUrl = ref();
const downloadUrl = ref();
const queryFormRef = ref<ElFormInstance>(); const queryFormRef = ref<ElFormInstance>();
const demoFormRef = ref<ElFormInstance>(); const demoFormRef = ref<ElFormInstance>();
@@ -202,13 +204,26 @@ const handlePlay = async (row?: any) => {
monitorVideoUrl.value = row.videoUrl; monitorVideoUrl.value = row.videoUrl;
dialog.visible = true; dialog.visible = true;
}; };
const handleUpload = async (row?: any) => { const handleDown = async (row?: any) => {
if (!row || !row.zipUrl) { if (!row || !row.zipUrl) {
proxy?.$modal.msgError('下载地址不存在'); proxy?.$modal.msgError('下载地址不存在');
return; return;
} }
proxy?.$download.zip(row.zipUrl, row.zipUrl); const fileName = row.videoName || `file_${new Date().getTime()}.zip`;
console.log('点击下载'); //console.log(row, fileName);
// 1. 创建隐藏的 a 元素
const link = document.createElement('a');
link.href = row.zipUrl; // 文件路径
link.download = fileName; // 指定下载的文件名
link.style.display = 'none';
// 2. 挂载到 DOM 并模拟点击
document.body.appendChild(link);
link.click();
// 3. 移除元素,保持页面整洁
document.body.removeChild(link);
}; };
/** 提交按钮 */ /** 提交按钮 */