Skip to content

Commit 95b7eb9

Browse files
YunaiVgitee-org
authored andcommitted
!68 Vue3 重构:基础设施 -> 代码生成
Merge pull request !68 from xiaowuye/dev
2 parents e3bcfa5 + bedcd22 commit 95b7eb9

File tree

12 files changed

+967
-489
lines changed

12 files changed

+967
-489
lines changed

src/api/infra/codegen/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,56 @@ import request from '@/config/axios'
22
import type { CodegenUpdateReqVO, CodegenCreateListReqVO } from './types'
33

44
// 查询列表代码生成表定义
5-
export const getCodegenTablePageApi = (params) => {
5+
export const getCodegenTablePage = (params) => {
66
return request.get({ url: '/infra/codegen/table/page', params })
77
}
88

99
// 查询详情代码生成表定义
10-
export const getCodegenTableApi = (id: number) => {
10+
export const getCodegenTable = (id: number) => {
1111
return request.get({ url: '/infra/codegen/detail?tableId=' + id })
1212
}
1313

1414
// 新增代码生成表定义
15-
export const createCodegenTableApi = (data: CodegenCreateListReqVO) => {
15+
export const createCodegenTable = (data: CodegenCreateListReqVO) => {
1616
return request.post({ url: '/infra/codegen/create', data })
1717
}
1818

1919
// 修改代码生成表定义
20-
export const updateCodegenTableApi = (data: CodegenUpdateReqVO) => {
20+
export const updateCodegenTable = (data: CodegenUpdateReqVO) => {
2121
return request.put({ url: '/infra/codegen/update', data })
2222
}
2323

2424
// 基于数据库的表结构,同步数据库的表和字段定义
25-
export const syncCodegenFromDBApi = (id: number) => {
25+
export const syncCodegenFromDB = (id: number) => {
2626
return request.put({ url: '/infra/codegen/sync-from-db?tableId=' + id })
2727
}
2828

2929
// 基于 SQL 建表语句,同步数据库的表和字段定义
30-
export const syncCodegenFromSQLApi = (id: number, sql: string) => {
30+
export const syncCodegenFromSQL = (id: number, sql: string) => {
3131
return request.put({ url: '/infra/codegen/sync-from-sql?tableId=' + id + '&sql=' + sql })
3232
}
3333

3434
// 预览生成代码
35-
export const previewCodegenApi = (id: number) => {
35+
export const previewCodegen = (id: number) => {
3636
return request.get({ url: '/infra/codegen/preview?tableId=' + id })
3737
}
3838

3939
// 下载生成代码
40-
export const downloadCodegenApi = (id: number) => {
40+
export const downloadCodegen = (id: number) => {
4141
return request.download({ url: '/infra/codegen/download?tableId=' + id })
4242
}
4343

4444
// 获得表定义
45-
export const getSchemaTableListApi = (params) => {
45+
export const getSchemaTableList = (params) => {
4646
return request.get({ url: '/infra/codegen/db/table/list', params })
4747
}
4848

4949
// 基于数据库的表结构,创建代码生成器的表定义
50-
export const createCodegenListApi = (data) => {
50+
export const createCodegenList = (data) => {
5151
return request.post({ url: '/infra/codegen/create-list', data })
5252
}
5353

5454
// 删除代码生成表定义
55-
export const deleteCodegenTableApi = (id: number) => {
55+
export const deleteCodegenTable = (id: number) => {
5656
return request.delete({ url: '/infra/codegen/delete?tableId=' + id })
5757
}

src/api/infra/codegen/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export type CodegenPreviewVO = {
5252
code: string
5353
}
5454
export type CodegenUpdateReqVO = {
55-
table: CodegenTableVO
55+
table: CodegenTableVO | any
5656
columns: CodegenColumnVO[]
5757
}
5858
export type CodegenCreateListReqVO = {

src/locales/zh-CN.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ export default {
298298
typeUpdate: '字典类型编辑',
299299
dataCreate: '字典数据新增',
300300
dataUpdate: '字典数据编辑',
301-
fileUpload: '上传文件'
301+
fileUpload: '上传文件',
302+
back: '返回'
302303
},
303304
dialog: {
304305
dialog: '弹窗',

src/views/infra/codegen/EditTable.vue

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,74 @@
11
<template>
2-
<ContentWrap>
3-
<ContentDetailWrap :title="title" @back="push('/infra/codegen')">
4-
<el-tabs v-model="activeName">
5-
<el-tab-pane label="基本信息" name="basicInfo">
6-
<BasicInfoForm ref="basicInfoRef" :basicInfo="tableCurrentRow" />
7-
</el-tab-pane>
8-
<el-tab-pane label="字段信息" name="cloum">
9-
<CloumInfoForm ref="cloumInfoRef" :info="cloumCurrentRow" />
10-
</el-tab-pane>
11-
</el-tabs>
12-
<template #right>
13-
<XButton
14-
type="primary"
15-
:title="t('action.save')"
16-
:loading="loading"
17-
@click="submitForm()"
18-
/>
19-
</template>
20-
</ContentDetailWrap>
21-
</ContentWrap>
2+
<content-wrap v-loading="loading">
3+
<el-tabs v-model="activeName">
4+
<el-tab-pane label="基本信息" name="basicInfo">
5+
<basic-info-form ref="basicInfoRef" :table="formData.table" />
6+
</el-tab-pane>
7+
<el-tab-pane label="字段信息" name="colum">
8+
<colum-info-form ref="columInfoRef" :columns="formData.columns" />
9+
</el-tab-pane>
10+
<el-tab-pane label="生成信息" name="generateInfo">
11+
<generate-info-form ref="generateInfoRef" :table="formData.table" />
12+
</el-tab-pane>
13+
</el-tabs>
14+
<el-form label-width="100px">
15+
<el-form-item style="text-align: center; margin-left: -100px; margin-top: 10px">
16+
<el-button type="primary" @click="submitForm" :loading="submitLoading">
17+
{{ t('action.save') }}
18+
</el-button>
19+
<el-button @click="close">{{ t('action.back') }}</el-button>
20+
</el-form-item>
21+
</el-form>
22+
</content-wrap>
2223
</template>
2324
<script setup lang="ts">
24-
import { BasicInfoForm, CloumInfoForm } from './components'
25-
import { getCodegenTableApi, updateCodegenTableApi } from '@/api/infra/codegen'
26-
import { CodegenTableVO, CodegenColumnVO, CodegenUpdateReqVO } from '@/api/infra/codegen/types'
25+
import { BasicInfoForm, ColumInfoForm, GenerateInfoForm } from './components'
26+
import * as CodegenApi from '@/api/infra/codegen'
27+
import ContentWrap from '@/components/ContentWrap/src/ContentWrap.vue'
28+
import { useTagsViewStore } from '@/store/modules/tagsView'
29+
import { CodegenUpdateReqVO } from '@/api/infra/codegen/types'
2730
2831
const { t } = useI18n() // 国际化
2932
const message = useMessage() // 消息弹窗
30-
const { push } = useRouter()
33+
const { push, currentRoute } = useRouter()
3134
const { query } = useRoute()
35+
const { delView } = useTagsViewStore()
3236
const loading = ref(false)
33-
const title = ref('代码生成')
37+
const submitLoading = ref(false)
3438
const activeName = ref('basicInfo')
35-
const cloumInfoRef = ref(null)
36-
const tableCurrentRow = ref<CodegenTableVO>()
37-
const cloumCurrentRow = ref<CodegenColumnVO[]>([])
3839
const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>()
40+
const columInfoRef = ref<ComponentRef<typeof ColumInfoForm>>()
41+
const generateInfoRef = ref<ComponentRef<typeof GenerateInfoForm>>()
42+
const formData = ref<CodegenUpdateReqVO>({
43+
table: {},
44+
columns: []
45+
})
3946
40-
const getList = async () => {
47+
const getDetail = async () => {
4148
const id = query.id as unknown as number
4249
if (id) {
50+
loading.value = true
4351
// 获取表详细信息
44-
const res = await getCodegenTableApi(id)
45-
title.value = '修改[ ' + res.table.tableName + ' ]生成配置'
46-
tableCurrentRow.value = res.table
47-
cloumCurrentRow.value = res.columns
52+
formData.value = await CodegenApi.getCodegenTable(id)
53+
loading.value = false
4854
}
4955
}
5056
const submitForm = async () => {
51-
const basicInfo = unref(basicInfoRef)
52-
const basicForm = await basicInfo?.elFormRef?.validate()?.catch(() => {})
53-
if (basicForm) {
54-
const basicInfoData = (await basicInfo?.getFormData()) as CodegenTableVO
55-
const genTable: CodegenUpdateReqVO = {
56-
table: basicInfoData,
57-
columns: cloumCurrentRow.value
58-
}
59-
await updateCodegenTableApi(genTable)
57+
if (!unref(formData)) return
58+
try {
59+
await unref(basicInfoRef)?.validate()
60+
await unref(generateInfoRef)?.validate()
61+
await CodegenApi.updateCodegenTable(unref(formData))
6062
message.success(t('common.updateSuccess'))
6163
push('/infra/codegen')
62-
}
64+
} catch {}
65+
}
66+
/** 关闭按钮 */
67+
const close = () => {
68+
delView(unref(currentRoute))
69+
push('/infra/codegen')
6370
}
6471
onMounted(() => {
65-
getList()
72+
getDetail()
6673
})
6774
</script>

0 commit comments

Comments
 (0)