lcw
This commit is contained in:
@ -1,20 +1,20 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="titleBox">
|
||||
<PageTitle title="文件中转">
|
||||
<el-button type="primary" @click="getDataById('add', '')">
|
||||
|
||||
<!-- 搜索 -->
|
||||
<div ref="searchBox" class="mt10">
|
||||
<Search :searchArr="searchConfiger" @submit="onSearch" :key="pageData.keyCount" />
|
||||
</div>
|
||||
<PageTitle :malginLeft="10" :height="35" backgroundColor="#ffff" :marginBottom="5" :marginTop="5">
|
||||
<template #left>
|
||||
<el-button size="small" type="primary" @click="getDataById('add', '')">
|
||||
<el-icon style="vertical-align: middle">
|
||||
<CirclePlus />
|
||||
</el-icon>
|
||||
<span style="vertical-align: middle">新增</span>
|
||||
</el-button>
|
||||
|
||||
</PageTitle>
|
||||
</div>
|
||||
<!-- 搜索 -->
|
||||
<div ref="searchBox">
|
||||
<Search :searchArr="searchConfiger" @submit="onSearch" :key="pageData.keyCount" />
|
||||
</div>
|
||||
</template>
|
||||
</PageTitle>
|
||||
<!-- 表格 -->
|
||||
<div class="tabBox">
|
||||
<MyTable :tableData="pageData.tableData" :tableColumn="pageData.tableColumn" :tableHeight="pageData.tableHeight"
|
||||
@ -28,11 +28,12 @@
|
||||
</template>
|
||||
<!-- 操作 -->
|
||||
<template #controls="{ row }">
|
||||
<el-link size="small" type="primary" @click="getDataById('edit',row)">修改</el-link>
|
||||
<el-link size="small" type="primary" @click="getDataById('detail',row)">详情</el-link>
|
||||
<el-link size="small" type="primary" @click="previewFile(row)" v-if="row.wjlx == '.png'||row.wjlx == '.jpg'||row.wjlx == '.jpeg'">预览</el-link>
|
||||
<el-link size="small" type="primary" @click="downloadFile(row)">下载</el-link>
|
||||
<el-link size="small" type="danger" @click="deleteFile(row)">删除</el-link>
|
||||
<el-link size="small" type="primary" @click="getDataById('edit', row)">修改</el-link>
|
||||
<el-link size="small" type="primary" @click="getDataById('detail', row)">详情</el-link>
|
||||
<el-link size="small" type="primary" @click="previewFile(row)"
|
||||
v-if="row.wjlx == '.png' || row.wjlx == '.jpg' || row.wjlx == '.jpeg'">预览</el-link>
|
||||
<el-link size="small" type="primary" @click="downloadFile(row)">下载</el-link>
|
||||
<el-link size="small" type="danger" @click="deleteFile(row)">删除</el-link>
|
||||
</template>
|
||||
</MyTable>
|
||||
<Pages @changeNo="changeNo" @changeSize="changeSize" :tableHeight="pageData.tableHeight" :pageConfiger="{
|
||||
@ -41,7 +42,7 @@
|
||||
}"></Pages>
|
||||
</div>
|
||||
</div>
|
||||
<AddForm ref="addForm" @getList="getList"/>
|
||||
<AddForm ref="addForm" @getList="getList" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@ -53,7 +54,7 @@ import { useRoute } from 'vue-router'
|
||||
import { qbcjZxsSelectPage } from "@/api/qbcj.js";
|
||||
import { reactive, ref, onMounted, getCurrentInstance, watch } from "vue";
|
||||
import { getItem } from '@//utils/storage.js'
|
||||
import { deleteWjZzzAddEntity, getWjZzzAddEntity } from '@//api/qbcj.js'
|
||||
import { deleteWjZzzAddEntity, getWjZzzAddEntity } from '@//api/qbcj.js'
|
||||
import AddForm from "./components/addForm.vue";
|
||||
const { proxy } = getCurrentInstance();
|
||||
// const { D_BZ_CJLX, D_GS_XS_LX } = proxy.$dict("D_BZ_CJLX", "D_GS_XS_LX"); //获取字典数据
|
||||
@ -88,7 +89,7 @@ const qxkz = reactive({
|
||||
})
|
||||
|
||||
const searchConfiger = ref([
|
||||
{ label: "情报标题", prop: 'qbmc', placeholder: "请输入情报标题", showType: "input" },
|
||||
{ label: "文件名称", prop: 'wjmc', placeholder: "请输入文件名称", showType: "input" },
|
||||
// { label: "情报来源", prop: 'cjLx', placeholder: "请选择情报来源", showType: "select", options: D_BZ_CJLX },
|
||||
// { label: "来源单位", prop: 'ssbmdm', placeholder: "请选择来源单位", showType: "department" }
|
||||
]);
|
||||
@ -145,7 +146,7 @@ const changeSize = (val) => {
|
||||
// 获取列表
|
||||
const getList = () => {
|
||||
pageData.tableConfiger.loading = true;
|
||||
let data = { ...pageData.pageConfiger, ...queryFrom.value,wjlb:'01' };
|
||||
let data = { ...pageData.pageConfiger, ...queryFrom.value, wjlb: '01' };
|
||||
getWjZzzAddEntity(data).then(res => {
|
||||
pageData.tableData = res.records || [];
|
||||
pageData.total = res.total;
|
||||
@ -156,7 +157,7 @@ const getList = () => {
|
||||
|
||||
// 表格高度计算
|
||||
const tabHeightFn = () => {
|
||||
pageData.tableHeight = window.innerHeight - searchBox.value.offsetHeight - 250;
|
||||
pageData.tableHeight = window.innerHeight - searchBox.value.offsetHeight - 270;
|
||||
window.onresize = function () {
|
||||
tabHeightFn();
|
||||
};
|
||||
@ -168,47 +169,78 @@ const getRouter = () => {
|
||||
}
|
||||
const addForm = ref(null)
|
||||
const getDataById = (type, row) => {
|
||||
addForm.value.init(type, row,'01');
|
||||
addForm.value.init(type, row, '01');
|
||||
}
|
||||
const previewFile = (item) => {
|
||||
window.open(item.wjdz);
|
||||
window.open(item.wjdz);
|
||||
}
|
||||
const downloadFile = async (item) => {
|
||||
console.log(item);
|
||||
try {
|
||||
// 显示加载提示
|
||||
// proxy.$message({
|
||||
// message: '开始下载文件...',
|
||||
// type: 'info',
|
||||
// duration: 0,
|
||||
// showClose: true
|
||||
// });
|
||||
proxy.$message.info('开始下载文件...');
|
||||
// 使用fetch获取文件内容
|
||||
const response = await fetch(item.wjdz);
|
||||
if (!response.ok) {
|
||||
throw new Error('文件下载失败');
|
||||
const dataList =JSON.parse(item.wjdz)
|
||||
if (dataList.length === 0) {
|
||||
proxy.$message.warning('没有文件可下载');
|
||||
return;
|
||||
}
|
||||
console.log(dataList);
|
||||
|
||||
// 将响应转换为Blob对象
|
||||
const blob = await response.blob();
|
||||
const downloadCount = dataList.length;
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
|
||||
// 创建下载链接
|
||||
const downloadLink = document.createElement('a');
|
||||
downloadLink.href = URL.createObjectURL(blob);
|
||||
proxy.$message.info(`开始下载${downloadCount}个文件...`);
|
||||
|
||||
// 设置下载文件的名称
|
||||
downloadLink.download = item.wjmc;
|
||||
// 并行下载所有文件
|
||||
const downloadPromises = dataList.map(async (fileData, index) => {
|
||||
|
||||
// 触发下载
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
try {
|
||||
// 使用fetch获取文件内容
|
||||
const response = await fetch(fileData.url);
|
||||
if (!response.ok) {
|
||||
throw new Error('文件下载失败');
|
||||
}
|
||||
|
||||
// 清理
|
||||
document.body.removeChild(downloadLink);
|
||||
URL.revokeObjectURL(downloadLink.href);
|
||||
// 将响应转换为Blob对象
|
||||
const blob = await response.blob();
|
||||
|
||||
// 显示下载成功提示
|
||||
proxy.$message.success('文件下载成功');
|
||||
// 创建下载链接
|
||||
const downloadLink = document.createElement('a');
|
||||
downloadLink.href = URL.createObjectURL(blob);
|
||||
|
||||
// 设置下载文件的名称,避免冲突
|
||||
const fileName = dataList.length > 1
|
||||
? `${item.wjmc}_${index + 1}`
|
||||
: item.wjmc;
|
||||
downloadLink.download = fileName;
|
||||
|
||||
// 触发下载
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
|
||||
// 清理
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(downloadLink);
|
||||
URL.revokeObjectURL(downloadLink.href);
|
||||
}, 100);
|
||||
|
||||
successCount++;
|
||||
} catch (error) {
|
||||
console.error(`文件${index + 1}下载失败:`, error);
|
||||
failCount++;
|
||||
}
|
||||
});
|
||||
|
||||
// 等待所有下载完成
|
||||
await Promise.all(downloadPromises);
|
||||
|
||||
// 显示下载结果
|
||||
if (failCount === 0) {
|
||||
proxy.$message.success(`成功下载${successCount}个文件`);
|
||||
} else if (successCount === 0) {
|
||||
proxy.$message.error(`所有${failCount}个文件下载失败`);
|
||||
} else {
|
||||
proxy.$message.warning(`成功下载${successCount}个文件,失败${failCount}个文件`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('文件下载失败:', error);
|
||||
proxy.$message.error('文件下载失败,请稍后重试');
|
||||
@ -220,7 +252,7 @@ const deleteFile = (row) => {
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
deleteWjZzzAddEntity({ids:[row.id]}).then(res => {
|
||||
deleteWjZzzAddEntity({ ids: [row.id] }).then(res => {
|
||||
proxy.$message.success('删除成功');
|
||||
getList();
|
||||
}).catch(() => {
|
||||
|
||||
Reference in New Issue
Block a user