REVIEW 代码生成

This commit is contained in:
YunaiV 2023-03-29 09:09:34 +08:00
parent 95b7eb9856
commit 76c5c7c1de
6 changed files with 128 additions and 173 deletions

View File

@ -1,8 +1,74 @@
import request from '@/config/axios' import request from '@/config/axios'
import type { CodegenUpdateReqVO, CodegenCreateListReqVO } from './types'
export type CodegenTableVO = {
id: number
tableId: number
isParentMenuIdValid: boolean
dataSourceConfigId: number
scene: number
tableName: string
tableComment: string
remark: string
moduleName: string
businessName: string
className: string
classComment: string
author: string
createTime: Date
updateTime: Date
templateType: number
parentMenuId: number
}
export type CodegenColumnVO = {
id: number
tableId: number
columnName: string
dataType: string
columnComment: string
nullable: number
primaryKey: number
autoIncrement: string
ordinalPosition: number
javaType: string
javaField: string
dictType: string
example: string
createOperation: number
updateOperation: number
listOperation: number
listOperationCondition: string
listOperationResult: number
htmlType: string
}
export type DatabaseTableVO = {
name: string
comment: string
}
export type CodegenDetailVO = {
table: CodegenTableVO
columns: CodegenColumnVO[]
}
export type CodegenPreviewVO = {
filePath: string
code: string
}
export type CodegenUpdateReqVO = {
table: CodegenTableVO | any
columns: CodegenColumnVO[]
}
export type CodegenCreateListReqVO = {
dataSourceConfigId: number
tableNames: string[]
}
// 查询列表代码生成表定义 // 查询列表代码生成表定义
export const getCodegenTablePage = (params) => { export const getCodegenTablePage = (params: PageParam) => {
return request.get({ url: '/infra/codegen/table/page', params }) return request.get({ url: '/infra/codegen/table/page', params })
} }

View File

@ -1,61 +0,0 @@
export type CodegenTableVO = {
id: number
tableId: number
isParentMenuIdValid: boolean
dataSourceConfigId: number
scene: number
tableName: string
tableComment: string
remark: string
moduleName: string
businessName: string
className: string
classComment: string
author: string
createTime: Date
updateTime: Date
templateType: number
parentMenuId: number
}
export type CodegenColumnVO = {
id: number
tableId: number
columnName: string
dataType: string
columnComment: string
nullable: number
primaryKey: number
autoIncrement: string
ordinalPosition: number
javaType: string
javaField: string
dictType: string
example: string
createOperation: number
updateOperation: number
listOperation: number
listOperationCondition: string
listOperationResult: number
htmlType: string
}
export type DatabaseTableVO = {
name: string
comment: string
}
export type CodegenDetailVO = {
table: CodegenTableVO
columns: CodegenColumnVO[]
}
export type CodegenPreviewVO = {
filePath: string
code: string
}
export type CodegenUpdateReqVO = {
table: CodegenTableVO | any
columns: CodegenColumnVO[]
}
export type CodegenCreateListReqVO = {
dataSourceConfigId: number
tableNames: string[]
}

View File

@ -298,8 +298,7 @@ export default {
typeUpdate: '字典类型编辑', typeUpdate: '字典类型编辑',
dataCreate: '字典数据新增', dataCreate: '字典数据新增',
dataUpdate: '字典数据编辑', dataUpdate: '字典数据编辑',
fileUpload: '上传文件', fileUpload: '上传文件'
back: '返回'
}, },
dialog: { dialog: {
dialog: '弹窗', dialog: '弹窗',

View File

@ -16,7 +16,7 @@
<el-button type="primary" @click="submitForm" :loading="submitLoading"> <el-button type="primary" @click="submitForm" :loading="submitLoading">
{{ t('action.save') }} {{ t('action.save') }}
</el-button> </el-button>
<el-button @click="close">{{ t('action.back') }}</el-button> <el-button @click="close">返回</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</content-wrap> </content-wrap>

View File

@ -1,53 +0,0 @@
import type { VxeCrudSchema } from '@/hooks/web/useVxeCrudSchemas'
const { t } = useI18n() // 国际化
// 表单校验
export const rules = reactive({
title: [required],
type: [required],
status: [required]
})
// CrudSchema
const crudSchemas = reactive<VxeCrudSchema>({
primaryKey: 'id',
primaryType: 'seq',
action: true,
actionWidth: '400px',
columns: [
{
title: '表名称',
field: 'tableName',
isSearch: true
},
{
title: '表描述',
field: 'tableComment',
isSearch: true
},
{
title: '实体',
field: 'className',
isSearch: true
},
{
title: t('common.createTime'),
field: 'createTime',
formatter: 'formatDate',
isForm: false,
search: {
show: true,
itemRender: {
name: 'XDataTimePicker'
}
}
},
{
title: t('common.updateTime'),
field: 'updateTime',
formatter: 'formatDate',
isForm: false
}
]
})
export const { allSchemas } = useVxeCrudSchemas(crudSchemas)

View File

@ -1,13 +1,20 @@
<template> <template>
<!-- 搜索 --> <!-- 搜索 -->
<content-wrap> <content-wrap>
<el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true"> <el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="表名称" prop="tableName"> <el-form-item label="表名称" prop="tableName">
<el-input <el-input
v-model="queryParams.tableName" v-model="queryParams.tableName"
placeholder="请输入表名称" placeholder="请输入表名称"
clearable clearable
@keyup.enter="handleQuery" @keyup.enter="handleQuery"
class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="表描述" prop="tableComment"> <el-form-item label="表描述" prop="tableComment">
@ -16,23 +23,25 @@
placeholder="请输入表描述" placeholder="请输入表描述"
clearable clearable
@keyup.enter="handleQuery" @keyup.enter="handleQuery"
class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item label="创建时间" prop="createTime"> <el-form-item label="创建时间" prop="createTime">
<el-date-picker <el-date-picker
v-model="queryParams.createTime" v-model="queryParams.createTime"
value-format="yyyy-MM-dd HH:mm:ss" value-format="YYYY-MM-dd HH:mm:ss"
type="daterange" type="daterange"
start-placeholder="开始日期" start-placeholder="开始日期"
end-placeholder="结束日期" end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
/> />
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" />搜索</el-button> <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" />搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" />重置</el-button> <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" />重置</el-button>
<el-button type="primary" v-hasPermi="['infra:codegen:create']" @click="openImportTable()"> <el-button type="primary" v-hasPermi="['infra:codegen:create']" @click="openImportTable()">
<Icon icon="ep:zoom-in" class="mr-5px" />{{ t('action.import') }} <Icon icon="ep:zoom-in" class="mr-5px" /> 导入
</el-button> </el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -41,14 +50,20 @@
<!-- 列表 --> <!-- 列表 -->
<content-wrap> <content-wrap>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column label="数据源" align="center" :formatter="dataSourceConfigNameFormat" /> <el-table-column label="数据源" align="center">
<template #default="scope">
{{
dataSourceConfigList.find((config) => config.id === scope.row.dataSourceConfigId)?.name
}}
</template>
</el-table-column>
<el-table-column label="表名称" align="center" prop="tableName" width="200" /> <el-table-column label="表名称" align="center" prop="tableName" width="200" />
<el-table-column <el-table-column
label="表描述" label="表描述"
align="center" align="center"
prop="tableComment" prop="tableComment"
:show-overflow-tooltip="true" :show-overflow-tooltip="true"
width="120" width="200"
/> />
<el-table-column label="实体" align="center" prop="className" width="200" /> <el-table-column label="实体" align="center" prop="className" width="200" />
<el-table-column <el-table-column
@ -65,53 +80,53 @@
width="180" width="180"
:formatter="dateFormatter" :formatter="dateFormatter"
/> />
<el-table-column <el-table-column label="操作" align="center" width="300px" fixed="right">
label="操作"
align="center"
width="300px"
class-name="small-padding fixed-width"
>
<template #default="scope"> <template #default="scope">
<el-button <el-button
link link
type="primary" type="primary"
@click="handlePreview(scope.row)" @click="handlePreview(scope.row)"
v-hasPermi="['infra:codegen:preview']" v-hasPermi="['infra:codegen:preview']"
>预览</el-button
> >
预览
</el-button>
<el-button <el-button
link link
type="primary" type="primary"
@click="handleUpdate(scope.row.id)" @click="handleUpdate(scope.row.id)"
v-hasPermi="['infra:codegen:update']" v-hasPermi="['infra:codegen:update']"
>编辑</el-button
> >
编辑
</el-button>
<el-button <el-button
link link
type="danger" type="danger"
@click="handleDelete(scope.row.id)" @click="handleDelete(scope.row.id)"
v-hasPermi="['infra:codegen:delete']" v-hasPermi="['infra:codegen:delete']"
>删除</el-button
> >
删除
</el-button>
<el-button <el-button
link link
type="primary" type="primary"
@click="handleSynchDb(scope.row)" @click="handleSyncDB(scope.row)"
v-hasPermi="['infra:codegen:update']" v-hasPermi="['infra:codegen:update']"
>同步</el-button
> >
同步
</el-button>
<el-button <el-button
link link
type="primary" type="primary"
@click="handleGenTable(scope.row)" @click="handleGenTable(scope.row)"
v-hasPermi="['infra:codegen:download']" v-hasPermi="['infra:codegen:download']"
>生成代码</el-button
> >
生成代码
</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination <!-- 分页 -->
v-show="total > 0" <Pagination
:total="total" :total="total"
v-model:page="queryParams.pageNo" v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize" v-model:limit="queryParams.pageSize"
@ -120,20 +135,16 @@
</content-wrap> </content-wrap>
<!-- 弹窗导入表 --> <!-- 弹窗导入表 -->
<ImportTable ref="importRef" @ok="reload()" /> <ImportTable ref="importRef" @ok="getList" />
<!-- 弹窗预览代码 --> <!-- 弹窗预览代码 -->
<Preview ref="previewRef" /> <Preview ref="previewRef" />
</template> </template>
<script setup lang="ts" name="Codegen"> <script setup lang="ts" name="Codegen">
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download' import download from '@/utils/download'
import * as CodegenApi from '@/api/infra/codegen' import * as CodegenApi from '@/api/infra/codegen'
import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig' import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig'
import { CodegenTableVO } from '@/api/infra/codegen/types'
import { ImportTable, Preview } from './components' import { ImportTable, Preview } from './components'
import ContentWrap from '@/components/ContentWrap/src/ContentWrap.vue'
import { DataSourceConfigVO } from '@/api/infra/dataSourceConfig'
import { dateFormatter } from '@/utils/formatTime'
const message = useMessage() // const message = useMessage() //
const { t } = useI18n() // const { t } = useI18n() //
const { push } = useRouter() // const { push } = useRouter() //
@ -149,8 +160,7 @@ const queryParams = reactive({
createTime: [] createTime: []
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) //
const dataSourceConfigs = ref<DataSourceConfigVO[]>([]) //
/** 查询参数列表 */ /** 查询参数列表 */
const getList = async () => { const getList = async () => {
@ -176,35 +186,21 @@ const resetQuery = () => {
handleQuery() handleQuery()
} }
/** 初始化 **/
onMounted(async () => {
getList()
dataSourceConfigs.value = await DataSourceConfigApi.getDataSourceConfigList()
})
//
const dataSourceConfigNameFormat = (row) => {
for (const config of dataSourceConfigs.value) {
if (row.dataSourceConfigId === config.id) {
return config.name
}
}
return '未知【' + row.leaderUserId + '】'
}
// //
const importRef = ref() const importRef = ref()
const openImportTable = () => { const openImportTable = () => {
importRef.value.show() importRef.value.show()
} }
//
const previewRef = ref() /** 编辑操作 */
const handlePreview = (row: CodegenTableVO) => { const handleUpdate = (id: number) => {
previewRef.value.openModal(row.id) push('/codegen/edit?id=' + id)
} }
//
const handleUpdate = (rowId: number) => { /** 预览操作 */
push('/codegen/edit?id=' + rowId) const previewRef = ref()
const handlePreview = (row: CodegenApi.CodegenTableVO) => {
previewRef.value.openModal(row.id)
} }
/** 删除按钮操作 */ /** 删除按钮操作 */
@ -219,8 +215,9 @@ const handleDelete = async (id: number) => {
await getList() await getList()
} catch {} } catch {}
} }
//
const handleSynchDb = async (row: CodegenTableVO) => { /** 同步操作 */
const handleSyncDB = async (row: CodegenApi.CodegenTableVO) => {
// DB // DB
const tableName = row.tableName const tableName = row.tableName
try { try {
@ -230,9 +227,16 @@ const handleSynchDb = async (row: CodegenTableVO) => {
} catch {} } catch {}
} }
// /** 生成代码操作 */
const handleGenTable = async (row: CodegenTableVO) => { const handleGenTable = async (row: CodegenApi.CodegenTableVO) => {
const res = await CodegenApi.downloadCodegen(row.id) const res = await CodegenApi.downloadCodegen(row.id)
download.zip(res, 'codegen-' + row.className + '.zip') download.zip(res, 'codegen-' + row.className + '.zip')
} }
/** 初始化 **/
onMounted(async () => {
await getList()
//
dataSourceConfigList.value = await DataSourceConfigApi.getDataSourceConfigList()
})
</script> </script>