diff --git a/src/api/mall/product/spu.ts b/src/api/mall/product/spu.ts index ace7e417..9c3f98bf 100644 --- a/src/api/mall/product/spu.ts +++ b/src/api/mall/product/spu.ts @@ -84,7 +84,7 @@ export const deleteSpu = (id: number) => { return request.delete({ url: `/product/spu/delete?id=${id}` }) } -// 导出商品 Spu -export const exportUser = (params) => { - return request.download({ url: '/product/spu/export', params }) +// 导出商品 Spu Excel +export const exportSpu = async (params) => { + return await request.download({ url: '/product/spu/export', params }) } diff --git a/src/views/mall/product/spu/index.vue b/src/views/mall/product/spu/index.vue index 6fd3f5f1..2065edc3 100644 --- a/src/views/mall/product/spu/index.vue +++ b/src/views/mall/product/spu/index.vue @@ -50,11 +50,21 @@ 重置 - + 新增 + + + 导出 + @@ -196,15 +206,17 @@ import { createImageViewer } from '@/components/ImageViewer' import { dateFormatter } from '@/utils/formatTime' import { defaultProps, handleTree } from '@/utils/tree' import { ProductSpuStatusEnum } from '@/utils/constants' +import { formatToFraction } from '@/utils' +import download from '@/utils/download' import * as ProductSpuApi from '@/api/mall/product/spu' import * as ProductCategoryApi from '@/api/mall/product/category' -import { formatToFraction } from '@/utils' const message = useMessage() // 消息弹窗 const { t } = useI18n() // 国际化 const { currentRoute, push } = useRouter() // 路由跳转 const loading = ref(false) // 列表的加载中 +const exportLoading = ref(false) // 导出的加载中 const total = ref(0) // 列表的总页数 const list = ref([]) // 列表的数据 // tabs 数据 @@ -373,6 +385,22 @@ const openForm = (id?: number) => { const openDetail = () => { message.alert('查看详情未完善!!!') } + +/** 导出按钮操作 */ +const handleExport = async () => { + try { + // 导出的二次确认 + await message.exportConfirm() + // 发起导出 + exportLoading.value = true + const data = await ProductSpuApi.exportSpu(queryParams) + download.excel(data, '商品spu.xls') + } catch { + } finally { + exportLoading.value = false + } +} + // 监听路由变化更新列表 TODO @puhui999:这个是必须加的么?fix: 因为编辑表单是以路由的方式打开,保存表单后列表不会刷新 watch( () => currentRoute.value,