| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { ref } from "vue";
- import { TableEventCB } from './interface';
- /**
- * 表格事件
- * @param param TableEventCB
- * @returns
- */
- export function getTableEvent<T>(param: TableEventCB) {
- // 表格展开行
- const expandedRowKeys = ref<string[]>([]);
- // 表格选中的数据
- 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 }
- }
|