新增代码生成详情页功能

master
RuoYi 3 weeks ago
parent 99daf649da
commit ba90333076

@ -31,6 +31,9 @@ public class GenConstants
/** 上级菜单名称字段 */ /** 上级菜单名称字段 */
public static final String PARENT_MENU_NAME = "parentMenuName"; public static final String PARENT_MENU_NAME = "parentMenuName";
/** 生成详情页开关 */
public static final String GEN_VIEW = "genView";
/** 数据库字符串类型 */ /** 数据库字符串类型 */
public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" }; public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" };

@ -98,6 +98,9 @@ public class GenTable extends BaseEntity
/** 上级菜单名称字段 */ /** 上级菜单名称字段 */
private String parentMenuName; private String parentMenuName;
/** 是否生成详情页 */
private boolean isView;
public Long getTableId() public Long getTableId()
{ {
return tableId; return tableId;
@ -338,6 +341,16 @@ public class GenTable extends BaseEntity
this.parentMenuName = parentMenuName; this.parentMenuName = parentMenuName;
} }
public boolean isView()
{
return isView;
}
public void setView(boolean isView)
{
this.isView = isView;
}
public boolean isSub() public boolean isSub()
{ {
return isSub(this.tplCategory); return isSub(this.tplCategory);

@ -219,7 +219,7 @@ public class GenTableServiceImpl implements IGenTableService
VelocityContext context = VelocityUtils.prepareContext(table); VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表 // 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); List<String> templates = VelocityUtils.getTemplateList(table);
for (String template : templates) for (String template : templates)
{ {
// 渲染模板 // 渲染模板
@ -267,7 +267,7 @@ public class GenTableServiceImpl implements IGenTableService
VelocityContext context = VelocityUtils.prepareContext(table); VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表 // 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); List<String> templates = VelocityUtils.getTemplateList(table);
for (String template : templates) for (String template : templates)
{ {
if (!StringUtils.contains(template, "sql.vm")) if (!StringUtils.contains(template, "sql.vm"))
@ -380,7 +380,7 @@ public class GenTableServiceImpl implements IGenTableService
VelocityContext context = VelocityUtils.prepareContext(table); VelocityContext context = VelocityUtils.prepareContext(table);
// 获取模板列表 // 获取模板列表
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); List<String> templates = VelocityUtils.getTemplateList(table);
for (String template : templates) for (String template : templates)
{ {
// 渲染模板 // 渲染模板
@ -506,12 +506,14 @@ public class GenTableServiceImpl implements IGenTableService
String treeName = paramsObj.getString(GenConstants.TREE_NAME); String treeName = paramsObj.getString(GenConstants.TREE_NAME);
String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID); String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME); String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
boolean isView = paramsObj.getBooleanValue(GenConstants.GEN_VIEW);
genTable.setTreeCode(treeCode); genTable.setTreeCode(treeCode);
genTable.setTreeParentCode(treeParentCode); genTable.setTreeParentCode(treeParentCode);
genTable.setTreeName(treeName); genTable.setTreeName(treeName);
genTable.setParentMenuId(parentMenuId); genTable.setParentMenuId(parentMenuId);
genTable.setParentMenuName(parentMenuName); genTable.setParentMenuName(parentMenuName);
genTable.setView(isView);
} }
} }

@ -58,6 +58,7 @@ public class VelocityUtils
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
velocityContext.put("columns", genTable.getColumns()); velocityContext.put("columns", genTable.getColumns());
velocityContext.put("table", genTable); velocityContext.put("table", genTable);
setExtensionsContext(velocityContext, genTable.getOptions());
setMenuVelocityContext(velocityContext, genTable); setMenuVelocityContext(velocityContext, genTable);
if (GenConstants.TPL_TREE.equals(tplCategory)) if (GenConstants.TPL_TREE.equals(tplCategory))
{ {
@ -70,6 +71,13 @@ public class VelocityUtils
return velocityContext; return velocityContext;
} }
public static void setExtensionsContext(VelocityContext context, String options)
{
JSONObject paramsObj = JSONObject.parseObject(options);
boolean genView = genView(paramsObj);
context.put("genView", genView);
}
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
{ {
String options = genTable.getOptions(); String options = genTable.getOptions();
@ -123,8 +131,11 @@ public class VelocityUtils
* *
* @return * @return
*/ */
public static List<String> getTemplateList(String tplCategory) public static List<String> getTemplateList(GenTable table)
{ {
String tplCategory = table.getTplCategory();
JSONObject paramsObj = JSONObject.parseObject(table.getOptions());
boolean isView = genView(paramsObj);
List<String> templates = new ArrayList<String>(); List<String> templates = new ArrayList<String>();
templates.add("vm/java/domain.java.vm"); templates.add("vm/java/domain.java.vm");
templates.add("vm/java/mapper.java.vm"); templates.add("vm/java/mapper.java.vm");
@ -146,6 +157,10 @@ public class VelocityUtils
templates.add("vm/html/list.html.vm"); templates.add("vm/html/list.html.vm");
templates.add("vm/java/sub-domain.java.vm"); templates.add("vm/java/sub-domain.java.vm");
} }
if (isView)
{
templates.add("vm/html/view.html.vm");
}
templates.add("vm/html/add.html.vm"); templates.add("vm/html/add.html.vm");
templates.add("vm/html/edit.html.vm"); templates.add("vm/html/edit.html.vm");
templates.add("vm/sql/sql.vm"); templates.add("vm/sql/sql.vm");
@ -220,6 +235,10 @@ public class VelocityUtils
{ {
fileName = StringUtils.format("{}/edit.html", htmlPath); fileName = StringUtils.format("{}/edit.html", htmlPath);
} }
else if (template.contains("view.html.vm"))
{
fileName = StringUtils.format("{}/view.html", htmlPath);
}
else if (template.contains("sql.vm")) else if (template.contains("sql.vm"))
{ {
fileName = businessName + "Menu.sql"; fileName = businessName + "Menu.sql";
@ -342,6 +361,21 @@ public class VelocityUtils
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
/**
* /
*
* @param paramsObj
* @return
*/
public static boolean genView(JSONObject paramsObj)
{
if (paramsObj.containsKey(GenConstants.GEN_VIEW))
{
return paramsObj.getBoolean(GenConstants.GEN_VIEW);
}
return false;
}
/** /**
* *
* *

@ -4,7 +4,7 @@
<th:block th:include="include :: header('修改生成信息')" /> <th:block th:include="include :: header('修改生成信息')" />
<th:block th:include="include :: select2-css" /> <th:block th:include="include :: select2-css" />
<style type="text/css"> <style type="text/css">
.select-table table{table-layout:fixed;}.table>thead>tr>th{text-align:center;}.select-table .table td{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.form-control{padding:3px 6px 4px;height:30px;}.icheckbox-blue{top:0px;left:6px;}.form-control.select2-hidden-accessible{position:static!important;}.select-table table label.error{position: inherit;}select + label.error{z-index:1;right:40px;} .select-table table{table-layout:fixed;}.table>thead>tr>th{text-align:center;}.select-table .table td{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}.form-control{padding:3px 6px 4px;height:30px;}.table .icheckbox-blue{top:0px;left:6px;}.form-control.select2-hidden-accessible{position:static!important;}.select-table table label.error{position: inherit;}select + label.error{z-index:1;right:40px;}
</style> </style>
</head> </head>
<body class="gray-bg" style="font: 14px Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif !important;"> <body class="gray-bg" style="font: 14px Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif !important;">
@ -146,6 +146,18 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label class="col-sm-2 control-label">扩展功能:</label>
<div class="col-sm-10">
<label class="check-box">
<input type="checkbox" name="params[genView]" value="1" th:checked="${table.view}"> 生成详情页
</label>
</div>
</div>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-sm-6"> <div class="col-sm-6">
<div class="form-group"> <div class="form-group">

@ -100,6 +100,9 @@
expandColumn: "${expandColumn}", expandColumn: "${expandColumn}",
uniqueId: "${pkColumn.javaField}", uniqueId: "${pkColumn.javaField}",
url: prefix + "/list", url: prefix + "/list",
#if($genView)
viewUrl: prefix + "/view/{id}",
#end
createUrl: prefix + "/add/{id}", createUrl: prefix + "/add/{id}",
updateUrl: prefix + "/edit/{id}", updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove/{id}", removeUrl: prefix + "/remove/{id}",
@ -141,6 +144,9 @@
align: 'left', align: 'left',
formatter: function(value, row, index) { formatter: function(value, row, index) {
var actions = []; var actions = [];
#if($genView)
actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.operate.view(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-eye"></i>查看</a> ');
#end
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-edit"></i>编辑</a> '); actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-plus"></i>新增</a> '); actions.push('<a class="btn btn-info btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-plus"></i>新增</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-remove"></i>删除</a>'); actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-remove"></i>删除</a>');

@ -98,6 +98,9 @@
$(function() { $(function() {
var options = { var options = {
url: prefix + "/list", url: prefix + "/list",
#if($genView)
viewUrl: prefix + "/view/{id}",
#end
createUrl: prefix + "/add", createUrl: prefix + "/add",
updateUrl: prefix + "/edit/{id}", updateUrl: prefix + "/edit/{id}",
removeUrl: prefix + "/remove", removeUrl: prefix + "/remove",
@ -141,6 +144,9 @@
align: 'center', align: 'center',
formatter: function(value, row, index) { formatter: function(value, row, index) {
var actions = []; var actions = [];
#if($genView)
actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.operate.view(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-eye"></i>查看</a> ');
#end
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-edit"></i>编辑</a> '); actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-remove"></i>删除</a>'); actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.${pkColumn.javaField} + '\')"><i class="fa fa-remove"></i>删除</a>');
return actions.join(''); return actions.join('');

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('${functionName}详细')" />
</head>
<body>
<div class="main-content">
<form class="form-horizontal" th:object="${${className}}">
<h4 class="form-header h4">基本信息</h4>
#set($i = 0)
#foreach($column in $columns)
#if(!$column.pk && $column.list)
#set($dictType=$column.dictType)
#set($javaField=$column.javaField)
#set($parentheseIndex=$column.columnComment.indexOf(""))
#if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else
#set($comment=$column.columnComment)
#end
#if($i % 2 == 0)
<div class="row">
#end
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-4 control-label">${comment}</label>
<div class="col-sm-8">
#if("" != $dictType)
<p class="form-control-plaintext" th:text="*{@dict.getLabel('${dictType}', ${javaField})}"></p>
#elseif($column.javaType == "Date")
<p class="form-control-plaintext" th:text="*{#dates.format(${javaField}, 'yyyy-MM-dd HH:mm:ss')}"></p>
#else
<p class="form-control-plaintext" th:text="*{${javaField}}"></p>
#end
</div>
</div>
</div>
#set($i = $i + 1)
#if($i % 2 == 0)
</div>
#end
#end
#end
#if($i % 2 != 0)
</div>
#end
</form>
</div>
<th:block th:include="include :: footer" />
</body>
</html>

@ -86,6 +86,20 @@ public class ${ClassName}Controller extends BaseController
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class); ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
return util.exportExcel(list, "${functionName}数据"); return util.exportExcel(list, "${functionName}数据");
} }
#if($genView)
/**
* 查看${functionName}详情
*/
@RequiresPermissions("${permissionPrefix}:view")
@GetMapping("/view/{${pkColumn.javaField}}")
public String view(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}, ModelMap mmap)
{
${ClassName} ${className} = ${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField});
mmap.put("${className}", ${className});
return prefix + "/view";
}
#end
#if($table.crud || $table.sub) #if($table.crud || $table.sub)
/** /**

Loading…
Cancel
Save