ExpandTable.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <PageWrapper
  3. title="可展开表格"
  4. content="不可与scroll共用。TableAction组件可配置stopButtonPropagation来阻止操作按钮的点击事件冒泡,以便配合Table组件的expandRowByClick"
  5. >
  6. <BasicTable @register="registerTable">
  7. <template #expandedRowRender="{ record }">
  8. <span>No: {{ record.no }} </span>
  9. </template>
  10. <template #bodyCell="{ column, record }">
  11. <template v-if="column.key === 'action'">
  12. <TableAction
  13. stopButtonPropagation
  14. :actions="[
  15. {
  16. label: '删除',
  17. icon: 'ic:outline-delete-outline',
  18. onClick: handleDelete.bind(null, record),
  19. },
  20. ]"
  21. :dropDownActions="[
  22. {
  23. label: '启用',
  24. popConfirm: {
  25. title: '是否启用?',
  26. confirm: handleOpen.bind(null, record),
  27. },
  28. },
  29. ]"
  30. />
  31. </template>
  32. </template>
  33. </BasicTable>
  34. </PageWrapper>
  35. </template>
  36. <script lang="ts">
  37. import { defineComponent } from 'vue';
  38. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  39. import { PageWrapper } from '/@/components/Page';
  40. import { getBasicColumns } from './tableData';
  41. import { demoListApi } from '/@/api/demo/table';
  42. export default defineComponent({
  43. components: { BasicTable, TableAction, PageWrapper },
  44. setup() {
  45. const [registerTable] = useTable({
  46. api: demoListApi,
  47. title: '可展开表格演示',
  48. titleHelpMessage: ['已启用expandRowByClick', '已启用stopButtonPropagation'],
  49. columns: getBasicColumns(),
  50. rowKey: 'id',
  51. canResize: false,
  52. expandRowByClick: true,
  53. actionColumn: {
  54. width: 160,
  55. title: 'Action',
  56. dataIndex: 'action',
  57. // slots: { customRender: 'action' },
  58. },
  59. });
  60. function handleDelete(record: Recordable) {
  61. console.log('点击了删除', record);
  62. }
  63. function handleOpen(record: Recordable) {
  64. console.log('点击了启用', record);
  65. }
  66. return {
  67. registerTable,
  68. handleDelete,
  69. handleOpen,
  70. };
  71. },
  72. });
  73. </script>