批量删除

This commit is contained in:
liu
2026-08-23 14:26:37 +08:00
parent 01e67e02b5
commit 5d58075644
5 changed files with 132 additions and 4 deletions
+46 -3
View File
@@ -15,7 +15,7 @@ import {
Typography,
Upload,
} from 'antd';
import { DownloadOutlined, InboxOutlined, TableOutlined, UploadOutlined } from '@ant-design/icons';
import { DeleteOutlined, DownloadOutlined, InboxOutlined, TableOutlined, UploadOutlined } from '@ant-design/icons';
import type { TableProps } from 'antd';
import XinTable from '@/components/XinTable';
import AuthButton from '@/components/AuthButton';
@@ -28,7 +28,7 @@ import type {IProductCategoryTree} from '@/domain/iProductCategory.ts';
import { getSupplierOptions } from '@/api/customer/supplier.ts';
import type ISupplier from '@/domain/iSupplier.ts';
import { getCategoryTree } from '@/api/product/category.ts';
import { batchPrice, getPriceMatrix } from '@/api/product/goods.ts';
import { batchDeleteProducts, batchPrice, getPriceMatrix } from '@/api/product/goods.ts';
import type { IImportError } from '@/api/product/goods.ts';
import { downloadProductTemplate, exportProducts, importProducts } from '@/api/product/goods.ts';
@@ -70,7 +70,35 @@ const ProductGoodsPage: React.FC = () => {
// ===== 分类侧栏 =====
const [activeCategory, setActiveCategory] = useState<number | undefined>(undefined);
const tableRef = useRef<XinTableInstance<IProduct> | null>(null);
useEffect(() => { tableRef.current?.reset() }, [activeCategory]);
useEffect(() => {
setSelectedRowKeys([]);
tableRef.current?.reset();
}, [activeCategory]);
// ===== 批量删除 =====
const [selectedRowKeys, setSelectedRowKeys] = useState<number[]>([]);
const [batchDeleting, setBatchDeleting] = useState(false);
/** 批量删除(软删除,成功后清空勾选并刷新列表) */
const handleBatchDelete = () => {
window.$modal?.confirm({
title: `确定要删除选中的 ${selectedRowKeys.length} 件商品吗?`,
okText: '删除',
okButtonProps: { danger: true },
cancelText: '取消',
onOk: async () => {
setBatchDeleting(true);
try {
await batchDeleteProducts(selectedRowKeys);
message.success('批量删除成功');
setSelectedRowKeys([]);
await tableRef.current?.reload();
} finally {
setBatchDeleting(false);
}
},
});
};
// ===== 价格矩阵抽屉 =====
const [matrixOpen, setMatrixOpen] = useState(false);
@@ -489,6 +517,17 @@ const ProductGoodsPage: React.FC = () => {
actionBarRender: (dom) => [
dom.add,
dom.search,
<AuthButton key="batchDelete" auth="product.goods.delete">
<Button
danger
icon={<DeleteOutlined />}
disabled={selectedRowKeys.length === 0}
loading={batchDeleting}
onClick={handleBatchDelete}
>
{selectedRowKeys.length > 0 ? ` (${selectedRowKeys.length})` : ''}
</Button>
</AuthButton>,
<Button key="matrix" icon={<TableOutlined />} onClick={openMatrix}>
</Button>,
@@ -514,6 +553,10 @@ const ProductGoodsPage: React.FC = () => {
...params,
category_id: activeCategory
}),
rowSelection: {
selectedRowKeys,
onChange: (keys) => setSelectedRowKeys(keys.map(Number)),
},
modalProps: {
width: 800,
centered: true,