修改文件管理下载逻辑

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