|
1 | 1 | <template>
|
2 |
| - <Dialog :title="modelTitle" v-model="modelVisible"> |
3 |
| - <el-form :model="queryParams" ref="queryFormRef" :inline="true"> |
| 2 | + <Dialog title="导入表" v-model="modelVisible" width="800px"> |
| 3 | + <!-- 搜索栏 --> |
| 4 | + <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px"> |
4 | 5 | <el-form-item label="数据源" prop="dataSourceConfigId">
|
5 |
| - <el-select v-model="queryParams.dataSourceConfigId" placeholder="请选择数据源"> |
| 6 | + <el-select |
| 7 | + v-model="queryParams.dataSourceConfigId" |
| 8 | + placeholder="请选择数据源" |
| 9 | + class="!w-240px" |
| 10 | + > |
6 | 11 | <el-option
|
7 |
| - v-for="config in dataSourceConfigs" |
| 12 | + v-for="config in dataSourceConfigList" |
8 | 13 | :key="config.id"
|
9 | 14 | :label="config.name"
|
10 | 15 | :value="config.id"
|
|
16 | 21 | v-model="queryParams.name"
|
17 | 22 | placeholder="请输入表名称"
|
18 | 23 | clearable
|
19 |
| - @keyup.enter="handleQuery" |
| 24 | + @keyup.enter="getList" |
| 25 | + class="!w-240px" |
20 | 26 | />
|
21 | 27 | </el-form-item>
|
22 | 28 | <el-form-item label="表描述" prop="comment">
|
23 | 29 | <el-input
|
24 | 30 | v-model="queryParams.comment"
|
25 | 31 | placeholder="请输入表描述"
|
26 | 32 | clearable
|
27 |
| - @keyup.enter="handleQuery" |
| 33 | + @keyup.enter="getList" |
| 34 | + class="!w-240px" |
28 | 35 | />
|
29 | 36 | </el-form-item>
|
30 | 37 | <el-form-item>
|
31 |
| - <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> |
| 38 | + <el-button @click="getList"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> |
32 | 39 | <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
33 | 40 | </el-form-item>
|
34 | 41 | </el-form>
|
35 |
| - |
| 42 | + <!-- 列表 --> |
36 | 43 | <el-row>
|
37 | 44 | <el-table
|
38 |
| - v-loading="dbLoading" |
39 |
| - @row-click="clickRow" |
| 45 | + v-loading="dbTableLoading" |
| 46 | + @row-click="handleRowClick" |
40 | 47 | ref="tableRef"
|
41 | 48 | :data="dbTableList"
|
42 | 49 | @selection-change="handleSelectionChange"
|
|
47 | 54 | <el-table-column prop="comment" label="表描述" :show-overflow-tooltip="true" />
|
48 | 55 | </el-table>
|
49 | 56 | </el-row>
|
50 |
| - |
| 57 | + <!-- 操作 --> |
51 | 58 | <template #footer>
|
52 |
| - <div class="dialog-footer"> |
53 |
| - <el-button @click="handleImportTable" type="primary" :disabled="tables.length === 0">{{ |
54 |
| - t('action.import') |
55 |
| - }}</el-button> |
56 |
| - <el-button @click="handleClose">{{ t('dialog.close') }}</el-button> |
57 |
| - </div> |
| 59 | + <el-button @click="handleImportTable" type="primary" :disabled="tableList.length === 0"> |
| 60 | + 导入 |
| 61 | + </el-button> |
| 62 | + <el-button @click="close">关闭</el-button> |
58 | 63 | </template>
|
59 | 64 | </Dialog>
|
60 | 65 | </template>
|
61 | 66 | <script setup lang="ts">
|
62 |
| -import type { DatabaseTableVO } from '@/api/infra/codegen/types' |
63 | 67 | import * as CodegenApi from '@/api/infra/codegen'
|
64 |
| -import { getDataSourceConfigList, DataSourceConfigVO } from '@/api/infra/dataSourceConfig' |
| 68 | +import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig' |
65 | 69 | import { ElTable } from 'element-plus'
|
66 |
| -
|
67 |
| -const { t } = useI18n() // 国际化 |
68 | 70 | const message = useMessage() // 消息弹窗
|
69 |
| -const emit = defineEmits(['ok']) |
70 | 71 |
|
71 | 72 | const modelVisible = ref(false) // 弹窗的是否展示
|
72 |
| -const modelTitle = ref('导入表') // 弹窗的标题 |
73 |
| -const dbLoading = ref(true) |
| 73 | +const dbTableLoading = ref(true) // 数据源的加载中 |
| 74 | +const dbTableList = ref<CodegenApi.DatabaseTableVO[]>([]) // 表的列表 |
74 | 75 | const queryParams = reactive({
|
75 | 76 | name: undefined,
|
76 | 77 | comment: undefined,
|
77 | 78 | dataSourceConfigId: 0
|
78 | 79 | })
|
79 |
| -const dataSourceConfigs = ref<DataSourceConfigVO[]>([]) |
80 |
| -const show = async () => { |
81 |
| - dataSourceConfigs.value = await getDataSourceConfigList() |
82 |
| - queryParams.dataSourceConfigId = dataSourceConfigs.value[0].id as number |
83 |
| - modelVisible.value = true |
84 |
| - await getList() |
85 |
| -} |
86 |
| -/** 查询表数据 */ |
87 |
| -const dbTableList = ref<DatabaseTableVO[]>([]) |
| 80 | +const queryFormRef = ref() // 搜索的表单 |
| 81 | +const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) // 数据源列表 |
88 | 82 |
|
89 | 83 | /** 查询表数据 */
|
90 | 84 | const getList = async () => {
|
91 |
| - dbLoading.value = true |
92 |
| - dbTableList.value = await CodegenApi.getSchemaTableList(queryParams) |
93 |
| - dbLoading.value = false |
| 85 | + dbTableLoading.value = true |
| 86 | + try { |
| 87 | + dbTableList.value = await CodegenApi.getSchemaTableList(queryParams) |
| 88 | + } finally { |
| 89 | + dbTableLoading.value = false |
| 90 | + } |
94 | 91 | }
|
95 |
| -// 查询操作 |
96 |
| -const handleQuery = async () => { |
97 |
| - await getList() |
98 |
| -} |
99 |
| -// 重置操作 |
| 92 | +
|
| 93 | +/** 重置操作 */ |
100 | 94 | const resetQuery = async () => {
|
101 | 95 | queryParams.name = undefined
|
102 | 96 | queryParams.comment = undefined
|
103 |
| - queryParams.dataSourceConfigId = dataSourceConfigs.value[0].id as number |
| 97 | + queryParams.dataSourceConfigId = dataSourceConfigList.value[0].id as number |
104 | 98 | await getList()
|
105 | 99 | }
|
106 |
| -const tableRef = ref<typeof ElTable>() |
107 |
| -/** 多选框选中数据 */ |
108 |
| -const tables = ref<string[]>([]) |
109 |
| -const clickRow = (row) => { |
| 100 | +
|
| 101 | +/** 打开弹窗 */ |
| 102 | +const open = async () => { |
| 103 | + // 加载数据源的列表 |
| 104 | + dataSourceConfigList.value = await DataSourceConfigApi.getDataSourceConfigList() |
| 105 | + queryParams.dataSourceConfigId = dataSourceConfigList.value[0].id as number |
| 106 | + modelVisible.value = true |
| 107 | + // 加载表的列表 |
| 108 | + await getList() |
| 109 | +} |
| 110 | +defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
| 111 | +
|
| 112 | +/** 关闭弹窗 */ |
| 113 | +const close = () => { |
| 114 | + modelVisible.value = false |
| 115 | + tableList.value = [] |
| 116 | +} |
| 117 | +
|
| 118 | +const tableRef = ref<typeof ElTable>() // 表格的 Ref |
| 119 | +const tableList = ref<string[]>([]) // 选中的表名 |
| 120 | +
|
| 121 | +/** 处理某一行的点击 */ |
| 122 | +const handleRowClick = (row) => { |
110 | 123 | unref(tableRef)?.toggleRowSelection(row)
|
111 | 124 | }
|
112 |
| -// 多选框选中数据 |
| 125 | +
|
| 126 | +/** 多选框选中数据 */ |
113 | 127 | const handleSelectionChange = (selection) => {
|
114 |
| - tables.value = selection.map((item) => item.name) |
| 128 | + tableList.value = selection.map((item) => item.name) |
115 | 129 | }
|
| 130 | +
|
116 | 131 | /** 导入按钮操作 */
|
117 | 132 | const handleImportTable = async () => {
|
118 | 133 | await CodegenApi.createCodegenList({
|
119 | 134 | dataSourceConfigId: queryParams.dataSourceConfigId,
|
120 |
| - tableNames: tables.value |
| 135 | + tableNames: tableList.value |
121 | 136 | })
|
122 | 137 | message.success('导入成功')
|
123 |
| - emit('ok') |
124 |
| - handleClose() |
| 138 | + emit('success') |
| 139 | + close() |
125 | 140 | }
|
126 |
| -const handleClose = () => { |
127 |
| - modelVisible.value = false |
128 |
| - tables.value = [] |
129 |
| -} |
130 |
| -defineExpose({ |
131 |
| - show |
132 |
| -}) |
| 141 | +const emit = defineEmits(['success']) |
133 | 142 | </script>
|
0 commit comments