diff --git a/apps/web-antd/src/views/infra/codegen/codegen.data.ts b/apps/web-antd/src/views/infra/codegen/codegen.data.ts index cde6b5ae..73d353d9 100644 --- a/apps/web-antd/src/views/infra/codegen/codegen.data.ts +++ b/apps/web-antd/src/views/infra/codegen/codegen.data.ts @@ -4,6 +4,7 @@ import type { VxeGridProps } from '#/adapter/vxe-table'; import type { CodegenApi } from '#/api/infra/codegen'; import { getDataSourceConfigList } from '#/api/infra/data-source-config'; +import { $t } from '#/locales'; export namespace CodegenDefaultData { /** @@ -26,10 +27,11 @@ export namespace CodegenDefaultData { { field: 'createTime', title: '创建时间', formatter: 'formatDateTime' }, { field: 'updateTime', title: '更新时间', formatter: 'formatDateTime' }, { - title: '操作', - width: 'auto', + field: 'action', fixed: 'right', + width: 'auto', slots: { default: 'action' }, + title: $t('page.action.action'), }, ]; /** diff --git a/apps/web-antd/src/views/infra/codegen/components/import-table-modal.vue b/apps/web-antd/src/views/infra/codegen/components/import-table-modal.vue index 242550f9..93d644e9 100644 --- a/apps/web-antd/src/views/infra/codegen/components/import-table-modal.vue +++ b/apps/web-antd/src/views/infra/codegen/components/import-table-modal.vue @@ -8,13 +8,19 @@ import { type VxeGridProps, } from '@vben/plugins/vxe-table'; -import { getSchemaTableList } from '#/api/infra/codegen'; +import { + type CodegenApi, + createCodegenList, + getSchemaTableList, +} from '#/api/infra/codegen'; import { CodegenImportTableModalData } from '../codegen.data'; +const confirmLoading = ref(false); + // checked const checkedStatus = ref(false); - +const checkedRecords = ref([]); /** * 表格查询表单配置 */ @@ -55,8 +61,9 @@ const gridOptions = reactive({ const gridEvents = reactive({ checkboxChange: (params) => { - const { checked } = params; + const { checked, $grid } = params; checkedStatus.value = checked; + checkedRecords.value = $grid.getCheckboxRecords(); }, checkboxAll: (params) => { const { checked } = params; @@ -73,11 +80,30 @@ const [Grid, gridApi] = useVbenVxeGrid( }), ); -const [Modal] = useVbenModal({ +const [Modal, modalApi] = useVbenModal({ class: 'w-[800px] h-[800px]', + confirmLoading: confirmLoading.value, + closeOnClickModal: false, + closeOnPressEscape: false, onOpened: async () => { gridApi.reload(await gridApi.formApi.getValues()); }, + onConfirm: async () => { + modalApi.setState({ confirmLoading: true }); + const formValues = await gridApi.formApi.getValues(); + // 获取选中的数据 + const checkedRecords = + gridApi.grid.getCheckboxRecords() as CodegenApi.DatabaseTableRespVO[]; + try { + await createCodegenList({ + dataSourceConfigId: formValues.dataSourceConfigId, + tableNames: checkedRecords.map((item) => item.name), + }); + } finally { + modalApi.setState({ confirmLoading: false }); + } + modalApi.close(); + }, }); diff --git a/apps/web-antd/src/views/infra/codegen/index.vue b/apps/web-antd/src/views/infra/codegen/index.vue index f80d023c..5f472834 100644 --- a/apps/web-antd/src/views/infra/codegen/index.vue +++ b/apps/web-antd/src/views/infra/codegen/index.vue @@ -3,24 +3,16 @@ import { defineAsyncComponent, reactive, ref } from 'vue'; import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui'; -import { Button } from 'ant-design-vue'; - import { useVbenVxeGrid, type VxeGridListeners, type VxeGridProps, } from '#/adapter/vxe-table'; import { type CodegenApi, getCodegenTablePage } from '#/api/infra/codegen'; +import { ActionButtons, IconEnum } from '#/components/action-buttons'; import { CodegenDefaultData } from './codegen.data'; -// 使用导入表弹窗组件 -const [ImportTableModal, importTableModalApi] = useVbenModal({ - connectedComponent: defineAsyncComponent( - () => import('./components/import-table-modal.vue'), - ), -}); - // checked const checkedStatus = ref(false); @@ -52,14 +44,6 @@ const handleBatchDelete = (_rows: CodegenApi.CodegenTableRespVO[]) => { // console.log('批量删除', rows); }; -/** - * 导入表 - */ -const handleImportTable = () => { - // console.log('导入表', importTableModalApi); - importTableModalApi.open(); -}; - /** * 同步 */ @@ -109,10 +93,9 @@ const formOptions = reactive({ */ const gridOptions = reactive({ columns: CodegenDefaultData.tableColumns, - toolbarConfig: { - slots: { - buttons: 'toolbar_buttons', - }, + height: 'auto', + checkboxConfig: { + reserve: true, }, proxyConfig: { ajax: { @@ -140,53 +123,99 @@ const gridEvents = reactive({ } as VxeGridListeners); // 使用表格组件 -const [Grid] = useVbenVxeGrid({ +const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions, gridEvents, }); + +// 使用导入表弹窗组件 +const [ImportTableModal, importTableModalApi] = useVbenModal({ + connectedComponent: defineAsyncComponent( + () => import('./components/import-table-modal.vue'), + ), + onClosed: () => { + gridApi.reload(formOptions.values); + }, +});