feat 添加下载excel
All checks were successful
Build image / build (push) Successful in 30s

This commit is contained in:
timerzz 2025-03-30 21:37:45 +08:00
parent 7cf190dff9
commit e7d80dc36e
4 changed files with 103 additions and 7 deletions

25
src/api/tools.js Normal file
View File

@ -0,0 +1,25 @@
import {mande} from "mande";
const tools = mande('/api/v2/tools')
// 下载Coach Outlet Excel文件
export const DownloadCoachOutletExcel = (providerId) => {
// return tools.get(`/excel/coach-outlet/${providerId}`, {
// responseType: 'blob' // 指定响应类型为blob用于文件下载
// })
return fetch(`/api/v2/tools/excel/coach-outlet/${providerId}`, {
method: "get",
mode: "no-cors",
referrerPolicy: "no-referrer",
})
.then((res) => res.blob())
.then((res) => {
const aElement = document.createElement("a");
aElement.setAttribute("download", providerId + ".xlsx");
const href = URL.createObjectURL(res);
aElement.href = href;
aElement.setAttribute("target", "_blank");
aElement.click();
URL.revokeObjectURL(href);
});
}

View File

@ -0,0 +1,56 @@
<template>
<a-card bordered hoverable class="w-150px" @click="downloadExcel">
<template #title>
<div class="text-xxl">
导出{{ providerName }}优惠商品
</div>
</template>
<div class="flex space-x-2 items-center">
<FileExcelOutlined class="text-lg" />
<span>Excel导出</span>
</div>
</a-card>
</template>
<script setup>
import { FileExcelOutlined } from "@ant-design/icons-vue";
import { computed } from "vue";
import { DownloadCoachOutletExcel } from "@/api/tools.js";
import { message } from "ant-design-vue";
const props = defineProps({
providerId: {
type: String,
required: true
},
});
const loading = defineModel('loading')
// providerId
const providerName = computed(() => {
if (props.providerId === 'us-coach-outlet') {
return '美国Coach Outlet';
} else if (props.providerId === 'ca-coach-outlet') {
return '加拿大Coach Outlet';
}
return 'Coach Outlet';
});
// Excel
const downloadExcel = () => {
loading.value = true;
DownloadCoachOutletExcel(props.providerId)
.catch(err => {
console.error(err);
message.error('导出失败');
})
.finally(() => {
loading.value = false;
});
};
</script>
<style scoped>
</style>

View File

@ -1,15 +1,23 @@
<template>
<div class="h-full m-4 bg-gray-50 rounded-2 shadow-lg p-8 flex flex-col justify-between space-y-4">
<a-flex wrap="wrap" >
<call-ats-tool></call-ats-tool>
</a-flex>
<div class="h-full m-4 bg-white rounded-2 shadow-lg p-8 flex flex-col space-y-4 overscroll-auto">
<div class="text-2xl font-bold mb-4">工具箱</div>
<a-spin tip="Loading..." :spinning="loading">
<div class="flex space-x-4">
<call-ats-tool></call-ats-tool>
<ExportCheaper providerId="us-coach-outlet" v-model:loading="loading"></ExportCheaper>
<ExportCheaper providerId="ca-coach-outlet" v-model:loading="loading"></ExportCheaper>
</div>
</a-spin>
</div>
</template>
<script setup>
<script setup>
import CallAtsTool from "@/componse/tools/call-ats-tool.vue";
import ExportCheaper from "@/componse/tools/ExportCheaper.vue";
import {ref} from "vue";
const loading = ref(false)
</script>
<style scoped>
</style>

View File

@ -82,7 +82,14 @@ export default defineConfig({
changeOrigin: true,
secure: false,
ws: true,
}
},
'/api/v2/tools': {
// target: 'https://ht.timerzz.com:20443/',
target: 'http://localhost:8085/',
changeOrigin: true,
secure: false,
ws: true,
},
},
},
resolve: {