Files
ipms-sjy/yudao-ui-admin-vue3/src/hooks/web/useXTable.ts

40 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-01-03 10:10:51 +08:00
import { XTableProps } from '@/components/XTable/src/type'
export interface tableMethod {
reload: () => void // 刷新表格
2023-01-03 10:10:51 +08:00
setProps: (props: XTableProps) => void
2023-01-17 12:10:20 +08:00
deleteData: (id: string | number) => void // 删除数据
2023-01-17 14:05:07 +08:00
deleteBatch: () => void // 批量删除
exportList: (fileName?: string) => void // 导出列表
getCurrentColumn: () => void // 获取当前列
getRadioRecord: () => void // 获取当前选中列redio
getCheckboxRecords: () => void //获取当前选中列, checkbox
2023-01-03 10:10:51 +08:00
}
2023-01-03 14:23:48 +08:00
export const useXTable = (props: XTableProps): [Function, tableMethod] => {
2023-01-03 10:10:51 +08:00
const tableRef = ref<Nullable<tableMethod>>(null)
2023-01-03 14:23:48 +08:00
const register = (instance) => {
2023-01-03 10:10:51 +08:00
tableRef.value = instance
props && instance.setProps(props)
}
2023-01-03 14:23:48 +08:00
const getInstance = (): tableMethod => {
2023-01-03 10:10:51 +08:00
const table = unref(tableRef)
if (!table) {
console.error('表格实例不存在')
}
return table as tableMethod
}
const methods: tableMethod = {
reload: () => getInstance().reload(),
2023-01-03 10:40:53 +08:00
setProps: (props) => getInstance().setProps(props),
2023-01-17 12:10:20 +08:00
deleteData: (id: string | number) => getInstance().deleteData(id),
2023-01-17 14:05:07 +08:00
deleteBatch: () => getInstance().deleteBatch(),
exportList: (fileName?: string) => getInstance().exportList(fileName),
getCurrentColumn: () => getInstance().getCheckboxRecords(),
getRadioRecord: () => getInstance().getRadioRecord(),
getCheckboxRecords: () => getInstance().getCheckboxRecords()
2023-01-03 10:10:51 +08:00
}
return [register, methods]
}