index.vue 2.3 KB

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