import { ref } from "vue"; import { TableEventCB } from './interface'; /** * 表格事件 * @param param TableEventCB * @returns */ export function getTableEvent(param: TableEventCB) { // 表格展开行 const expandedRowKeys = ref([]); // 表格选中的数据 const selectedRow = ref({}) function Rowclick(record: T, index: number) { return { onClick: () => { // 表格点击 selectedRow.value = record const value = expandedRowKeys.value; if (value.length) { const key = value[0]; expandedRowKeys.value = key === index.toString() ? [] : [`${index}`]; } else { expandedRowKeys.value = [`${index}`] } param.clickCB && param.clickCB() }, // onDblclick: () => { // 双击 // console.log('onDblclick'); // }, onContextmenu: () => { // 表格右键 selectedRow.value = record param.contextmenuCB && param.contextmenuCB() }, }; } function btnClick(record: T) { selectedRow.value = record } return { expandedRowKeys, selectedRow, Rowclick, btnClick } }