新增 listselect 代码生成模板。
This commit is contained in:
@@ -424,7 +424,7 @@ public class EmpUserController extends BaseController {
|
||||
@RequestMapping(value = "empUserSelect")
|
||||
public String empUserSelect(EmpUser empUser, String selectData, Model model) {
|
||||
String selectDataJson = EncodeUtils.decodeUrl(selectData);
|
||||
if (JSONValidator.from(selectDataJson).validate()){
|
||||
if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()){
|
||||
model.addAttribute("selectData", selectDataJson);
|
||||
}
|
||||
model.addAttribute("empUser", empUser);
|
||||
|
||||
@@ -200,7 +200,7 @@ public class UserController extends BaseController {
|
||||
@RequestMapping(value = "userSelect")
|
||||
public String userSelect(User user, String selectData, Model model) {
|
||||
String selectDataJson = EncodeUtils.decodeUrl(selectData);
|
||||
if (JSONValidator.from(selectDataJson).validate()){
|
||||
if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()){
|
||||
model.addAttribute("selectData", selectDataJson);
|
||||
}
|
||||
model.addAttribute("user", user);
|
||||
|
||||
@@ -14,7 +14,14 @@
|
||||
<template>category-ref:dao</template>
|
||||
</childTable>
|
||||
</category>
|
||||
<category value="crud_cloud" label="单表/主子表 (增删改查 Cloud)">
|
||||
<category value="crud_select" label="单表/主子表 (增删改查,含 listselect 选择页面)">
|
||||
<template>category-ref:crud</template>
|
||||
<template>crud/viewSelect.xml</template>
|
||||
<childTable>
|
||||
<template>category-ref:dao</template>
|
||||
</childTable>
|
||||
</category>
|
||||
<category value="crud_cloud" label="单表/主子表 (增删改查 Cloud,生成 Api/Client)">
|
||||
<template>crud/mapper.xml</template>
|
||||
<template>crud_cloud/entity.xml</template>
|
||||
<template>crud/dao.xml</template>
|
||||
@@ -33,19 +40,19 @@
|
||||
<category value="treeGrid" label="树表/树结构表(增删改查)">
|
||||
<template>category-ref:crud</template>
|
||||
</category>
|
||||
<category value="treeGrid_cloud" label="树表/树结构表(增删改查 Cloud)">
|
||||
<category value="treeGrid_cloud" label="树表/树结构表(增删改查 Cloud,生成 Api/Client)">
|
||||
<template>category-ref:crud</template>
|
||||
</category>
|
||||
<category value="service" label="业务层和持久层(不含控制器和视图)">
|
||||
<category value="service" label="业务层和持久层(dao/service,不含控制器和视图)">
|
||||
<template>category-ref:dao</template>
|
||||
<template>crud/service.xml</template>
|
||||
</category>
|
||||
<category value="dao" label="仅持久层(dao/mapper/entity)">
|
||||
<category value="dao" label="关系表/仅持久层(dao/mapper/entity)">
|
||||
<template>crud/mapper.xml</template>
|
||||
<template>crud/entity.xml</template>
|
||||
<template>crud/dao.xml</template>
|
||||
</category>
|
||||
<category value="query" label="仅查询功能(不含增删改)">
|
||||
<category value="query" label="仅查询功能(不含增删改,仅数据展现)">
|
||||
<template>crud/mapper.xml</template>
|
||||
<template>crud/entity.xml</template>
|
||||
<template>query/dao.xml</template>
|
||||
|
||||
@@ -39,6 +39,10 @@ import com.jeesite.modules.sys.utils.UserUtils;
|
||||
<% }else{ %>
|
||||
import com.jeesite.common.entity.Page;
|
||||
<% } %>
|
||||
<% if (table.tplCategory == 'crud_select'){ %>
|
||||
import com.alibaba.fastjson.JSONValidator;
|
||||
import com.jeesite.common.codec.EncodeUtils;
|
||||
<% } %>
|
||||
import com.jeesite.common.web.BaseController;
|
||||
import ${packageName}.${moduleName}.entity${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${ClassName};
|
||||
import ${packageName}.${moduleName}.service${isNotEmpty(subModuleName)?'.'+subModuleName:''}.${ClassName}Service;
|
||||
@@ -276,6 +280,22 @@ public class ${ClassName}Controller extends BaseController {
|
||||
return renderResult(Global.TRUE, "数据修复成功");
|
||||
}
|
||||
<% } %>
|
||||
<% if (table.tplCategory == 'crud_select'){ %>
|
||||
|
||||
/**
|
||||
* 列表选择对话框
|
||||
*/
|
||||
@RequiresPermissions("${permissionPrefix}:view")
|
||||
@RequestMapping(value = "${className}Select")
|
||||
public String empUserSelect(${ClassName} ${className}, String selectData, Model model) {
|
||||
String selectDataJson = EncodeUtils.decodeUrl(selectData);
|
||||
if (selectDataJson != null && JSONValidator.from(selectDataJson).validate()){
|
||||
model.addAttribute("selectData", selectDataJson);
|
||||
}
|
||||
model.addAttribute("${ClassName}", ${className});
|
||||
return "${lastPackageName}/${viewPrefix}Select";
|
||||
}
|
||||
<% } %>
|
||||
|
||||
}]]>
|
||||
</content>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2013-Now http://jeesite.com All rights reserved. -->
|
||||
<template>
|
||||
<name>viewSelect</name>
|
||||
<filePath>src/main/resources/views/${lastPackageName}/${moduleName}/${subModuleName}</filePath>
|
||||
<fileName>${className}Select.html</fileName>
|
||||
<content><![CDATA[
|
||||
\<% layout('/layouts/default.html', {title: '${functionNameSimple}管理', libs: ['dataGrid']}){ %>
|
||||
<div class="main-content">
|
||||
<div class="box box-main">
|
||||
<div class="box-body">
|
||||
<% include('/templates/modules/gen/include/searchForm.html'){} %>
|
||||
<div class="row">
|
||||
<div class="col-xs-10 pr10">
|
||||
<table id="dataGrid"></table>
|
||||
<% if(!table.isTreeEntity){ %>
|
||||
<div id="dataGridPage"></div>
|
||||
<% } %>
|
||||
</div>
|
||||
<div class="col-xs-2 pl0">
|
||||
<div id="selectData" class="tags-input"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
\<% } %>
|
||||
<% include('/templates/modules/gen/include/dataGridSelectScript.html'){} %>]]>
|
||||
</content>
|
||||
</template>
|
||||
@@ -0,0 +1,149 @@
|
||||
<script>
|
||||
var selectData = \${isNotBlank(selectData!) ? selectData! : "{\}"},
|
||||
selectNum = 0, dataGrid = $('#dataGrid').dataGrid({
|
||||
searchForm: $("#searchForm"),
|
||||
columnModel: [
|
||||
<%
|
||||
// 是否是第一列
|
||||
var firstColumn = true;
|
||||
var firstColumnName = "";
|
||||
// 生成树表的节点列
|
||||
if(table.isTreeEntity){
|
||||
for(c in table.columnList){
|
||||
if(c.attrName == table.treeViewNameAttrName){
|
||||
%>
|
||||
{header:'\${text("${c.columnLabel}")}', name:'${c.attrName}', index:'a.${c.columnName}', width:250, align:"left", frozen:true, formatter: function(val, obj, row, act){
|
||||
return '( '+row.${table.treeViewCodeAttrName}+' ) '+(val||row.id);
|
||||
}},
|
||||
<%
|
||||
firstColumn = false;
|
||||
firstColumnName = c.attrName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
<%
|
||||
for(c in table.columnList){
|
||||
if(c.isList == "1"){
|
||||
// 如果是树结构的字段,则自动忽略
|
||||
if(table.isTreeEntity && @StringUtils.inString(c.columnName, 'parent_code',
|
||||
'parent_codes', 'tree_sorts', 'tree_leaf', 'tree_level', 'tree_names')
|
||||
&& c.attrName != table.treeViewCodeAttrName
|
||||
&& c.attrName != table.treeViewNameAttrName){
|
||||
}
|
||||
// 如果是首列,则输出带链接的列
|
||||
else if(firstColumn){
|
||||
firstColumn = false;
|
||||
firstColumnName = c.attrName;
|
||||
%>
|
||||
{header:'\${text("${c.columnLabel}")}', name:'${c.attrName}', index:'a.${c.columnName}', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
|
||||
return (val||row.id);
|
||||
}},
|
||||
<% }else if(c.showType == 'select' || c.showType == 'select_multiple' || c.showType == 'checkbox' || c.showType == 'radio'){ %>
|
||||
{header:'\${text("${c.columnLabel}")}', name:'${c.attrName}', index:'a.${c.columnName}', width:150, align:"center", formatter: function(val, obj, row, act){
|
||||
return js.getDictLabel(\${@DictUtils.getDictListJson('${c.optionMap['dictType']}')}, val, '\${text("未知")}', true);
|
||||
}},
|
||||
<% }else if(c.showType == "userselect" || c.showType == "officeselect" || c.showType == "areaselect"){ %>
|
||||
{header:'\${text("${c.columnLabel}")}', name:'${c.attrName2}', index:'a.${c.columnName}', width:150, align:"center"},
|
||||
<% }else{
|
||||
if (@StringUtils.inString(c.attrType, 'java.util.Date', 'Integer', 'Long')){
|
||||
%>
|
||||
{header:'\${text("${c.columnLabel}")}', name:'${c.attrName}', index:'a.${c.columnName}', width:150, align:"center"},
|
||||
<%
|
||||
}else if (@StringUtils.inString(c.attrType, 'Float', 'Double')){
|
||||
%>
|
||||
{header:'\${text("${c.columnLabel}")}', name:'${c.attrName}', index:'a.${c.columnName}', width:150, align:"right", formatter: function(val, obj, row, act){
|
||||
return js.formatNumber(val, 2, false, ''); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值,金额情况下设置0.00);
|
||||
}},
|
||||
<%
|
||||
}else {
|
||||
%>
|
||||
{header:'\${text("${c.columnLabel}")}', name:'${c.attrName}', index:'a.${c.columnName}', width:150, align:"left"},
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
{header:'行数据', name:'rowData', hidden:true, formatter: function(val, obj, row, act){
|
||||
return JSON.stringify(row);
|
||||
}}
|
||||
],
|
||||
<% if(table.isTreeEntity){ %>
|
||||
treeGrid: true, // 启用树结构表格
|
||||
defaultExpandLevel: 0, // 默认展开的层次
|
||||
expandNodeClearPostData: '<%
|
||||
for(c in table.columnList){
|
||||
if(c.isQuery == "1" && !c.isTreeEntityColumn && c.attrName != 'status'){
|
||||
print(c.attrName + ',');
|
||||
}
|
||||
} %>', // 展开节点清理请求参数数据(一般设置查询条件的字段属性,否则在查询后,不能展开子节点数据)
|
||||
<% } %>
|
||||
autoGridHeight: function(){
|
||||
var height = $(window).height() - $('#searchForm').height() - $('#dataGridPage').height() - 74;
|
||||
$('.tags-input').height($('.ui-jqgrid').height() - 10);
|
||||
return height;
|
||||
},
|
||||
showCheckbox: '\${parameter.checkbox}' == 'true',
|
||||
multiboxonly: false, // 单击复选框时再多选
|
||||
ajaxSuccess: function(data){
|
||||
$.each(selectData, function(key, value){
|
||||
dataGrid.dataGrid('setSelectRow', key);
|
||||
});
|
||||
initSelectTag();
|
||||
},
|
||||
onSelectRow: function(id, isSelect, event){
|
||||
if ('\${parameter.checkbox}' == 'true'){
|
||||
if(isSelect){
|
||||
selectData[id] = JSON.parse(dataGrid.dataGrid('getRowData', id).rowData);
|
||||
}else{
|
||||
delete selectData[id];
|
||||
}
|
||||
}else{
|
||||
selectData = {};
|
||||
selectData[id] = JSON.parse(dataGrid.dataGrid('getRowData', id).rowData);
|
||||
}
|
||||
initSelectTag();
|
||||
},
|
||||
onSelectAll: function(ids, isSelect){
|
||||
if ('\${parameter.checkbox}' == 'true'){
|
||||
for (var i=0; i<ids.length; i++){
|
||||
if(isSelect){
|
||||
selectData[ids[i]] = JSON.parse(dataGrid.dataGrid('getRowData', ids[i]).rowData);
|
||||
}else{
|
||||
delete selectData[ids[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
initSelectTag();
|
||||
},
|
||||
ondblClickRow: function(id, rownum, colnum, event){
|
||||
if ('\${parameter.checkbox}' != 'true'){
|
||||
js.layer.$('#' + window.name).closest('.layui-layer')
|
||||
.find(".layui-layer-btn0").trigger("click");
|
||||
}
|
||||
initSelectTag();
|
||||
}
|
||||
});
|
||||
function initSelectTag(){
|
||||
selectNum = 0;
|
||||
var html = [];
|
||||
$.each(selectData, function(key, value){
|
||||
selectNum ++;
|
||||
html.push('<span class="tag" id="'+key+'_tags-input"><span>'+(value.${firstColumnName}||value.id)+' </span>'
|
||||
+ '<a href="#" onclick="removeSelectTag(\''+key+'\');" title="\${text("取消选择")}">x</a></span>');
|
||||
});
|
||||
html.unshift('<div class="title">\${text("当前已选择 {0\} 项", "<span id=\"selectNum\">'+selectNum+'</span>")}:</div>');
|
||||
$('#selectData').empty().append(html.join(''));
|
||||
}
|
||||
function removeSelectTag(key){
|
||||
delete selectData[key];
|
||||
dataGrid.dataGrid('resetSelection', key);
|
||||
$('#selectNum').html(--selectNum);
|
||||
$('#'+key+'_tags-input').remove();
|
||||
}
|
||||
function getSelectData(){
|
||||
return selectData;
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user