VxeTable.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <PageWrapper
  3. title="VxeTable表格"
  4. content="只展示部分操作,详细功能请查看VxeTable官网事例"
  5. contentFullHeight
  6. fixedHeight
  7. >
  8. <VxeBasicTable ref="tableRef" v-bind="gridOptions">
  9. <template #action="{ row }">
  10. <TableAction outside :actions="createActions(row)" />
  11. </template>
  12. </VxeBasicTable>
  13. </PageWrapper>
  14. </template>
  15. <script lang="ts" setup>
  16. import { reactive, ref } from 'vue';
  17. import { ActionItem, TableAction } from '@/components/Table';
  18. import { PageWrapper } from '@/components/Page';
  19. import { useMessage } from '@/hooks/web/useMessage';
  20. import { vxeTableColumns, vxeTableFormSchema } from './tableData';
  21. import { BasicTableProps, VxeBasicTable, VxeGridInstance } from '@/components/VxeTable';
  22. import { demoListApi } from '@/api/demo/table';
  23. const { createMessage } = useMessage();
  24. const tableRef = ref<VxeGridInstance>();
  25. const gridOptions = reactive<BasicTableProps>({
  26. id: 'VxeTable',
  27. keepSource: true,
  28. editConfig: { trigger: 'click', mode: 'cell', showStatus: true },
  29. columns: vxeTableColumns,
  30. toolbarConfig: {
  31. buttons: [
  32. {
  33. content: '在第一行新增',
  34. buttonRender: {
  35. name: 'AButton',
  36. props: {
  37. type: 'primary',
  38. preIcon: 'mdi:page-next-outline',
  39. },
  40. events: {
  41. click: () => {
  42. tableRef.value?.insert({ name: '新增的' });
  43. createMessage.success('新增成功');
  44. },
  45. },
  46. },
  47. },
  48. {
  49. content: '在最后一行新增',
  50. buttonRender: {
  51. name: 'AButton',
  52. props: {
  53. type: 'warning',
  54. },
  55. events: {
  56. click: () => {
  57. tableRef.value?.insertAt({ name: '新增的' }, -1);
  58. },
  59. },
  60. },
  61. },
  62. ],
  63. },
  64. formConfig: {
  65. enabled: true,
  66. items: vxeTableFormSchema,
  67. },
  68. height: 'auto',
  69. proxyConfig: {
  70. ajax: {
  71. query: async ({ page, form }) => {
  72. return demoListApi({
  73. page: page.currentPage,
  74. pageSize: page.pageSize,
  75. ...form,
  76. });
  77. },
  78. queryAll: async ({ form }) => {
  79. return await demoListApi(form);
  80. },
  81. },
  82. },
  83. });
  84. // 操作按钮(权限控制)
  85. const createActions = (record) => {
  86. const actions: ActionItem[] = [
  87. {
  88. label: '详情',
  89. onClick: () => {
  90. console.log(record);
  91. },
  92. },
  93. {
  94. label: '编辑',
  95. onClick: () => {},
  96. },
  97. {
  98. label: '删除',
  99. color: 'error',
  100. popConfirm: {
  101. title: '是否确认删除',
  102. confirm: () => {
  103. tableRef.value?.remove(record);
  104. },
  105. },
  106. },
  107. ];
  108. return actions;
  109. };
  110. </script>