index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <script lang="ts" setup>
  2. import { useAccess } from '@vben/access';
  3. import { Page, useVbenModal } from '@vben/common-ui';
  4. import { Button, message, Modal } from 'ant-design-vue';
  5. import { useVbenVxeGrid } from '#/adapter';
  6. import { TenantApi } from '#/api';
  7. import { TableAction } from '#/components/table-action';
  8. import FormEdit from './components/edit.vue';
  9. import { gridOptions, searchFormOptions } from './data.config';
  10. const { hasAccessByCodes } = useAccess();
  11. const [Grid, { reload }] = useVbenVxeGrid({
  12. formOptions: searchFormOptions,
  13. gridOptions,
  14. });
  15. const [FormEditModal, formEditApi] = useVbenModal({
  16. connectedComponent: FormEdit,
  17. });
  18. const handleCreateDb = (id: number) => {
  19. Modal.confirm({
  20. iconType: 'info',
  21. title: '提示',
  22. content: `确定创建/更新租户数据库?`,
  23. cancelText: `关闭`,
  24. onOk: async () => {
  25. await TenantApi.createDb(id);
  26. message.success('创建/更新租户数据库成功');
  27. },
  28. });
  29. };
  30. const handleDelete = (id: number) => {
  31. Modal.confirm({
  32. iconType: 'info',
  33. title: '删除提示',
  34. content: `确定要删除选择的记录吗?`,
  35. cancelText: `关闭`,
  36. onOk: async () => {
  37. await TenantApi.deleteDetail(id);
  38. message.success('数据删除成功');
  39. reload();
  40. },
  41. });
  42. };
  43. const handleEdit = (record: any, isUpdate: boolean) => {
  44. formEditApi.setData({
  45. isUpdate,
  46. baseData: { id: record.id },
  47. });
  48. formEditApi.open();
  49. };
  50. const handelSuccess = () => {
  51. reload();
  52. };
  53. </script>
  54. <template>
  55. <Page auto-content-height>
  56. <FormEditModal :close-on-click-modal="false" @success="handelSuccess" />
  57. <Grid>
  58. <template #toolbar-tools>
  59. <Button
  60. class="mr-2"
  61. type="primary"
  62. v-access:code="'tenant:add'"
  63. @click="() => handleEdit({}, false)"
  64. >
  65. 新增租户
  66. </Button>
  67. </template>
  68. <template #action="{ row }">
  69. <TableAction
  70. :actions="[
  71. {
  72. label: '创建库',
  73. type: 'text',
  74. disabled:
  75. !hasAccessByCodes(['tenant:createDb']) || row.tenantType === 0,
  76. onClick: handleCreateDb.bind(null, row),
  77. },
  78. {
  79. label: '编辑',
  80. type: 'text',
  81. danger: true,
  82. disabled: !hasAccessByCodes(['tenant:edit']),
  83. onClick: handleEdit.bind(null, row, true),
  84. },
  85. ]"
  86. :drop-down-actions="[
  87. {
  88. label: '重置密码',
  89. type: 'link',
  90. disabled: !hasAccessByCodes(['tenant:resetPwd']),
  91. },
  92. {
  93. label: '删除',
  94. type: 'link',
  95. disabled: !hasAccessByCodes(['tenant:delete']),
  96. onClick: handleDelete.bind(null, row.id),
  97. },
  98. ]"
  99. />
  100. </template>
  101. </Grid>
  102. </Page>
  103. </template>