{/* 左侧操作按钮区 */}
- {actions.map((action) => (
+ {/* 常规操作按钮(无选中时显示) */}
+ {!hasSelection && actions.map((action) => (
{/* 右侧搜索筛选区 */}
diff --git a/src/components/ListTable/ListTable.css b/src/components/ListTable/ListTable.css
index 43e43f1..38deeee 100644
--- a/src/components/ListTable/ListTable.css
+++ b/src/components/ListTable/ListTable.css
@@ -8,3 +8,42 @@
overflow-y: auto;
width: 100%;
}
+
+/* 行选中样式 */
+.list-table-container .row-selected {
+ background-color: #e6f7ff;
+}
+
+.list-table-container .row-selected:hover > td {
+ background-color: #bae7ff !important;
+}
+
+/* 分页器中的选择信息样式 */
+.table-selection-info {
+ display: inline-flex;
+ align-items: center;
+ gap: 8px;
+}
+
+.selection-count {
+ color: rgba(0, 0, 0, 0.65);
+ font-size: 14px;
+}
+
+.count-highlight {
+ color: #1677ff;
+ font-weight: 600;
+}
+
+.selection-action {
+ color: #1677ff;
+ font-size: 14px;
+ cursor: pointer;
+ text-decoration: none;
+ transition: color 0.3s;
+ margin-left: 4px;
+}
+
+.selection-action:hover {
+ color: #4096ff;
+}
diff --git a/src/components/ListTable/ListTable.jsx b/src/components/ListTable/ListTable.jsx
index 69b90e5..77dd322 100644
--- a/src/components/ListTable/ListTable.jsx
+++ b/src/components/ListTable/ListTable.jsx
@@ -9,6 +9,10 @@ import './ListTable.css'
* @param {string} props.rowKey - 行唯一标识字段
* @param {Array} props.selectedRowKeys - 选中的行
* @param {Function} props.onSelectionChange - 选择变化回调
+ * @param {boolean} props.isAllPagesSelected - 是否跨页全选所有数据
+ * @param {number} props.totalCount - 总数据量(用于跨页全选)
+ * @param {Function} props.onSelectAllPages - 选择所有页回调
+ * @param {Function} props.onClearSelection - 清除选择回调
* @param {Object} props.pagination - 分页配置
* @param {Object} props.scroll - 表格滚动配置
* @param {Function} props.onRowClick - 行点击回调
@@ -22,11 +26,14 @@ function ListTable({
rowKey = 'id',
selectedRowKeys = [],
onSelectionChange,
+ isAllPagesSelected = false,
+ totalCount,
+ onSelectAllPages,
+ onClearSelection,
pagination = {
pageSize: 10,
showSizeChanger: true,
showQuickJumper: true,
- showTotal: (total) => `共 ${total} 条`,
},
scroll = { x: 1200},
onRowClick,
@@ -40,6 +47,49 @@ function ListTable({
onChange: (newSelectedRowKeys) => {
onSelectionChange?.(newSelectedRowKeys)
},
+ // 当跨页全选时,禁用单个复选框
+ getCheckboxProps: () => ({
+ disabled: isAllPagesSelected,
+ }),
+ }
+
+ // 合并分页配置,添加选择信息显示
+ const mergedPagination = pagination === false ? false : {
+ ...pagination,
+ showTotal: (total) => (
+
+ {isAllPagesSelected ? (
+ <>
+
+ 已选择 {totalCount || total} 项
+
+ {onClearSelection && (
+
+ 清除选择
+
+ )}
+ >
+ ) : selectedRowKeys.length > 0 ? (
+ <>
+
+ 已选择 {selectedRowKeys.length} 项
+
+ {onSelectAllPages && selectedRowKeys.length < (totalCount || total) && (
+
+ 选择全部 {totalCount || total} 项
+
+ )}
+ {onClearSelection && (
+
+ 清除
+
+ )}
+ >
+ ) : (
+
已选择 0 项
+ )}
+
+ ),
}
return (
@@ -50,10 +100,7 @@ function ListTable({
columns={columns}
dataSource={dataSource}
rowKey={rowKey}
- pagination={{
- ...pagination,
- total: dataSource?.length || 0,
- }}
+ pagination={mergedPagination}
scroll={scroll}
loading={loading}
onRow={(record) => ({
diff --git a/src/components/SelectionAlert/SelectionAlert.css b/src/components/SelectionAlert/SelectionAlert.css
new file mode 100644
index 0000000..bfd2069
--- /dev/null
+++ b/src/components/SelectionAlert/SelectionAlert.css
@@ -0,0 +1,49 @@
+.selection-alert-container {
+ margin-bottom: 16px;
+}
+
+.selection-alert-content {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 16px;
+}
+
+.selection-alert-content span {
+ flex: 1;
+ color: rgba(0, 0, 0, 0.85);
+}
+
+.selection-alert-content strong {
+ color: #1677ff;
+ font-weight: 600;
+ margin: 0 4px;
+}
+
+.selection-alert-content a {
+ color: #1677ff;
+ cursor: pointer;
+ white-space: nowrap;
+ transition: all 0.2s;
+ text-decoration: none;
+ padding: 0 8px;
+ border-radius: 4px;
+}
+
+.selection-alert-content a:hover {
+ background: rgba(22, 119, 255, 0.08);
+ text-decoration: underline;
+}
+
+/* 响应式处理 */
+@media (max-width: 768px) {
+ .selection-alert-content {
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 8px;
+ }
+
+ .selection-alert-content a {
+ padding: 4px 8px;
+ }
+}
diff --git a/src/components/SelectionAlert/SelectionAlert.jsx b/src/components/SelectionAlert/SelectionAlert.jsx
new file mode 100644
index 0000000..82502cd
--- /dev/null
+++ b/src/components/SelectionAlert/SelectionAlert.jsx
@@ -0,0 +1,89 @@
+import { Alert } from 'antd'
+import './SelectionAlert.css'
+
+/**
+ * 全选提示条组件
+ * @param {Object} props
+ * @param {number} props.currentPageCount - 当前页选中数量
+ * @param {number} props.totalCount - 总数据量
+ * @param {boolean} props.isAllPagesSelected - 是否已选择所有页
+ * @param {Function} props.onSelectAllPages - 选择所有页的回调
+ * @param {Function} props.onClearSelection - 清除选择的回调
+ */
+function SelectionAlert({
+ currentPageCount,
+ totalCount,
+ isAllPagesSelected,
+ onSelectAllPages,
+ onClearSelection,
+}) {
+ // 如果没有选中任何项,不显示
+ if (currentPageCount === 0) {
+ return null
+ }
+
+ // 如果已选择所有页
+ if (isAllPagesSelected) {
+ return (
+
+
+
+ 已选择全部 {totalCount} 条数据
+
+ 清除选择
+
+ }
+ type="info"
+ showIcon
+ closable={false}
+ />
+
+ )
+ }
+
+ // 如果只选择了当前页,且总数大于当前页
+ if (currentPageCount > 0 && totalCount > currentPageCount) {
+ return (
+
+ {/* 页面标题 */}
+
+
+ {/* 操作栏 */}
+
,
+ onClick: () => message.info('新建设备'),
+ },
+ ]}
+
+ // 批量操作按钮(始终显示,无选中时禁用)
+ batchActions={[
+ {
+ key: 'edit',
+ label: '批量编辑',
+ icon:
,
+ disabled: selectedRowKeys.length === 0,
+ onClick: handleBatchEdit,
+ },
+ {
+ key: 'export',
+ label: '批量导出',
+ icon:
,
+ disabled: selectedRowKeys.length === 0,
+ onClick: handleBatchExport,
+ },
+ {
+ key: 'delete',
+ label: '批量删除',
+ icon:
,
+ danger: true,
+ disabled: selectedRowKeys.length === 0,
+ onClick: handleBatchDelete,
+ },
+ ]}
+
+ // 搜索配置
+ search={{
+ placeholder: '搜索设备名称、IP地址',
+ value: searchValue,
+ onChange: setSearchValue,
+ onSearch: handleSearch,
+ }}
+
+ // 刷新按钮
+ showRefresh
+ onRefresh={handleRefresh}
+ />
+
+ {/* 列表表格 */}
+
{
+ setCurrentPage(page)
+ setPageSize(size)
+ },
+ }}
+ />
+
+ {/* 使用说明 */}
+
+
📖 使用说明
+
+ - 当前页全选:勾选表格左上角的全选框,选择当前页的所有数据
+ - 跨页全选:选择部分数据后,在表格底部左侧点击"选择全部 100 项"
+ - 清除选择:点击表格底部左侧的"清除"链接
+ - 批量操作:选中数据后,操作栏会显示批量操作按钮(批量编辑、批量导出、批量删除)
+ - 跨页保持:在不同页面之间切换时,选择状态会自动保持
+
+
+
+ )
+}
+
+export default CrossPageSelectionDemo