index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <script lang="ts" setup>
  2. import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter';
  3. import { useAccess } from '@vben/access';
  4. import { alert, Page, useVbenModal } from '@vben/common-ui';
  5. import { Button } from 'ant-design-vue';
  6. import { useTableGridOptions, useVbenVxeGrid } from '#/adapter';
  7. import { DatabaseApi } from '#/api';
  8. import { TableAction } from '#/components/table-action';
  9. import FormEdit from './components/edit.vue';
  10. import { useColumns, useSearchSchema } from './data.config';
  11. const { hasAccessByCodes } = useAccess();
  12. const [FormEditModal, formEditApi] = useVbenModal({
  13. connectedComponent: FormEdit,
  14. });
  15. const handleDelete = async (id: number) => {
  16. await DatabaseApi.deleteDetail(id);
  17. alert('数据删除成功');
  18. reload();
  19. };
  20. const handelCreate = async (id: number) => {
  21. await DatabaseApi.getCreate(id);
  22. alert('创建表成功');
  23. reload();
  24. };
  25. const handleEdit = (record: any, isUpdate: boolean) => {
  26. formEditApi
  27. .setData({
  28. isUpdate,
  29. baseData: { id: record.id },
  30. })
  31. .open();
  32. };
  33. const handelSuccess = () => {
  34. reload();
  35. };
  36. const handleActionClick = async ({
  37. code,
  38. row,
  39. }: OnActionClickParams<DatabaseApi.RecordItem>) => {
  40. switch (code) {
  41. case 'create': {
  42. handelCreate(row.id);
  43. break;
  44. }
  45. case 'delete': {
  46. await handleDelete(row.id);
  47. break;
  48. }
  49. case 'edit': {
  50. handleEdit(row, true);
  51. break;
  52. }
  53. }
  54. };
  55. const [Grid, { reload }] = useVbenVxeGrid(
  56. useTableGridOptions({
  57. formOptions: {
  58. schema: useSearchSchema(),
  59. },
  60. gridOptions: {
  61. columns: useColumns(handleActionClick),
  62. proxyConfig: {
  63. ajax: {
  64. query: async ({ page }, formValues) => {
  65. return await DatabaseApi.getPage({
  66. pageIndex: page.currentPage,
  67. pageSize: page.pageSize,
  68. ...formValues,
  69. });
  70. },
  71. },
  72. },
  73. } as VxeTableGridOptions,
  74. }),
  75. );
  76. </script>
  77. <template>
  78. <Page auto-content-height>
  79. <FormEditModal @success="handelSuccess" />
  80. <Grid>
  81. <template #toolbar-tools>
  82. <Button
  83. class="mr-2"
  84. type="primary"
  85. v-access:code="'table:add'"
  86. @click="() => handleEdit({}, false)"
  87. >
  88. 新增表
  89. </Button>
  90. </template>
  91. <template #action="{ row }">
  92. <TableAction
  93. :actions="[
  94. {
  95. label: '编辑',
  96. type: 'text',
  97. disabled: !hasAccessByCodes(['table:edit']),
  98. onClick: handleEdit.bind(null, row, true),
  99. },
  100. {
  101. label: '创建表',
  102. type: 'text',
  103. disabled: !hasAccessByCodes(['table:create']),
  104. onClick: handelCreate.bind(null, row.id),
  105. },
  106. ]"
  107. :drop-down-actions="[
  108. {
  109. label: '删除',
  110. type: 'link',
  111. disabled: !hasAccessByCodes(['table:delete']),
  112. onClick: handleDelete.bind(null, row.id),
  113. },
  114. ]"
  115. />
  116. </template>
  117. </Grid>
  118. </Page>
  119. </template>