Browse Source

涉访涉诉--数据导出

master
buaixuexideshitongxue 4 weeks ago
parent
commit
77375416dc
  1. 42
      src/api/data/complaintCollection.ts
  2. 10
      src/views/data/ComplaintCollection.vue

42
src/api/data/complaintCollection.ts

@ -1,4 +1,6 @@
import request from "@/api/request";
import feedback from "../../utils/feedback";
import {getToken} from "../../utils/token";
export function getComplaintCollectionPage(body) {
return request.post({
@ -64,3 +66,43 @@ export function handlerData(body) {
body
});
}
/**
*
*/
export async function exportData(body) {
const response = await fetch('/api/v2/data/complaintCollection/exportData', {
method: 'POST',
headers: {
'Authorization': getToken(),
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
if (!response.ok) {
feedback.msgError('导出失败')
return
}
// 👉 关键:直接拿 blob
const blob = await response.blob()
let filename = '涉访涉诉数据.xlsx'
const disposition = response.headers.get('content-disposition')
if (disposition) {
const match = disposition.match(/filename\*=UTF-8''(.+)/)
if (match) {
filename = decodeURIComponent(match[1])
}
}
// 👉 触发下载
const url = window.URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = filename
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
window.URL.revokeObjectURL(url)
}

10
src/views/data/ComplaintCollection.vue

@ -212,6 +212,7 @@
<!-- >数据导入-->
<!-- </el-button>-->
<el-button type="primary" @click="add()">添加</el-button>
<el-button type="primary" @click="handleExport">数据导出</el-button>
</div>
<div>
<el-button type="primary" @click="getList">
@ -413,7 +414,7 @@ import feedback from "@/utils/feedback";
import useCatchStore from "@/stores/modules/catch";
import {
addComplaintCollection, addComplaintCollectionBlame,
delComplaintCollection,
delComplaintCollection, exportData,
getComplaintCollectionPage, handlerData,
updateComplaintCollection
} from "@/api/data/complaintCollection.ts";
@ -872,6 +873,13 @@ const handleWatchDetail = async (row) => {
}
// endregion
// region
const handleExport = async () => {
let body = {
...query.value
}
await exportData(body);
}
</script>

Loading…
Cancel
Save