1
0

VxeTable.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. },
  39. events: {
  40. click: () => {
  41. tableRef.value?.insert({ name: '新增的' });
  42. createMessage.success('新增成功');
  43. },
  44. },
  45. },
  46. },
  47. {
  48. content: '在最后一行新增',
  49. buttonRender: {
  50. name: 'AButton',
  51. props: {
  52. type: 'warning',
  53. },
  54. events: {
  55. click: () => {
  56. tableRef.value?.insertAt({ name: '新增的' }, -1);
  57. },
  58. },
  59. },
  60. },
  61. ],
  62. },
  63. formConfig: {
  64. enabled: true,
  65. items: vxeTableFormSchema,
  66. },
  67. height: 'auto',
  68. proxyConfig: {
  69. ajax: {
  70. query: async ({ page, form }) => {
  71. return demoListApi({
  72. pageNum: page.currentPage,
  73. pageSize: page.pageSize,
  74. ...form,
  75. });
  76. },
  77. queryAll: async ({ form }) => {
  78. return await demoListApi(form);
  79. },
  80. },
  81. },
  82. });
  83. // 操作按钮(权限控制)
  84. const createActions = (record) => {
  85. const actions: ActionItem[] = [
  86. {
  87. label: '详情',
  88. onClick: () => {
  89. console.log(record);
  90. },
  91. },
  92. {
  93. label: '编辑',
  94. onClick: () => {},
  95. },
  96. {
  97. label: '删除',
  98. color: 'error',
  99. popConfirm: {
  100. title: '是否确认删除',
  101. confirm: () => {
  102. tableRef.value?.remove(record);
  103. },
  104. },
  105. },
  106. ];
  107. return actions;
  108. };
  109. </script>