修复代码生成父菜单选择无效,前端代码缺少字段,格式错误

pull/2/head
jueying 2022-10-31 17:13:05 +08:00
parent 3cee922e69
commit faea04546e
6 changed files with 227 additions and 221 deletions

View File

@ -1,35 +1,35 @@
import { useAxios } from '@/hooks/web/useAxios' import { useAxios } from '@/hooks/web/useAxios'
import { ${simpleClassName}VO,${simpleClassName}PageReqVO,${simpleClassName}ExcelReqVO } from './types' import { ${simpleClassName}VO, ${simpleClassName}PageReqVO, ${simpleClassName}ExcelReqVO } from './types'
const request = useAxios() const request = useAxios()
#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}") #set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}")
// 查询${table.classComment}列表 // 查询${table.classComment}列表
export const get${simpleClassName}PageApi = async (params: ${simpleClassName}PageReqVO) => { export const get${simpleClassName}PageApi = async (params: ${simpleClassName}PageReqVO) => {
return await request.get({ url: '${baseURL}/page', params }) return await request.get({ url: '${baseURL}/page', params })
} }
// 查询${table.classComment}详情 // 查询${table.classComment}详情
export const get${simpleClassName}Api = async (id: number) => { export const get${simpleClassName}Api = async (id: number) => {
return await request.get({ url: '${baseURL}/get?id=' + id }) return await request.get({ url: '${baseURL}/get?id=' + id })
} }
// 新增${table.classComment} // 新增${table.classComment}
export const create${simpleClassName}Api = async (data: ${simpleClassName}VO) => { export const create${simpleClassName}Api = async (data: ${simpleClassName}VO) => {
return await request.post({ url: '${baseURL}/create', data }) return await request.post({ url: '${baseURL}/create', data })
} }
// 修改${table.classComment} // 修改${table.classComment}
export const update${simpleClassName}Api = async (data: ${simpleClassName}VO) => { export const update${simpleClassName}Api = async (data: ${simpleClassName}VO) => {
return await request.put({ url: '${baseURL}/update', data }) return await request.put({ url: '${baseURL}/update', data })
} }
// 删除${table.classComment} // 删除${table.classComment}
export const delete${simpleClassName}Api = async (id: number) => { export const delete${simpleClassName}Api = async (id: number) => {
return await request.delete({ url: '${baseURL}/delete?id=' + id }) return await request.delete({ url: '${baseURL}/delete?id=' + id })
} }
// 导出${table.classComment} Excel // 导出${table.classComment} Excel
export const export${simpleClassName}Api = async (params: ${simpleClassName}ExcelReqVO) => { export const export${simpleClassName}Api = async (params: ${simpleClassName}ExcelReqVO) => {
return await request.download({ url: '${baseURL}/export-excel', params }) return await request.download({ url: '${baseURL}/export-excel', params })
} }

View File

@ -2,9 +2,11 @@ export type ${simpleClassName}VO = {
#foreach ($column in $columns) #foreach ($column in $columns)
#if ($column.createOperation || $column.updateOperation) #if ($column.createOperation || $column.updateOperation)
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer")
${column.javaField}: number ${column.javaField}: number
#elseif(${column.javaType.toLowerCase()} == "date")
${column.javaField}: string
#else #else
${column.javaField}: ${column.javaType.toLowerCase()} ${column.javaField}: ${column.javaType.toLowerCase()}
#end #end
#end #end
#end #end
@ -14,9 +16,11 @@ export type ${simpleClassName}PageReqVO = {
#foreach ($column in $columns) #foreach ($column in $columns)
#if (${column.listOperation})##查询操作 #if (${column.listOperation})##查询操作
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer")
${column.javaField}: number ${column.javaField}: number
#elseif(${column.javaType.toLowerCase()} == "date")
${column.javaField}: string
#else #else
${column.javaField}: ${column.javaType.toLowerCase()} ${column.javaField}: ${column.javaType.toLowerCase()}
#end #end
#end #end
#end #end
@ -26,9 +30,11 @@ export type ${simpleClassName}ExcelReqVO = {
#foreach ($column in $columns) #foreach ($column in $columns)
#if (${column.listOperation})##查询操作 #if (${column.listOperation})##查询操作
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer")
${column.javaField}: number ${column.javaField}: number
#elseif(${column.javaType.toLowerCase()} == "date")
${column.javaField}: string
#else #else
${column.javaField}: ${column.javaType.toLowerCase()} ${column.javaField}: ${column.javaType.toLowerCase()}
#end #end
#end #end
#end #end

View File

@ -8,104 +8,104 @@ export const rules = reactive({
#foreach ($column in $columns) #foreach ($column in $columns)
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
#set($comment=$column.columnComment) #set($comment=$column.columnComment)
$column.javaField: [{ required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }], $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == "select")'change'#else'blur'#end }],
#end #end
#end #end
}) })
// CrudSchema // CrudSchema
const crudSchemas = reactive<CrudSchema[]>([ const crudSchemas = reactive<CrudSchema[]>([
#foreach($column in $columns) #foreach($column in $columns)
#if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation) #if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation)
#set ($dictType = $column.dictType) #set ($dictType = $column.dictType)
{ {
label: '${column.columnComment}', label: '${column.columnComment}',
field: '${column.javaField}', field: '${column.javaField}',
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
dictType: DICT_TYPE.$dictType.toUpperCase(), dictType: DICT_TYPE.$dictType.toUpperCase(),
#end #end
#if($column.primaryKey) #if($column.primaryKey)
type: 'index', type: 'index',
form: { form: {
show: false show: false
}, },
detail: { detail: {
show: false show: false
}
#else
#if (!$column.createOperation && !$column.updateOperation)
form: {
show: false
},
#elseif(!("" != $column.dictType))
form: {
show: true,
#if ($column.htmlType == "datetime")## 时间框
component: 'DatePicker',
componentProps: {
type: 'datetime',
valueFormat: 'YYYY-MM-DD HH:mm:ss'
} }
#else #elseif($column.htmlType == "editor")## 文本编辑器
#if (!$column.createOperation && !$column.updateOperation) component: 'Editor',
form: { colProps: {
false span: 24
}, },
#elseif(!("" != $column.dictType)) componentProps: {
form: { valueHtml: ''
show: true, }
#if ($column.htmlType == "datetime")## 时间框 #elseif($column.htmlType == "textarea")## 文本框
component: 'DatePicker', component: 'Input',
componentProps: { componentProps: {
type: 'datetime', type: 'textarea',
valueFormat: 'YYYY-MM-DD HH:mm:ss' rows: 4
} },
#elseif($column.htmlType == "editor")## 文本编辑器 colProps: {
component: 'Editor', span: 24
colProps: {
span: 24
},
componentProps: {
valueHtml: ''
}
#elseif($column.htmlType == "textarea")## 文本框
component: 'Input',
componentProps: {
type: 'textarea',
rows: 4
},
colProps: {
span: 24
}
#end
},
#end
#if ($column.listOperationResult)
search: {
#if($column.htmlType == "input")
show: true
#else
#if($column.htmlType == "datetime")
show: true,
component: 'DatePicker',
componentProps: {
type: 'datetimerange',
valueFormat: 'YYYY-MM-DD HH:mm:ss'
}
#elseif($column.htmlType == "select" || $column.htmlType == "radio")
#if ("" == $dictType)## 没有数据字典
show: true,
component: 'Select',
componentProps: {
option: [{'','请选择字典生成'}]
}
#else
show: true
#end
#end
#end
} }
#end
#end #end
}, },
#end #end
#end #if ($column.listOperationResult)
{ search: {
label: t('table.action'), #if($column.htmlType == "input")
field: 'action', show: true
width: '240px', #else
form: { #if($column.htmlType == "datetime")
show: false show: true,
}, component: 'DatePicker',
detail: { componentProps: {
show: false type: 'datetimerange',
} valueFormat: 'YYYY-MM-DD HH:mm:ss'
}
#elseif($column.htmlType == "select" || $column.htmlType == "radio")
#if ("" == $dictType)## 没有数据字典
show: true,
component: 'Select',
componentProps: {
option: [{'','请选择字典生成'}]
}
#else
show: true
#end
#end
#end
} }
#end
#end
},
#end
#end
{
label: t('table.action'),
field: 'action',
width: '240px',
form: {
show: false
},
detail: {
show: false
}
}
]) ])
export const { allSchemas } = useCrudSchemas(crudSchemas) export const { allSchemas } = useCrudSchemas(crudSchemas)

View File

@ -1,92 +1,92 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, unref } from 'vue' import { ref, unref } from 'vue'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { DICT_TYPE } from '@/utils/dict' import { DICT_TYPE } from '@/utils/dict'
import { useTable } from '@/hooks/web/useTable' import { useTable } from '@/hooks/web/useTable'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { FormExpose } from '@/components/Form' import { FormExpose } from '@/components/Form'
import type { ${simpleClassName}VO } from '@/api/${table.moduleName}/${simpleClassName}/types' import type { ${simpleClassName}VO } from '@/api/${table.moduleName}/${simpleClassName}/types'
import { rules, allSchemas } from './${simpleClassName}.data' import { rules, allSchemas } from './${simpleClassName}.data'
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${simpleClassName}' import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${simpleClassName}'
const { t } = useI18n() // 国际化 const { t } = useI18n() // 国际化
// ========== 列表相关 ========== // ========== 列表相关 ==========
const { register, tableObject, methods } = useTable<${simpleClassName}VO>({ const { register, tableObject, methods } = useTable<${simpleClassName}VO>({
getListApi: ${simpleClassName}Api.get${simpleClassName}PageApi, getListApi: ${simpleClassName}Api.get${simpleClassName}PageApi,
delListApi: ${simpleClassName}Api.delete${simpleClassName}Api, delListApi: ${simpleClassName}Api.delete${simpleClassName}Api,
exportListApi: ${simpleClassName}Api.export${simpleClassName}Api exportListApi: ${simpleClassName}Api.export${simpleClassName}Api
}) })
const { getList, setSearchParams, delList, exportList } = methods const { getList, setSearchParams, delList, exportList } = methods
// ========== CRUD 相关 ========== // ========== CRUD 相关 ==========
const actionLoading = ref(false) // 遮罩层 const actionLoading = ref(false) // 遮罩层
const actionType = ref('') // 操作按钮的类型 const actionType = ref('') // 操作按钮的类型
const dialogVisible = ref(false) // 是否显示弹出层 const dialogVisible = ref(false) // 是否显示弹出层
const dialogTitle = ref('edit') // 弹出层标题 const dialogTitle = ref('edit') // 弹出层标题
const formRef = ref<FormExpose>() // 表单 Ref const formRef = ref<FormExpose>() // 表单 Ref
// 设置标题 // 设置标题
const setDialogTile = (type: string) => { const setDialogTile = (type: string) => {
dialogTitle.value = t('action.' + type) dialogTitle.value = t('action.' + type)
actionType.value = type actionType.value = type
dialogVisible.value = true dialogVisible.value = true
} }
// 新增操作 // 新增操作
const handleCreate = () => { const handleCreate = () => {
setDialogTile('create') setDialogTile('create')
// 重置表单 // 重置表单
unref(formRef)?.getElFormRef()?.resetFields() unref(formRef)?.getElFormRef()?.resetFields()
} }
// 修改操作 // 修改操作
const handleUpdate = async (row: ${simpleClassName}VO) => { const handleUpdate = async (row: ${simpleClassName}VO) => {
setDialogTile('update') setDialogTile('update')
// 设置数据 // 设置数据
const res = await ${simpleClassName}Api.get${simpleClassName}Api(row.id) const res = await ${simpleClassName}Api.get${simpleClassName}Api(row.id)
unref(formRef)?.setValues(res) unref(formRef)?.setValues(res)
} }
// 提交按钮 // 提交按钮
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef() const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return if (!elForm) return
elForm.validate(async (valid) => { elForm.validate(async (valid) => {
if (valid) { if (valid) {
actionLoading.value = true actionLoading.value = true
// 提交请求 // 提交请求
try { try {
const data = unref(formRef)?.formModel as ${simpleClassName}VO const data = unref(formRef)?.formModel as ${simpleClassName}VO
if (actionType.value === 'create') { if (actionType.value === 'create') {
await ${simpleClassName}Api.create${simpleClassName}Api(data) await ${simpleClassName}Api.create${simpleClassName}Api(data)
ElMessage.success(t('common.createSuccess')) ElMessage.success(t('common.createSuccess'))
} else { } else {
await ${simpleClassName}Api.update${simpleClassName}Api(data) await ${simpleClassName}Api.update${simpleClassName}Api(data)
ElMessage.success(t('common.updateSuccess')) ElMessage.success(t('common.updateSuccess'))
}
// 操作成功,重新加载列表
dialogVisible.value = false
await getList()
} finally {
actionLoading.value = false
} }
// 操作成功,重新加载列表
dialogVisible.value = false
await getList()
} finally {
actionLoading.value = false
} }
}) }
} })
}
// ========== 详情相关 ========== // ========== 详情相关 ==========
const detailRef = ref() // 详情 Ref const detailRef = ref() // 详情 Ref
// 详情操作 // 详情操作
const handleDetail = async (row: ${simpleClassName}VO) => { const handleDetail = async (row: ${simpleClassName}VO) => {
// 设置数据 // 设置数据
detailRef.value = row detailRef.value = row
setDialogTile('detail') setDialogTile('detail')
} }
// ========== 初始化 ========== // ========== 初始化 ==========
getList() getList()
</script> </script>
<template> <template>
@ -101,63 +101,63 @@
<Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }} <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
</el-button> </el-button>
<el-button <el-button
type="warning" type="warning"
v-hasPermi="['${permissionPrefix}:export']" v-hasPermi="['${permissionPrefix}:export']"
:loading="tableObject.exportLoading" :loading="tableObject.exportLoading"
@click="exportList('数据.xls')" @click="exportList('数据.xls')"
> >
<Icon icon="ep:download" class="mr-5px" /> {{ t('action.export') }} <Icon icon="ep:download" class="mr-5px" /> {{ t('action.export') }}
</el-button> </el-button>
</div> </div>
<!-- 列表 --> <!-- 列表 -->
<Table <Table
:columns="allSchemas.tableColumns" :columns="allSchemas.tableColumns"
:selection="false" :selection="false"
:data="tableObject.tableList" :data="tableObject.tableList"
:loading="tableObject.loading" :loading="tableObject.loading"
:pagination="{ :pagination="{
total: tableObject.total total: tableObject.total
}" }"
v-model:pageSize="tableObject.pageSize" v-model:pageSize="tableObject.pageSize"
v-model:currentPage="tableObject.currentPage" v-model:currentPage="tableObject.currentPage"
@register="register" @register="register"
> >
#foreach($column in $columns) #foreach($column in $columns)
#if ($column.listOperationResult) #if ($column.listOperationResult)
#set ($dictType=$column.dictType) #set ($dictType=$column.dictType)
#if ($column.javaType == "Date")## 时间类型 #if ($column.javaType == "Date")## 时间类型
<template #${column.javaField}="{ row }"> <template #${column.javaField}="{ row }">
<span>{{ dayjs(row.${column.javaField}).format('YYYY-MM-DD HH:mm:ss') }}</span> <span>{{ dayjs(row.${column.javaField}).format('YYYY-MM-DD HH:mm:ss') }}</span>
</template> </template>
#elseif("" != $column.dictType)## 数据字典 #elseif("" != $column.dictType)## 数据字典
<template #${column.javaField}="{ row }"> <template #${column.javaField}="{ row }">
<DictTag :type="DICT_TYPE.$dictType.toUpperCase()" :value="row.${column.javaField}" /> <DictTag :type="DICT_TYPE.$dictType.toUpperCase()" :value="row.${column.javaField}" />
</template> </template>
#end #end
#end #end
#end #end
<template #action="{ row }"> <template #action="{ row }">
<el-button <el-button
link link
type="primary" type="primary"
v-hasPermi="['${permissionPrefix}:update']" v-hasPermi="['${permissionPrefix}:update']"
@click="handleUpdate(row)" @click="handleUpdate(row)"
> >
<Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }} <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
</el-button> </el-button>
<el-button <el-button
link link
type="primary" type="primary"
v-hasPermi="['${permissionPrefix}:update']" v-hasPermi="['${permissionPrefix}:update']"
@click="handleDetail(row)" @click="handleDetail(row)"
> >
<Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }} <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
</el-button> </el-button>
<el-button <el-button
link link
type="primary" type="primary"
v-hasPermi="['${permissionPrefix}:delete']" v-hasPermi="['${permissionPrefix}:delete']"
@click="delList(row.id, false)" @click="delList(row.id, false)"
> >
<Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }} <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
</el-button> </el-button>
@ -168,16 +168,16 @@
<Dialog v-model="dialogVisible" :title="dialogTitle"> <Dialog v-model="dialogVisible" :title="dialogTitle">
<!-- 对话框(添加 / 修改) --> <!-- 对话框(添加 / 修改) -->
<Form <Form
v-if="['create', 'update'].includes(actionType)" v-if="['create', 'update'].includes(actionType)"
:schema="allSchemas.formSchema" :schema="allSchemas.formSchema"
:rules="rules" :rules="rules"
ref="formRef" ref="formRef"
/> />
<!-- 对话框(详情) --> <!-- 对话框(详情) -->
<Descriptions <Descriptions
v-if="actionType === 'detail'" v-if="actionType === 'detail'"
:schema="allSchemas.detailSchema" :schema="allSchemas.detailSchema"
:data="detailRef" :data="detailRef"
> >
#foreach($column in $columns) #foreach($column in $columns)
#if ($column.listOperationResult) #if ($column.listOperationResult)
@ -197,10 +197,10 @@
<!-- 操作按钮 --> <!-- 操作按钮 -->
<template #footer> <template #footer>
<el-button <el-button
v-if="['create', 'update'].includes(actionType)" v-if="['create', 'update'].includes(actionType)"
type="primary" type="primary"
:loading="actionLoading" :loading="actionLoading"
@click="submitForm" @click="submitForm"
> >
{{ t('action.save') }} {{ t('action.save') }}
</el-button> </el-button>

View File

@ -38,15 +38,15 @@ const submitForm = async () => {
if (basicForm && genForm) { 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 genInfoData = (await genInfo?.getFormData()) as CodegenTableVO
const genTable: CodegenUpdateReqVO = {
table: Object.assign({}, basicInfoData, genInfoData),
columns: cloumCurrentRow.value
}
if (parentMenuId.value) { if (parentMenuId.value) {
genInfoData.parentMenuId = parentMenuId.value genInfoData.parentMenuId = parentMenuId.value
} else { } else {
genInfoData.parentMenuId = 0 genInfoData.parentMenuId = 0
} }
const genTable: CodegenUpdateReqVO = {
table: Object.assign({}, basicInfoData, genInfoData),
columns: cloumCurrentRow.value
}
await updateCodegenTableApi(genTable) await updateCodegenTableApi(genTable)
ElMessage.success(t('common.updateSuccess')) ElMessage.success(t('common.updateSuccess'))
push('/infra/codegen') push('/infra/codegen')

View File

@ -150,7 +150,7 @@ defineExpose({
:props="menuProps" :props="menuProps"
:data="menuOptions" :data="menuOptions"
check-strictly check-strictly
@node-click="handleNodeClick" @change="handleNodeClick"
/> />
</template> </template>
</Form> </Form>