mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-16 05:13:41 +00:00
v3.0.0 init
This commit is contained in:
@@ -3,8 +3,8 @@ gen:
|
||||
# 作者
|
||||
author: ageerle
|
||||
# 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
|
||||
packageName: org.ruoyi.aihuman
|
||||
packageName: org.ruoyi.system
|
||||
# 自动去除表前缀,默认是false
|
||||
autoRemovePre: false
|
||||
# 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
|
||||
tablePrefix: aihuman_
|
||||
tablePrefix: sys_
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.ruoyi.generator.mapper.GenTableColumnMapper">
|
||||
|
||||
<resultMap type="org.ruoyi.generator.domain.GenTableColumn" id="GenTableColumnResult">
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.ruoyi.generator.mapper.GenTableMapper">
|
||||
|
||||
<!-- 多结构嵌套自动映射需带上每个实体的主键id 否则映射会失败 -->
|
||||
<resultMap type="org.ruoyi.generator.domain.GenTable" id="GenTableResult">
|
||||
<id property="tableId" column="table_id" />
|
||||
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="org.ruoyi.generator.domain.GenTableColumn" id="GenTableColumnResult">
|
||||
<id property="columnId" column="column_id"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="genSelect">
|
||||
SELECT t.table_id, t.data_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
|
||||
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
||||
FROM gen_table t
|
||||
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
||||
</sql>
|
||||
|
||||
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
|
||||
<include refid="genSelect"/>
|
||||
where t.table_id = #{tableId} order by c.sort
|
||||
</select>
|
||||
|
||||
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
|
||||
<include refid="genSelect"/>
|
||||
where t.table_name = #{tableName} order by c.sort
|
||||
</select>
|
||||
|
||||
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
|
||||
<include refid="genSelect"/>
|
||||
order by c.sort
|
||||
</select>
|
||||
|
||||
<select id="selectTableNameList" resultType="java.lang.String">
|
||||
select table_name from gen_table where data_name = #{dataName,jdbcType=VARCHAR}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,3 @@
|
||||
java包使用 `.` 分割 resource 目录使用 `/` 分割
|
||||
<br>
|
||||
此文件目的 防止文件夹粘连找不到 `xml` 文件
|
||||
@@ -1,17 +1,13 @@
|
||||
package ${packageName}.domain.bo;
|
||||
|
||||
import ${packageName}.domain.${ClassName};
|
||||
import org.ruoyi.core.domain.BaseEntity;
|
||||
import org.ruoyi.common.mybatis.core.domain.BaseEntity;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import jakarta.validation.constraints.*;
|
||||
#foreach ($import in $importList)
|
||||
import ${import};
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
#end
|
||||
|
||||
/**
|
||||
@@ -21,34 +17,32 @@ import org.ruoyi.common.core.validate.EditGroup;
|
||||
* @date ${datetime}
|
||||
*/
|
||||
@Data
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = ${ClassName}.class, reverseConvertGenerate = false)
|
||||
public class ${ClassName}Bo implements Serializable {
|
||||
public class ${ClassName}Bo extends BaseEntity {
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if($column.isPk)
|
||||
private $column.javaType $column.javaField;
|
||||
#foreach ($column in $columns)
|
||||
#if(!$table.isSuperColumn($column.javaField) && ($column.query || $column.insert || $column.edit))
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#if($column.insert && $column.edit)
|
||||
#set($Group="AddGroup.class, EditGroup.class")
|
||||
#elseif($column.insert)
|
||||
#set($Group="AddGroup.class")
|
||||
#elseif($column.edit)
|
||||
#set($Group="EditGroup.class")
|
||||
#end
|
||||
#if($column.required)
|
||||
#if($column.javaType == 'String')
|
||||
@NotBlank(message = "$column.columnComment不能为空", groups = { $Group })
|
||||
#else
|
||||
@NotNull(message = "$column.columnComment不能为空", groups = { $Group })
|
||||
#end
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
#elseif($column.insert || $column.edit)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#if($column.insert && $column.edit)
|
||||
#set($Group="AddGroup.class, EditGroup.class")
|
||||
#elseif($column.insert)
|
||||
#set($Group="AddGroup.class")
|
||||
#elseif($column.edit)
|
||||
#set($Group="EditGroup.class")
|
||||
#end
|
||||
#if($column.required)
|
||||
#if($column.javaType == 'String')
|
||||
@NotBlank(message = "$column.columnComment不能为空", groups = { $Group })
|
||||
#else
|
||||
@NotNull(message = "$column.columnComment不能为空", groups = { $Group })
|
||||
#end
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.ruoyi.common.idempotent.annotation.RepeatSubmit;
|
||||
import org.ruoyi.common.log.annotation.Log;
|
||||
import org.ruoyi.common.web.core.BaseController;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.common.mybatis.core.page.PageQuery;
|
||||
import org.ruoyi.common.core.domain.R;
|
||||
import org.ruoyi.common.core.validate.AddGroup;
|
||||
import org.ruoyi.common.core.validate.EditGroup;
|
||||
@@ -19,9 +19,9 @@ import org.ruoyi.common.log.enums.BusinessType;
|
||||
import org.ruoyi.common.excel.utils.ExcelUtil;
|
||||
import ${packageName}.domain.vo.${ClassName}Vo;
|
||||
import ${packageName}.domain.bo.${ClassName}Bo;
|
||||
import ${packageName}.service.${ClassName}Service;
|
||||
#if($table.crud || $table.sub)
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import ${packageName}.service.I${ClassName}Service;
|
||||
#if($table.crud)
|
||||
import org.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||
#elseif($table.tree)
|
||||
#end
|
||||
|
||||
@@ -37,23 +37,23 @@ import org.ruoyi.core.page.TableDataInfo;
|
||||
@RequestMapping("/${moduleName}/${businessName}")
|
||||
public class ${ClassName}Controller extends BaseController {
|
||||
|
||||
private final ${ClassName}Service ${className}Service;
|
||||
private final I${ClassName}Service ${className}Service;
|
||||
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
*/
|
||||
@SaCheckPermission("${permissionPrefix}:list")
|
||||
@GetMapping("/list")
|
||||
#if($table.crud || $table.sub)
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
*/
|
||||
@SaCheckPermission("${permissionPrefix}:list")
|
||||
@GetMapping("/list")
|
||||
#if($table.crud)
|
||||
public TableDataInfo<${ClassName}Vo> list(${ClassName}Bo bo, PageQuery pageQuery) {
|
||||
return ${className}Service.queryPageList(bo, pageQuery);
|
||||
}
|
||||
#elseif($table.tree)
|
||||
public R<List<${ClassName}Vo>> list(${ClassName}Bo bo) {
|
||||
List<${ClassName}Vo> list = ${className}Service.queryList(bo);
|
||||
return R.ok(list);
|
||||
}
|
||||
#end
|
||||
#elseif($table.tree)
|
||||
public R<List<${ClassName}Vo>> list(${ClassName}Bo bo) {
|
||||
List<${ClassName}Vo> list = ${className}Service.queryList(bo);
|
||||
return R.ok(list);
|
||||
}
|
||||
#end
|
||||
|
||||
/**
|
||||
* 导出${functionName}列表
|
||||
|
||||
@@ -1,39 +1,59 @@
|
||||
package ${packageName}.domain;
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if($column.javaField=='tenantId')
|
||||
#set($IsTenant=1)
|
||||
#end
|
||||
#end
|
||||
#if($IsTenant==1)
|
||||
import org.ruoyi.common.tenant.core.TenantEntity;
|
||||
#else
|
||||
#end
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
#foreach ($import in $importList)
|
||||
import ${import};
|
||||
#end
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* ${functionName}对象 ${tableName}
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
#if($IsTenant==1)
|
||||
#set($Entity="TenantEntity")
|
||||
#else
|
||||
#set($Entity="BaseEntity")
|
||||
#end
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("${tableName}")
|
||||
public class ${ClassName} implements Serializable{
|
||||
public class ${ClassName} extends ${Entity} {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if(!$table.isSuperColumn($column.javaField))
|
||||
#if(!$table.isSuperColumn($column.javaField))
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#if($column.javaField=='delFlag')
|
||||
@TableLogic
|
||||
#end
|
||||
#if($column.javaField=='version')
|
||||
@Version
|
||||
#end
|
||||
#if($column.isPk==1)
|
||||
@TableId(value = "${column.columnName}", type = IdType.AUTO)
|
||||
#end
|
||||
#if($column.javaField=='delFlag')
|
||||
@TableLogic
|
||||
#end
|
||||
#if($column.javaField=='version')
|
||||
@Version
|
||||
#end
|
||||
#if($column.isPk==1)
|
||||
@TableId(value = "$column.columnName")
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ package ${packageName}.mapper;
|
||||
|
||||
import ${packageName}.domain.${ClassName};
|
||||
import ${packageName}.domain.vo.${ClassName}Vo;
|
||||
import org.ruoyi.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.ruoyi.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
|
||||
/**
|
||||
* ${functionName}Mapper接口
|
||||
@@ -11,7 +10,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${ClassName}Mapper extends BaseMapperPlus<${ClassName}, ${ClassName}Vo> {
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package ${packageName}.service;
|
||||
|
||||
import ${packageName}.domain.vo.${ClassName}Vo;
|
||||
import ${packageName}.domain.bo.${ClassName}Bo;
|
||||
#if($table.crud || $table.sub)
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
#end
|
||||
#if($table.crud)
|
||||
import org.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||
import org.ruoyi.common.mybatis.core.page.PageQuery;
|
||||
#end
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -16,37 +16,57 @@ import java.util.List;
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
public interface ${ClassName}Service {
|
||||
public interface I${ClassName}Service {
|
||||
|
||||
/**
|
||||
* 查询${functionName}
|
||||
*
|
||||
* @param ${pkColumn.javaField} 主键
|
||||
* @return ${functionName}
|
||||
*/
|
||||
${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField});
|
||||
${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField});
|
||||
|
||||
#if($table.crud || $table.sub)
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
*/
|
||||
TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery);
|
||||
#end
|
||||
#if($table.crud)
|
||||
/**
|
||||
* 分页查询${functionName}列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param pageQuery 分页参数
|
||||
* @return ${functionName}分页列表
|
||||
*/
|
||||
TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery);
|
||||
#end
|
||||
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
* 查询符合条件的${functionName}列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return ${functionName}列表
|
||||
*/
|
||||
List<${ClassName}Vo> queryList(${ClassName}Bo bo);
|
||||
|
||||
/**
|
||||
* 新增${functionName}
|
||||
*
|
||||
* @param bo ${functionName}
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
Boolean insertByBo(${ClassName}Bo bo);
|
||||
|
||||
/**
|
||||
* 修改${functionName}
|
||||
*
|
||||
* @param bo ${functionName}
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
Boolean updateByBo(${ClassName}Bo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除${functionName}信息
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package ${packageName}.service.impl;
|
||||
|
||||
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||
#if($table.crud || $table.sub)
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
#end
|
||||
#if($table.crud)
|
||||
import org.ruoyi.common.mybatis.core.page.TableDataInfo;
|
||||
import org.ruoyi.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
#end
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ${packageName}.domain.bo.${ClassName}Bo;
|
||||
import ${packageName}.domain.vo.${ClassName}Vo;
|
||||
import ${packageName}.domain.${ClassName};
|
||||
import ${packageName}.mapper.${ClassName}Mapper;
|
||||
import ${packageName}.service.${ClassName}Service;
|
||||
import org.ruoyi.common.core.utils.StringUtils;
|
||||
import ${packageName}.service.I${ClassName}Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -27,34 +27,45 @@ import java.util.Collection;
|
||||
* @author ${author}
|
||||
* @date ${datetime}
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||
public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
|
||||
private final ${ClassName}Mapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询${functionName}
|
||||
*
|
||||
* @param ${pkColumn.javaField} 主键
|
||||
* @return ${functionName}
|
||||
*/
|
||||
@Override
|
||||
public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}) {
|
||||
public ${ClassName}Vo queryById(${pkColumn.javaType} ${pkColumn.javaField}){
|
||||
return baseMapper.selectVoById(${pkColumn.javaField});
|
||||
}
|
||||
|
||||
#if($table.crud || $table.sub)
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<${ClassName}> lqw = buildQueryWrapper(bo);
|
||||
Page<${ClassName}Vo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
#end
|
||||
#if($table.crud)
|
||||
/**
|
||||
* 分页查询${functionName}列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @param pageQuery 分页参数
|
||||
* @return ${functionName}分页列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<${ClassName}Vo> queryPageList(${ClassName}Bo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<${ClassName}> lqw = buildQueryWrapper(bo);
|
||||
Page<${ClassName}Vo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
#end
|
||||
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
* 查询符合条件的${functionName}列表
|
||||
*
|
||||
* @param bo 查询条件
|
||||
* @return ${functionName}列表
|
||||
*/
|
||||
@Override
|
||||
public List<${ClassName}Vo> queryList(${ClassName}Bo bo) {
|
||||
@@ -63,40 +74,48 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<${ClassName}> buildQueryWrapper(${ClassName}Bo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<${ClassName}> lqw = Wrappers.lambdaQuery();
|
||||
#foreach($column in $columns)
|
||||
#if($column.query)
|
||||
#set($queryType=$column.queryType)
|
||||
#set($javaField=$column.javaField)
|
||||
#set($javaType=$column.javaType)
|
||||
#set($columnName=$column.columnName)
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
#set($mpMethod=$column.queryType.toLowerCase())
|
||||
#if($queryType != 'BETWEEN')
|
||||
#if($javaType == 'String')
|
||||
#set($condition='StringUtils.isNotBlank(bo.get'+$AttrName+'())')
|
||||
#else
|
||||
#set($condition='bo.get'+$AttrName+'() != null')
|
||||
#end
|
||||
lqw.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName());
|
||||
#else
|
||||
lqw.between(params.get("begin$AttrName") != null && params.get("end$AttrName") != null,
|
||||
${ClassName}::get$AttrName , params.get("begin$AttrName"), params.get("end$AttrName"));
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#foreach($column in $columns)
|
||||
#if($column.query)
|
||||
#set($queryType=$column.queryType)
|
||||
#set($javaField=$column.javaField)
|
||||
#set($javaType=$column.javaType)
|
||||
#set($columnName=$column.columnName)
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
#set($mpMethod=$column.queryType.toLowerCase())
|
||||
#if($queryType != 'BETWEEN')
|
||||
#if($javaType == 'String')
|
||||
#set($condition='StringUtils.isNotBlank(bo.get'+$AttrName+'())')
|
||||
#else
|
||||
#set($condition='bo.get'+$AttrName+'() != null')
|
||||
#end
|
||||
lqw.$mpMethod($condition, ${ClassName}::get$AttrName, bo.get$AttrName());
|
||||
#else
|
||||
lqw.between(params.get("begin$AttrName") != null && params.get("end$AttrName") != null,
|
||||
${ClassName}::get$AttrName ,params.get("begin$AttrName"), params.get("end$AttrName"));
|
||||
#end
|
||||
#end
|
||||
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||
#if($column.isPk==1)
|
||||
lqw.orderByAsc(${ClassName}::get$AttrName);
|
||||
#end
|
||||
#end
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增${functionName}
|
||||
*
|
||||
* @param bo ${functionName}
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(${ClassName}Bo bo) {
|
||||
${ClassName} add = MapstructUtils.convert(bo, ${ClassName}. class);
|
||||
${ClassName} add = MapstructUtils.convert(bo, ${ClassName}.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
#set($pk=$pkColumn.javaField.substring(0,1).toUpperCase() + ${pkColumn.javaField.substring(1)})
|
||||
#set($pk=$pkColumn.javaField.substring(0,1).toUpperCase() + ${pkColumn.javaField.substring(1)})
|
||||
if (flag) {
|
||||
bo.set$pk(add.get$pk());
|
||||
}
|
||||
@@ -105,10 +124,13 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||
|
||||
/**
|
||||
* 修改${functionName}
|
||||
*
|
||||
* @param bo ${functionName}
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(${ClassName}Bo bo) {
|
||||
${ClassName} update = MapstructUtils.convert(bo, ${ClassName}. class);
|
||||
${ClassName} update = MapstructUtils.convert(bo, ${ClassName}.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
@@ -116,18 +138,22 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(${ClassName} entity) {
|
||||
private void validEntityBeforeSave(${ClassName} entity){
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除${functionName}
|
||||
* 校验并批量删除${functionName}信息
|
||||
*
|
||||
* @param ids 待删除的主键集合
|
||||
* @param isValid 是否进行有效性校验
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<${pkColumn.javaType}> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
if(isValid){
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
return baseMapper.deleteByIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
package ${packageName}.domain.vo;
|
||||
|
||||
#foreach ($import in $importList)
|
||||
import ${import};
|
||||
#end
|
||||
#foreach ($import in $importList)
|
||||
import ${import};
|
||||
#end
|
||||
import ${packageName}.domain.${ClassName};
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import org.ruoyi.common.excel.annotation.ExcelDictFormat;
|
||||
import org.ruoyi.common.excel.convert.ExcelDictConvert;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ${functionName}视图对象 ${tableName}
|
||||
*
|
||||
@@ -23,30 +28,39 @@ import java.util.Date;
|
||||
@AutoMapper(target = ${ClassName}.class)
|
||||
public class ${ClassName}Vo implements Serializable {
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if($column.isPk)
|
||||
private $column.javaType $column.javaField;
|
||||
#elseif($column.list)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#if(${column.dictType} && ${column.dictType} != '')
|
||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "${column.dictType}")
|
||||
#elseif($parentheseIndex != -1)
|
||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
|
||||
#else
|
||||
@ExcelProperty(value = "${comment}")
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
#end
|
||||
#end
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if($column.list)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#if(${column.dictType} && ${column.dictType} != '')
|
||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "${column.dictType}")
|
||||
#elseif($parentheseIndex != -1)
|
||||
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
|
||||
#else
|
||||
@ExcelProperty(value = "${comment}")
|
||||
#end
|
||||
private $column.javaType $column.javaField;
|
||||
|
||||
#if($column.htmlType == "imageUpload")
|
||||
/**
|
||||
* ${column.columnComment}Url
|
||||
*/
|
||||
@Translation(type = TransConstant.OSS_ID_TO_URL, mapper = "${column.javaField}")
|
||||
private String ${column.javaField}Url;
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import request from '@/utils/request';
|
||||
import { AxiosPromise } from 'axios';
|
||||
import { ${BusinessName}VO, ${BusinessName}Form, ${BusinessName}Query } from '@/api/${moduleName}/${businessName}/types';
|
||||
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
* @param query
|
||||
* @returns {*}
|
||||
*/
|
||||
|
||||
export const list${BusinessName} = (query?: ${BusinessName}Query): AxiosPromise<${BusinessName}VO[]> => {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询${functionName}详细
|
||||
* @param ${pkColumn.javaField}
|
||||
*/
|
||||
export const get${BusinessName} = (${pkColumn.javaField}: string | number): AxiosPromise<${BusinessName}VO> => {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
|
||||
method: 'get'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 新增${functionName}
|
||||
* @param data
|
||||
*/
|
||||
export const add${BusinessName} = (data: ${BusinessName}Form) => {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}',
|
||||
method: 'post',
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改${functionName}
|
||||
* @param data
|
||||
*/
|
||||
export const update${BusinessName} = (data: ${BusinessName}Form) => {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}',
|
||||
method: 'put',
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除${functionName}
|
||||
* @param ${pkColumn.javaField}
|
||||
*/
|
||||
export const del${BusinessName} = (${pkColumn.javaField}: string | number | Array<string | number>) => {
|
||||
return request({
|
||||
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
|
||||
method: 'delete'
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
export interface ${BusinessName}VO {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.list)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
$column.javaField:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number;
|
||||
#elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number;
|
||||
#elseif($column.javaType == 'Boolean') boolean;
|
||||
#else string;
|
||||
#end
|
||||
#if($column.htmlType == "imageUpload")
|
||||
/**
|
||||
* ${column.columnComment}Url
|
||||
*/
|
||||
${column.javaField}Url: string;
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if ($table.tree)
|
||||
/**
|
||||
* 子对象
|
||||
*/
|
||||
children: ${BusinessName}VO[];
|
||||
#end
|
||||
}
|
||||
|
||||
export interface ${BusinessName}Form extends BaseEntity {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.insert || $column.edit)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
$column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number;
|
||||
#elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number;
|
||||
#elseif($column.javaType == 'Boolean') boolean;
|
||||
#else string;
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
export interface ${BusinessName}Query #if(!${treeCode})extends PageQuery #end{
|
||||
|
||||
#foreach ($column in $columns)
|
||||
#if($column.query)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
$column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number;
|
||||
#elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number;
|
||||
#elseif($column.javaType == 'Boolean') boolean;
|
||||
#else string;
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
/**
|
||||
* 日期范围参数
|
||||
*/
|
||||
params?: any;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import type { ${BusinessName}VO, ${BusinessName}Form, ${BusinessName}Query } from './model';
|
||||
|
||||
import type { ID, IDS } from '#/api/common';
|
||||
#if($tplCategory != 'tree')
|
||||
import type { PageResult } from '#/api/common';
|
||||
#end
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
* @param params
|
||||
* @returns ${functionName}列表
|
||||
*/
|
||||
export function ${businessName}List(params?: ${BusinessName}Query) {
|
||||
#if($tplCategory != 'tree')
|
||||
return requestClient.get<PageResult<${BusinessName}VO>>('/${moduleName}/${businessName}/list', { params });
|
||||
#else
|
||||
return requestClient.get<${BusinessName}VO[]>(`/${moduleName}/${businessName}/list`, { params });
|
||||
#end
|
||||
}
|
||||
|
||||
#if($tplCategory != 'tree')
|
||||
/**
|
||||
* 导出${functionName}列表
|
||||
* @param params
|
||||
* @returns ${functionName}列表
|
||||
*/
|
||||
export function ${businessName}Export(params?: ${BusinessName}Query) {
|
||||
return commonExport('/${moduleName}/${businessName}/export', params ?? {});
|
||||
}
|
||||
#end
|
||||
|
||||
/**
|
||||
* 查询${functionName}详情
|
||||
* @param ${pkColumn.javaField} id
|
||||
* @returns ${functionName}详情
|
||||
*/
|
||||
export function ${businessName}Info(${pkColumn.javaField}: ID) {
|
||||
return requestClient.get<${BusinessName}VO>(`/${moduleName}/${businessName}/${${pkColumn.javaField}}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增${functionName}
|
||||
* @param data
|
||||
* @returns void
|
||||
*/
|
||||
export function ${businessName}Add(data: ${BusinessName}Form) {
|
||||
return requestClient.postWithMsg<void>('/${moduleName}/${businessName}', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新${functionName}
|
||||
* @param data
|
||||
* @returns void
|
||||
*/
|
||||
export function ${businessName}Update(data: ${BusinessName}Form) {
|
||||
return requestClient.putWithMsg<void>('/${moduleName}/${businessName}', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除${functionName}
|
||||
* @param ${pkColumn.javaField} id
|
||||
* @returns void
|
||||
*/
|
||||
export function ${businessName}Remove(${pkColumn.javaField}: ID | IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`/${moduleName}/${businessName}/${${pkColumn.javaField}}`);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { PageQuery, BaseEntity } from '#/api/common';
|
||||
|
||||
export interface ${BusinessName}VO {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.list)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
$column.javaField:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number;
|
||||
#elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number;
|
||||
#elseif($column.javaType == 'Boolean') boolean;
|
||||
#else string;
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
#if ($table.tree)
|
||||
/**
|
||||
* 子对象
|
||||
*/
|
||||
children: ${BusinessName}VO[];
|
||||
#end
|
||||
}
|
||||
|
||||
export interface ${BusinessName}Form extends BaseEntity {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.insert || $column.edit)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
$column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number;
|
||||
#elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number;
|
||||
#elseif($column.javaType == 'Boolean') boolean;
|
||||
#else string;
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
export interface ${BusinessName}Query #if(!${treeCode})extends PageQuery #end{
|
||||
#foreach ($column in $columns)
|
||||
#if($column.query)
|
||||
/**
|
||||
* $column.columnComment
|
||||
*/
|
||||
$column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number;
|
||||
#elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number;
|
||||
#elseif($column.javaType == 'Boolean') boolean;
|
||||
#else string;
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
/**
|
||||
* 日期范围参数
|
||||
*/
|
||||
params?: any;
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
import type { FormSchemaGetter } from '#/adapter/form';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
#if(${dicts} != '')
|
||||
import { getDictOptions } from '#/utils/dict';
|
||||
import { renderDict } from '#/utils/render';
|
||||
#end
|
||||
|
||||
export const querySchema: FormSchemaGetter = () => [
|
||||
#foreach($column in $columns)
|
||||
#if($column.query)
|
||||
#if($column.dictType)
|
||||
#set($dictType=$column.dictType)
|
||||
#else
|
||||
#set($dictType="")
|
||||
#end
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#if($column.htmlType == "input")
|
||||
#set($component="Input")
|
||||
#elseif($column.htmlType == "textarea")
|
||||
#set($component="Textarea")
|
||||
#elseif($column.htmlType == "select")
|
||||
#set($component="Select")
|
||||
#elseif($column.htmlType == "radio")
|
||||
#set($component="RadioGroup")
|
||||
#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
|
||||
#set($component="DatePicker")
|
||||
#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||
#set($component="RangePicker")
|
||||
#else
|
||||
#set($component="Input")
|
||||
#end
|
||||
{
|
||||
component: '${component}',
|
||||
#if($component == "Select" || $component == "RadioGroup")
|
||||
componentProps: {
|
||||
#if($dictType != "")
|
||||
// 可选从 DictEnum 中获取字典选项,便于统一维护: DictEnum.${dictType.toUpperCase()}
|
||||
options: getDictOptions('$dictType'),
|
||||
#end
|
||||
#if($component == "RadioGroup")
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
#end
|
||||
},
|
||||
#elseif($component == "DatePicker" || $component == "RangePicker")
|
||||
componentProps: {
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
#end
|
||||
fieldName: '${column.javaField}',
|
||||
label: '${comment}',
|
||||
},
|
||||
#end
|
||||
#end
|
||||
];
|
||||
|
||||
/**
|
||||
* 表格列配置
|
||||
* 如果需要使用 i18n 国际化,请使用 getter 函数形式,否则切换语言时列配置不会刷新
|
||||
* 使用方式: export const columns: () => VxeGridProps['columns'] = () => [...]
|
||||
*/
|
||||
export const columns: VxeGridProps['columns'] = [
|
||||
#if($tplCategory != 'tree')
|
||||
{ type: 'checkbox', width: 60 },
|
||||
#end
|
||||
#foreach($column in $columns)
|
||||
#if($column.list)
|
||||
#if($column.dictType)
|
||||
#set($dictType=$column.dictType)
|
||||
#else
|
||||
#set($dictType="")
|
||||
#end
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
{
|
||||
title: '${comment}',
|
||||
field: '${column.javaField}',
|
||||
#if( $foreach.count == 1 && $tplCategory == 'tree')
|
||||
treeNode: true,
|
||||
#end
|
||||
#if($dictType != "")
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
// 可选从 DictEnum 中获取字典选项,便于统一维护: DictEnum.${dictType.toUpperCase()}
|
||||
return renderDict(row.${column.javaField}, '$dictType');
|
||||
},
|
||||
},
|
||||
#end
|
||||
},
|
||||
#end
|
||||
#end
|
||||
{
|
||||
field: 'action',
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
title: '操作',
|
||||
width: 180,
|
||||
},
|
||||
];
|
||||
|
||||
#if($formComponent == "useForm")
|
||||
export const ${popupComponent}Schema: FormSchemaGetter = () => [
|
||||
#foreach($column in $columns)
|
||||
#if($column.edit)
|
||||
#if($column.dictType)
|
||||
#set($dictType=$column.dictType)
|
||||
#else
|
||||
#set($dictType="")
|
||||
#end
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#if($column.htmlType == "input")
|
||||
#set($component="Input")
|
||||
#elseif($column.htmlType == "textarea")
|
||||
#set($component="Textarea")
|
||||
#elseif($column.htmlType == "select")
|
||||
#set($component="Select")
|
||||
#elseif($column.htmlType == "radio")
|
||||
#set($component="RadioGroup")
|
||||
#elseif($column.htmlType == "checkbox")
|
||||
#set($component="Checkbox")
|
||||
#elseif($column.htmlType == "imageUpload")
|
||||
#set($component="ImageUpload")
|
||||
#elseif($column.htmlType == "fileUpload")
|
||||
#set($component="FileUpload")
|
||||
#elseif($column.htmlType == "editor")
|
||||
#set($component="RichTextarea")
|
||||
#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
|
||||
#set($component="DatePicker")
|
||||
#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||
#set($component="RangePicker")
|
||||
#else
|
||||
#set($component="Input")
|
||||
#end
|
||||
#if($column.required && $column.pk == false)
|
||||
#set($required='true')
|
||||
#else
|
||||
#set($required='false')
|
||||
#end
|
||||
{
|
||||
label: '${comment}',
|
||||
fieldName: '${column.javaField}',
|
||||
#if("" != $treeParentCode && $column.javaField == $treeParentCode)
|
||||
component: 'TreeSelect',
|
||||
#else
|
||||
component: '${component}',
|
||||
#end
|
||||
#if($component == "DatePicker" || $component == "RangePicker")
|
||||
componentProps: {
|
||||
showTime: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
},
|
||||
#elseif($component == "ImageUpload")
|
||||
componentProps: {
|
||||
// accept: ['jpg', 'png'], // 支持的文件类型(扩展名,不带点)或 MIME 类型(如 image/png)
|
||||
// maxNumber: 1, // 最大上传文件数,默认为 1,为 1 时绑定为 string 类型,否则为 string[] 类型
|
||||
// resultField: 'url', // 上传成功后返回的字段名,默认 'url',可选: 'ossId' | 'url' | 'fileName'
|
||||
},
|
||||
#elseif($component == "FileUpload")
|
||||
/**
|
||||
* 文件上传组件配置
|
||||
* 注意: 该组件返回数组类型,需要根据业务需求自行处理回显和提交逻辑
|
||||
*/
|
||||
componentProps: {
|
||||
// accept: ['xlsx', 'pdf'], // 支持的文件类型(扩展名,不带点)
|
||||
// maxNumber: 1, // 最大上传文件数
|
||||
// resultField: 'url', // 上传成功后返回的字段名,默认 'url',可选: 'ossId' | 'url' | 'fileName'
|
||||
},
|
||||
#elseif($component == "RichTextarea")
|
||||
componentProps: {
|
||||
// options: {
|
||||
// readonly: false, // 是否只读
|
||||
// },
|
||||
// width: '100%', // 编辑器宽度
|
||||
// showImageUpload: true, // 是否显示图片上传功能
|
||||
// height: 400, // 编辑器高度,默认 400px
|
||||
},
|
||||
#elseif($component == "Select" || $component == "RadioGroup" || $component == "Checkbox")
|
||||
componentProps: {
|
||||
#if($dictType != "")
|
||||
// 可选从 DictEnum 中获取字典选项,便于统一维护: DictEnum.${dictType.toUpperCase()}
|
||||
options: getDictOptions('$dictType'),
|
||||
#end
|
||||
#if($component == "RadioGroup")
|
||||
buttonStyle: 'solid',
|
||||
optionType: 'button',
|
||||
#end
|
||||
},
|
||||
#end
|
||||
#if(${column.pk})
|
||||
dependencies: {
|
||||
show: () => false,
|
||||
triggerFields: [''],
|
||||
},
|
||||
#end
|
||||
#if($required == 'true' && $column.pk == false)
|
||||
#if($component == "Select" || $component == "RadioGroup" || $component == "Checkbox")
|
||||
rules: 'selectRequired',
|
||||
#else
|
||||
rules: 'required',
|
||||
#end
|
||||
#end
|
||||
},
|
||||
#end
|
||||
#end
|
||||
];
|
||||
#end
|
||||
@@ -0,0 +1,182 @@
|
||||
<script setup lang="ts">
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { Page, useVben${PopupComponent}, type VbenFormProps } from '@vben/common-ui';
|
||||
import { getVxePopupContainer } from '@vben/utils';
|
||||
|
||||
import { Modal, Popconfirm, Space } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
useVbenVxeGrid,
|
||||
vxeCheckboxChecked,
|
||||
type VxeGridProps
|
||||
} from '#/adapter/vxe-table';
|
||||
|
||||
import {
|
||||
${businessName}Export,
|
||||
${businessName}List,
|
||||
${businessName}Remove,
|
||||
} from '#/api/${moduleName}/${businessName}';
|
||||
import type { ${BusinessName}Form } from '#/api/${moduleName}/${businessName}/model';
|
||||
import { commonDownloadExcel } from '#/utils/file/download';
|
||||
|
||||
import ${businessName}${PopupComponent} from './${businessName}-${popupComponent}.vue';
|
||||
import { columns, querySchema } from './data';
|
||||
|
||||
const formOptions: VbenFormProps = {
|
||||
commonConfig: {
|
||||
labelWidth: 80,
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
schema: querySchema(),
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||
// 处理区间选择器 RangePicker 时间格式映射
|
||||
// 将一个时间区间字段映射为两个独立的开始/结束时间字段,用于搜索和导出
|
||||
// 示例: 将 createTime 字段映射为 params[beginTime] 和 params[endTime]
|
||||
// fieldMappingTime: [
|
||||
// [
|
||||
// 'createTime', // 表单中的字段名
|
||||
// ['params[beginTime]', 'params[endTime]'], // 映射后的字段名
|
||||
// ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'], // 时间格式
|
||||
// ],
|
||||
// ],
|
||||
};
|
||||
|
||||
const gridOptions: VxeGridProps = {
|
||||
checkboxConfig: {
|
||||
// 高亮
|
||||
highlight: true,
|
||||
// 翻页时保留选中状态
|
||||
reserve: true,
|
||||
// 点击行选中
|
||||
// trigger: 'row',
|
||||
},
|
||||
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
|
||||
// columns: columns(),
|
||||
columns,
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues = {}) => {
|
||||
return await ${businessName}List({
|
||||
pageNum: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: '${pkColumn.javaField}',
|
||||
},
|
||||
// 表格全局唯一标识,用于保存列配置
|
||||
id: '${moduleName}-${businessName}-index'
|
||||
};
|
||||
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
});
|
||||
|
||||
const [${BusinessName}${PopupComponent}, ${popupComponent}Api] = useVben${PopupComponent}({
|
||||
connectedComponent: ${businessName}${PopupComponent},
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
${popupComponent}Api.setData({});
|
||||
${popupComponent}Api.open();
|
||||
}
|
||||
|
||||
async function handleEdit(row: Required<${BusinessName}Form>) {
|
||||
${popupComponent}Api.setData({ id: row.${pkColumn.javaField} });
|
||||
${popupComponent}Api.open();
|
||||
}
|
||||
|
||||
async function handleDelete(row: Required<${BusinessName}Form>) {
|
||||
await ${businessName}Remove(row.${pkColumn.javaField});
|
||||
await tableApi.query();
|
||||
}
|
||||
|
||||
function handleMultiDelete() {
|
||||
const rows = tableApi.grid.getCheckboxRecords();
|
||||
const ids = rows.map((row: Required<${BusinessName}Form>) => row.${pkColumn.javaField});
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
okType: 'danger',
|
||||
content: `确认删除选中的${ids.length}条记录吗?`,
|
||||
onOk: async () => {
|
||||
await ${businessName}Remove(ids);
|
||||
await tableApi.query();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function handleDownloadExcel() {
|
||||
commonDownloadExcel(${businessName}Export, '${functionName}数据', tableApi.formApi.form.values, {
|
||||
fieldMappingTime: formOptions.fieldMappingTime,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page :auto-content-height="true">
|
||||
<BasicTable table-title="${functionName}列表">
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<a-button
|
||||
v-access:code="['${permissionPrefix}:export']"
|
||||
@click="handleDownloadExcel"
|
||||
>
|
||||
{{ $t('pages.common.export') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
:disabled="!vxeCheckboxChecked(tableApi)"
|
||||
danger
|
||||
type="primary"
|
||||
v-access:code="['${permissionPrefix}:remove']"
|
||||
@click="handleMultiDelete">
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-access:code="['${permissionPrefix}:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Space>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<ghost-button
|
||||
v-access:code="['${permissionPrefix}:edit']"
|
||||
@click.stop="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</ghost-button>
|
||||
<Popconfirm
|
||||
:get-popup-container="getVxePopupContainer"
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<ghost-button
|
||||
danger
|
||||
v-access:code="['${permissionPrefix}:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</ghost-button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<${BusinessName}${PopupComponent} @reload="tableApi.query()" />
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,152 @@
|
||||
<script setup lang="ts">
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import { nextTick } from 'vue';
|
||||
|
||||
import { Page, useVben${PopupComponent}, type VbenFormProps } from '@vben/common-ui';
|
||||
import { getVxePopupContainer } from '@vben/utils';
|
||||
|
||||
import { Popconfirm, Space } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter/vxe-table';
|
||||
import { ${businessName}List, ${businessName}Remove } from '#/api/${moduleName}/${businessName}';
|
||||
import type { ${BusinessName}Form } from '#/api/${moduleName}/${businessName}/model';
|
||||
|
||||
import { columns, querySchema } from './data';
|
||||
import ${businessName}${PopupComponent} from './${businessName}-${popupComponent}.vue';
|
||||
|
||||
const formOptions: VbenFormProps = {
|
||||
commonConfig: {
|
||||
labelWidth: 80,
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
schema: querySchema(),
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
||||
};
|
||||
|
||||
const gridOptions: VxeGridProps = {
|
||||
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
|
||||
// columns: columns(),
|
||||
columns,
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async (_, formValues = {}) => {
|
||||
const resp = await ${businessName}List({
|
||||
...formValues,
|
||||
});
|
||||
return { rows: resp };
|
||||
},
|
||||
// 默认请求接口后展开全部 不需要可以删除这段
|
||||
querySuccess: () => {
|
||||
nextTick(() => {
|
||||
expandAll();
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
keyField: '${pkColumn.javaField}',
|
||||
},
|
||||
/**
|
||||
* 虚拟滚动配置(默认关闭)
|
||||
* 数据量小时建议关闭
|
||||
* 如果遇到样式问题(空白、错位、滚动异常等)可以关闭虚拟滚动
|
||||
*/
|
||||
scrollY: {
|
||||
enabled: false,
|
||||
gt: 0,
|
||||
},
|
||||
treeConfig: {
|
||||
parentField: '${treeParentCode}',
|
||||
rowField: '${treeCode}',
|
||||
// 自动转换为树形结构,由 vxe-table 处理,无需手动转换
|
||||
transform: true,
|
||||
},
|
||||
// 表格全局唯一标识,用于保存列配置
|
||||
id: '${moduleName}-${businessName}-index'
|
||||
};
|
||||
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
||||
const [${BusinessName}${PopupComponent}, ${popupComponent}Api] = useVben${PopupComponent}({
|
||||
connectedComponent: ${businessName}${PopupComponent},
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
${popupComponent}Api.setData({});
|
||||
${popupComponent}Api.open();
|
||||
}
|
||||
|
||||
async function handleEdit(row: Required<${BusinessName}Form>) {
|
||||
${popupComponent}Api.setData({ id: row.${pkColumn.javaField} });
|
||||
${popupComponent}Api.open();
|
||||
}
|
||||
|
||||
async function handleDelete(row: Required<${BusinessName}Form>) {
|
||||
await ${businessName}Remove(row.${pkColumn.javaField});
|
||||
await tableApi.query();
|
||||
}
|
||||
|
||||
function expandAll() {
|
||||
tableApi.grid?.setAllTreeExpand(true);
|
||||
}
|
||||
|
||||
function collapseAll() {
|
||||
tableApi.grid?.setAllTreeExpand(false);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page :auto-content-height="true">
|
||||
<BasicTable table-title="${functionName}列表">
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<a-button @click="collapseAll">
|
||||
{{ $t('pages.common.collapse') }}
|
||||
</a-button>
|
||||
<a-button @click="expandAll">
|
||||
{{ $t('pages.common.expand') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-access:code="['${permissionPrefix}:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Space>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<ghost-button
|
||||
v-access:code="['${permissionPrefix}:edit']"
|
||||
@click.stop="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</ghost-button>
|
||||
<Popconfirm
|
||||
:get-popup-container="getVxePopupContainer"
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<ghost-button
|
||||
danger
|
||||
v-access:code="['${permissionPrefix}:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</ghost-button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<${BusinessName}${PopupComponent} @reload="tableApi.query()" />
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,348 @@
|
||||
#if($formComponent == "useForm")
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVben${PopupComponent} } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { cloneDeep } from '@vben/utils';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { ${businessName}Add, ${businessName}Info, ${businessName}Update } from '#/api/${moduleName}/${businessName}';
|
||||
|
||||
import { ${popupComponent}Schema } from './data';
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const title = computed(() => {
|
||||
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||
});
|
||||
|
||||
const [BasicForm, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
// 默认占满两列
|
||||
formItemClass: 'col-span-2',
|
||||
// 默认label宽度 px
|
||||
labelWidth: 80,
|
||||
// 通用配置项 会影响到所有表单项
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
}
|
||||
},
|
||||
schema: ${popupComponent}Schema(),
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
const [Basic${PopupComponent}, ${popupComponent}Api] = useVben${PopupComponent}({
|
||||
// 在这里更改宽度
|
||||
class: 'w-[550px]',
|
||||
fullscreenButton: false,
|
||||
// 点击遮罩是否关闭
|
||||
closeOnClickModal: false,
|
||||
onCancel: handleCancel,
|
||||
onConfirm: handleConfirm,
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
${popupComponent}Api.${popupComponent}Loading(true);
|
||||
|
||||
const { id } = ${popupComponent}Api.getData() as { id?: number | string };
|
||||
isUpdate.value = !!id;
|
||||
|
||||
if (isUpdate.value && id) {
|
||||
const record = await ${businessName}Info(id);
|
||||
await formApi.setValues(record);
|
||||
}
|
||||
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
${popupComponent}Api.${popupComponent}Loading(true);
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
|
||||
const data = cloneDeep(await formApi.getValues());
|
||||
await (isUpdate.value ? ${businessName}Update(data) : ${businessName}Add(data));
|
||||
emit('reload');
|
||||
await handleCancel();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCancel() {
|
||||
${popupComponent}Api.close();
|
||||
await formApi.resetForm();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Basic${PopupComponent} :title="title">
|
||||
<BasicForm />
|
||||
</Basic${PopupComponent}>
|
||||
</template>
|
||||
#else
|
||||
<!--
|
||||
使用 Ant Design Vue 原生 Form 组件生成表单
|
||||
详细用法参考: https://antdv.com/components/form-cn
|
||||
注意: 如果 VSCode 配置了自动移除未使用的导入,可能会误删某些组件导入
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import type { RuleObject } from 'ant-design-vue/es/form';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Input, Textarea, Select, RadioGroup, CheckboxGroup, DatePicker, Form, FormItem } from 'ant-design-vue';
|
||||
import { ImageUpload, FileUpload } from '#/components/upload';
|
||||
import { Tinymce } from '#/components/tinymce';
|
||||
import { getPopupContainer } from '@vben/utils';
|
||||
import { pick } from 'lodash-es';
|
||||
|
||||
#if(${dicts} != '')
|
||||
import { getDictOptions } from '#/utils/dict';
|
||||
#end
|
||||
|
||||
import { useVben${PopupComponent} } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { cloneDeep } from '@vben/utils';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { ${businessName}Add, ${businessName}Info, ${businessName}Update } from '#/api/${moduleName}/${businessName}';
|
||||
import type { ${BusinessName}Form } from '#/api/${moduleName}/${businessName}/model';
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const title = computed(() => {
|
||||
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||
});
|
||||
|
||||
/**
|
||||
* 定义默认值 用于reset
|
||||
*/
|
||||
const defaultValues: Partial<${BusinessName}Form> = {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.insert || $column.edit)
|
||||
#if($column.htmlType == "checkbox")
|
||||
$column.javaField: []#if($foreach.count != $columns.size()),#end
|
||||
#else
|
||||
$column.javaField: undefined#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单数据ref
|
||||
*/
|
||||
const formData = ref(defaultValues);
|
||||
|
||||
type AntdFormRules<T> = Partial<Record<keyof T, RuleObject[]>> & {
|
||||
[key: string]: RuleObject[];
|
||||
};
|
||||
/**
|
||||
* 表单校验规则
|
||||
*/
|
||||
const formRules = ref<AntdFormRules<${BusinessName}Form>>({
|
||||
#foreach ($column in $columns)
|
||||
#if($column.insert || $column.edit)
|
||||
#if($column.required && $column.pk == false)
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
$column.javaField: [
|
||||
{ required: true, message: "$comment不能为空" }
|
||||
]#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
});
|
||||
|
||||
/**
|
||||
* useForm解构出表单方法
|
||||
*/
|
||||
const { validate, validateInfos, resetFields } = Form.useForm(
|
||||
formData,
|
||||
formRules,
|
||||
);
|
||||
|
||||
const [Basic${PopupComponent}, ${popupComponent}Api] = useVben${PopupComponent}({
|
||||
class: 'w-[550px]',
|
||||
fullscreenButton: false,
|
||||
closeOnClickModal: false,
|
||||
onClosed: handleCancel,
|
||||
onConfirm: handleConfirm,
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
${popupComponent}Api.${popupComponent}Loading(true);
|
||||
|
||||
const { id } = ${popupComponent}Api.getData() as { id?: number | string };
|
||||
isUpdate.value = !!id;
|
||||
|
||||
if (isUpdate.value && id) {
|
||||
const record = await ${businessName}Info(id);
|
||||
// 只赋值存在的字段
|
||||
const filterRecord = pick(record, Object.keys(defaultValues));
|
||||
formData.value = filterRecord;
|
||||
}
|
||||
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
${popupComponent}Api.${popupComponent}Loading(true);
|
||||
await validate();
|
||||
// 可能会做数据处理 使用cloneDeep深拷贝
|
||||
const data = cloneDeep(formData.value);
|
||||
await (isUpdate.value ? ${businessName}Update(data) : ${businessName}Add(data));
|
||||
emit('reload');
|
||||
await handleCancel();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCancel() {
|
||||
${popupComponent}Api.close();
|
||||
formData.value = cloneDeep(defaultValues);
|
||||
resetFields();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Basic${PopupComponent} :title="title">
|
||||
<Form :label-col="{ span: 4 }">
|
||||
#foreach($column in $columns)
|
||||
#set($field=$column.javaField)
|
||||
#if(($column.insert || $column.edit) && !$column.pk)
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#set($dictType=$column.dictType)
|
||||
#if($column.htmlType == "input")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<Input v-model:value="formData.${field}" :placeholder="$t('ui.formRules.required')" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "imageUpload")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<!-- 图片上传组件,支持单张图片上传,返回 ossId -->
|
||||
<ImageUpload resultField="ossId" :max-number="1" v-model:value="formData.${field}" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "fileUpload")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<FileUpload resultField="ossId" :max-number="1" v-model:value="formData.${field}" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "editor")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<Tinymce
|
||||
:options="{ readonly: false }"
|
||||
v-model="formData.${field}"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "select" && "" != $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<Select
|
||||
v-model:value="formData.${field}"
|
||||
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:options="getDictOptions('$dictType', true)"
|
||||
#else
|
||||
:options="getDictOptions('$dictType')"
|
||||
#end
|
||||
:getPopupContainer="getPopupContainer"
|
||||
:placeholder="$t('ui.formRules.selectRequired')"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "select" && $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<Select
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
:getPopupContainer="getPopupContainer"
|
||||
:placeholder="$t('ui.formRules.selectRequired')"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "checkbox" && "" != $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<CheckboxGroup
|
||||
v-model:value="formData.${field}"
|
||||
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:options="getDictOptions('$dictType', true)"
|
||||
#else
|
||||
:options="getDictOptions('$dictType')"
|
||||
#end
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "checkbox" && $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<CheckboxGroup
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "radio" && "" != $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<RadioGroup
|
||||
option-type="button"
|
||||
button-style="solid"
|
||||
v-model:value="formData.${field}"
|
||||
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:options="getDictOptions('$dictType', true)"
|
||||
#else
|
||||
:options="getDictOptions('$dictType')"
|
||||
#end
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "radio" && $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<RadioGroup
|
||||
option-type="button"
|
||||
button-style="solid"
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "datetime")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<!-- 日期时间选择器,可根据需求调整 format/valueFormat/showTime 等参数 -->
|
||||
<DatePicker
|
||||
v-model:value="formData.${field}"
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "textarea")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<Textarea
|
||||
v-model:value="formData.${field}"
|
||||
:placeholder="$t('ui.formRules.required')"
|
||||
:rows="4"
|
||||
/>
|
||||
</FormItem>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
</Form>
|
||||
</Basic${PopupComponent}>
|
||||
</template>
|
||||
#end
|
||||
|
||||
@@ -0,0 +1,382 @@
|
||||
#if($formComponent == "useForm")
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVben${PopupComponent} } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { cloneDeep, getPopupContainer, listToTree } from '@vben/utils';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { ${businessName}Add, ${businessName}Info, ${businessName}List, ${businessName}Update } from '#/api/${moduleName}/${businessName}';
|
||||
|
||||
import { ${popupComponent}Schema } from './data';
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const title = computed(() => {
|
||||
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||
});
|
||||
|
||||
const [BasicForm, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
// 默认占满两列
|
||||
formItemClass: 'col-span-2',
|
||||
// 默认label宽度 px
|
||||
labelWidth: 80,
|
||||
// 通用配置项 会影响到所有表单项
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
}
|
||||
},
|
||||
schema: ${popupComponent}Schema(),
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
async function setup${BusinessName}Select() {
|
||||
const listData = await ${businessName}List();
|
||||
const treeData = listToTree(listData, { id: '${treeCode}', pid: '${treeParentCode}' });
|
||||
formApi.updateSchema([{
|
||||
fieldName: '${treeParentCode}',
|
||||
componentProps: {
|
||||
treeData,
|
||||
treeLine: { showLeafIcon: false },
|
||||
fieldNames: { label: '${treeName}', value: '${treeCode}' },
|
||||
treeDefaultExpandAll: true,
|
||||
getPopupContainer,
|
||||
},
|
||||
}]);
|
||||
}
|
||||
|
||||
const [Basic${PopupComponent}, ${popupComponent}Api] = useVben${PopupComponent}({
|
||||
// 在这里更改宽度
|
||||
class: 'w-[550px]',
|
||||
fullscreenButton: false,
|
||||
// 点击遮罩是否关闭
|
||||
closeOnClickModal: false,
|
||||
onCancel: handleCancel,
|
||||
onConfirm: handleConfirm,
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
${popupComponent}Api.${popupComponent}Loading(true);
|
||||
|
||||
const { id } = ${popupComponent}Api.getData() as { id?: number | string };
|
||||
isUpdate.value = !!id;
|
||||
|
||||
if (isUpdate.value && id) {
|
||||
const record = await ${businessName}Info(id);
|
||||
await formApi.setValues(record);
|
||||
}
|
||||
await setup${BusinessName}Select();
|
||||
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
${popupComponent}Api.${popupComponent}Loading(true);
|
||||
const { valid } = await formApi.validate();
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
|
||||
const data = cloneDeep(await formApi.getValues());
|
||||
await (isUpdate.value ? ${businessName}Update(data) : ${businessName}Add(data));
|
||||
emit('reload');
|
||||
await handleCancel();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCancel() {
|
||||
${popupComponent}Api.close();
|
||||
await formApi.resetForm();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Basic${PopupComponent} :title="title">
|
||||
<BasicForm />
|
||||
</Basic${PopupComponent}>
|
||||
</template>
|
||||
#else
|
||||
<!--
|
||||
使用 Ant Design Vue 原生 Form 组件生成表单
|
||||
详细用法参考: https://antdv.com/components/form-cn
|
||||
注意: 如果 VSCode 配置了自动移除未使用的导入,可能会误删某些组件导入
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import type { RuleObject } from 'ant-design-vue/es/form';
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Input, Textarea, Select, RadioGroup, CheckboxGroup, DatePicker, Form, FormItem, TreeSelect } from 'ant-design-vue';
|
||||
import { ImageUpload, FileUpload } from '#/components/upload';
|
||||
import { Tinymce } from '#/components/tinymce';
|
||||
import { getPopupContainer } from '@vben/utils';
|
||||
import { pick } from 'lodash-es';
|
||||
|
||||
#if(${dicts} != '')
|
||||
import { getDictOptions } from '#/utils/dict';
|
||||
#end
|
||||
|
||||
import { useVben${PopupComponent} } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { cloneDeep, listToTree } from '@vben/utils';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { ${businessName}Add, ${businessName}Info, ${businessName}List, ${businessName}Update } from '#/api/${moduleName}/${businessName}';
|
||||
import type { ${BusinessName}Form } from '#/api/${moduleName}/${businessName}/model';
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const title = computed(() => {
|
||||
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||
});
|
||||
|
||||
/**
|
||||
* 定义默认值 用于reset
|
||||
*/
|
||||
const defaultValues: Partial<${BusinessName}Form> = {
|
||||
#foreach ($column in $columns)
|
||||
#if($column.insert || $column.edit)
|
||||
#if($column.htmlType == "checkbox")
|
||||
$column.javaField: []#if($foreach.count != $columns.size()),#end
|
||||
#else
|
||||
$column.javaField: undefined#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单数据ref
|
||||
*/
|
||||
const formData = ref(defaultValues);
|
||||
|
||||
type AntdFormRules<T> = Partial<Record<keyof T, RuleObject[]>> & {
|
||||
[key: string]: RuleObject[];
|
||||
};
|
||||
/**
|
||||
* 表单校验规则
|
||||
*/
|
||||
const formRules = ref<AntdFormRules<${BusinessName}Form>>({
|
||||
#foreach ($column in $columns)
|
||||
#if($column.insert || $column.edit)
|
||||
#if($column.required && $column.pk == false)
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
$column.javaField: [
|
||||
{ required: true, message: "$comment不能为空" }
|
||||
]#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
});
|
||||
|
||||
/**
|
||||
* useForm解构出表单方法
|
||||
*/
|
||||
const { validate, validateInfos, resetFields } = Form.useForm(
|
||||
formData,
|
||||
formRules,
|
||||
);
|
||||
|
||||
const treeData = ref<any[]>([]);
|
||||
async function setup${BusinessName}Select() {
|
||||
const listData = await ${businessName}List();
|
||||
treeData.value = listToTree(listData, { id: '${treeCode}', pid: '${treeParentCode}' });
|
||||
}
|
||||
|
||||
const [Basic${PopupComponent}, ${popupComponent}Api] = useVben${PopupComponent}({
|
||||
class: 'w-[550px]',
|
||||
fullscreenButton: false,
|
||||
closeOnClickModal: false,
|
||||
onClosed: handleCancel,
|
||||
onConfirm: handleConfirm,
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
${popupComponent}Api.${popupComponent}Loading(true);
|
||||
|
||||
const { id } = ${popupComponent}Api.getData() as { id?: number | string };
|
||||
isUpdate.value = !!id;
|
||||
|
||||
if (isUpdate.value && id) {
|
||||
const record = await ${businessName}Info(id);
|
||||
// 只赋值存在的字段
|
||||
const filterRecord = pick(record, Object.keys(defaultValues));
|
||||
formData.value = filterRecord;
|
||||
}
|
||||
await setup${BusinessName}Select();
|
||||
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
${popupComponent}Api.${popupComponent}Loading(true);
|
||||
await validate();
|
||||
// 可能会做数据处理 使用cloneDeep深拷贝
|
||||
const data = cloneDeep(formData.value);
|
||||
await (isUpdate.value ? ${businessName}Update(data) : ${businessName}Add(data));
|
||||
emit('reload');
|
||||
await handleCancel();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCancel() {
|
||||
${popupComponent}Api.close();
|
||||
formData.value = cloneDeep(defaultValues);
|
||||
resetFields();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Basic${PopupComponent} :title="title">
|
||||
<Form :label-col="{ span: 4 }">
|
||||
#foreach($column in $columns)
|
||||
#set($field=$column.javaField)
|
||||
#if(($column.insert || $column.edit) && !$column.pk)
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||
#else
|
||||
#set($comment=$column.columnComment)
|
||||
#end
|
||||
#set($dictType=$column.dictType)
|
||||
#if("" != $treeParentCode && $column.javaField == $treeParentCode)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<TreeSelect
|
||||
v-model:value="formData.${treeParentCode}"
|
||||
:treeData="treeData"
|
||||
:tree-line="{ showLeafIcon: false }"
|
||||
:treeDefaultExpandAll="true"
|
||||
:fieldNames="{ label: '${treeName}', value: '${treeCode}' }"
|
||||
:placeholder="$t('ui.formRules.selectRequired')"
|
||||
:getPopupContainer="getPopupContainer"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "input")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<Input v-model:value="formData.${field}" :placeholder="$t('ui.formRules.required')" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "imageUpload")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<!-- 图片上传组件,支持单张图片上传,返回 ossId -->
|
||||
<ImageUpload resultField="ossId" :max-number="1" v-model:value="formData.${field}" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "fileUpload")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<FileUpload resultField="ossId" :max-number="1" v-model:value="formData.${field}" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "editor")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<Tinymce
|
||||
:options="{ readonly: false }"
|
||||
v-model="formData.${field}"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "select" && "" != $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<Select
|
||||
v-model:value="formData.${field}"
|
||||
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:options="getDictOptions('$dictType', true)"
|
||||
#else
|
||||
:options="getDictOptions('$dictType')"
|
||||
#end
|
||||
:getPopupContainer="getPopupContainer"
|
||||
:placeholder="$t('ui.formRules.selectRequired')"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "select" && $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<Select
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
:getPopupContainer="getPopupContainer"
|
||||
:placeholder="$t('ui.formRules.selectRequired')"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "checkbox" && "" != $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<CheckboxGroup
|
||||
v-model:value="formData.${field}"
|
||||
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:options="getDictOptions('$dictType', true)"
|
||||
#else
|
||||
:options="getDictOptions('$dictType')"
|
||||
#end
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "checkbox" && $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<CheckboxGroup
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "radio" && "" != $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<RadioGroup
|
||||
option-type="button"
|
||||
button-style="solid"
|
||||
v-model:value="formData.${field}"
|
||||
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||
:options="getDictOptions('$dictType', true)"
|
||||
#else
|
||||
:options="getDictOptions('$dictType')"
|
||||
#end
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "radio" && $dictType)
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<RadioGroup
|
||||
option-type="button"
|
||||
button-style="solid"
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "datetime")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<!-- 日期时间选择器,可根据需求调整 format/valueFormat/showTime 等参数 -->
|
||||
<DatePicker
|
||||
v-model:value="formData.${field}"
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "textarea")
|
||||
<FormItem label="${comment}" v-bind="validateInfos.${field}">
|
||||
<Textarea
|
||||
v-model:value="formData.${field}"
|
||||
:placeholder="$t('ui.formRules.required')"
|
||||
:rows="4"
|
||||
/>
|
||||
</FormItem>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
</Form>
|
||||
</Basic${PopupComponent}>
|
||||
</template>
|
||||
#end
|
||||
@@ -3,5 +3,4 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="${packageName}.mapper.${ClassName}Mapper">
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user