index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <script lang="ts" setup>
  2. import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter';
  3. import { watch } from 'vue';
  4. import { Page, useVbenModal } from '@vben/common-ui';
  5. import { useWatermark } from '@vben/hooks';
  6. import { preferences } from '@vben/preferences';
  7. import { Button, message } from 'ant-design-vue';
  8. import { useTableGridOptions, useVbenVxeGrid } from '#/adapter';
  9. import { ConfigApi } from '#/api';
  10. import { useAppStore } from '#/store';
  11. import FormEdit from './components/edit.vue';
  12. import { useColumns, useSearchSchema } from './data.config';
  13. const [FormEditModal, formEditApi] = useVbenModal({
  14. connectedComponent: FormEdit,
  15. destroyOnClose: true,
  16. });
  17. const appStore = useAppStore();
  18. const { destroyWatermark, updateWatermark } = useWatermark();
  19. watch(
  20. () => preferences.app.watermark,
  21. async (enable) => {
  22. if (enable) {
  23. await updateWatermark({
  24. content: appStore.appInfo?.webWatermark,
  25. });
  26. } else {
  27. destroyWatermark();
  28. }
  29. },
  30. {
  31. immediate: true,
  32. },
  33. );
  34. const handelSuccess = async () => {
  35. await reload();
  36. await appStore.loadAppInfo();
  37. };
  38. const handleDelete = async (id: number) => {
  39. await ConfigApi.deleteDetail(id);
  40. message.success('数据删除成功');
  41. handelSuccess();
  42. };
  43. const handleEdit = (record: Record<string, any>, isUpdate: boolean) => {
  44. formEditApi
  45. .setData({
  46. isUpdate,
  47. baseData: { id: record.id },
  48. })
  49. .open();
  50. };
  51. const handleActionClick = async ({
  52. code,
  53. row,
  54. }: OnActionClickParams<ConfigApi.RecordItem>) => {
  55. switch (code) {
  56. case 'delete': {
  57. await handleDelete(row.id);
  58. break;
  59. }
  60. case 'edit': {
  61. handleEdit(row, true);
  62. break;
  63. }
  64. }
  65. };
  66. const [Grid, { reload }] = useVbenVxeGrid(
  67. useTableGridOptions({
  68. formOptions: {
  69. schema: useSearchSchema(),
  70. },
  71. gridOptions: {
  72. columns: useColumns(handleActionClick),
  73. proxyConfig: {
  74. ajax: {
  75. query: async ({ page }, formValues) => {
  76. return await ConfigApi.getPage({
  77. pageIndex: page.currentPage,
  78. pageSize: page.pageSize,
  79. ...formValues,
  80. });
  81. },
  82. },
  83. },
  84. } as VxeTableGridOptions,
  85. }),
  86. );
  87. </script>
  88. <template>
  89. <Page auto-content-height>
  90. <FormEditModal @success="handelSuccess" />
  91. <Grid>
  92. <template #table-title>
  93. <span class="border-l-primary border-l-8 border-solid pl-2">
  94. 参数配置列表
  95. </span>
  96. </template>
  97. <template #toolbar-tools>
  98. <Button
  99. class="mr-2"
  100. type="primary"
  101. v-access:code="'config:add'"
  102. @click="() => handleEdit({}, false)"
  103. >
  104. 新增参数配置
  105. </Button>
  106. </template>
  107. </Grid>
  108. </Page>
  109. </template>