修改文件管理下载逻辑
This commit is contained in:
parent
3586bb8cb4
commit
2f961f285c
|
|
@ -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/";
|
||||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue