From 6dabd7d10f4d680dd3033b44247c5dc821861c3a Mon Sep 17 00:00:00 2001 From: jameszow Date: Tue, 24 Oct 2023 14:08:48 +0800 Subject: [PATCH] Add handleExport method --- src/views/product/info/index.vue | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/views/product/info/index.vue b/src/views/product/info/index.vue index 379e60c..4a377ce 100644 --- a/src/views/product/info/index.vue +++ b/src/views/product/info/index.vue @@ -7,7 +7,7 @@ 批量启用 批量禁用 导入 - 导出 + 导出 批量编辑 修正库存 @@ -50,6 +50,7 @@ import ProductInfoModal from "@/views/product/info/components/ProductInfoModal.v import BatchEditModal from "@/views/product/info/components/BatchEditModal.vue"; import {getProductInfo, deleteProduct, updateProductStatus} from "@/api/product/product"; import ImportFileModal from "@/components/Tools/ImportFileModal.vue"; +import {exportXlsx} from "@/api/basic/common"; export default defineComponent({ name: 'ProductInfo', @@ -155,6 +156,29 @@ export default defineComponent({ importModalRef.value.title = "商品信息数据导入"; } + const getTimestamp = (date) => { + return ( + date.getFullYear() * 10000000000 + + (date.getMonth() + 1) * 100000000 + + date.getDate() * 1000000 + + date.getHours() * 10000 + + date.getMinutes() * 100 + + date.getSeconds() + ).toString(); + }; + + async function handleExport() { + const file = await exportXlsx("商品信息列表") + const blob = new Blob([file]); + const link = document.createElement("a"); + link.href = URL.createObjectURL(blob); + const timestamp = getTimestamp(new Date()); + link.download = "商品信息数据" + timestamp + ".xlsx"; + link.target = "_blank"; + link.click(); + } + + return { registerTable, handleCreate, @@ -169,6 +193,7 @@ export default defineComponent({ batchProductInfoModalRef, handleBatchProductInfo, handleImport, + handleExport, importModalRef } }