Skip to content

Commit b1e74a1

Browse files
committed
REVIEW 代码生成(ImportTable)
1 parent d5f3f0a commit b1e74a1

File tree

4 files changed

+73
-65
lines changed

4 files changed

+73
-65
lines changed
Lines changed: 67 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<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">
45
<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+
>
611
<el-option
7-
v-for="config in dataSourceConfigs"
12+
v-for="config in dataSourceConfigList"
813
:key="config.id"
914
:label="config.name"
1015
:value="config.id"
@@ -16,27 +21,29 @@
1621
v-model="queryParams.name"
1722
placeholder="请输入表名称"
1823
clearable
19-
@keyup.enter="handleQuery"
24+
@keyup.enter="getList"
25+
class="!w-240px"
2026
/>
2127
</el-form-item>
2228
<el-form-item label="表描述" prop="comment">
2329
<el-input
2430
v-model="queryParams.comment"
2531
placeholder="请输入表描述"
2632
clearable
27-
@keyup.enter="handleQuery"
33+
@keyup.enter="getList"
34+
class="!w-240px"
2835
/>
2936
</el-form-item>
3037
<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>
3239
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
3340
</el-form-item>
3441
</el-form>
35-
42+
<!-- 列表 -->
3643
<el-row>
3744
<el-table
38-
v-loading="dbLoading"
39-
@row-click="clickRow"
45+
v-loading="dbTableLoading"
46+
@row-click="handleRowClick"
4047
ref="tableRef"
4148
:data="dbTableList"
4249
@selection-change="handleSelectionChange"
@@ -47,87 +54,89 @@
4754
<el-table-column prop="comment" label="表描述" :show-overflow-tooltip="true" />
4855
</el-table>
4956
</el-row>
50-
57+
<!-- 操作 -->
5158
<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>
5863
</template>
5964
</Dialog>
6065
</template>
6166
<script setup lang="ts">
62-
import type { DatabaseTableVO } from '@/api/infra/codegen/types'
6367
import * as CodegenApi from '@/api/infra/codegen'
64-
import { getDataSourceConfigList, DataSourceConfigVO } from '@/api/infra/dataSourceConfig'
68+
import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig'
6569
import { ElTable } from 'element-plus'
66-
67-
const { t } = useI18n() // 国际化
6870
const message = useMessage() // 消息弹窗
69-
const emit = defineEmits(['ok'])
7071
7172
const modelVisible = ref(false) // 弹窗的是否展示
72-
const modelTitle = ref('导入表') // 弹窗的标题
73-
const dbLoading = ref(true)
73+
const dbTableLoading = ref(true) // 数据源的加载中
74+
const dbTableList = ref<CodegenApi.DatabaseTableVO[]>([]) // 表的列表
7475
const queryParams = reactive({
7576
name: undefined,
7677
comment: undefined,
7778
dataSourceConfigId: 0
7879
})
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[]>([]) // 数据源列表
8882
8983
/** 查询表数据 */
9084
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+
}
9491
}
95-
// 查询操作
96-
const handleQuery = async () => {
97-
await getList()
98-
}
99-
// 重置操作
92+
93+
/** 重置操作 */
10094
const resetQuery = async () => {
10195
queryParams.name = undefined
10296
queryParams.comment = undefined
103-
queryParams.dataSourceConfigId = dataSourceConfigs.value[0].id as number
97+
queryParams.dataSourceConfigId = dataSourceConfigList.value[0].id as number
10498
await getList()
10599
}
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) => {
110123
unref(tableRef)?.toggleRowSelection(row)
111124
}
112-
// 多选框选中数据
125+
126+
/** 多选框选中数据 */
113127
const handleSelectionChange = (selection) => {
114-
tables.value = selection.map((item) => item.name)
128+
tableList.value = selection.map((item) => item.name)
115129
}
130+
116131
/** 导入按钮操作 */
117132
const handleImportTable = async () => {
118133
await CodegenApi.createCodegenList({
119134
dataSourceConfigId: queryParams.dataSourceConfigId,
120-
tableNames: tables.value
135+
tableNames: tableList.value
121136
})
122137
message.success('导入成功')
123-
emit('ok')
124-
handleClose()
138+
emit('success')
139+
close()
125140
}
126-
const handleClose = () => {
127-
modelVisible.value = false
128-
tables.value = []
129-
}
130-
defineExpose({
131-
show
132-
})
141+
const emit = defineEmits(['success'])
133142
</script>
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import BasicInfoForm from './BasicInfoForm.vue'
22
import ColumInfoForm from './ColumInfoForm.vue'
33
import GenerateInfoForm from './GenerateInfoForm.vue'
4-
import ImportTable from './ImportTable.vue'
5-
import Preview from './Preview.vue'
6-
export { BasicInfoForm, ColumInfoForm, GenerateInfoForm, ImportTable, Preview }
4+
export { BasicInfoForm, ColumInfoForm, GenerateInfoForm }

src/views/infra/codegen/index.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,17 @@
135135
</content-wrap>
136136

137137
<!-- 弹窗:导入表 -->
138-
<ImportTable ref="importRef" @ok="getList" />
138+
<ImportTable ref="importRef" success="getList" />
139139
<!-- 弹窗:预览代码 -->
140-
<Preview ref="previewRef" />
140+
<PreviewCode ref="previewRef" />
141141
</template>
142142
<script setup lang="ts" name="Codegen">
143143
import { dateFormatter } from '@/utils/formatTime'
144144
import download from '@/utils/download'
145145
import * as CodegenApi from '@/api/infra/codegen'
146146
import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig'
147-
import { ImportTable, Preview } from './components'
147+
import ImportTable from './ImportTable.vue'
148+
import PreviewCode from './PreviewCode.vue'
148149
const message = useMessage() // 消息弹窗
149150
const { t } = useI18n() // 国际化
150151
const { push } = useRouter() // 路由跳转
@@ -189,7 +190,7 @@ const resetQuery = () => {
189190
// 导入操作
190191
const importRef = ref()
191192
const openImportTable = () => {
192-
importRef.value.show()
193+
importRef.value.open()
193194
}
194195
195196
/** 编辑操作 */

0 commit comments

Comments
 (0)