FixedColumn.vue 2.0 KB

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