From e6c660aa32d55339ba7c7cfbe8519f89bbacebc5 Mon Sep 17 00:00:00 2001 From: teukkk Date: Wed, 13 Mar 2024 11:05:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=85=A8=E5=B1=80):=20table=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=A2=9E=E5=8A=A0=E6=8B=96=E6=8B=BD=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/pure/ms-table/base-table.vue | 33 +++++++++++++- .../components/management/case/caseTable.vue | 43 +++++-------------- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/frontend/src/components/pure/ms-table/base-table.vue b/frontend/src/components/pure/ms-table/base-table.vue index b783241549..826226c27f 100644 --- a/frontend/src/components/pure/ms-table/base-table.vue +++ b/frontend/src/components/pure/ms-table/base-table.vue @@ -11,6 +11,7 @@ :expanded-keys="props.expandedKeys" :span-all="props.spanAll" @expand="(rowKey, record) => emit('expand', record)" + @change="(data: TableData[], extra: TableChangeExtra, currentData: TableData[]) => handleDragChange(data, extra, currentData)" @sorter-change="(dataIndex: string,direction: string) => handleSortChange(dataIndex, direction)" @cell-click="(record: TableData,column: TableColumnData,ev: Event) => emit('cell-click',record, column,ev)" > @@ -264,6 +265,7 @@ import { useI18n } from '@/hooks/useI18n'; import { useAppStore, useTableStore } from '@/store'; + import { DragSortParams } from '@/models/common'; import { ColumnEditTypeEnum, SelectAllEnum, SpecialColumnEnum } from '@/enums/tableEnum'; import type { @@ -275,7 +277,7 @@ MsTableDataItem, MsTableProps, } from './type'; - import type { TableColumnData, TableData } from '@arco-design/web-vue'; + import type { TableChangeExtra, TableColumnData, TableData } from '@arco-design/web-vue'; import type { TableOperationColumn } from '@arco-design/web-vue/es/table/interface'; const batchLeft = ref('10px'); @@ -317,6 +319,7 @@ (e: 'rowNameChange', value: TableData, cb: (v: boolean) => void): void; (e: 'rowSelectChange', key: string): void; (e: 'selectAllChange', value: SelectAllEnum): void; + (e: 'dragChange', value: DragSortParams): void; (e: 'sorterChange', value: { [key: string]: string }): void; (e: 'expand', record: TableData): void | Promise; (e: 'cell-click', record: TableData, column: TableColumnData, ev: Event): void | Promise; @@ -515,6 +518,34 @@ emit('sorterChange', sortOrder ? { [dataIndex]: sortOrder } : {}); }; + // 拖拽排序 + const handleDragChange = (data: TableData[], extra: TableChangeExtra, currentData: TableData[]) => { + if (!currentData || currentData.length === 1) { + return; + } + + if (extra && extra.dragTarget?.id) { + const params: DragSortParams = { + projectId: appStore.currentProjectId, + targetId: '', // 放置目标id + moveMode: 'BEFORE', + moveId: extra.dragTarget.id as string, // 拖拽id + }; + const index = currentData.findIndex((item: any) => item.key === extra.dragTarget?.id); + + if (index > -1 && currentData[index + 1]) { + params.moveMode = 'BEFORE'; + params.targetId = currentData[index + 1].raw.id; + } else if (index > -1 && !currentData[index + 1]) { + if (index > -1 && currentData[index - 1]) { + params.moveMode = 'AFTER'; + params.targetId = currentData[index - 1].raw.id; + } + } + emit('dragChange', params); + } + }; + // 编辑单元格的input const handleEdit = (dataIndex: string, rowIndex: number, record: TableData) => { editActiveKey.value = dataIndex + rowIndex; diff --git a/frontend/src/views/api-test/management/components/management/case/caseTable.vue b/frontend/src/views/api-test/management/components/management/case/caseTable.vue index 2cee13a540..e22ce10623 100644 --- a/frontend/src/views/api-test/management/components/management/case/caseTable.vue +++ b/frontend/src/views/api-test/management/components/management/case/caseTable.vue @@ -24,7 +24,7 @@ v-on="propsEvent" @selected-change="handleTableSelect" @batch-action="handleTableBatch" - @change="changeHandler" + @drag-change="handleDragChange" >