From 85ad42278b113401b2c8542668822bdfbce1d0fb Mon Sep 17 00:00:00 2001 From: tikkhun Date: Tue, 27 Jan 2026 10:30:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BA=A7=E5=93=81=E5=88=97=E8=A1=A8):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=87=8F=E5=88=9B=E5=BB=BA=E5=A5=97?= =?UTF-8?q?=E8=A3=85=E4=BA=A7=E5=93=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增批量创建套装产品功能,包含以下主要修改: 1. 添加 BatchCreateBundleModal 组件用于批量创建套装 2. 在产品列表页面添加批量创建套装按钮 3. 实现批量创建逻辑,支持选择单品和数量组合创建套装 --- .../Product/List/BatchCreateBundleModal.tsx | 118 ++++++++++++++++++ src/pages/Product/List/index.tsx | 16 +++ src/pages/SiteProduct/List/index.tsx | 0 3 files changed, 134 insertions(+) create mode 100644 src/pages/Product/List/BatchCreateBundleModal.tsx create mode 100644 src/pages/SiteProduct/List/index.tsx diff --git a/src/pages/Product/List/BatchCreateBundleModal.tsx b/src/pages/Product/List/BatchCreateBundleModal.tsx new file mode 100644 index 0000000..22b0a12 --- /dev/null +++ b/src/pages/Product/List/BatchCreateBundleModal.tsx @@ -0,0 +1,118 @@ +import { productcontrollerCreateproduct, productcontrollerGetproductlist } from '@/servers/api/product'; +import { + ModalForm, + ProFormSelect, +} from '@ant-design/pro-components'; +import { App } from 'antd'; +import React from 'react'; + +const BatchCreateBundleModal: React.FC<{ + visible: boolean; + onClose: () => void; + onSuccess: () => void; +}> = ({ visible, onClose, onSuccess }) => { + const { message } = App.useApp(); + + // 批量创建数量选项 + const quantityOptions = [ + { label: '1', value: 1 }, + { label: '5', value: 5 }, + { label: '10', value: 10 }, + { label: '20', value: 20 }, + { label: '50', value: 50 }, + { label: '100', value: 100 }, + ]; + + return ( + !open && onClose()} + modalProps={{ destroyOnClose: true }} + onFinish={async (values) => { + const { products, quantity } = values; + + if (!products || products.length === 0) { + message.error('请选择至少一个单品'); + return false; + } + + // 生成批量创建的 Promise 数组 + const createPromises = products.flatMap((product: any) => { + return quantity.map((q: number) => { + const bundleSku = `bundle-${product.sku}-${q}`; + return productcontrollerCreateproduct({ + sku: bundleSku, + name: `套装 ${product.name} x ${q}`, + type: 'bundle', + components: [ + { + sku: product.sku, + quantity: q + } + ], + attributes: [], + }); + }); + }); + + try { + // 并行执行批量创建 + const results = await Promise.all(createPromises); + + // 检查是否所有创建都成功 + const allSuccess = results.every((result) => result.success); + + if (allSuccess) { + const totalCreated = createPromises.length; + message.success(`成功创建 ${totalCreated} 个套装产品`); + onSuccess(); + return true; + } else { + message.error('部分产品创建失败,请检查'); + return false; + } + } catch (error) { + message.error('创建失败,请重试'); + return false; + } + }} + > + { + const params = keyWords + ? { sku: keyWords, name: keyWords, type: 'single' } + : { pageSize: 9999, type: 'single' }; + const { data } = await productcontrollerGetproductlist( + params as any, + ); + if (!data || !data.items) { + return []; + } + // 只返回类型为单品的产品 + return data.items + .filter((item: any) => item.type === 'single' && item.sku) + .map((item: any) => ({ + label: `${item.sku} - ${item.name}`, + value: item, + })); + }} + /> + + + ); +}; + +export default BatchCreateBundleModal; \ No newline at end of file diff --git a/src/pages/Product/List/index.tsx b/src/pages/Product/List/index.tsx index d327291..bc6f658 100644 --- a/src/pages/Product/List/index.tsx +++ b/src/pages/Product/List/index.tsx @@ -21,6 +21,7 @@ import React, { useEffect, useRef, useState } from 'react'; import CreateForm from './CreateForm'; import EditForm from './EditForm'; import SyncToSiteModal from './SyncToSiteModal'; +import BatchCreateBundleModal from './BatchCreateBundleModal'; const NameCn: React.FC<{ id: number; @@ -188,6 +189,7 @@ const List: React.FC = () => { const [batchEditModalVisible, setBatchEditModalVisible] = useState(false); const [syncProducts, setSyncProducts] = useState([]); const [syncModalVisible, setSyncModalVisible] = useState(false); + const [batchCreateBundleModalVisible, setBatchCreateBundleModalVisible] = useState(false); const { message } = App.useApp(); // 导出产品 CSV(带认证请求) @@ -463,6 +465,12 @@ const List: React.FC = () => { > 批量修改 , + // 批量创建 bundle 产品按钮 + , // 批量同步按钮