SelectTableDemo.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div class="p-4">
  3. <!--引用表格-->
  4. <BasicTable @register="registerTable" :rowSelection="rowSelection">
  5. <!--操作栏-->
  6. <template #action="{ record }">
  7. <TableAction :actions="getTableAction(record)" />
  8. </template>
  9. </BasicTable>
  10. </div>
  11. </template>
  12. <script lang="ts" name="basic-table-demo" setup>
  13. import { BasicColumn, BasicTable, TableAction } from '/@/components/Table';
  14. import { useListPage } from '/@/hooks/system/useListPage';
  15. //定义表格列
  16. const columns: BasicColumn[] = [
  17. {
  18. title: '姓名',
  19. dataIndex: 'name',
  20. key: 'name',
  21. resizable: true,
  22. },
  23. {
  24. title: '年龄',
  25. dataIndex: 'age',
  26. key: 'age',
  27. },
  28. {
  29. title: '住址',
  30. dataIndex: 'address',
  31. key: 'address',
  32. },
  33. ];
  34. // 列表页面公共参数、方法
  35. const { tableContext } = useListPage({
  36. designScope: 'basic-table-demo',
  37. tableProps: {
  38. title: '可选择表格',
  39. dataSource: [
  40. {
  41. id: '1',
  42. name: '胡歌',
  43. age: 32,
  44. address: '朝阳区林萃路1号',
  45. },
  46. {
  47. id: '2',
  48. name: '刘诗诗',
  49. age: 32,
  50. address: '昌平区白沙路1号',
  51. },
  52. ],
  53. columns: columns,
  54. rowSelection: { type: 'checkbox' }, //默认是 checkbox 多选,可以设置成 radio 单选
  55. useSearchForm: false,
  56. },
  57. });
  58. //注册table数据
  59. const [registerTable, { reload }, { rowSelection, selectedRows, selectedRowKeys }] = tableContext;
  60. /**
  61. * 操作栏
  62. */
  63. function getTableAction(record): ActionItem[] {
  64. return [
  65. {
  66. label: '编辑',
  67. onClick: handleEdit.bind(null, record),
  68. },
  69. ];
  70. }
  71. function handleEdit(record) {
  72. console.log(record);
  73. console.log(selectedRows.value);
  74. console.log(selectedRowKeys.value);
  75. }
  76. </script>
  77. <style scoped></style>