feat: 表格批量操作支持跨页全选

This commit is contained in:
RubyLiu 2023-09-21 14:09:29 +08:00 committed by 刘瑞斌
parent be7d73ada4
commit 72eebe62e0
7 changed files with 50 additions and 33 deletions

View File

@ -1,6 +1,6 @@
export default {
msPagination: {
total: '共 {total} 项数据',
total: '共 {total} ',
current: '当前页数 {current}',
countPerPage: '条/页',
pageSize: '每页条数',

View File

@ -146,17 +146,18 @@
</a-table>
<div
class="mt-[16px] flex h-[32px] w-[100%] flex-row flex-nowrap items-center justify-end px-0"
:class="{ 'batch-action': showBatchAction }"
:class="{ 'justify-between': showBatchAction }"
>
<batch-action
v-if="showBatchAction"
:select-row-count="selectCurrent"
:action-config="props.actionConfig"
@batch-action="(item: BatchActionParams) => emit('batchAction', item)"
@batch-action="handleBatchAction"
@clear="emit('clearSelector')"
/>
<ms-pagination
v-if="attrs.showPagination"
v-show="props.selectorStatus !== SelectAllEnum.CURRENT"
size="small"
v-bind="attrs.msPagination"
hide-on-single-page
@ -178,7 +179,14 @@
import ColumnSelector from './columnSelector.vue';
import MsIcon from '@/components/pure/ms-icon-font/index.vue';
import type { MsTableProps, BatchActionParams, BatchActionConfig, MsTableColumn, MsPaginationI } from './type';
import type {
MsTableProps,
BatchActionParams,
BatchActionConfig,
MsTableColumn,
MsPaginationI,
BatchActionQueryParams,
} from './type';
import type { TableData } from '@arco-design/web-vue';
import MsCheckbox from '../ms-checkbox/MsCheckbox.vue';
@ -199,7 +207,7 @@
spanMethod?: (params: { record: TableData; rowIndex: number; columnIndex: number }) => void;
}>();
const emit = defineEmits<{
(e: 'batchAction', value: BatchActionParams): void;
(e: 'batchAction', value: BatchActionParams, queryParams: BatchActionQueryParams): void;
(e: 'pageChange', value: number): void;
(e: 'pageSizeChange', value: number): void;
(e: 'rowNameChange', value: TableData): void;
@ -213,10 +221,10 @@
// -
const selectTotal = computed(() => {
const { selectorStatus } = props;
if (selectorStatus === SelectAllEnum.ALL) {
return (attrs.msPagination as MsPaginationI)?.total || appStore.pageSize;
if (selectorStatus === SelectAllEnum.CURRENT) {
return (attrs.msPagination as MsPaginationI)?.pageSize || appStore.pageSize;
}
return (attrs.msPagination as MsPaginationI).pageSize || appStore.pageSize;
return (attrs.msPagination as MsPaginationI)?.total || appStore.pageSize;
});
// -
@ -288,9 +296,22 @@
};
const showBatchAction = computed(() => {
return selectCurrent.value > 0 && attrs.showSelectAll;
return selectCurrent.value > 0 && attrs.selectable;
});
const handleBatchAction = (value: BatchActionParams) => {
const { selectorStatus, selectedKeys, excludeKeys } = props;
const queryParams: BatchActionQueryParams = {
selectedIds: Array.from(selectedKeys),
excludeIds: Array.from(excludeKeys),
selectAll: selectorStatus === SelectAllEnum.ALL,
params: {
...(attrs.msPagination as MsPaginationI),
},
};
emit('batchAction', value, queryParams);
};
const handleEditInputEnter = (record: TableData) => {
editActiveKey.value = '';
emit('rowNameChange', record);
@ -365,9 +386,6 @@
<style lang="less" scoped>
.ms-base-table {
position: relative;
.batch-action {
justify-content: flex-start;
}
.ms-table-edit-active {
color: rgb(var(--primary-5));
}

View File

@ -5,16 +5,16 @@ export default {
enable: 'Enable',
disable: 'Disable',
batch: {
title: '批量操作',
selected: '已选择 {count} 项',
export: '导出',
edit: '编辑',
delete: '删除',
moveTo: '移动到',
copyTo: '复制到',
related: '关联需求',
generateDep: '生成依赖关系',
addPublic: '添加到公用用例库',
title: 'Batch Operation',
selected: 'Selected {count} ',
export: 'Export',
edit: 'Edit',
delete: 'Delete',
moveTo: 'Move To',
copyTo: 'Copy To',
related: 'Related Requirements',
generateDep: 'Generate Dependency',
addPublic: 'Add to Public Case Library',
clear: 'clear',
},
columnSetting: {

View File

@ -6,7 +6,7 @@ export default {
disable: '禁用',
batch: {
title: '批量操作',
selected: '已选择 {count} ',
selected: '已选择 {count} ',
export: '导出',
edit: '编辑',
delete: '删除',

View File

@ -1,4 +1,5 @@
import { ColumnEditTypeEnum, SelectAllEnum } from '@/enums/tableEnum';
import { TableQueryParams } from '@/models/common';
import { TableColumnData, TableData, TableDraggable, TableChangeExtra } from '@arco-design/web-vue';
export interface MsPaginationI {
@ -110,3 +111,10 @@ export interface SetPaginationPrams {
current: number;
total?: number;
}
export interface BatchActionQueryParams {
excludeIds?: string[]; // 排除的id
selectedIds?: string[]; // 选中的id
selectAll: boolean; // 是否跨页全选
params?: TableQueryParams; // 查询参数
}

View File

@ -62,16 +62,6 @@ export default function useTableProps<T>(
// 属性组
const propsRes = ref<MsTableProps<T>>(defaultProps);
const oldPagination = ref<Pagination>({
current: 1,
pageSize: appStore.pageSize,
total: 0,
showPageSize: appStore.showPageSize,
showTotal: appStore.showTotal,
showJumper: appStore.showJumper,
hideOnSinglePage: appStore.hideOnSinglePage,
simple: defaultProps.pageSimple,
} as Pagination);
// 排序
const sortItem = ref<object>({});

View File

@ -269,6 +269,7 @@
columns,
size: 'default',
selectable: true,
pageSimple: true,
},
(record) => ({
...record,