修改文件管理下载逻辑

This commit is contained in:
junleea 2025-05-16 18:40:23 +08:00
parent 3586bb8cb4
commit 2f961f285c
2 changed files with 33 additions and 23 deletions

View File

@ -9,4 +9,5 @@ export interface File {
file_store_name: string;
}
export const fileUrl ="https://pm.ljsea.top/tool/file/";
export const fileUrl ="https://pm.ljsea.top/tool/file/";
export const fileUrl2 = "https://pm.ljsea.top/tool/file/general/";

View File

@ -22,6 +22,16 @@
<TableDetail :data="viewData"></TableDetail>
</el-dialog>
</div>
<el-dialog
v-model="downloadFileVisible"
title="下载文件"
width="20%"
>
<!-- 下载链接 -->
<a :href="downloadFileUrl">点击下载</a>
</el-dialog>
</template>
<script setup lang="ts" name="system-user">
@ -32,7 +42,7 @@ import { Session } from '@/types/session';
import {FindUserFileService} from "@/api/file";
import {UpdateUserFileService} from "@/api/file";
import {DelUserFileService} from "@/api/file";
import { File,fileUrl } from '@/types/file';
import { File,fileUrl,fileUrl2 } from '@/types/file';
import TableCustom from '@/components/table-custom.vue';
import TableDetail from '@/components/table-detail.vue';
import TableSearch from '@/components/table-search.vue';
@ -48,6 +58,8 @@ const page = reactive({
})
const tableData = ref<File[]>([]);
const allData = ref<File[]>([]);
const downloadFileVisible = ref(false);
const downloadFileUrl = ref('');
//
const query = reactive({
@ -237,32 +249,29 @@ const handleView =async (row: File) => {
const handleGenOperate = async (row: File) => {
console.log("gen row:", row);
//
ElMessageBox.confirm('确定要下载吗?', '提示', {
type: 'warning'
})
.then(async () => {
//
downloadFile(row);
})
.catch(() => { });
downloadFile(row);
}
const downloadFile = async (row: File) => {
const fileUrl_ = fileUrl+row.file_store_name;
const response = await fetch(fileUrl_)
const blob = await response.blob()
const fileUrl_ = fileUrl2+row.file_store_name +"?token=" + localStorage.getItem('token');
//<a>
downloadFileVisible.value = true;
downloadFileUrl.value = fileUrl_;
// const response = await fetch(fileUrl_)
// const blob = await response.blob()
const url = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = row.UserFileName //
// const url = window.URL.createObjectURL(blob)
// const link = document.createElement('a')
// link.href = url
// link.download = row.UserFileName //
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
//
window.URL.revokeObjectURL(url)
ElMessage.success('文件下载成功')
// document.body.appendChild(link)
// link.click()
// document.body.removeChild(link)
// //
// window.URL.revokeObjectURL(url)
// ElMessage.success('')
};
//
const handleDelete = async (row: File) => {