This commit is contained in:
lcw
2026-01-23 15:43:22 +08:00
parent 47a7081963
commit 5b62d707ff
76 changed files with 3333 additions and 880 deletions

View File

@ -0,0 +1,205 @@
<template>
<div style="width: 100%;">
<div style="margin: 0 auto;">
<MOSTY.Upload v-model="listQuery.img" :isImg="isImg" :limit="limit" :isAll="false" :disabled="disabled"
:showBtn="true" :showFileList="false" />
</div>
<MyTable :tableData="pageData.tableData" :tableColumn="pageData.tableColumn" :tableHeight="pageData.tableHeight"
:key="pageData.keyCount" :tableConfiger="pageData.tableConfiger" :controlsWidth="pageData.controlsWidth">
<!-- 操作 -->
<template #controls="{ row }">
<div class="operation-links">
<el-link size="small" type="primary" @click="previewFile(row)" class="link-item primary-link"
v-if="row.wjlx == '.png' || row.wjlx == '.jpg' || row.wjlx == '.jpeg'">预览</el-link>
<el-link size="small" type="primary" @click="downloadFile(row)" class="link-item primary-link">下载</el-link>
<el-link size="small" type="danger" @click="deleteFile(row)" class="link-item danger-link">删除</el-link>
</div>
</template>
</MyTable>
</div>
</template>
<script setup>
import * as MOSTY from "@/components/MyComponents/index";
import MyTable from "@/components/aboutTable/MyTable.vue";
import { reactive, watch,getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
const props = defineProps({
isImg: {
type: Boolean,
default: false,
},
limit: {
type: Number,
default: 0,
}, disabled: {
type: Boolean,
default: () => { },
},
imgMsg: {
type: Array,
default: () => { },
}
});
const emit = defineEmits(["changeData"]);
const listQuery = reactive({
img: "",
});
const pageData = reactive({
tableData: [],
keyCount: 0,
tableConfiger: {
rowHieght: 61,
showSelectType: "null",
loading: false
},
total: 0,
pageConfiger: {
pageSize: 20,
pageCurrent: 1
},
controlsWidth: 280,
tableColumn: [
{ label: "文件名称", prop: "wjmc" },
{ label: "文件大小", prop: "wjdx" },
]
});
watch(() => listQuery.img, (newVal, oldVal) => {
pageData.tableData = newVal.map(item => {
return {
wjmc: item.name,
wjdx:parseFloat((item.id.fileSize/1024/1024).toFixed(2)),
url: item.id.url
}
})
emit("changeData", pageData.tableData);
})
watch(() => props.imgMsg, (newVal, oldVal) => {
pageData.tableData = newVal.map(item => {
return {
...item,
}
})
},{deep:true,immediate:true})
const deleteFile = (row) => {
pageData.tableData = pageData.tableData.filter(item => item.url !== row.url)
const data=pageData.tableData.map(item => {
return {
wjmc: item.wjmc,
wjdx: parseFloat(item.wjdx),
url: item.url
}
})
emit("changeData",data);
}
const downloadFile = async (item) => {
console.log(item);
try {
const dataList =[item]
if (dataList.length === 0) {
proxy.$message.warning('没有文件可下载');
return;
}
const downloadCount = dataList.length;
let successCount = 0;
let failCount = 0;
proxy.$message.info(`开始下载${downloadCount}个文件...`);
// 并行下载所有文件
const downloadPromises = dataList.map(async (fileData, index) => {
try {
// 使用fetch获取文件内容
const response = await fetch(fileData.url);
if (!response.ok) {
throw new Error('文件下载失败');
}
// 将响应转换为Blob对象
const blob = await response.blob();
// 创建下载链接
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('文件下载失败,请稍后重试');
}
}
</script>
<style scoped lang="scss">
.operation-links {
display: flex;
flex-wrap: wrap;
gap: 12px;
.link-item {
display: inline-block;
padding: 4px 12px;
border-radius: 4px;
font-size: 12px;
transition: all 0.3s ease;
&:hover {
opacity: 0.8;
transform: translateY(-1px);
}
}
.primary-link {
color: #409EFF;
background-color: #ECF5FF;
&:hover {
background-color: #D9ECFF;
}
}
.danger-link {
color: #F56C6C;
background-color: #FEF0F0;
&:hover {
background-color: #FEE2E2;
}
}
}
</style>

View File

@ -1,20 +1,19 @@
<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 +27,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 +41,8 @@
}"></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 { reactive, ref, onMounted, getCurrentInstance, watch } from "vue";
import { getItem } from '@//utils/storage.js'
import { deleteWjZzzAddEntity, getWjZzzAddEntity ,selectDxzjList} from '@//api/qbcj.js'
import { deleteWjZzzAddEntity, getWjZzzAddEntity, selectDxzjList } from '@//api/qbcj.js'
import AddForm from "@/views/backOfficeSystem/HumanIntelligence/fileTransfer/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" }
]);
@ -109,12 +110,14 @@ const pageData = reactive({
controlsWidth: 240,
tableColumn: [
{ label: "文件名称", prop: "wjmc" },
{ label: "上传人", prop: "scrxm" },
{ label: "文件大小", prop: "wjdx", showSolt: true },
{ label: "文件类别", prop: "wjlb", showSolt: true },
{ label: "所属部门", prop: "ssbm" },
{ label: "文件描述", prop: "qbnr" },
]
});
const queryFrom = ref({});
// 搜索
@ -145,7 +148,7 @@ const changeSize = (val) => {
// 获取列表
const getList = () => {
pageData.tableConfiger.loading = true;
let data = { ...pageData.pageConfiger, ...queryFrom.value ,wjlb:'02'};
let data = { ...pageData.pageConfiger, ...queryFrom.value, wjlb: '02' };
selectDxzjList(data).then(res => {
pageData.tableData = res.records || [];
pageData.total = res.total;
@ -156,7 +159,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 +171,77 @@ const getRouter = () => {
}
const addForm = ref(null)
const getDataById = (type, row) => {
addForm.value.init(type, row,'02');
addForm.value.init(type, row, '02');
}
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 +253,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(() => {