【代码优化】代码生成: vue3_vben5_antd schema 主子表模版优化
This commit is contained in:
parent
da248cd126
commit
f3aa501e94
|
@ -4,6 +4,26 @@ import { requestClient } from '#/api/request';
|
|||
#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}")
|
||||
|
||||
export namespace ${simpleClassName}Api {
|
||||
## 特殊:主子表专属逻辑
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#set ($subColumns = $subColumnsList.get($index))##当前字段数组
|
||||
/** ${subTable.classComment}信息 */
|
||||
export interface ${subSimpleClassName} {
|
||||
#foreach ($column in $subColumns)
|
||||
#if ($column.createOperation || $column.updateOperation)
|
||||
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal")
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment}
|
||||
#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime")
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: Date; // ${column.columnComment}
|
||||
#else
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: ${column.javaType.toLowerCase()}; // ${column.columnComment}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
#end
|
||||
/** ${table.classComment}信息 */
|
||||
export interface ${simpleClassName} {
|
||||
#foreach ($column in $columns)
|
||||
|
@ -33,26 +53,6 @@ export namespace ${simpleClassName}Api {
|
|||
#end
|
||||
#end
|
||||
}
|
||||
## 特殊:主子表专属逻辑
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#set ($subColumns = $subColumnsList.get($index))##当前字段数组
|
||||
/** ${subTable.classComment}信息 */
|
||||
export interface ${subSimpleClassName} {
|
||||
#foreach ($column in $subColumns)
|
||||
#if ($column.createOperation || $column.updateOperation)
|
||||
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal")
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment}
|
||||
#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime")
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: Date; // ${column.columnComment}
|
||||
#else
|
||||
${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: ${column.javaType.toLowerCase()}; // ${column.columnComment}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
#if ( $table.templateType != 2 )
|
||||
|
|
|
@ -167,13 +167,13 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||
{
|
||||
fieldName: '${javaField}',
|
||||
label: '${comment}',
|
||||
#if ($column.htmlType == "input")
|
||||
#if ($column.htmlType == "input" || $column.htmlType == "textarea" || $column.htmlType == "editor")
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
placeholder: '请输入${comment}',
|
||||
},
|
||||
#elseif ($column.htmlType == "select")
|
||||
#elseif ($column.htmlType == "select" || $column.htmlType == "radio")
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
|
@ -184,16 +184,6 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||
#end
|
||||
placeholder: '请选择${comment}',
|
||||
},
|
||||
#elseif ($column.htmlType == "radio")
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
|
||||
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
||||
#else## 未设置 dictType 数据字典的情况
|
||||
options: [],
|
||||
#end
|
||||
},
|
||||
#elseif($column.htmlType == "datetime")
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
|
@ -400,7 +390,7 @@ export function use${subSimpleClassName}FormSchema(): VbenFormSchema[] {
|
|||
/** 列表的字段 */
|
||||
export function use${subSimpleClassName}GridColumns(
|
||||
onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>,
|
||||
): VxeTableGridOptions<${subSimpleClassName}Api.${subSimpleClassName}>['columns'] {
|
||||
): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] {
|
||||
return [
|
||||
#foreach($column in $subColumns)
|
||||
#if ($column.listOperationResult)
|
||||
|
@ -471,37 +461,39 @@ export function use${subSimpleClassName}GridColumns(
|
|||
/** 列表的字段 */
|
||||
export function use${subSimpleClassName}GridColumns(
|
||||
onActionClick?: OnActionClickFn<${simpleClassName}Api.${subSimpleClassName}>,
|
||||
): VxeTableGridOptions<${subSimpleClassName}Api.${subSimpleClassName}>['columns'] {
|
||||
): VxeTableGridOptions<${simpleClassName}Api.${subSimpleClassName}>['columns'] {
|
||||
return [
|
||||
#foreach($column in $subColumns)
|
||||
#if (!$column.primaryKey && $column.listOperationResult && $column.id != $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||
#set ($dictType = $column.dictType)
|
||||
#set ($javaField = $column.javaField)
|
||||
#set ($comment = $column.columnComment)
|
||||
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||
#set ($dictMethod = "number")
|
||||
#elseif ($javaType == "String")
|
||||
#set ($dictMethod = "string")
|
||||
#elseif ($javaType == "Boolean")
|
||||
#set ($dictMethod = "boolean")
|
||||
#end
|
||||
{
|
||||
field: '${javaField}',
|
||||
title: '${comment}',
|
||||
minWidth: 120,
|
||||
slots: { default: '${javaField}' },
|
||||
#if ($column.htmlType == "select" || $column.htmlType == "checkbox" || $column.htmlType == "radio")
|
||||
#if ("" != $dictType)## 有数据字典
|
||||
params: {
|
||||
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
||||
},
|
||||
#else
|
||||
params: {
|
||||
options: [],
|
||||
#if ($column.createOperation || $column.updateOperation)
|
||||
#if (!$column.primaryKey && $column.listOperationResult && $column.id != $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||
#set ($dictType = $column.dictType)
|
||||
#set ($javaField = $column.javaField)
|
||||
#set ($comment = $column.columnComment)
|
||||
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
|
||||
#set ($dictMethod = "number")
|
||||
#elseif ($javaType == "String")
|
||||
#set ($dictMethod = "string")
|
||||
#elseif ($javaType == "Boolean")
|
||||
#set ($dictMethod = "boolean")
|
||||
#end
|
||||
{
|
||||
field: '${javaField}',
|
||||
title: '${comment}',
|
||||
minWidth: 120,
|
||||
slots: { default: '${javaField}' },
|
||||
#if ($column.htmlType == "select" || $column.htmlType == "checkbox" || $column.htmlType == "radio")
|
||||
#if ("" != $dictType)## 有数据字典
|
||||
params: {
|
||||
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
|
||||
},
|
||||
#else
|
||||
params: {
|
||||
options: [],
|
||||
},
|
||||
#end
|
||||
#end
|
||||
},
|
||||
#end
|
||||
#end
|
||||
},
|
||||
#end
|
||||
#end
|
||||
{
|
||||
|
|
|
@ -57,8 +57,7 @@ const subTabsName = ref('$subClassNameVars.get(0)')
|
|||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||
#if ($subTable.subJoinMany) ## 一对多
|
||||
/** {$subTable.classComment}表格配置 */
|
||||
const [${subSimpleClassName}Grid, {$subClassNameVar}GridApi] = useVbenVxeGrid({
|
||||
const [${subSimpleClassName}Grid, ${subClassNameVar}GridApi] = useVbenVxeGrid({
|
||||
gridOptions: {
|
||||
columns: use${subSimpleClassName}GridColumns(),
|
||||
border: true,
|
||||
|
@ -77,9 +76,9 @@ const [${subSimpleClassName}Grid, {$subClassNameVar}GridApi] = useVbenVxeGrid({
|
|||
},
|
||||
});
|
||||
#else
|
||||
const [${subSimpleClassName}Form, {$subClassNameVar}FormApi] = useVbenForm({
|
||||
const [${subSimpleClassName}Form, ${subClassNameVar}FormApi] = useVbenForm({
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
schema: use${subSimpleClassName}FormSchema(),
|
||||
showDefaultActions: false
|
||||
});
|
||||
#end
|
||||
|
@ -107,12 +106,15 @@ const [Modal, modalApi] = useVbenModal({
|
|||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||
try {
|
||||
await ${subClassNameVar}FormRef.value.validate()
|
||||
} catch (e) {
|
||||
subTabsName.value = '${subClassNameVar}'
|
||||
return
|
||||
}
|
||||
#if ($subTable.subJoinMany) ## 一对多
|
||||
|
||||
#else
|
||||
const { valid: ${subClassNameVar}Valid } = await ${subClassNameVar}FormApi.validate();
|
||||
if (!${subClassNameVar}Valid) {
|
||||
subTabsName.value = '${subClassNameVar}';
|
||||
return;
|
||||
}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
@ -126,7 +128,11 @@ const [Modal, modalApi] = useVbenModal({
|
|||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||
data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = ${subClassNameVar}FormRef.value.getData()
|
||||
#if ($subTable.subJoinMany)
|
||||
data.${subClassNameVar}s = ${subClassNameVar}GridApi.grid.getData();
|
||||
#else
|
||||
data.${subClassNameVar} = await ${subClassNameVar}FormApi.getValues();
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
@ -238,7 +244,7 @@ const [Modal, modalApi] = useVbenModal({
|
|||
#end
|
||||
#end
|
||||
#end
|
||||
</Grid>
|
||||
</${subSimpleClassName}Grid>
|
||||
#else
|
||||
<${subSimpleClassName}Form class="mx-4" />
|
||||
#end
|
||||
|
|
|
@ -134,12 +134,11 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
|||
},
|
||||
#else## 标准表数据加载
|
||||
query: async ({ page }, formValues) => {
|
||||
const { items, total } = await get${simpleClassName}Page({
|
||||
return await get${simpleClassName}Page({
|
||||
pageNo: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
return { items, total };
|
||||
},
|
||||
#end
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue