perf: 重构代码生成 优化性能

This commit is contained in:
xingyu 2023-01-13 23:58:14 +08:00
parent 258577e86a
commit 4941a43e08
5 changed files with 187 additions and 230 deletions

View File

@ -8,9 +8,6 @@
<el-tab-pane label="字段信息" name="cloum"> <el-tab-pane label="字段信息" name="cloum">
<CloumInfoForm ref="cloumInfoRef" :info="cloumCurrentRow" /> <CloumInfoForm ref="cloumInfoRef" :info="cloumCurrentRow" />
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="生成信息" name="genInfo">
<GenInfoForm ref="genInfoRef" :genInfo="tableCurrentRow" />
</el-tab-pane>
</el-tabs> </el-tabs>
<template #right> <template #right>
<XButton <XButton
@ -30,7 +27,7 @@ import { ElTabs, ElTabPane } from 'element-plus'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage' import { useMessage } from '@/hooks/web/useMessage'
import { ContentDetailWrap } from '@/components/ContentDetailWrap' import { ContentDetailWrap } from '@/components/ContentDetailWrap'
import { BasicInfoForm, CloumInfoForm, GenInfoForm } from './components' import { BasicInfoForm, CloumInfoForm } from './components'
import { getCodegenTableApi, updateCodegenTableApi } from '@/api/infra/codegen' import { getCodegenTableApi, updateCodegenTableApi } from '@/api/infra/codegen'
import { CodegenTableVO, CodegenColumnVO, CodegenUpdateReqVO } from '@/api/infra/codegen/types' import { CodegenTableVO, CodegenColumnVO, CodegenUpdateReqVO } from '@/api/infra/codegen/types'
@ -40,12 +37,11 @@ const { push } = useRouter()
const { query } = useRoute() const { query } = useRoute()
const loading = ref(false) const loading = ref(false)
const title = ref('代码生成') const title = ref('代码生成')
const activeName = ref('cloum') const activeName = ref('basicInfo')
const cloumInfoRef = ref(null) const cloumInfoRef = ref(null)
const tableCurrentRow = ref<CodegenTableVO>() const tableCurrentRow = ref<CodegenTableVO>()
const cloumCurrentRow = ref<CodegenColumnVO[]>([]) const cloumCurrentRow = ref<CodegenColumnVO[]>([])
const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>() const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>()
const genInfoRef = ref<ComponentRef<typeof GenInfoForm>>()
const getList = async () => { const getList = async () => {
const id = query.id as unknown as number const id = query.id as unknown as number
@ -59,14 +55,11 @@ const getList = async () => {
} }
const submitForm = async () => { const submitForm = async () => {
const basicInfo = unref(basicInfoRef) const basicInfo = unref(basicInfoRef)
const genInfo = unref(genInfoRef)
const basicForm = await basicInfo?.elFormRef?.validate()?.catch(() => {}) const basicForm = await basicInfo?.elFormRef?.validate()?.catch(() => {})
const genForm = await genInfo?.elFormRef?.validate()?.catch(() => {}) if (basicForm) {
if (basicForm && genForm) {
const basicInfoData = (await basicInfo?.getFormData()) as CodegenTableVO const basicInfoData = (await basicInfo?.getFormData()) as CodegenTableVO
const genInfoData = (await genInfo?.getFormData()) as CodegenTableVO
const genTable: CodegenUpdateReqVO = { const genTable: CodegenUpdateReqVO = {
table: Object.assign({}, basicInfoData, genInfoData), table: basicInfoData,
columns: cloumCurrentRow.value columns: cloumCurrentRow.value
} }
await updateCodegenTableApi(genTable) await updateCodegenTableApi(genTable)

View File

@ -2,23 +2,42 @@
<Form :rules="rules" @register="register" /> <Form :rules="rules" @register="register" />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { PropType, reactive, watch } from 'vue' import { onMounted, PropType, reactive, ref, watch } from 'vue'
import { required } from '@/utils/formRules' import { required } from '@/utils/formRules'
import { useForm } from '@/hooks/web/useForm' import { useForm } from '@/hooks/web/useForm'
import { Form } from '@/components/Form' import { Form } from '@/components/Form'
import { FormSchema } from '@/types/form' import { FormSchema } from '@/types/form'
import { CodegenTableVO } from '@/api/infra/codegen/types' import { CodegenTableVO } from '@/api/infra/codegen/types'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { listSimpleMenusApi } from '@/api/system/menu'
import { handleTree, defaultProps } from '@/utils/tree'
const props = defineProps({ const props = defineProps({
basicInfo: { basicInfo: {
type: Object as PropType<Nullable<CodegenTableVO>>, type: Object as PropType<Nullable<CodegenTableVO>>,
default: () => null default: () => null
} }
}) })
const templateTypeOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)
const sceneOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
const menuOptions = ref<any>([]) //
const getTree = async () => {
const res = await listSimpleMenusApi()
menuOptions.value = handleTree(res)
}
const rules = reactive({ const rules = reactive({
tableName: [required], tableName: [required],
tableComment: [required], tableComment: [required],
className: [required], className: [required],
author: [required] author: [required],
templateType: [required],
scene: [required],
moduleName: [required],
businessName: [required],
businessPackage: [required],
classComment: [required]
}) })
const schema = reactive<FormSchema[]>([ const schema = reactive<FormSchema[]>([
{ {
@ -45,6 +64,79 @@ const schema = reactive<FormSchema[]>([
span: 12 span: 12
} }
}, },
{
label: '生成模板',
field: 'templateType',
component: 'Select',
componentProps: {
options: templateTypeOptions
},
colProps: {
span: 12
}
},
{
label: '生成场景',
field: 'scene',
component: 'Select',
componentProps: {
options: sceneOptions
},
colProps: {
span: 12
}
},
{
label: '模块名',
field: 'moduleName',
component: 'Input',
labelMessage: '模块名,即一级目录,例如 system、infra、tool 等等',
colProps: {
span: 12
}
},
{
label: '业务名',
field: 'businessName',
component: 'Input',
labelMessage: '业务名,即二级目录,例如 user、permission、dict 等等',
colProps: {
span: 12
}
},
{
label: '类名称',
field: 'className',
component: 'Input',
labelMessage: '类名称首字母大写例如SysUser、SysMenu、SysDictData 等等',
colProps: {
span: 12
}
},
{
label: '类描述',
field: 'classComment',
component: 'Input',
labelMessage: '用作类描述,例如 用户',
colProps: {
span: 12
}
},
{
label: '上级菜单',
field: 'parentMenuId',
component: 'TreeSelect',
componentProps: {
data: menuOptions,
props: defaultProps,
checkStrictly: true,
nodeKey: 'id'
},
labelMessage: '分配到指定菜单下,例如 系统管理',
colProps: {
span: 12
}
},
{ {
label: '作者', label: '作者',
field: 'author', field: 'author',
@ -81,6 +173,10 @@ watch(
immediate: true immediate: true
} }
) )
// ========== ==========
onMounted(async () => {
await getTree()
})
defineExpose({ defineExpose({
elFormRef, elFormRef,

View File

@ -1,113 +1,117 @@
<template> <template>
<vxe-table <vxe-table
ref="dragTable" ref="dragTable"
border
:data="info" :data="info"
max-height="600" max-height="600"
stripe stripe
class="xtable-scrollbar" class="xtable-scrollbar"
:column-config="{ resizable: true }" :column-config="{ resizable: true }"
> >
<vxe-column title="字段列名" field="columnName" fixed="left" width="80" /> <vxe-column title="字段列名" field="columnName" fixed="left" width="10%" />
<vxe-column title="字段描述" field="columnComment"> <vxe-colgroup title="基础属性">
<template #default="{ row }"> <vxe-column title="字段描述" field="columnComment" width="10%">
<el-input v-model="row.columnComment" /> <template #default="{ row }">
</template> <vxe-input v-model="row.columnComment" placeholder="请输入字段描述" />
</vxe-column> </template>
<vxe-column title="物理类型" field="dataType" width="10%" /> </vxe-column>
<vxe-column title="Java类型" width="10%" field="javaType"> <vxe-column title="物理类型" field="dataType" width="10%" />
<template #default="{ row }"> <vxe-column title="Java类型" width="10%" field="javaType">
<el-select v-model="row.javaType"> <template #default="{ row }">
<el-option label="Long" value="Long" /> <vxe-select v-model="row.javaType" placeholder="请选择Java类型">
<el-option label="String" value="String" /> <vxe-option label="Long" value="Long" />
<el-option label="Integer" value="Integer" /> <vxe-option label="String" value="String" />
<el-option label="Double" value="Double" /> <vxe-option label="Integer" value="Integer" />
<el-option label="BigDecimal" value="BigDecimal" /> <vxe-option label="Double" value="Double" />
<el-option label="LocalDateTime" value="LocalDateTime" /> <vxe-option label="BigDecimal" value="BigDecimal" />
<el-option label="Boolean" value="Boolean" /> <vxe-option label="LocalDateTime" value="LocalDateTime" />
</el-select> <vxe-option label="Boolean" value="Boolean" />
</template> </vxe-select>
</vxe-column> </template>
<vxe-column title="java属性" width="10%" field="javaField"> </vxe-column>
<template #default="{ row }"> <vxe-column title="java属性" width="8%" field="javaField">
<el-input v-model="row.javaField" /> <template #default="{ row }">
</template> <vxe-input v-model="row.javaField" placeholder="请输入java属性" />
</vxe-column> </template>
<vxe-column title="插入" width="4%" field="createOperation"> </vxe-column>
<template #default="{ row }"> </vxe-colgroup>
<vxe-checkbox true-label="true" false-label="false" v-model="row.createOperation" /> <vxe-colgroup title="增删改查">
</template> <vxe-column title="插入" width="40px" field="createOperation">
</vxe-column> <template #default="{ row }">
<vxe-column title="编辑" width="4%" field="updateOperation"> <vxe-checkbox true-label="true" false-label="false" v-model="row.createOperation" />
<template #default="{ row }"> </template>
<vxe-checkbox true-label="true" false-label="false" v-model="row.updateOperation" /> </vxe-column>
</template> <vxe-column title="编辑" width="40px" field="updateOperation">
</vxe-column> <template #default="{ row }">
<vxe-column title="列表" width="4%" field="listOperationResult"> <vxe-checkbox true-label="true" false-label="false" v-model="row.updateOperation" />
<template #default="{ row }"> </template>
<vxe-checkbox true-label="true" false-label="false" v-model="row.listOperationResult" /> </vxe-column>
</template> <vxe-column title="列表" width="40px" field="listOperationResult">
</vxe-column> <template #default="{ row }">
<vxe-column title="查询" width="4%" field="listOperation"> <vxe-checkbox true-label="true" false-label="false" v-model="row.listOperationResult" />
<template #default="{ row }"> </template>
<vxe-checkbox true-label="true" false-label="false" v-model="row.listOperation" /> </vxe-column>
</template> <vxe-column title="查询" width="40px" field="listOperation">
</vxe-column> <template #default="{ row }">
<vxe-column title="查询方式" width="8%" field="listOperationCondition"> <vxe-checkbox true-label="true" false-label="false" v-model="row.listOperation" />
<template #default="{ row }"> </template>
<el-select v-model="row.listOperationCondition"> </vxe-column>
<el-option label="=" value="=" /> <vxe-column title="允许空" width="40px" field="nullable">
<el-option label="!=" value="!=" /> <template #default="{ row }">
<el-option label=">" value=">" /> <vxe-checkbox true-label="true" false-label="false" v-model="row.nullable" />
<el-option label=">=" value=">=" /> </template>
<el-option label="<" value="<>" /> </vxe-column>
<el-option label="<=" value="<=" /> <vxe-column title="查询方式" width="60px" field="listOperationCondition">
<el-option label="LIKE" value="LIKE" /> <template #default="{ row }">
<el-option label="BETWEEN" value="BETWEEN" /> <vxe-select v-model="row.listOperationCondition" placeholder="请选择查询方式">
</el-select> <vxe-option label="=" value="=" />
</template> <vxe-option label="!=" value="!=" />
</vxe-column> <vxe-option label=">" value=">" />
<vxe-column title="允许空" width="4%" field="nullable"> <vxe-option label=">=" value=">=" />
<template #default="{ row }"> <vxe-option label="<" value="<>" />
<vxe-checkbox true-label="true" false-label="false" v-model="row.nullable" /> <vxe-option label="<=" value="<=" />
</template> <vxe-option label="LIKE" value="LIKE" />
</vxe-column> <vxe-option label="BETWEEN" value="BETWEEN" />
</vxe-select>
</template>
</vxe-column>
</vxe-colgroup>
<vxe-column title="显示类型" width="10%" field="htmlType"> <vxe-column title="显示类型" width="10%" field="htmlType">
<template #default="{ row }"> <template #default="{ row }">
<el-select v-model="row.htmlType"> <vxe-select v-model="row.htmlType" placeholder="请选择显示类型">
<el-option label="文本框" value="input" /> <vxe-option label="文本框" value="input" />
<el-option label="文本域" value="textarea" /> <vxe-option label="文本域" value="textarea" />
<el-option label="下拉框" value="select" /> <vxe-option label="下拉框" value="select" />
<el-option label="单选框" value="radio" /> <vxe-option label="单选框" value="radio" />
<el-option label="复选框" value="checkbox" /> <vxe-option label="复选框" value="checkbox" />
<el-option label="日期控件" value="datetime" /> <vxe-option label="日期控件" value="datetime" />
<el-option label="图片上传" value="imageUpload" /> <vxe-option label="图片上传" value="imageUpload" />
<el-option label="文件上传" value="fileUpload" /> <vxe-option label="文件上传" value="fileUpload" />
<el-option label="富文本控件" value="editor" /> <vxe-option label="富文本控件" value="editor" />
</el-select> </vxe-select>
</template> </template>
</vxe-column> </vxe-column>
<vxe-column title="字典类型" width="10%" field="dictType"> <vxe-column title="字典类型" width="10%" field="dictType">
<template #default="{ row }"> <template #default="{ row }">
<el-select v-model="row.dictType" clearable filterable placeholder="请选择"> <vxe-select v-model="row.dictType" clearable filterable placeholder="请选择字典类型">
<el-option <vxe-option
v-for="dict in dictOptions" v-for="dict in dictOptions"
:key="dict.id" :key="dict.id"
:label="dict.name" :label="dict.name"
:value="dict.type" :value="dict.type"
/> />
</el-select> </vxe-select>
</template> </template>
</vxe-column> </vxe-column>
<vxe-column title="示例" field="example"> <vxe-column title="示例" field="example">
<template #default="{ row }"> <template #default="{ row }">
<el-input v-model="row.example" /> <vxe-input v-model="row.example" placeholder="请输入示例" />
</template> </template>
</vxe-column> </vxe-column>
</vxe-table> </vxe-table>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, PropType, ref } from 'vue' import { onMounted, PropType, ref } from 'vue'
import { ElInput, ElSelect, ElOption } from 'element-plus'
import { DictTypeVO } from '@/api/system/dict/types' import { DictTypeVO } from '@/api/system/dict/types'
import { CodegenColumnVO } from '@/api/infra/codegen/types' import { CodegenColumnVO } from '@/api/infra/codegen/types'
import { listSimpleDictTypeApi } from '@/api/system/dict/dict.type' import { listSimpleDictTypeApi } from '@/api/system/dict/dict.type'

View File

@ -1,135 +0,0 @@
<template>
<Form :rules="rules" @register="register" />
</template>
<script setup lang="ts">
import { onMounted, PropType, reactive, ref, watch } from 'vue'
import { Form } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { required } from '@/utils/formRules'
import { handleTree, defaultProps } from '@/utils/tree'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { listSimpleMenusApi } from '@/api/system/menu'
import { CodegenTableVO } from '@/api/infra/codegen/types'
import { FormSchema } from '@/types/form'
const props = defineProps({
genInfo: {
type: Object as PropType<Nullable<CodegenTableVO>>,
default: () => null
}
})
const rules = reactive({
templateType: [required],
scene: [required],
moduleName: [required],
businessName: [required],
businessPackage: [required],
className: [required],
classComment: [required]
})
const templateTypeOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)
const sceneOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
const menuOptions = ref<any>([]) //
const getTree = async () => {
const res = await listSimpleMenusApi()
menuOptions.value = handleTree(res)
}
const schema = reactive<FormSchema[]>([
{
label: '生成模板',
field: 'templateType',
component: 'Select',
componentProps: {
options: templateTypeOptions
},
colProps: {
span: 12
}
},
{
label: '生成场景',
field: 'scene',
component: 'Select',
componentProps: {
options: sceneOptions
},
colProps: {
span: 12
}
},
{
label: '模块名',
field: 'moduleName',
component: 'Input',
labelMessage: '模块名,即一级目录,例如 system、infra、tool 等等',
colProps: {
span: 12
}
},
{
label: '业务名',
field: 'businessName',
component: 'Input',
labelMessage: '业务名,即二级目录,例如 user、permission、dict 等等',
colProps: {
span: 12
}
},
{
label: '类名称',
field: 'className',
component: 'Input',
labelMessage: '类名称首字母大写例如SysUser、SysMenu、SysDictData 等等',
colProps: {
span: 12
}
},
{
label: '类描述',
field: 'classComment',
component: 'Input',
labelMessage: '用作类描述,例如 用户',
colProps: {
span: 12
}
},
{
label: '上级菜单',
field: 'parentMenuId',
component: 'TreeSelect',
componentProps: {
data: menuOptions,
props: defaultProps,
checkStrictly: true,
nodeKey: 'id'
},
labelMessage: '分配到指定菜单下,例如 系统管理',
colProps: {
span: 12
}
}
])
const { register, methods, elFormRef } = useForm({
schema
})
// ========== ==========
onMounted(async () => {
await getTree()
})
watch(
() => props.genInfo,
(genInfo) => {
if (!genInfo) return
const { setValues } = methods
setValues(genInfo)
},
{
deep: true,
immediate: true
}
)
defineExpose({
elFormRef,
getFormData: methods.getFormData
})
</script>

View File

@ -1,6 +1,5 @@
import BasicInfoForm from './BasicInfoForm.vue' import BasicInfoForm from './BasicInfoForm.vue'
import CloumInfoForm from './CloumInfoForm.vue' import CloumInfoForm from './CloumInfoForm.vue'
import GenInfoForm from './GenInfoForm.vue'
import ImportTable from './ImportTable.vue' import ImportTable from './ImportTable.vue'
import Preview from './Preview.vue' import Preview from './Preview.vue'
export { BasicInfoForm, CloumInfoForm, GenInfoForm, ImportTable, Preview } export { BasicInfoForm, CloumInfoForm, ImportTable, Preview }