Skip to content

Commit 4565656

Browse files
committed
代码生成:支持设置主子表的信息
1 parent 999d8de commit 4565656

File tree

10 files changed

+612
-70
lines changed

10 files changed

+612
-70
lines changed

src/api/infra/codegen/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export type CodegenCreateListReqVO = {
6767
tableNames: string[]
6868
}
6969

70+
// 查询列表代码生成表定义
71+
export const getCodegenTableList = (dataSourceConfigId: number) => {
72+
return request.get({ url: '/infra/codegen/table/list?dataSourceConfigId=' + dataSourceConfigId })
73+
}
74+
7075
// 查询列表代码生成表定义
7176
export const getCodegenTablePage = (params: PageParam) => {
7277
return request.get({ url: '/infra/codegen/table/page', params })
@@ -92,11 +97,6 @@ export const syncCodegenFromDB = (id: number) => {
9297
return request.put({ url: '/infra/codegen/sync-from-db?tableId=' + id })
9398
}
9499

95-
// 基于 SQL 建表语句,同步数据库的表和字段定义
96-
export const syncCodegenFromSQL = (id: number, sql: string) => {
97-
return request.put({ url: '/infra/codegen/sync-from-sql?tableId=' + id + '&sql=' + sql })
98-
}
99-
100100
// 预览生成代码
101101
export const previewCodegen = (id: number) => {
102102
return request.get({ url: '/infra/codegen/preview?tableId=' + id })

src/api/infra/demo12/index.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,52 @@ export const exportDemo12Student = async (params) => {
4444

4545
// ==================== 子表(学生联系人) ====================
4646

47-
// 获得学生联系人列表
48-
export const getDemo12StudentContactListByStudentId = async (studentId) => {
49-
return await request.get({ url: `/infra/demo12-student/demo12-student/list-by-student-id?studentId=` + studentId })
47+
// 获得学生联系人分页
48+
export const getDemo12StudentContactPage = async (params) => {
49+
return await request.get({ url: `/infra/demo12-student/demo12-student-contact/page`, params })
50+
}
51+
// 新增学生联系人
52+
export const createDemo12StudentContact = async (data) => {
53+
return await request.post({ url: `/infra/demo12-student/demo12-student-contact/create`, data })
54+
}
55+
56+
// 修改学生联系人
57+
export const updateDemo12StudentContact = async (data) => {
58+
return await request.put({ url: `/infra/demo12-student/demo12-student-contact/update`, data })
59+
}
60+
61+
// 删除学生联系人
62+
export const deleteDemo12StudentContact = async (id: number) => {
63+
return await request.delete({ url: `/infra/demo12-student/demo12-student-contact/delete?id=` + id })
64+
}
65+
66+
// 获得学生联系人
67+
export const getDemo12StudentContact = async (id: number) => {
68+
return await request.get({ url: `/infra/demo12-student/demo12-student-contact/get?id=` + id })
5069
}
5170

5271
// ==================== 子表(学生班主任) ====================
5372

73+
// 获得学生班主任分页
74+
export const getDemo12StudentTeacherPage = async (params) => {
75+
return await request.get({ url: `/infra/demo12-student/demo12-student-teacher/page`, params })
76+
}
77+
// 新增学生班主任
78+
export const createDemo12StudentTeacher = async (data) => {
79+
return await request.post({ url: `/infra/demo12-student/demo12-student-teacher/create`, data })
80+
}
81+
82+
// 修改学生班主任
83+
export const updateDemo12StudentTeacher = async (data) => {
84+
return await request.put({ url: `/infra/demo12-student/demo12-student-teacher/update`, data })
85+
}
86+
87+
// 删除学生班主任
88+
export const deleteDemo12StudentTeacher = async (id: number) => {
89+
return await request.delete({ url: `/infra/demo12-student/demo12-student-teacher/delete?id=` + id })
90+
}
91+
5492
// 获得学生班主任
55-
export const getDemo12StudentTeacherByStudentId = async (studentId) => {
56-
return await request.get({ url: `/infra/demo12-student/demo12-student/get-by-student-id?studentId=` + studentId })
93+
export const getDemo12StudentTeacher = async (id: number) => {
94+
return await request.get({ url: `/infra/demo12-student/demo12-student-teacher/get?id=` + id })
5795
}

src/views/infra/codegen/EditTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<colum-info-form ref="columInfoRef" :columns="formData.columns" />
99
</el-tab-pane>
1010
<el-tab-pane label="生成信息" name="generateInfo">
11-
<generate-info-form ref="generateInfoRef" :table="formData.table" />
11+
<generate-info-form ref="generateInfoRef" :table="formData.table" :columns="formData.columns" />
1212
</el-tab-pane>
1313
</el-tabs>
1414
<el-form>

src/views/infra/codegen/components/GenerateInfoForm.vue

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<el-row>
44
<el-col :span="12">
55
<el-form-item label="生成模板" prop="templateType">
6-
<el-select v-model="formData.templateType" @change="tplSelectChange">
6+
<el-select v-model="formData.templateType">
77
<el-option
88
v-for="dict in getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)"
99
:key="dict.value"
@@ -246,48 +246,68 @@
246246
</el-form-item>
247247
</el-col>
248248
</el-row>
249-
<el-row v-show="formData.tplCategory === 'sub'">
250-
<h4 class="form-header">关联信息</h4>
249+
250+
<!-- 主表信息 -->
251+
<el-row v-if="formData.templateType === 15">
252+
<el-col :span="24">
253+
<h4 class="form-header">主表信息</h4>
254+
</el-col>
251255
<el-col :span="12">
252-
<el-form-item>
256+
<el-form-item prop="masterTableId">
253257
<template #label>
254258
<span>
255-
关联子表的表名
256-
<el-tooltip content="关联子表的表名, 如:sys_user" placement="top">
259+
关联的主表
260+
<el-tooltip content="关联主表(父表)的表名, 如:system_user" placement="top">
257261
<Icon icon="ep:question-filled" />
258262
</el-tooltip>
259263
</span>
260264
</template>
261-
<el-select v-model="formData.subTableName" placeholder="请选择" @change="subSelectChange">
265+
<el-select v-model="formData.masterTableId" placeholder="请选择">
262266
<el-option
263267
v-for="(table0, index) in tables"
264268
:key="index"
265269
:label="table0.tableName + ':' + table0.tableComment"
266-
:value="table0.tableName"
270+
:value="table0.id"
267271
/>
268272
</el-select>
269273
</el-form-item>
270274
</el-col>
271275
<el-col :span="12">
272-
<el-form-item>
276+
<el-form-item prop="subJoinColumnId">
273277
<template #label>
274278
<span>
275-
子表关联的外键名
276-
<el-tooltip content="子表关联的外键名, 如:user_id" placement="top">
279+
子表关联的字段
280+
<el-tooltip content="子表关联的字段, 如:user_id" placement="top">
277281
<Icon icon="ep:question-filled" />
278282
</el-tooltip>
279283
</span>
280284
</template>
281-
<el-select v-model="formData.subTableFkName" placeholder="请选择">
285+
<el-select v-model="formData.subJoinColumnId" placeholder="请选择">
282286
<el-option
283-
v-for="(column, index) in subColumns"
287+
v-for="(column, index) in props.columns"
284288
:key="index"
285289
:label="column.columnName + ':' + column.columnComment"
286-
:value="column.columnName"
290+
:value="column.id"
287291
/>
288292
</el-select>
289293
</el-form-item>
290294
</el-col>
295+
<el-col :span="12">
296+
<el-form-item prop="subJoinMany">
297+
<template #label>
298+
<span>
299+
关联关系
300+
<el-tooltip content="主表与子表的关联关系" placement="top">
301+
<Icon icon="ep:question-filled" />
302+
</el-tooltip>
303+
</span>
304+
</template>
305+
<el-radio-group v-model="formData.subJoinMany" placeholder="请选择">
306+
<el-radio :label="true">一对多</el-radio>
307+
<el-radio :label="false">一对一</el-radio>
308+
</el-radio-group>
309+
</el-form-item>
310+
</el-col>
291311
</el-row>
292312
</el-form>
293313
</template>
@@ -305,6 +325,10 @@ const props = defineProps({
305325
table: {
306326
type: Object as PropType<Nullable<CodegenApi.CodegenTableVO>>,
307327
default: () => null
328+
},
329+
columns: {
330+
type: Array as unknown as PropType<CodegenApi.CodegenColumnVO[]>,
331+
default: () => null
308332
}
309333
})
310334
@@ -323,9 +347,10 @@ const formData = ref({
323347
treeParentCode: '',
324348
treeName: '',
325349
tplCategory: '',
326-
subTableName: '',
327-
subTableFkName: '',
328-
genType: ''
350+
genType: '',
351+
masterTableId: undefined,
352+
subJoinColumnId: undefined,
353+
subJoinMany: undefined
329354
})
330355
331356
const rules = reactive({
@@ -336,41 +361,27 @@ const rules = reactive({
336361
businessName: [required],
337362
businessPackage: [required],
338363
className: [required],
339-
classComment: [required]
364+
classComment: [required],
365+
masterTableId: [required],
366+
subJoinColumnId: [required],
367+
subJoinMany: [required]
340368
})
341369
342-
const tables = ref([])
343-
const subColumns = ref([])
370+
const tables = ref([]) // 表定义列表
344371
const menus = ref<any[]>([])
345372
const menuTreeProps = {
346373
label: 'name'
347374
}
348375
349-
/** 选择子表名触发 */
350-
const subSelectChange = () => {
351-
formData.value.subTableFkName = ''
352-
}
353-
354-
/** 选择生成模板触发 */
355-
const tplSelectChange = (value) => {
356-
if (value !== 1) {
357-
// TODO 芋艿:暂时不考虑支持树形结构
358-
message.error(
359-
'暂时不考虑支持【树形】和【主子表】的代码生成。原因是:导致 vm 模板过于复杂,不利于胖友二次开发'
360-
)
361-
return false
362-
}
363-
if (value !== 'sub') {
364-
formData.value.subTableName = ''
365-
formData.value.subTableFkName = ''
366-
}
367-
}
368-
369376
watch(
370377
() => props.table,
371-
(table) => {
378+
async (table) => {
372379
if (!table) return
373380
formData.value = table as any
381+
// 加载表列表
382+
if (table.dataSourceConfigId >= 0) {
383+
tables.value = await CodegenApi.getCodegenTableList(formData.value.dataSourceConfigId)
384+
}
374385
},
375386
{
376387
deep: true,
@@ -380,6 +391,7 @@ watch(
380391
381392
onMounted(async () => {
382393
try {
394+
// 加载菜单
383395
const resp = await MenuApi.getSimpleMenusList()
384396
menus.value = handleTree(resp)
385397
} catch {}

src/views/infra/demo12/Demo12StudentForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</el-radio>
4343
</el-radio-group>
4444
</el-form-item>
45-
<el-form-item label="头像">
45+
<el-form-item label="头像" prop="avatar">
4646
<UploadImg v-model="formData.avatar" />
4747
</el-form-item>
4848
<el-form-item label="附件" prop="video">

0 commit comments

Comments
 (0)