diff --git a/src/service/api/pendingChange.ts b/src/service/api/pendingChange.ts index e1dd84c..2903dc2 100644 --- a/src/service/api/pendingChange.ts +++ b/src/service/api/pendingChange.ts @@ -17,3 +17,12 @@ export function effectListApi(params:{page_num:number,page_size:number}) { params, }); } + +// 变更投入和效果导出 +export function exportEffectApi() { + return request({ + url: `/api/reports/invest-effect/export`, + method: 'get', + responseType: 'blob', // 重点,responseType设置为 blob + }); +} diff --git a/src/views/my/effect/index.vue b/src/views/my/effect/index.vue index 32f63ef..88b9afb 100644 --- a/src/views/my/effect/index.vue +++ b/src/views/my/effect/index.vue @@ -5,7 +5,7 @@ import { useThemeStore } from '@/store/modules/theme'; import { useRouterPush } from '@/hooks/common/router'; import { tagTextColor, tagBgColor, tagBorderColor } from '@/utils/common'; import { systemConfigApi } from '@/service/api/system'; -import { effectListApi } from '@/service/api/pendingChange'; +import { effectListApi, exportEffectApi } from '@/service/api/pendingChange'; const themeStore = useThemeStore(); const { routerPushByKey } = useRouterPush(); @@ -30,8 +30,28 @@ const typeList = ref([]); const levelList = ref([]); // 导出文件 -const exportFile = () => { - window.$message?.info('还差接口') +const exportFile = async () => { + const {data,error} = await exportEffectApi(); + if(!error){ + console.log(data); + // 确保 res 为 Blob 类型(若 API 返回 ArrayBuffer 或原始数据,需适配) + let blob; + if (data instanceof Blob) { + blob = data; + } else { + // 假设返回的是二进制数据(如 ArrayBuffer),指定 MIME 类型 + blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); + } + const url = window.URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + link.download = '变更投入和效果.xlsx'; // 推荐使用 download 属性 + document.body.appendChild(link); + link.click(); + // 清理:移除链接并释放 URL 对象 + document.body.removeChild(link); + window.URL.revokeObjectURL(url); + } } // 查看 const openRow = (r: any) => {