Browse Source

fix: Table emit 更新
useTablePage hooks 更新 默认多选变更

lanceJiang 1 year ago
parent
commit
b34eb77374
2 changed files with 10 additions and 1 deletions
  1. 1 1
      src/components/Table/index.vue
  2. 9 0
      src/hooks/useTablePage.ts

+ 1 - 1
src/components/Table/index.vue

@@ -103,7 +103,7 @@ const TableComponent = defineComponent({
 	name: 'LeTable',
 	props: tableProps,
 	// 更新搜索条件, 更新列配置, table Sort 排序, table 刷新
-	emits: ['update:searchParams', 'update:checkedOptions', 'sortChange', 'refresh', 'row-click'],
+	emits: ['update:searchParams', 'update:checkedOptions', 'update:curRow', 'sortChange', 'refresh', 'row-click'],
 	setup(props, { attrs, slots, emit, expose }) {
 		const { t } = useI18n()
 		// const tableRef = ref<Table>(/*tableRef*/)

+ 9 - 0
src/hooks/useTablePage.ts

@@ -31,6 +31,11 @@ export const useTablePage = (tableProps: Partial<LeTableProps> = {}, config: Par
 		},
 		config
 	)
+	const curSelectionRows = ref<any[]>([])
+	const selectionChange = (rows: any[]) => {
+		// console.error('rows...', rows)
+		curSelectionRows.value = rows
+	}
 	const tableOpts = reactive<LeTableProps>({
 		total: 0,
 		list: [],
@@ -49,6 +54,8 @@ export const useTablePage = (tableProps: Partial<LeTableProps> = {}, config: Par
 			loading: false,
 			showOverflowTooltip: false,
 			multipleSelect: true, // 是否支持列表项选中功能
+			// 多选变更
+			onSelectionChange: selectionChange,
 			// stripe: true, // 是否为斑马纹 table
 			// highlightCurrentRow: true, // 是否支持当前行高亮显示
 			...(tableProps.options || {})
@@ -106,6 +113,8 @@ export const useTablePage = (tableProps: Partial<LeTableProps> = {}, config: Par
 		tableOpts,
 		checkedColumns,
 		activeColumns,
+		// 多选数据
+		curSelectionRows,
 		// 搜索表单数据
 		searchData,
 		// 刷新数据方法