FixedColumn.vue 2.2 KB

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