FixedColumn.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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" setup>
  30. import { BasicTable, useTable, BasicColumn, TableAction } from '@/components/Table';
  31. import { demoListApi } from '@/api/demo/table';
  32. const columns: BasicColumn[] = [
  33. {
  34. title: 'ID',
  35. dataIndex: 'id',
  36. fixed: 'left',
  37. width: 280,
  38. },
  39. {
  40. title: '姓名',
  41. dataIndex: 'name',
  42. width: 260,
  43. },
  44. {
  45. title: '地址',
  46. dataIndex: 'address',
  47. },
  48. {
  49. title: '编号',
  50. dataIndex: 'no',
  51. width: 300,
  52. },
  53. {
  54. title: '开始时间',
  55. width: 200,
  56. dataIndex: 'beginTime',
  57. },
  58. {
  59. title: '结束时间',
  60. dataIndex: 'endTime',
  61. width: 200,
  62. },
  63. ];
  64. const [registerTable] = useTable({
  65. title: 'TableAction组件及固定列示例',
  66. api: demoListApi,
  67. columns: columns,
  68. rowSelection: { type: 'radio' },
  69. bordered: true,
  70. actionColumn: {
  71. width: 160,
  72. title: 'Action',
  73. dataIndex: 'action',
  74. },
  75. });
  76. function handleDelete(record: Recordable) {
  77. console.log('点击了删除', record);
  78. }
  79. function handleOpen(record: Recordable) {
  80. console.log('点击了启用', record);
  81. }
  82. </script>