VxeTable.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 :actions="createActions(row)" />
  11. </template>
  12. </VxeBasicTable>
  13. </PageWrapper>
  14. </template>
  15. <script lang="ts" setup>
  16. import { reactive, ref } from 'vue';
  17. import { TableAction, ActionItem } from '/@/components/Table';
  18. import { PageWrapper } from '/@/components/Page';
  19. import { useMessage } from '/@/hooks/web/useMessage';
  20. import { vxeTableColumns, vxeTableFormSchema } from './tableData';
  21. import { VxeBasicTable, BasicTableProps, 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. editConfig: { trigger: 'click', mode: 'cell', showStatus: true },
  28. columns: vxeTableColumns,
  29. toolbarConfig: {
  30. buttons: [
  31. {
  32. content: '自定义按钮',
  33. buttonRender: {
  34. name: 'AButton',
  35. props: {
  36. type: 'primary',
  37. },
  38. events: {
  39. click: () => {
  40. createMessage.success('点击了自定义按钮');
  41. },
  42. },
  43. },
  44. },
  45. ],
  46. },
  47. formConfig: {
  48. enabled: true,
  49. items: vxeTableFormSchema,
  50. },
  51. height: 'auto',
  52. proxyConfig: {
  53. ajax: {
  54. query: async ({ page, form }) => {
  55. return demoListApi({
  56. pageNum: page.currentPage,
  57. pageSize: page.pageSize,
  58. ...form,
  59. });
  60. },
  61. queryAll: async ({ form }) => {
  62. const data = await demoListApi(form);
  63. return data;
  64. },
  65. },
  66. },
  67. });
  68. // 操作按钮(权限控制)
  69. const createActions = (record) => {
  70. const actions: ActionItem[] = [
  71. {
  72. label: '详情',
  73. onClick: () => {
  74. console.log(record);
  75. },
  76. },
  77. {
  78. label: '编辑',
  79. onClick: () => {},
  80. },
  81. {
  82. label: '删除',
  83. color: 'error',
  84. popConfirm: {
  85. title: '是否确认删除',
  86. confirm: () => {},
  87. },
  88. },
  89. ];
  90. return actions;
  91. };
  92. </script>