mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-07 23:31:08 +08:00
feat(generator): 添加antdv-next专用代码生成模板
添加针对antdv-next框架的代码生成模板,支持useVbenForm和原生antd表单两种表单生成方式 包含API层、视图层、数据模型等完整模板文件,新增更新指南文档说明迁移步骤
This commit is contained in:
23
scripts/代码生成模板antdv-next专用/README.md
Normal file
23
scripts/代码生成模板antdv-next专用/README.md
Normal file
File diff suppressed because one or more lines are too long
414
scripts/代码生成模板antdv-next专用/VelocityUtils.java
Normal file
414
scripts/代码生成模板antdv-next专用/VelocityUtils.java
Normal file
@@ -0,0 +1,414 @@
|
||||
package org.dromara.generator.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.dromara.common.mybatis.enums.DataBaseType;
|
||||
import org.dromara.generator.constant.GenConstants;
|
||||
import org.dromara.common.core.utils.DateUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.json.utils.JsonUtils;
|
||||
import org.dromara.common.mybatis.helper.DataBaseHelper;
|
||||
import org.dromara.generator.domain.GenTable;
|
||||
import org.dromara.generator.domain.GenTableColumn;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 模板处理工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class VelocityUtils {
|
||||
|
||||
/**
|
||||
* 项目空间路径
|
||||
*/
|
||||
private static final String PROJECT_PATH = "main/java";
|
||||
|
||||
/**
|
||||
* mybatis空间路径
|
||||
*/
|
||||
private static final String MYBATIS_PATH = "main/resources/mapper";
|
||||
|
||||
/**
|
||||
* 默认上级菜单,系统工具
|
||||
*/
|
||||
private static final String DEFAULT_PARENT_MENU_ID = "3";
|
||||
|
||||
/**
|
||||
* 设置模板变量信息
|
||||
*
|
||||
* @return 模板列表
|
||||
*/
|
||||
public static VelocityContext prepareContext(GenTable genTable) {
|
||||
String moduleName = genTable.getModuleName();
|
||||
String businessName = genTable.getBusinessName();
|
||||
String packageName = genTable.getPackageName();
|
||||
String tplCategory = genTable.getTplCategory();
|
||||
String functionName = genTable.getFunctionName();
|
||||
|
||||
VelocityContext velocityContext = new VelocityContext();
|
||||
velocityContext.put("tplCategory", genTable.getTplCategory());
|
||||
velocityContext.put("tableName", genTable.getTableName());
|
||||
velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】");
|
||||
velocityContext.put("ClassName", genTable.getClassName());
|
||||
velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName()));
|
||||
velocityContext.put("moduleName", genTable.getModuleName());
|
||||
velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName()));
|
||||
velocityContext.put("businessName", genTable.getBusinessName());
|
||||
velocityContext.put("basePackage", getPackagePrefix(packageName));
|
||||
velocityContext.put("packageName", packageName);
|
||||
velocityContext.put("author", genTable.getFunctionAuthor());
|
||||
velocityContext.put("datetime", DateUtils.getDate());
|
||||
velocityContext.put("pkColumn", genTable.getPkColumn());
|
||||
velocityContext.put("importList", getImportList(genTable));
|
||||
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
|
||||
velocityContext.put("columns", genTable.getColumns());
|
||||
velocityContext.put("table", genTable);
|
||||
velocityContext.put("dicts", getDicts(genTable));
|
||||
setMenuVelocityContext(velocityContext, genTable);
|
||||
if (GenConstants.TPL_TREE.equals(tplCategory)) {
|
||||
setTreeVelocityContext(velocityContext, genTable);
|
||||
}
|
||||
// 判断是modal还是drawer
|
||||
Dict paramsObj = JsonUtils.parseMap(genTable.getOptions());
|
||||
if (ObjectUtil.isNotNull(paramsObj)) {
|
||||
String popupComponent = Optional
|
||||
.ofNullable(paramsObj.getStr("popupComponent"))
|
||||
.orElse("modal");
|
||||
velocityContext.put("popupComponent", popupComponent);
|
||||
velocityContext.put("PopupComponent", StringUtils.capitalize(popupComponent));
|
||||
} else {
|
||||
velocityContext.put("popupComponent", "modal");
|
||||
velocityContext.put("PopupComponent", "Modal");
|
||||
}
|
||||
// 判断是原生antd表单还是useForm表单
|
||||
// native 原生antd表单
|
||||
// useForm useVbenForm
|
||||
if (ObjectUtil.isNotNull(paramsObj)) {
|
||||
String formComponent = Optional
|
||||
.ofNullable(paramsObj.getStr("formComponent"))
|
||||
.orElse("useForm");
|
||||
velocityContext.put("formComponent", formComponent);
|
||||
} else {
|
||||
velocityContext.put("formComponent", "useForm");
|
||||
}
|
||||
return velocityContext;
|
||||
}
|
||||
|
||||
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
|
||||
String options = genTable.getOptions();
|
||||
Dict paramsObj = JsonUtils.parseMap(options);
|
||||
String parentMenuId = getParentMenuId(paramsObj);
|
||||
context.put("parentMenuId", parentMenuId);
|
||||
}
|
||||
|
||||
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
|
||||
String options = genTable.getOptions();
|
||||
Dict paramsObj = JsonUtils.parseMap(options);
|
||||
String treeCode = getTreecode(paramsObj);
|
||||
String treeParentCode = getTreeParentCode(paramsObj);
|
||||
String treeName = getTreeName(paramsObj);
|
||||
|
||||
context.put("treeCode", treeCode);
|
||||
context.put("treeParentCode", treeParentCode);
|
||||
context.put("treeName", treeName);
|
||||
context.put("expandColumn", getExpandColumn(genTable));
|
||||
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
|
||||
context.put("tree_parent_code", paramsObj.get(GenConstants.TREE_PARENT_CODE));
|
||||
}
|
||||
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
|
||||
context.put("tree_name", paramsObj.get(GenConstants.TREE_NAME));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板信息
|
||||
*
|
||||
* @return 模板列表
|
||||
*/
|
||||
public static List<String> getTemplateList(String tplCategory) {
|
||||
List<String> templates = new ArrayList<>();
|
||||
templates.add("vm/java/domain.java.vm");
|
||||
templates.add("vm/java/vo.java.vm");
|
||||
templates.add("vm/java/bo.java.vm");
|
||||
templates.add("vm/java/mapper.java.vm");
|
||||
templates.add("vm/java/service.java.vm");
|
||||
templates.add("vm/java/serviceImpl.java.vm");
|
||||
templates.add("vm/java/controller.java.vm");
|
||||
templates.add("vm/xml/mapper.xml.vm");
|
||||
DataBaseType dataBaseType = DataBaseHelper.getDataBaseType();
|
||||
if (dataBaseType.isOracle()) {
|
||||
templates.add("vm/sql/oracle/sql.vm");
|
||||
} else if (dataBaseType.isPostgreSql()) {
|
||||
templates.add("vm/sql/postgres/sql.vm");
|
||||
} else if (dataBaseType.isSqlServer()) {
|
||||
templates.add("vm/sql/sqlserver/sql.vm");
|
||||
} else {
|
||||
templates.add("vm/sql/sql.vm");
|
||||
}
|
||||
templates.add("vm/ts/api.ts.vm");
|
||||
templates.add("vm/ts/types.ts.vm");
|
||||
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
|
||||
templates.add("vm/vue/index.vue.vm");
|
||||
} else if (GenConstants.TPL_TREE.equals(tplCategory)) {
|
||||
templates.add("vm/vue/index-tree.vue.vm");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加vben5
|
||||
*/
|
||||
templates.add("vm/vben5/api/index.ts.vm");
|
||||
templates.add("vm/vben5/api/model.d.ts.vm");
|
||||
templates.add("vm/vben5/views/data.ts.vm");
|
||||
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
|
||||
templates.add("vm/vben5/views/index_vben.vue.vm");
|
||||
templates.add("vm/vben5/views/popup.vue.vm");
|
||||
} else if (GenConstants.TPL_TREE.equals(tplCategory)) {
|
||||
templates.add("vm/vben5/views/index_vben_tree.vue.vm");
|
||||
templates.add("vm/vben5/views/popup_tree.vue.vm");
|
||||
}
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件名
|
||||
*/
|
||||
public static String getFileName(String template, GenTable genTable) {
|
||||
// 文件名称
|
||||
String fileName = "";
|
||||
// 包路径
|
||||
String packageName = genTable.getPackageName();
|
||||
// 模块名
|
||||
String moduleName = genTable.getModuleName();
|
||||
// 大写类名
|
||||
String className = genTable.getClassName();
|
||||
// 业务名称
|
||||
String businessName = genTable.getBusinessName();
|
||||
|
||||
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
|
||||
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
|
||||
String vuePath = "vue";
|
||||
|
||||
if (template.contains("domain.java.vm")) {
|
||||
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
|
||||
}
|
||||
if (template.contains("vo.java.vm")) {
|
||||
fileName = StringUtils.format("{}/domain/vo/{}Vo.java", javaPath, className);
|
||||
}
|
||||
if (template.contains("bo.java.vm")) {
|
||||
fileName = StringUtils.format("{}/domain/bo/{}Bo.java", javaPath, className);
|
||||
}
|
||||
if (template.contains("mapper.java.vm")) {
|
||||
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
|
||||
} else if (template.contains("service.java.vm")) {
|
||||
fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
|
||||
} else if (template.contains("serviceImpl.java.vm")) {
|
||||
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
|
||||
} else if (template.contains("controller.java.vm")) {
|
||||
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
|
||||
} else if (template.contains("mapper.xml.vm")) {
|
||||
fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
|
||||
} else if (template.contains("sql.vm")) {
|
||||
fileName = businessName + "Menu.sql";
|
||||
} else if (template.contains("api.ts.vm")) {
|
||||
fileName = StringUtils.format("{}/api/{}/{}/index.ts", vuePath, moduleName, businessName);
|
||||
} else if (template.contains("types.ts.vm")) {
|
||||
fileName = StringUtils.format("{}/api/{}/{}/types.ts", vuePath, moduleName, businessName);
|
||||
} else if (template.contains("index.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
|
||||
} else if (template.contains("index-tree.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
|
||||
}
|
||||
|
||||
// 判断是modal还是drawer
|
||||
Dict paramsObj = JsonUtils.parseMap(genTable.getOptions());
|
||||
String popupComponent = "modal";
|
||||
if (ObjectUtil.isNotNull(paramsObj)) {
|
||||
popupComponent = Optional
|
||||
.ofNullable(paramsObj.getStr("popupComponent"))
|
||||
.orElse("modal");
|
||||
}
|
||||
String vben5Path = "vben5";
|
||||
if (template.contains("vm/vben5/api/index.ts.vm")) {
|
||||
fileName = StringUtils.format("{}/api/{}/{}/index.ts", vben5Path, moduleName, businessName);
|
||||
}
|
||||
if (template.contains("vm/vben5/api/model.d.ts.vm")) {
|
||||
fileName = StringUtils.format("{}/api/{}/{}/model.d.ts", vben5Path, moduleName, businessName);
|
||||
}
|
||||
if (template.contains("vm/vben5/views/index_vben.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vben5Path, moduleName, businessName);
|
||||
}
|
||||
if (template.contains("vm/vben5/views/index_vben_tree.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vben5Path, moduleName, businessName);
|
||||
}
|
||||
if (template.contains("vm/vben5/views/data.ts.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/data.ts", vben5Path, moduleName, businessName);
|
||||
}
|
||||
if (template.contains("vm/vben5/views/popup.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/{}-{}.vue", vben5Path, moduleName, businessName, businessName, popupComponent);
|
||||
}
|
||||
if (template.contains("vm/vben5/views/popup_tree.vue.vm")) {
|
||||
fileName = StringUtils.format("{}/views/{}/{}/{}-{}.vue", vben5Path, moduleName, businessName, businessName, popupComponent);
|
||||
}
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取包前缀
|
||||
*
|
||||
* @param packageName 包名称
|
||||
* @return 包前缀名称
|
||||
*/
|
||||
public static String getPackagePrefix(String packageName) {
|
||||
int lastIndex = packageName.lastIndexOf(".");
|
||||
return StringUtils.substring(packageName, 0, lastIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据列类型获取导入包
|
||||
*
|
||||
* @param genTable 业务表对象
|
||||
* @return 返回需要导入的包列表
|
||||
*/
|
||||
public static HashSet<String> getImportList(GenTable genTable) {
|
||||
List<GenTableColumn> columns = genTable.getColumns();
|
||||
HashSet<String> importList = new HashSet<>();
|
||||
for (GenTableColumn column : columns) {
|
||||
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
|
||||
importList.add("java.util.Date");
|
||||
importList.add("com.fasterxml.jackson.annotation.JsonFormat");
|
||||
} else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
|
||||
importList.add("java.math.BigDecimal");
|
||||
} else if (!column.isSuperColumn() && "imageUpload".equals(column.getHtmlType())) {
|
||||
importList.add("org.dromara.common.translation.annotation.Translation");
|
||||
importList.add("org.dromara.common.translation.constant.TransConstant");
|
||||
}
|
||||
}
|
||||
return importList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据列类型获取字典组
|
||||
*
|
||||
* @param genTable 业务表对象
|
||||
* @return 返回字典组
|
||||
*/
|
||||
public static String getDicts(GenTable genTable) {
|
||||
List<GenTableColumn> columns = genTable.getColumns();
|
||||
Set<String> dicts = new HashSet<>();
|
||||
addDicts(dicts, columns);
|
||||
return StringUtils.join(dicts, ", ");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加字典列表
|
||||
*
|
||||
* @param dicts 字典列表
|
||||
* @param columns 列集合
|
||||
*/
|
||||
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns) {
|
||||
for (GenTableColumn column : columns) {
|
||||
if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
|
||||
column.getHtmlType(),
|
||||
new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX })) {
|
||||
dicts.add("'" + column.getDictType() + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限前缀
|
||||
*
|
||||
* @param moduleName 模块名称
|
||||
* @param businessName 业务名称
|
||||
* @return 返回权限前缀
|
||||
*/
|
||||
public static String getPermissionPrefix(String moduleName, String businessName) {
|
||||
return StringUtils.format("{}:{}", moduleName, businessName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上级菜单ID字段
|
||||
*
|
||||
* @param paramsObj 生成其他选项
|
||||
* @return 上级菜单ID字段
|
||||
*/
|
||||
public static String getParentMenuId(Dict paramsObj) {
|
||||
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)
|
||||
&& StringUtils.isNotEmpty(paramsObj.getStr(GenConstants.PARENT_MENU_ID))) {
|
||||
return paramsObj.getStr(GenConstants.PARENT_MENU_ID);
|
||||
}
|
||||
return DEFAULT_PARENT_MENU_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树编码
|
||||
*
|
||||
* @param paramsObj 生成其他选项
|
||||
* @return 树编码
|
||||
*/
|
||||
public static String getTreecode(Map<String, Object> paramsObj) {
|
||||
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_CODE)) {
|
||||
return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_CODE)));
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树父编码
|
||||
*
|
||||
* @param paramsObj 生成其他选项
|
||||
* @return 树父编码
|
||||
*/
|
||||
public static String getTreeParentCode(Dict paramsObj) {
|
||||
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
|
||||
return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_PARENT_CODE));
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树名称
|
||||
*
|
||||
* @param paramsObj 生成其他选项
|
||||
* @return 树名称
|
||||
*/
|
||||
public static String getTreeName(Dict paramsObj) {
|
||||
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) {
|
||||
return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_NAME));
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需要在哪一列上面显示展开按钮
|
||||
*
|
||||
* @param genTable 业务表对象
|
||||
* @return 展开按钮列序号
|
||||
*/
|
||||
public static int getExpandColumn(GenTable genTable) {
|
||||
String options = genTable.getOptions();
|
||||
Dict paramsObj = JsonUtils.parseMap(options);
|
||||
String treeName = paramsObj.getStr(GenConstants.TREE_NAME);
|
||||
int num = 0;
|
||||
for (GenTableColumn column : genTable.getColumns()) {
|
||||
if (column.isList()) {
|
||||
num++;
|
||||
String columnName = column.getColumnName();
|
||||
if (columnName.equals(treeName)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
69
scripts/代码生成模板antdv-next专用/vben5/api/index.ts.vm
Normal file
69
scripts/代码生成模板antdv-next专用/vben5/api/index.ts.vm
Normal file
@@ -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}}`);
|
||||
}
|
||||
56
scripts/代码生成模板antdv-next专用/vben5/api/model.d.ts.vm
Normal file
56
scripts/代码生成模板antdv-next专用/vben5/api/model.d.ts.vm
Normal file
@@ -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;
|
||||
}
|
||||
215
scripts/代码生成模板antdv-next专用/vben5/views/data.ts.vm
Normal file
215
scripts/代码生成模板antdv-next专用/vben5/views/data.ts.vm
Normal file
@@ -0,0 +1,215 @@
|
||||
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: 'image/*', // 可选拓展名或者mime类型 ,拼接
|
||||
// maxCount: 1, // 最大上传文件数 默认为1 为1会绑定为string而非string[]类型
|
||||
},
|
||||
#elseif($component == "FileUpload")
|
||||
/**
|
||||
* 注意这里获取为数组 需要自行定义回显/提交
|
||||
* 文件上传还在demo阶段 可能有重大改动!
|
||||
*/
|
||||
componentProps: {
|
||||
// accept: 'application/pdf', // 可选拓展名或者mime类型 ,拼接
|
||||
// maxCount: 1, // 最大上传文件数 默认为1 为1会绑定为string而非string[]类型
|
||||
},
|
||||
#elseif($component == "RichTextarea")
|
||||
componentProps: {
|
||||
// disabled: false, // 是否只读
|
||||
// height: 400 // 高度 默认400
|
||||
},
|
||||
#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
|
||||
173
scripts/代码生成模板antdv-next专用/vben5/views/index_vben.vue.vm
Normal file
173
scripts/代码生成模板antdv-next专用/vben5/views/index_vben.vue.vm
Normal file
@@ -0,0 +1,173 @@
|
||||
<script setup lang="ts">
|
||||
import type { VbenFormProps } from '@vben/common-ui';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { Page, useVben${PopupComponent} } from '@vben/common-ui';
|
||||
import { Popconfirm, Space } from 'antdv-next';
|
||||
|
||||
import { useVbenVxeGrid, vxeCheckboxChecked } 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 { useBlobExport } from '#/utils/file/export';
|
||||
|
||||
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时间格式 将一个字段映射为两个字段 搜索/导出会用到
|
||||
// 不需要直接删除
|
||||
// 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});
|
||||
window.modal.confirm({
|
||||
title: '提示',
|
||||
okType: 'danger',
|
||||
content: `确认删除选中的${ids.length}条记录吗?`,
|
||||
onOk: async () => {
|
||||
await ${businessName}Remove(ids);
|
||||
await tableApi.query();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const { exportBlob, exportLoading, buildExportFileName } = useBlobExport(${businessName}Export);
|
||||
|
||||
async function handleExport() {
|
||||
const formValues = await tableApi.formApi.getValues();
|
||||
const fileName = buildExportFileName('${functionName}数据');
|
||||
exportBlob({ data: formValues, fileName });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page :auto-content-height="true">
|
||||
<BasicTable table-title="${functionName}列表">
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<a-button
|
||||
v-access:code="['${permissionPrefix}:export']"
|
||||
:loading="exportLoading"
|
||||
:disabled="exportLoading"
|
||||
@click="handleExport"
|
||||
>
|
||||
{{ $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>
|
||||
<action-button
|
||||
v-access:code="['${permissionPrefix}:edit']"
|
||||
@click.stop="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</action-button>
|
||||
<Popconfirm placement="left" title="确认删除?" @confirm="handleDelete(row)">
|
||||
<action-button
|
||||
danger
|
||||
v-access:code="['${permissionPrefix}:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</action-button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<${BusinessName}${PopupComponent} @reload="tableApi.query()" />
|
||||
</Page>
|
||||
</template>
|
||||
147
scripts/代码生成模板antdv-next专用/vben5/views/index_vben_tree.vue.vm
Normal file
147
scripts/代码生成模板antdv-next专用/vben5/views/index_vben_tree.vue.vm
Normal file
@@ -0,0 +1,147 @@
|
||||
<script setup lang="ts">
|
||||
import type { VbenFormProps } from '@vben/common-ui';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { nextTick } from 'vue';
|
||||
|
||||
import { Page, useVben${PopupComponent} } from '@vben/common-ui';
|
||||
|
||||
import { Popconfirm, Space } from 'antdv-next';
|
||||
|
||||
import { useVbenVxeGrid } 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}',
|
||||
// 自动转换为tree 由vxe处理 无需手动转换
|
||||
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>
|
||||
<action-button
|
||||
v-access:code="['${permissionPrefix}:edit']"
|
||||
@click.stop="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</action-button>
|
||||
<Popconfirm placement="left" title="确认删除?" @confirm="handleDelete(row)">
|
||||
<action-button
|
||||
danger
|
||||
v-access:code="['${permissionPrefix}:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</action-button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<${BusinessName}${PopupComponent} @reload="tableApi.query()" />
|
||||
</Page>
|
||||
</template>
|
||||
376
scripts/代码生成模板antdv-next专用/vben5/views/popup.vue.vm
Normal file
376
scripts/代码生成模板antdv-next专用/vben5/views/popup.vue.vm
Normal file
@@ -0,0 +1,376 @@
|
||||
#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 { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||
|
||||
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 { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||
{
|
||||
initializedGetter: defaultFormValueGetter(formApi),
|
||||
currentGetter: defaultFormValueGetter(formApi),
|
||||
},
|
||||
);
|
||||
|
||||
const [Basic${PopupComponent}, ${popupComponent}Api] = useVben${PopupComponent}({
|
||||
// 在这里更改宽度
|
||||
class: 'w-[550px]',
|
||||
fullscreenButton: false,
|
||||
onBeforeClose,
|
||||
onClosed: handleClosed,
|
||||
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 markInitialized();
|
||||
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
${popupComponent}Api.lock(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));
|
||||
resetInitialized();
|
||||
emit('reload');
|
||||
${popupComponent}Api.close();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
${popupComponent}Api.lock(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClosed() {
|
||||
await formApi.resetForm();
|
||||
resetInitialized();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Basic${PopupComponent} :title="title">
|
||||
<BasicForm />
|
||||
</Basic${PopupComponent}>
|
||||
</template>
|
||||
#else
|
||||
<!--
|
||||
使用antdv-next原生Form生成 详细用法参考antdv-next Form组件文档
|
||||
vscode默认配置文件会自动格式化/移除未使用依赖
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import type { FormInstance } from 'antdv-next';
|
||||
import type { Rule } from 'antdv-next/dist/form/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import {
|
||||
CheckboxGroup,
|
||||
DatePicker,
|
||||
Form,
|
||||
FormItem,
|
||||
Input,
|
||||
RadioGroup,
|
||||
Select,
|
||||
Textarea,
|
||||
} from 'antdv-next';
|
||||
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 { ${businessName}Add, ${businessName}Info, ${businessName}Update } from '#/api/${moduleName}/${businessName}';
|
||||
import type { ${BusinessName}Form } from '#/api/${moduleName}/${businessName}/model';
|
||||
import { useBeforeCloseDiff } from '#/utils/popup';
|
||||
|
||||
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, Rule[]>> & {
|
||||
[key: string]: Rule[];
|
||||
};
|
||||
/**
|
||||
* 表单校验规则
|
||||
*/
|
||||
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
|
||||
});
|
||||
|
||||
const formInstance = ref<FormInstance>();
|
||||
|
||||
function customFormValueGetter() {
|
||||
return JSON.stringify(formData.value);
|
||||
}
|
||||
|
||||
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||
{
|
||||
initializedGetter: customFormValueGetter,
|
||||
currentGetter: customFormValueGetter,
|
||||
},
|
||||
);
|
||||
|
||||
const [Basic${PopupComponent}, ${popupComponent}Api] = useVben${PopupComponent}({
|
||||
class: 'w-[550px]',
|
||||
fullscreenButton: false,
|
||||
onBeforeClose,
|
||||
onClosed: handleClosed,
|
||||
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 markInitialized();
|
||||
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
${popupComponent}Api.lock(true);
|
||||
await formInstance.value?.validate();
|
||||
// 可能会做数据处理 使用cloneDeep深拷贝
|
||||
const data = cloneDeep(formData.value);
|
||||
await (isUpdate.value ? ${businessName}Update(data) : ${businessName}Add(data));
|
||||
resetInitialized();
|
||||
emit('reload');
|
||||
${popupComponent}Api.close();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
${popupComponent}Api.lock(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClosed() {
|
||||
formData.value = defaultValues;
|
||||
formInstance.value?.resetFields();
|
||||
resetInitialized();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Basic${PopupComponent} :title="title">
|
||||
<Form :label-col="{ span: 4 }" ref="formInstance" :model="formData">
|
||||
#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}" name="${field}" :rules="formRules.${field}">
|
||||
<Input v-model:value="formData.${field}" :placeholder="$t('ui.formRules.required')" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "imageUpload")
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${field}">
|
||||
<!-- props参考apps/web-antd/src/components/upload/src/props.d.ts -->
|
||||
<!-- maxCount为1(默认)时只允许上传一个文件 会自动绑定为string而非string[] -->
|
||||
<ImageUpload :max-count="1" v-model:value="formData.${field}" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "fileUpload")
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${field}">
|
||||
<!-- props参考apps/web-antd/src/components/upload/src/props.d.ts -->
|
||||
<!-- maxCount为1(默认)时只允许上传一个文件 会自动绑定为string而非string[] -->
|
||||
<FileUpload :max-count="1" v-model:value="formData.${field}" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "editor")
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${field}">
|
||||
<Tinymce
|
||||
:disabled="false"
|
||||
v-model="formData.${field}"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "select" && "" != $dictType)
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${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}" name="${field}" :rules="formRules.${field}">
|
||||
<Select
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
:getPopupContainer="getPopupContainer"
|
||||
:placeholder="$t('ui.formRules.selectRequired')"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "checkbox" && "" != $dictType)
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${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}" name="${field}" :rules="formRules.${field}">
|
||||
<CheckboxGroup
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "radio" && "" != $dictType)
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${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}" name="${field}" :rules="formRules.${field}">
|
||||
<RadioGroup
|
||||
option-type="button"
|
||||
button-style="solid"
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "datetime")
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${field}">
|
||||
<!-- 需要自行调整参数 -->
|
||||
<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}" name="${field}" :rules="formRules.${field}">
|
||||
<Textarea
|
||||
v-model:value="formData.${field}"
|
||||
:placeholder="$t('ui.formRules.required')"
|
||||
:rows="4"
|
||||
/>
|
||||
</FormItem>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
</Form>
|
||||
</Basic${PopupComponent}>
|
||||
</template>
|
||||
#end
|
||||
412
scripts/代码生成模板antdv-next专用/vben5/views/popup_tree.vue.vm
Normal file
412
scripts/代码生成模板antdv-next专用/vben5/views/popup_tree.vue.vm
Normal file
@@ -0,0 +1,412 @@
|
||||
#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 { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||
|
||||
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 { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||
{
|
||||
initializedGetter: defaultFormValueGetter(formApi),
|
||||
currentGetter: defaultFormValueGetter(formApi),
|
||||
},
|
||||
);
|
||||
|
||||
const [Basic${PopupComponent}, ${popupComponent}Api] = useVben${PopupComponent}({
|
||||
// 在这里更改宽度
|
||||
class: 'w-[550px]',
|
||||
fullscreenButton: false,
|
||||
onBeforeClose,
|
||||
onClosed: handleClosed,
|
||||
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();
|
||||
await markInitialized();
|
||||
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
${popupComponent}Api.lock(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));
|
||||
resetInitialized();
|
||||
emit('reload');
|
||||
${popupComponent}Api.close();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
${popupComponent}Api.lock(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClosed() {
|
||||
await formApi.resetForm();
|
||||
resetInitialized();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Basic${PopupComponent} :title="title">
|
||||
<BasicForm />
|
||||
</Basic${PopupComponent}>
|
||||
</template>
|
||||
#else
|
||||
<!--
|
||||
使用antdv-next原生Form生成 详细用法参考antdv-next Form组件文档
|
||||
vscode默认配置文件会自动格式化/移除未使用依赖
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import type { FormInstance } from 'antdv-next';
|
||||
import type { Rule } from 'antdv-next/dist/form/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import {
|
||||
CheckboxGroup,
|
||||
DatePicker,
|
||||
Form,
|
||||
FormItem,
|
||||
Input,
|
||||
RadioGroup,
|
||||
Select,
|
||||
Textarea,
|
||||
TreeSelect,
|
||||
} from 'antdv-next';
|
||||
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 { ${businessName}Add, ${businessName}Info, ${businessName}List, ${businessName}Update } from '#/api/${moduleName}/${businessName}';
|
||||
import type { ${BusinessName}Form } from '#/api/${moduleName}/${businessName}/model';
|
||||
import { useBeforeCloseDiff } from '#/utils/popup';
|
||||
|
||||
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, Rule[]>> & {
|
||||
[key: string]: Rule[];
|
||||
};
|
||||
/**
|
||||
* 表单校验规则
|
||||
*/
|
||||
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
|
||||
});
|
||||
|
||||
const formInstance = ref<FormInstance>();
|
||||
|
||||
function customFormValueGetter() {
|
||||
return JSON.stringify(formData.value);
|
||||
}
|
||||
|
||||
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||
{
|
||||
initializedGetter: customFormValueGetter,
|
||||
currentGetter: customFormValueGetter,
|
||||
},
|
||||
);
|
||||
|
||||
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,
|
||||
onBeforeClose,
|
||||
onClosed: handleClosed,
|
||||
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();
|
||||
await markInitialized();
|
||||
|
||||
${popupComponent}Api.${popupComponent}Loading(false);
|
||||
},
|
||||
});
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
${popupComponent}Api.lock(true);
|
||||
await formInstance.value?.validate();
|
||||
// 可能会做数据处理 使用cloneDeep深拷贝
|
||||
const data = cloneDeep(formData.value);
|
||||
await (isUpdate.value ? ${businessName}Update(data) : ${businessName}Add(data));
|
||||
resetInitialized();
|
||||
emit('reload');
|
||||
${popupComponent}Api.close();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
${popupComponent}Api.lock(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleClosed() {
|
||||
formData.value = defaultValues;
|
||||
formInstance.value?.resetFields();
|
||||
resetInitialized();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Basic${PopupComponent} :title="title">
|
||||
<Form :label-col="{ span: 4 }" ref="formInstance" :model="formData">
|
||||
#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}" name="${field}" :rules="formRules.${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}" name="${field}" :rules="formRules.${field}">
|
||||
<Input v-model:value="formData.${field}" :placeholder="$t('ui.formRules.required')" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "imageUpload")
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${field}">
|
||||
<!-- props参考apps/web-antd/src/components/upload/src/props.d.ts -->
|
||||
<!-- maxCount为1(默认)时只允许上传一个文件 会自动绑定为string而非string[] -->
|
||||
<ImageUpload :max-count="1" v-model:value="formData.${field}" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "fileUpload")
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${field}">
|
||||
<!-- props参考apps/web-antd/src/components/upload/src/props.d.ts -->
|
||||
<!-- maxCount为1(默认)时只允许上传一个文件 会自动绑定为string而非string[] -->
|
||||
<FileUpload :max-count="1" v-model:value="formData.${field}" />
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "editor")
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${field}">
|
||||
<Tinymce
|
||||
:disabled="false"
|
||||
v-model="formData.${field}"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "select" && "" != $dictType)
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${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}" name="${field}" :rules="formRules.${field}">
|
||||
<Select
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
:getPopupContainer="getPopupContainer"
|
||||
:placeholder="$t('ui.formRules.selectRequired')"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "checkbox" && "" != $dictType)
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${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}" name="${field}" :rules="formRules.${field}">
|
||||
<CheckboxGroup
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "radio" && "" != $dictType)
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${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}" name="${field}" :rules="formRules.${field}">
|
||||
<RadioGroup
|
||||
option-type="button"
|
||||
button-style="solid"
|
||||
v-model:value="formData.${field}"
|
||||
:options="[]"
|
||||
/>
|
||||
</FormItem>
|
||||
#elseif($column.htmlType == "datetime")
|
||||
<FormItem label="${comment}" name="${field}" :rules="formRules.${field}">
|
||||
<!-- 需要自行调整参数 -->
|
||||
<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}" name="${field}" :rules="formRules.${field}">
|
||||
<Textarea
|
||||
v-model:value="formData.${field}"
|
||||
:placeholder="$t('ui.formRules.required')"
|
||||
:rows="4"
|
||||
/>
|
||||
</FormItem>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
</Form>
|
||||
</Basic${PopupComponent}>
|
||||
</template>
|
||||
#end
|
||||
29
scripts/代码生成模板antdv-next专用/更新指南.md
Normal file
29
scripts/代码生成模板antdv-next专用/更新指南.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# 更新指南
|
||||
|
||||
**使用最新前端版本(>=2025 年 03 月 13 日提交)可以忽略该指南**
|
||||
|
||||
**使用最新前端版本(>=2025 年 03 月 13 日提交)可以忽略该指南**
|
||||
|
||||
**使用最新前端版本(>=2025 年 03 月 13 日提交)可以忽略该指南**
|
||||
|
||||
## 前言
|
||||
|
||||
最新版本已经支持`useVbenForm`/`原生antd表单` 两种表单生成方式, 需要做的改动可参考
|
||||
|
||||
如果你使用的代码版本 **>=2025 年 03 月 13 日提交** 可以直接跳过
|
||||
|
||||
## 后端
|
||||
|
||||
还是按`README.md`文档将`VelocityUtils.java`替换(必要操作)
|
||||
|
||||
## 前端
|
||||
|
||||
这里分几种情况
|
||||
|
||||
1. 我可以正常合并最新代码
|
||||
|
||||
那么开箱即用 直接 merge 最新代码后使用
|
||||
|
||||
2. 我的项目已经改动太多, 无法合并或者不需要升级, 但仍想用最新代码生成功能
|
||||
|
||||
由于只涉及到`代码生成相关功能`, 可以将最新版本的 zip 包下载 把`apps/web-antd/src/views/tool`文件夹替换覆盖即可
|
||||
Reference in New Issue
Block a user