注意:新增filesaver,需要更新依赖;修复批量下载问题
This commit is contained in:
parent
098ddef534
commit
8fdb1078ae
@ -20,6 +20,7 @@
|
|||||||
"echarts-gl": "^2.0.9",
|
"echarts-gl": "^2.0.9",
|
||||||
"echarts-wordcloud": "^2.1.0",
|
"echarts-wordcloud": "^2.1.0",
|
||||||
"element-plus": "^2.6.1",
|
"element-plus": "^2.6.1",
|
||||||
|
"file-saver": "^2.0.5",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"js-table2excel": "^1.1.2",
|
"js-table2excel": "^1.1.2",
|
||||||
"jsplumb": "^2.15.6",
|
"jsplumb": "^2.15.6",
|
||||||
@ -40,6 +41,7 @@
|
|||||||
"vue-router": "^4.3.0"
|
"vue-router": "^4.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/file-saver": "^2.0.7",
|
||||||
"@types/node": "^20.11.28",
|
"@types/node": "^20.11.28",
|
||||||
"@types/nprogress": "^0.2.3",
|
"@types/nprogress": "^0.2.3",
|
||||||
"@types/sortablejs": "^1.15.8",
|
"@types/sortablejs": "^1.15.8",
|
||||||
|
@ -26,11 +26,11 @@ export function attachmentApi() {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
downloadFiles: (ids: object) => {
|
downloadFiles: (ids: String) => {
|
||||||
return request({
|
return request({
|
||||||
url: baseUrlHost + '/enAttachment/uploadByType',
|
url: baseUrlHost + `/enAttachment/downloadFiles/${ids}`,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
ids,
|
responseType: 'blob',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -35,8 +35,13 @@
|
|||||||
批量下载
|
批量下载
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%" @selection-change="handleSelectionChange"
|
<el-table
|
||||||
ref="tableRef">
|
:data="state.tableData.data"
|
||||||
|
v-loading="state.tableData.loading"
|
||||||
|
style="width: 100%"
|
||||||
|
@selection-change="handleSelectionChange"
|
||||||
|
ref="tableRef"
|
||||||
|
>
|
||||||
<el-table-column type="selection" width="55" />
|
<el-table-column type="selection" width="55" />
|
||||||
<el-table-column prop="name" label="附件名称" show-overflow-tooltip></el-table-column>
|
<el-table-column prop="name" label="附件名称" show-overflow-tooltip></el-table-column>
|
||||||
<el-table-column prop="moduleName" label="模块" show-overflow-tooltip></el-table-column>
|
<el-table-column prop="moduleName" label="模块" show-overflow-tooltip></el-table-column>
|
||||||
@ -72,6 +77,7 @@ import { articleApi } from '/@/api/article';
|
|||||||
import { attachmentApi } from '/@/api/attachment';
|
import { attachmentApi } from '/@/api/attachment';
|
||||||
import { ElMessage, TableColumnCtx } from 'element-plus';
|
import { ElMessage, TableColumnCtx } from 'element-plus';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
import FileSaver from 'file-saver';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@ -94,15 +100,15 @@ const state = reactive({
|
|||||||
|
|
||||||
// 模块列表
|
// 模块列表
|
||||||
interface Module {
|
interface Module {
|
||||||
id: number;
|
id: number;
|
||||||
moduleName: string;
|
moduleName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const moduleList = ref<Module[]>([]);
|
const moduleList = ref<Module[]>([]);
|
||||||
|
|
||||||
// 标签列表
|
// 标签列表
|
||||||
interface Label {
|
interface Label {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const labelList = ref<Label[]>([]);
|
const labelList = ref<Label[]>([]);
|
||||||
@ -135,21 +141,17 @@ const handleSelectionChange = (selection: any[]) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 批量下载
|
// 批量下载
|
||||||
const downloadSelected = () => {
|
const downloadSelected = async () => {
|
||||||
if (!state.selectedRows.length) {
|
if (!state.selectedRows.length) {
|
||||||
ElMessage.warning('请先选择附件!');
|
ElMessage.warning('请先选择附件!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
state.selectedRows.forEach((file) => {
|
|
||||||
// 假设提供了 API 或工具进行文件下载
|
|
||||||
// 示例:使用 Blob URL 或直接调用下载 API
|
|
||||||
console.log(`下载文件: ${file.id}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 需要传给后端ids的数据
|
// 需要传给后端ids的数据
|
||||||
const ids = state.selectedRows.map((item) => item.id);
|
const ids = state.selectedRows.map((item) => item.id).join(',');
|
||||||
console.log(ids);
|
let res = await atcmApi.downloadFiles(ids);
|
||||||
atcmApi.downloadFiles(ids);
|
|
||||||
|
const blob = new Blob([res], { type: 'application/zip' });
|
||||||
|
FileSaver.saveAs(blob, "attachment.zip");
|
||||||
};
|
};
|
||||||
|
|
||||||
const getModuleList = async () => {
|
const getModuleList = async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user