|
50 | 50 | <Icon class="mr-5px" icon="ep:refresh" />
|
51 | 51 | 重置
|
52 | 52 | </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"> |
54 | 54 | <Icon class="mr-5px" icon="ep:plus" />
|
55 | 55 | 新增
|
56 | 56 | </el-button>
|
57 | 57 | <!-- 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> |
58 | 68 | </el-form-item>
|
59 | 69 | </el-form>
|
60 | 70 | </ContentWrap>
|
@@ -196,15 +206,17 @@ import { createImageViewer } from '@/components/ImageViewer'
|
196 | 206 | import { dateFormatter } from '@/utils/formatTime'
|
197 | 207 | import { defaultProps, handleTree } from '@/utils/tree'
|
198 | 208 | import { ProductSpuStatusEnum } from '@/utils/constants'
|
| 209 | +import { formatToFraction } from '@/utils' |
| 210 | +import download from '@/utils/download' |
199 | 211 | import * as ProductSpuApi from '@/api/mall/product/spu'
|
200 | 212 | import * as ProductCategoryApi from '@/api/mall/product/category'
|
201 |
| -import { formatToFraction } from '@/utils' |
202 | 213 |
|
203 | 214 | const message = useMessage() // 消息弹窗
|
204 | 215 | const { t } = useI18n() // 国际化
|
205 | 216 | const { currentRoute, push } = useRouter() // 路由跳转
|
206 | 217 |
|
207 | 218 | const loading = ref(false) // 列表的加载中
|
| 219 | +const exportLoading = ref(false) // 导出的加载中 |
208 | 220 | const total = ref(0) // 列表的总页数
|
209 | 221 | const list = ref<any[]>([]) // 列表的数据
|
210 | 222 | // tabs 数据
|
@@ -373,6 +385,22 @@ const openForm = (id?: number) => {
|
373 | 385 | const openDetail = () => {
|
374 | 386 | message.alert('查看详情未完善!!!')
|
375 | 387 | }
|
| 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 | +
|
376 | 404 | // 监听路由变化更新列表 TODO @puhui999:这个是必须加的么?fix: 因为编辑表单是以路由的方式打开,保存表单后列表不会刷新
|
377 | 405 | watch(
|
378 | 406 | () => currentRoute.value,
|
|
0 commit comments