修改文件管理下载逻辑
This commit is contained in:
parent
3586bb8cb4
commit
2f961f285c
|
|
@ -10,3 +10,4 @@ export interface File {
|
||||||
}
|
}
|
||||||
|
|
||||||
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>
|
<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('确定要下载吗?', '提示', {
|
|
||||||
type: 'warning'
|
|
||||||
})
|
|
||||||
.then(async () => {
|
|
||||||
// 处理下载逻辑
|
|
||||||
downloadFile(row);
|
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 url = window.URL.createObjectURL(blob)
|
// const response = await fetch(fileUrl_)
|
||||||
const link = document.createElement('a')
|
// const blob = await response.blob()
|
||||||
link.href = url
|
|
||||||
link.download = row.UserFileName // 设置下载的文件名
|
|
||||||
|
|
||||||
document.body.appendChild(link)
|
// const url = window.URL.createObjectURL(blob)
|
||||||
link.click()
|
// const link = document.createElement('a')
|
||||||
document.body.removeChild(link)
|
// link.href = url
|
||||||
// 释放内存
|
// link.download = row.UserFileName // 设置下载的文件名
|
||||||
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) => {
|
const handleDelete = async (row: File) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue