Skip to content

Commit d877bfd

Browse files
author
puhui999
committed
fix: 完善善品导出
1 parent c296c9e commit d877bfd

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/api/mall/product/spu.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const deleteSpu = (id: number) => {
8484
return request.delete({ url: `/product/spu/delete?id=${id}` })
8585
}
8686

87-
// 导出商品 Spu
88-
export const exportUser = (params) => {
89-
return request.download({ url: '/product/spu/export', params })
87+
// 导出商品 Spu Excel
88+
export const exportSpu = async (params) => {
89+
return await request.download({ url: '/product/spu/export', params })
9090
}

src/views/mall/product/spu/index.vue

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,21 @@
5050
<Icon class="mr-5px" icon="ep:refresh" />
5151
重置
5252
</el-button>
53-
<el-button v-hasPermi="['product:brand:create']" plain type="primary" @click="openForm">
53+
<el-button v-hasPermi="['product:spu:create']" plain type="primary" @click="openForm">
5454
<Icon class="mr-5px" icon="ep:plus" />
5555
新增
5656
</el-button>
5757
<!-- TODO @puhui999:增加一个【导出】操作 -->
58+
<el-button
59+
v-hasPermi="['product:spu:export']"
60+
:loading="exportLoading"
61+
plain
62+
type="success"
63+
@click="handleExport"
64+
>
65+
<Icon class="mr-5px" icon="ep:download" />
66+
导出
67+
</el-button>
5868
</el-form-item>
5969
</el-form>
6070
</ContentWrap>
@@ -196,15 +206,17 @@ import { createImageViewer } from '@/components/ImageViewer'
196206
import { dateFormatter } from '@/utils/formatTime'
197207
import { defaultProps, handleTree } from '@/utils/tree'
198208
import { ProductSpuStatusEnum } from '@/utils/constants'
209+
import { formatToFraction } from '@/utils'
210+
import download from '@/utils/download'
199211
import * as ProductSpuApi from '@/api/mall/product/spu'
200212
import * as ProductCategoryApi from '@/api/mall/product/category'
201-
import { formatToFraction } from '@/utils'
202213
203214
const message = useMessage() // 消息弹窗
204215
const { t } = useI18n() // 国际化
205216
const { currentRoute, push } = useRouter() // 路由跳转
206217
207218
const loading = ref(false) // 列表的加载中
219+
const exportLoading = ref(false) // 导出的加载中
208220
const total = ref(0) // 列表的总页数
209221
const list = ref<any[]>([]) // 列表的数据
210222
// tabs 数据
@@ -373,6 +385,22 @@ const openForm = (id?: number) => {
373385
const openDetail = () => {
374386
message.alert('查看详情未完善!!!')
375387
}
388+
389+
/** 导出按钮操作 */
390+
const handleExport = async () => {
391+
try {
392+
// 导出的二次确认
393+
await message.exportConfirm()
394+
// 发起导出
395+
exportLoading.value = true
396+
const data = await ProductSpuApi.exportSpu(queryParams)
397+
download.excel(data, '商品spu.xls')
398+
} catch {
399+
} finally {
400+
exportLoading.value = false
401+
}
402+
}
403+
376404
// 监听路由变化更新列表 TODO @puhui999:这个是必须加的么?fix: 因为编辑表单是以路由的方式打开,保存表单后列表不会刷新
377405
watch(
378406
() => currentRoute.value,

0 commit comments

Comments
 (0)