增加子表类型生成;表格组件和表单组件,完善泛型支持;

This commit is contained in:
thinkgem
2025-08-13 21:48:55 +08:00
parent b797bb99d0
commit c5bd0bc597
9 changed files with 106 additions and 30 deletions

View File

@@ -23,6 +23,7 @@
<template>vue/vueImport.xml</template>
<childTable>
<template>category-ref:dao</template>
<template>vue/vueApiChild.xml</template>
<template>vue/vueFormChildList.xml</template>
</childTable>
</category>
@@ -33,12 +34,14 @@
<template>vue/vueIndex.xml</template>
<template>vue/vueImport.xml</template>
<childTable>
<template>vue/vueApiChild.xml</template>
<template>vue/vueFormChildList.xml</template>
</childTable>
</category>
<category value="crud_only_vue_modal" label="单表/主子表 (增删改查,弹窗表单) 仅vue ">
<template>category-ref:crud_only_vue</template>
<childTable>
<template>vue/vueApiChild.xml</template>
<template>vue/vueFormChildList.xml</template>
</childTable>
</category>
@@ -49,6 +52,7 @@
<template>vue/vueIndex.xml</template>
<template>vue/vueImport.xml</template>
<childTable>
<template>vue/vueApiChild.xml</template>
<template>vue/vueFormChildList.xml</template>
</childTable>
</category>
@@ -64,6 +68,7 @@
<template>vue/vueSelect.xml</template>
<childTable>
<template>category-ref:dao</template>
<template>vue/vueApiChild.xml</template>
<template>vue/vueFormChildList.xml</template>
</childTable>
</category>
@@ -93,6 +98,7 @@
<template>vue/vueImport.xml</template>
<childTable>
<template>category-ref:dao_cloud</template>
<template>vue/vueApiChild.xml</template>
<template>vue/vueFormChildList.xml</template>
</childTable>
</category>
@@ -108,6 +114,7 @@
<template>vue/vueSelect.xml</template>
<childTable>
<template>category-ref:dao_cloud</template>
<template>vue/vueApiChild.xml</template>
<template>vue/vueFormChildList.xml</template>
</childTable>
</category>

View File

@@ -20,6 +20,10 @@ import { BasicModel, Page, TreeDataModel } from '@jeesite/core/api/model/baseMod
<% }else{ %>
import { BasicModel, Page } from '@jeesite/core/api/model/baseModel';
<% } %>
<% // 生成子表列表字段
for(child in table.childList){ %>
import { ${child.className} } from '@jeesite/${moduleMinus}/api${modulePath}${subModulePath}/${@StringUtils.uncap(child.classNameSimple)}';
<% } %>
<% if(toBoolean(table.optionMap['isImportExport'])){ %>
import { UploadApiResult } from '@jeesite/core/api/sys/upload';
import { UploadFileParams } from '@jeesite/types/axios';
@@ -59,12 +63,12 @@ for(c in table.columnList){
// 父类对象
if(table.parentExists && table.parentTableFkName == c.columnName){
%>
${c.simpleAttrName}?: ${attrType};<% if (isNotBlank(c.comments)){ %> // ${c.comments} 父类<% } %>
${c.simpleAttrName}${c.isRequired == '1' ? '' : '?'}: ${ParentClassName};<% if (isNotBlank(c.comments)){ %> // ${c.comments} 父类<% } %>
<%
// 其它字段
}else{
%>
${c.simpleAttrName}?: ${attrType};<%if(isNotBlank(c.comments)){%> // ${c.comments}<%}%>
${c.simpleAttrName}${c.isRequired == '1' ? '' : '?'}: ${attrType};<%if(isNotBlank(c.comments)){%> // ${c.comments}<%}%>
<%
}
}
@@ -73,7 +77,7 @@ for(c in table.columnList){
%>
<% // 生成子表列表字段
for(child in table.childList){ %>
${@StringUtils.uncap(child.classNameSimple)}List?: any[]; // 子表列表
${@StringUtils.uncap(child.classNameSimple)}List?: ${child.className}[]; // 子表列表
<% } %>
}

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013-Now http://jeesite.com All rights reserved.
No deletion without permission, or be held responsible to law. -->
<template>
<name>vueApi</name>
<filePath>${frontDir}/packages${modulePath}/api${modulePath}${subModulePath}</filePath>
<fileName>${@StringUtils.uncap(table.classNameSimple)}.ts</fileName>
<content><![CDATA[
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law.
* @author ${functionAuthor}
*/
<% if(table.isTreeEntity){ %>
import { TreeModel } from '@jeesite/core/api/model/baseModel';
<% }else{ %>
import { BasicModel } from '@jeesite/core/api/model/baseModel';
<% } %>
import { ${ParentClassName} } from '@jeesite/${moduleMinus}/api${modulePath}${subModulePath}/${funName}';
export interface ${ClassName} extends ${table.isTreeEntity?'Tree':'Basic'}Model<${ClassName}> {
<%
isExtend = false;
// 生成字段属性
for(c in table.columnList){
var attrType = c.simpleAttrType;
if (attrType == 'String') attrType = 'string';
else if (attrType == 'Long') attrType = 'number';
else if (attrType == 'Integer') attrType = 'number';
else if (attrType == 'Double') attrType = 'number';
else if (attrType == 'BigDecimal') attrType = 'number';
else if (attrType == 'Date') attrType = 'string';
else attrType = 'any';
if(!@StringUtils.equalsIgnoreCase(c.columnName, 'id') && !c.isSuperColumn){
// 如果是Extend类属性
if(table.isExtendEntity && c.isExtendColumn){
if(!isExtend){
isExtend = true;
%>
extend?: any; // 扩展字段
<%
}
}
// 如果不是基类属性
else if(!@StringUtils.equalsIgnoreCase(c.columnName, 'id') && !c.isSuperColumn){
// 父类对象
if(table.parentExists && table.parentTableFkName == c.columnName){
%>
${c.simpleAttrName}${c.isRequired == '1' ? '' : '?'}: ${ParentClassName};<% if (isNotBlank(c.comments)){ %> // ${c.comments} 父类<% } %>
<%
// 其它字段
}else{
%>
${c.simpleAttrName}${c.isRequired == '1' ? '' : '?'}: ${attrType};<%if(isNotBlank(c.comments)){%> // ${c.comments}<%}%>
<%
}
}
}
}
%>
}
<% %>
]]>
</content>
</template>

View File

@@ -117,7 +117,7 @@
value: record.value.isNewRecord ? t('新增${functionNameSimple}') : t('编辑${functionNameSimple}'),
}));
const inputFormSchemas: FormSchema[] = [
const inputFormSchemas: FormSchema<${ClassName}>[] = [
<% if(table.isTreeEntity){ %>
{
label: t('上级${functionNameSimple}'),
@@ -428,7 +428,7 @@ for (c in table.columnList){
}
}
%>
const [registerForm, { resetFields, setFieldsValue<% if(updateSchemas.~size > 0){ %>, updateSchema<% } %>, validate }] = useForm({
const [registerForm, { resetFields, setFieldsValue<% if(updateSchemas.~size > 0){ %>, updateSchema<% } %>, validate }] = useForm<${ClassName}>({
labelWidth: 120,
schemas: inputFormSchemas,
<% var formColNum = table.optionMap['formColNum']; %>
@@ -447,7 +447,7 @@ for (c in table.columnList){
record.value.parentName = data.parentName;
}
<% } %>
setFieldsValue(record.value);
await setFieldsValue(record.value);
<% for (child in table.childList){ %>
form${@StringUtils.cap(child.classNameSimple)}ListRef.value?.setTableData(record.value);
<% } %>

View File

@@ -27,6 +27,7 @@
import { Icon } from '@jeesite/core/components/Icon';
import { BasicTable, BasicColumn, useTable } from '@jeesite/core/components/Table';
import { ${ParentClassName} } from '@jeesite/${moduleMinus}/api${modulePath}${subModulePath}/${parentClassName}';
import { ${ClassName} } from '@jeesite/${moduleMinus}/api${modulePath}${subModulePath}/${className}';
<%
var userselectExists = false;
var officeselectExists = false;
@@ -59,7 +60,7 @@
const { t } = useI18n('${moduleName}${subModuleNameDot}.${funName}');
const record = ref<${ParentClassName}>({} as ${ParentClassName});
const tableColumns: BasicColumn[] = [
const tableColumns: BasicColumn<${ClassName}>[] = [
<%
for (c in table.columnList){
if (c.isEdit != '1' || c.isPk == '1'){
@@ -166,11 +167,11 @@ for (c in table.columnList){
<% } %>
];
const [registerTable, tableAction] = useTable({
const [registerTable, tableAction] = useTable<${ClassName}>({
columns: tableColumns,
actionColumn: {
width: 60,
actions: (record: Recordable) => [
actions: (record: ${ClassName}) => [
{
icon: 'i-ant-design:delete-outlined',
color: 'error',

View File

@@ -136,7 +136,7 @@ for(c in table.columnList){
setTitle(record.value.isNewRecord ? t('新增${functionNameSimple}') : t('编辑${functionNameSimple}'));
};
const inputFormSchemas: FormSchema[] = [
const inputFormSchemas: FormSchema<${ClassName}>[] = [
<% if(table.isTreeEntity){ %>
{
label: t('上级${functionNameSimple}'),
@@ -368,7 +368,7 @@ for (c in table.columnList){
<%
for (child in table.childList){ %>
const input${child.className}FormSchemas: FormSchema[] = [
const input${child.className}FormSchemas: FormSchema<${ClassName}>[] = [
{
field: '${@StringUtils.uncap(child.classNameSimple)}List',
component: 'Input',
@@ -381,7 +381,7 @@ for (c in table.columnList){
if(false && toBoolean(table.optionMap['isBpmForm'])){
%>
const inputBpmFormSchemas: FormSchema[] = [
const inputBpmFormSchemas: FormSchema<${ClassName}>[] = [
{
label: t('审批意见'),
field: 'bpm.comment',
@@ -459,7 +459,7 @@ for (c in table.columnList){
}
}
%>
const [registerForm, formAction] = useForm({
const [registerForm, formAction] = useForm<${ClassName}>({
labelWidth: 120,
schemas: inputFormSchemas,
<% var formColNum = table.optionMap['formColNum']; %>
@@ -467,16 +467,16 @@ for (c in table.columnList){
});
<% for (child in table.childList){ %>
const [register${child.className}Form, ${@StringUtils.uncap(child.className)}Form] = useForm({
const [register${child.className}Form, ${@StringUtils.uncap(child.className)}Form] = useForm<${ClassName}>({
labelWidth: 120,
schemas: input${child.className}FormSchemas,
baseColProps: { md: 24, lg: 24 },
});
const [register${child.className}Table, ${@StringUtils.uncap(child.classNameSimple)}Table] = useTable({
const [register${child.className}Table, ${@StringUtils.uncap(child.classNameSimple)}Table] = useTable<${ClassName}>({
actionColumn: {
width: 60,
actions: (record: Recordable) => [
actions: (record: ${ClassName}) => [
{
icon: 'i-ant-design:delete-outlined',
color: 'error',
@@ -687,7 +687,7 @@ for (c in table.columnList){
record.value.parentName = data.parentName;
}
<% } %>
setFieldsValue(record.value);
await setFieldsValue(record.value);
<% for (child in table.childList){ %>
set${child.className}TableData(res);
<% } %>

View File

@@ -22,12 +22,7 @@
:minHeight="120"
:width="400"
>
<Upload
accept=".xls,.xlsx"
:file-list="fileList"
:before-upload="beforeUpload"
@remove="handleRemove"
>
<Upload accept=".xls,.xlsx" :file-list="fileList" :before-upload="beforeUpload" @remove="handleRemove">
<a-button> <Icon icon="ant-design:upload-outlined" /> {{ t('选择文件') }} </a-button>
<span class="ml-4">{{ uploadInfo }}</span>
</Upload>

View File

@@ -193,7 +193,7 @@ if(table.isTreeEntity){
const loading = ref(false);
<% } %>
const searchForm: FormProps = {
const searchForm: FormProps<${ClassName}> = {
baseColProps: { md: 8, lg: 6 },
labelWidth: 90,
schemas: [
@@ -287,7 +287,7 @@ if(table.isTreeEntity){
<% } %>
};
const tableColumns: BasicColumn[] = [
const tableColumns: BasicColumn<${ClassName}>[] = [
<%
var firstColumn = true;
// 生成树表的节点列
@@ -357,9 +357,9 @@ for(c in table.columnList){
%>
];
const actionColumn: BasicColumn = {
const actionColumn: BasicColumn<${ClassName}> = {
width: 160,
actions: (record: Recordable) => [
actions: (record: ${ClassName}) => [
{
icon: 'i-clarity:note-edit-line',
title: t('编辑${functionNameSimple}'),
@@ -427,7 +427,7 @@ for(c in table.columnList){
],
};
const [registerTable, { reload<% if(table.isTreeEntity){ %>, expandAll, collapseAll, expandCollapse<% } %>, getForm }] = useTable({
const [registerTable, { reload<% if(table.isTreeEntity){ %>, expandAll, collapseAll, expandCollapse<% } %>, getForm }] = useTable<${ClassName}>({
api: ${className}ListData,
beforeFetch: (params) => {
<% if(table.isTreeEntity){ %>
@@ -466,7 +466,11 @@ for(c in table.columnList){
if (!isEmpty(props.treeCodes)) {
<% if (isNotBlank(table.optionMap['leftTreeRightTableFk'])) { %>
await getForm().setFieldsValue({
<% if (@StringUtils.contains(table.optionMap['leftTreeRightTableFk'], '.')) { %>
'${table.optionMap['leftTreeRightTableFk']}': props.treeCodes[0],
<% } else { %>
${table.optionMap['leftTreeRightTableFk']}: props.treeCodes[0],
<% } %>
});
<% } %>
await reload();

View File

@@ -44,7 +44,7 @@ const modalProps = {
title: t('${functionNameSimple}选择'),
};
const searchForm: FormProps = {
const searchForm: FormProps<${ClassName}> = {
baseColProps: { md: 8, lg: 6 },
labelWidth: 90,
schemas: [
@@ -130,7 +130,7 @@ const searchForm: FormProps = {
],
};
const tableColumns: BasicColumn[] = [
const tableColumns: BasicColumn<${ClassName}>[] = [
<%
var firstColumn = true;
// 生成树表的节点列