import { reactive, ref } from 'vue';

export function handleTableEvent<T>(clickCB?: Function) {
    const expandedRowKeys = ref<string[]>([]); // 表格展开行
    const selectedRow = reactive({})
    function Rowclick(record: T, index: number) {
        return {
            onClick: () => {  // 表格点击
                Object.assign(selectedRow, record)
                const value = expandedRowKeys.value;
                expandedRowKeys.value = value.length ? [] : [`${index}`];
                clickCB && clickCB()
            },
            // onDblclick: () => { // 双击
            //     console.log('onDblclick');
            // },
            onContextmenu: () => {  // 表格右键
                Object.assign(selectedRow, record)
            },
        };
    }
    return { expandedRowKeys, selectedRow, Rowclick }
}
