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. },
  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. bordered: true,
  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>