FixedColumn.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div class="p-4">
  3. <BasicTable @register="registerTable">
  4. <template #action="{ record }">
  5. <TableAction
  6. :actions="[
  7. {
  8. label: '删除',
  9. onClick: handleDelete.bind(null, record),
  10. },
  11. ]"
  12. :dropDownActions="[
  13. {
  14. label: '启用',
  15. onClick: handleOpen.bind(null, record),
  16. },
  17. ]"
  18. />
  19. </template>
  20. </BasicTable>
  21. </div>
  22. </template>
  23. <script lang="ts">
  24. import { defineComponent } from 'vue';
  25. import { BasicTable, useTable, BasicColumn, TableAction } from '/@/components/Table';
  26. import { demoListApi } from '/@/api/demo/table';
  27. const columns: BasicColumn[] = [
  28. {
  29. title: 'ID',
  30. dataIndex: 'id',
  31. fixed: 'left',
  32. width: 280,
  33. },
  34. {
  35. title: '姓名',
  36. dataIndex: 'name',
  37. width: 260,
  38. },
  39. {
  40. title: '地址',
  41. dataIndex: 'address',
  42. width: 260,
  43. },
  44. {
  45. title: '编号',
  46. dataIndex: 'no',
  47. width: 300,
  48. },
  49. {
  50. title: '开始时间',
  51. width: 200,
  52. dataIndex: 'beginTime',
  53. },
  54. {
  55. title: '结束时间',
  56. dataIndex: 'endTime',
  57. width: 200,
  58. },
  59. ];
  60. export default defineComponent({
  61. components: { BasicTable, TableAction },
  62. setup() {
  63. const [registerTable] = useTable({
  64. title: 'TableAction组件及固定列示例',
  65. api: demoListApi,
  66. columns: columns,
  67. rowSelection: { type: 'radio' },
  68. actionColumn: {
  69. width: 160,
  70. title: 'Action',
  71. dataIndex: 'action',
  72. slots: { customRender: 'action' },
  73. },
  74. });
  75. function handleDelete(record: any) {
  76. console.log('点击了删除', record);
  77. }
  78. function handleOpen(record: any) {
  79. console.log('点击了启用', record);
  80. }
  81. return {
  82. registerTable,
  83. handleDelete,
  84. handleOpen,
  85. };
  86. },
  87. });
  88. </script>