index.vue 2.2 KB

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