From 5417b19a8b7c01612f884ba4c342d7baa487dcaf Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 15 Dec 2025 16:07:47 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E3=80=90ele=E3=80=91=E3=80=90mall?= =?UTF-8?q?=E3=80=91spu=20=E9=80=89=E6=8B=A9=E7=BB=84=E4=BB=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spu/components/sku-table-select.vue | 119 +++++++---------- .../spu/components/spu-table-select.vue | 121 +++++++++++------- 2 files changed, 116 insertions(+), 124 deletions(-) diff --git a/apps/web-ele/src/views/mall/product/spu/components/sku-table-select.vue b/apps/web-ele/src/views/mall/product/spu/components/sku-table-select.vue index 11f9f887d..efb3b0311 100644 --- a/apps/web-ele/src/views/mall/product/spu/components/sku-table-select.vue +++ b/apps/web-ele/src/views/mall/product/spu/components/sku-table-select.vue @@ -1,16 +1,16 @@ diff --git a/apps/web-ele/src/views/mall/product/spu/components/spu-table-select.vue b/apps/web-ele/src/views/mall/product/spu/components/spu-table-select.vue index e97de6b6c..d2d165562 100644 --- a/apps/web-ele/src/views/mall/product/spu/components/spu-table-select.vue +++ b/apps/web-ele/src/views/mall/product/spu/components/spu-table-select.vue @@ -5,11 +5,12 @@ import type { VxeGridProps } from '#/adapter/vxe-table'; import type { MallCategoryApi } from '#/api/mall/product/category'; import type { MallSpuApi } from '#/api/mall/product/spu'; -import { computed, onMounted, ref } from 'vue'; +import { computed, nextTick, onMounted, ref } from 'vue'; -import { useVbenModal } from '@vben/common-ui'; import { handleTree } from '@vben/utils'; +import { ElDialog } from 'element-plus'; + import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { getCategoryList } from '#/api/mall/product/category'; import { getSpuPage } from '#/api/mall/product/spu'; @@ -30,12 +31,16 @@ const emit = defineEmits<{ const categoryList = ref([]); // 分类列表 const categoryTreeList = ref([]); // 分类树 +/** 弹窗显示状态 */ +const visible = ref(false); +const initData = ref(); + /** 单选:处理选中变化 */ function handleRadioChange() { const selectedRow = gridApi.grid.getRadioRecord() as MallSpuApi.Spu; if (selectedRow) { emit('change', selectedRow); - modalApi.close(); + closeModal(); } } @@ -153,56 +158,65 @@ const [Grid, gridApi] = useVbenVxeGrid({ }, }); -const [Modal, modalApi] = useVbenModal({ - destroyOnClose: true, - showConfirmButton: props.multiple, // 特殊:radio 单选情况下,走 handleRadioChange 处理。 - onConfirm: () => { - const selectedRows = gridApi.grid.getCheckboxRecords() as MallSpuApi.Spu[]; - emit('change', selectedRows); - modalApi.close(); - }, - async onOpenChange(isOpen: boolean) { - if (!isOpen) { - await gridApi.grid.clearCheckboxRow(); - await gridApi.grid.clearRadioRow(); - return; - } - - // 1. 先查询数据 - await gridApi.query(); - // 2. 设置已选中行 - const data = modalApi.getData(); - if (props.multiple && Array.isArray(data) && data.length > 0) { - setTimeout(() => { - const tableData = gridApi.grid.getTableData().fullData; - data.forEach((spu) => { - const row = tableData.find( - (item: MallSpuApi.Spu) => item.id === spu.id, - ); - if (row) { - gridApi.grid.setCheckboxRow(row, true); - } - }); - }, 300); - } else if (!props.multiple && data && !Array.isArray(data)) { - setTimeout(() => { - const tableData = gridApi.grid.getTableData().fullData; +/** 打开弹窗 */ +async function openModal(data?: MallSpuApi.Spu | MallSpuApi.Spu[]) { + initData.value = data; + visible.value = true; + await nextTick(); + // 1. 查询数据 + await gridApi.query(); + // 2. 设置已选中行 + const tableData = gridApi.grid.getTableData().fullData; + if ( + props.multiple && + Array.isArray(initData.value) && + initData.value.length > 0 + ) { + setTimeout(() => { + (initData.value as unknown as MallSpuApi.Spu[])!.forEach((spu) => { const row = tableData.find( - (item: MallSpuApi.Spu) => item.id === data.id, + (item: MallSpuApi.Spu) => item.id === spu.id, ); if (row) { - gridApi.grid.setRadioRow(row); + gridApi.grid.setCheckboxRow(row, true); } - }, 300); - } - }, -}); + }); + }, 300); + } else if ( + !props.multiple && + initData.value && + !Array.isArray(initData.value) + ) { + setTimeout(() => { + const row = tableData.find( + (item: MallSpuApi.Spu) => + item.id === (initData.value as MallSpuApi.Spu).id, + ); + if (row) { + gridApi.grid.setRadioRow(row); + } + }, 300); + } +} + +/** 关闭弹窗 */ +async function closeModal() { + visible.value = false; + await gridApi.grid.clearCheckboxRow(); + await gridApi.grid.clearRadioRow(); + initData.value = undefined; +} + +/** 确认选择(多选模式) */ +function handleConfirm() { + const selectedRows = gridApi.grid.getCheckboxRecords() as MallSpuApi.Spu[]; + emit('change', selectedRows); + closeModal(); +} /** 对外暴露的方法 */ defineExpose({ - open: (data?: MallSpuApi.Spu | MallSpuApi.Spu[]) => { - modalApi.setData(data).open(); - }, + open: openModal, }); /** 初始化分类数据 */ @@ -213,7 +227,18 @@ onMounted(async () => {