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