Commit b84047b34b4f026ea07c92507431f1c6bf118855
1 parent
9f42e8e1
refactor: import table
Showing
1 changed file
with
70 additions
and
69 deletions
yudao-ui-admin-vue3/src/views/infra/codegen/components/ImportTable.vue
| 1 | +<template> | |
| 2 | + <!-- 导入表 --> | |
| 3 | + <XModal title="导入表" v-model="visible"> | |
| 4 | + <el-form :model="queryParams" ref="queryRef" :inline="true"> | |
| 5 | + <el-form-item label="数据源" prop="dataSourceConfigId"> | |
| 6 | + <el-select v-model="queryParams.dataSourceConfigId" placeholder="请选择数据源" clearable> | |
| 7 | + <el-option | |
| 8 | + v-for="config in dataSourceConfigs" | |
| 9 | + :key="config.id" | |
| 10 | + :label="config.name" | |
| 11 | + :value="config.id" | |
| 12 | + /> | |
| 13 | + </el-select> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="表名称" prop="name"> | |
| 16 | + <el-input v-model="queryParams.name" placeholder="请输入表名称" clearable /> | |
| 17 | + </el-form-item> | |
| 18 | + <el-form-item label="表描述" prop="comment"> | |
| 19 | + <el-input v-model="queryParams.comment" placeholder="请输入表描述" clearable /> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item> | |
| 22 | + <XButton | |
| 23 | + type="primary" | |
| 24 | + preIcon="ep:search" | |
| 25 | + :title="t('common.query')" | |
| 26 | + @click="handleQuery()" | |
| 27 | + /> | |
| 28 | + <XButton preIcon="ep:refresh-right" :title="t('common.reset')" @click="resetQuery()" /> | |
| 29 | + </el-form-item> | |
| 30 | + </el-form> | |
| 31 | + <vxe-table | |
| 32 | + ref="xTable" | |
| 33 | + :data="dbTableList" | |
| 34 | + v-loading="dbLoading" | |
| 35 | + :checkbox-config="{ highlight: true, range: true }" | |
| 36 | + height="350px" | |
| 37 | + class="xtable-scrollbar" | |
| 38 | + > | |
| 39 | + <vxe-column type="checkbox" width="60" /> | |
| 40 | + <vxe-column field="name" title="表名称" /> | |
| 41 | + <vxe-column field="comment" title="表描述" /> | |
| 42 | + </vxe-table> | |
| 43 | + <template #footer> | |
| 44 | + <div class="dialog-footer"> | |
| 45 | + <XButton type="primary" :title="t('action.import')" @click="handleImportTable()" /> | |
| 46 | + <XButton :title="t('dialog.close')" @click="handleClose()" /> | |
| 47 | + </div> | |
| 48 | + </template> | |
| 49 | + </XModal> | |
| 50 | +</template> | |
| 51 | + | |
| 1 | 52 | <script setup lang="ts"> |
| 2 | -import { reactive, ref } from 'vue' | |
| 3 | -import { getSchemaTableListApi, createCodegenListApi } from '@/api/infra/codegen' | |
| 4 | -import { | |
| 5 | - ElMessage, | |
| 6 | - ElTable, | |
| 7 | - ElTableColumn, | |
| 8 | - ElForm, | |
| 9 | - ElFormItem, | |
| 10 | - ElInput, | |
| 11 | - ElSelect, | |
| 12 | - ElOption | |
| 13 | -} from 'element-plus' | |
| 53 | +import { ref, reactive } from 'vue' | |
| 14 | 54 | import { useI18n } from '@/hooks/web/useI18n' |
| 55 | +import { useMessage } from '@/hooks/web/useMessage' | |
| 56 | +import { getSchemaTableListApi, createCodegenListApi } from '@/api/infra/codegen' | |
| 57 | +import { ElForm, ElFormItem, ElInput, ElSelect, ElOption } from 'element-plus' | |
| 15 | 58 | import { getDataSourceConfigListApi } from '@/api/infra/dataSourceConfig' |
| 16 | 59 | import type { DataSourceConfigVO } from '@/api/infra/dataSourceConfig/types' |
| 17 | 60 | import type { DatabaseTableVO } from '@/api/infra/codegen/types' |
| 61 | +import { VxeTableInstance } from 'vxe-table' | |
| 18 | 62 | const { t } = useI18n() // 国际化 |
| 63 | +const message = useMessage() // 消息弹窗 | |
| 19 | 64 | const emit = defineEmits(['ok']) |
| 20 | 65 | // ======== 显示页面 ======== |
| 21 | 66 | const visible = ref(false) |
| ... | ... | @@ -54,76 +99,32 @@ const resetQuery = async () => { |
| 54 | 99 | queryParams.dataSourceConfigId = 0 |
| 55 | 100 | await getList() |
| 56 | 101 | } |
| 102 | +const xTable = ref<VxeTableInstance>() | |
| 57 | 103 | /** 多选框选中数据 */ |
| 58 | 104 | const tables = ref<string[]>([]) |
| 59 | -const handleSelectionChange = (val: DatabaseTableVO[]) => { | |
| 60 | - tables.value = val.map((item) => item.name) | |
| 61 | -} | |
| 105 | + | |
| 62 | 106 | /** 导入按钮操作 */ |
| 63 | 107 | const handleImportTable = async () => { |
| 64 | - if (tables.value.length === 0) { | |
| 65 | - ElMessage.error('请选择要导入的表') | |
| 108 | + if (xTable.value?.getCheckboxRecords().length === 0) { | |
| 109 | + message.error('请选择要导入的表') | |
| 66 | 110 | return |
| 67 | 111 | } |
| 112 | + xTable.value?.getCheckboxRecords().forEach((item) => { | |
| 113 | + tables.value.push(item.name) | |
| 114 | + }) | |
| 68 | 115 | await createCodegenListApi({ |
| 69 | 116 | dataSourceConfigId: queryParams.dataSourceConfigId, |
| 70 | 117 | tableNames: tables.value |
| 71 | 118 | }) |
| 72 | - ElMessage.success('导入成功') | |
| 73 | - visible.value = false | |
| 119 | + message.success('导入成功') | |
| 74 | 120 | emit('ok') |
| 121 | + handleClose() | |
| 122 | +} | |
| 123 | +const handleClose = () => { | |
| 124 | + visible.value = false | |
| 125 | + tables.value = [] | |
| 75 | 126 | } |
| 76 | 127 | defineExpose({ |
| 77 | 128 | show |
| 78 | 129 | }) |
| 79 | 130 | </script> |
| 80 | -<template> | |
| 81 | - <!-- 导入表 --> | |
| 82 | - <XModal title="导入表" v-model="visible"> | |
| 83 | - <el-form :model="queryParams" ref="queryRef" :inline="true"> | |
| 84 | - <el-form-item label="数据源" prop="dataSourceConfigId"> | |
| 85 | - <el-select v-model="queryParams.dataSourceConfigId" placeholder="请选择数据源" clearable> | |
| 86 | - <el-option | |
| 87 | - v-for="config in dataSourceConfigs" | |
| 88 | - :key="config.id" | |
| 89 | - :label="config.name" | |
| 90 | - :value="config.id" | |
| 91 | - /> | |
| 92 | - </el-select> | |
| 93 | - </el-form-item> | |
| 94 | - <el-form-item label="表名称" prop="name"> | |
| 95 | - <el-input v-model="queryParams.name" placeholder="请输入表名称" clearable /> | |
| 96 | - </el-form-item> | |
| 97 | - <el-form-item label="表描述" prop="comment"> | |
| 98 | - <el-input v-model="queryParams.comment" placeholder="请输入表描述" clearable /> | |
| 99 | - </el-form-item> | |
| 100 | - <el-form-item> | |
| 101 | - <el-button type="primary" @click="handleQuery"> | |
| 102 | - <Icon icon="ep:search" class="mr-5px" /> | |
| 103 | - {{ t('common.query') }} | |
| 104 | - </el-button> | |
| 105 | - <el-button @click="resetQuery"> | |
| 106 | - <Icon icon="ep:refresh-right" class="mr-5px" /> | |
| 107 | - {{ t('common.reset') }} | |
| 108 | - </el-button> | |
| 109 | - </el-form-item> | |
| 110 | - </el-form> | |
| 111 | - <el-table | |
| 112 | - ref="table" | |
| 113 | - :data="dbTableList" | |
| 114 | - @selection-change="handleSelectionChange" | |
| 115 | - v-loading="dbLoading" | |
| 116 | - height="400px" | |
| 117 | - > | |
| 118 | - <el-table-column type="selection" width="55" /> | |
| 119 | - <el-table-column prop="name" label="表名称" :show-overflow-tooltip="true" /> | |
| 120 | - <el-table-column prop="comment" label="表描述" :show-overflow-tooltip="true" /> | |
| 121 | - </el-table> | |
| 122 | - <template #footer> | |
| 123 | - <div class="dialog-footer"> | |
| 124 | - <el-button type="primary" @click="handleImportTable">{{ t('action.import') }}</el-button> | |
| 125 | - <el-button @click="visible = false">{{ t('dialog.close') }}</el-button> | |
| 126 | - </div> | |
| 127 | - </template> | |
| 128 | - </XModal> | |
| 129 | -</template> | ... | ... |