index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 { ConfigApi } 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. destroyOnClose: true,
  12. });
  13. const handelSuccess = () => {
  14. reload();
  15. };
  16. const handleDelete = async (id: number) => {
  17. await ConfigApi.deleteDetail(id);
  18. message.success('数据删除成功');
  19. handelSuccess();
  20. };
  21. const handleEdit = (record: Record<string, any>, isUpdate: boolean) => {
  22. formEditApi
  23. .setData({
  24. isUpdate,
  25. baseData: { id: record.id },
  26. })
  27. .open();
  28. };
  29. const handleActionClick = async ({
  30. code,
  31. row,
  32. }: OnActionClickParams<ConfigApi.RecordItem>) => {
  33. switch (code) {
  34. case 'delete': {
  35. await handleDelete(row.id);
  36. break;
  37. }
  38. case 'edit': {
  39. handleEdit(row, true);
  40. break;
  41. }
  42. }
  43. };
  44. const [Grid, { reload }] = useVbenVxeGrid(
  45. useTableGridOptions({
  46. formOptions: {
  47. schema: useSearchSchema(),
  48. },
  49. gridOptions: {
  50. columns: useColumns(handleActionClick),
  51. proxyConfig: {
  52. ajax: {
  53. query: async ({ page }, formValues) => {
  54. return await ConfigApi.getPage({
  55. pageIndex: page.currentPage,
  56. pageSize: page.pageSize,
  57. ...formValues,
  58. });
  59. },
  60. },
  61. },
  62. } as VxeTableGridOptions,
  63. }),
  64. );
  65. </script>
  66. <template>
  67. <Page auto-content-height>
  68. <FormEditModal @success="handelSuccess" />
  69. <Grid>
  70. <template #table-title>
  71. <span class="border-l-primary border-l-8 border-solid pl-2">
  72. 参数配置列表
  73. </span>
  74. </template>
  75. <template #toolbar-tools>
  76. <Button
  77. class="mr-2"
  78. type="primary"
  79. v-access:code="'config:add'"
  80. @click="() => handleEdit({}, false)"
  81. >
  82. 新增参数配置
  83. </Button>
  84. </template>
  85. </Grid>
  86. </Page>
  87. </template>