新增 form:treeselect 组件 fieldNames 属性,自定义数据源的字段名

This commit is contained in:
thinkgem
2025-01-28 11:41:17 +08:00
parent 4287437d2e
commit 4e6f27a2ab
2 changed files with 16 additions and 11 deletions

View File

@@ -39,6 +39,7 @@ var p = {
checkbox: toBoolean(checkbox!false), // 是否显示复选框是否支持多选如果设置canSelectParent=true则返回父节点数据 checkbox: toBoolean(checkbox!false), // 是否显示复选框是否支持多选如果设置canSelectParent=true则返回父节点数据
chkboxType: chkboxType!'', // 复选框级联选择规则 v4.0.6,默认:{'Y':'ps','N':'ps'} chkboxType: chkboxType!'', // 复选框级联选择规则 v4.0.6,默认:{'Y':'ps','N':'ps'}
fieldNames: fieldNames!'', // 自定义字段名 v5.10.1,默认:{'id':'id','pId':'pId','name':'name','title':'title'}
expandLevel: @ObjectUtils.toInteger(expandLevel!(-1)), // 默认展开层次级别(默认:如果有1个根节点则展开一级节点否则不展开 expandLevel: @ObjectUtils.toInteger(expandLevel!(-1)), // 默认展开层次级别(默认:如果有1个根节点则展开一级节点否则不展开
canSelectRoot: toBoolean(canSelectRoot!false), // 可以选择跟节点 canSelectRoot: toBoolean(canSelectRoot!false), // 可以选择跟节点
@@ -95,7 +96,7 @@ $("#${p.id}Button${p.allowInput?'':',#'+p.id+'Name'}").click(function(){
if ($("#${p.id}Button").hasClass("disabled") || $("#${p.id}Name").hasClass("disabled")){ if ($("#${p.id}Button").hasClass("disabled") || $("#${p.id}Name").hasClass("disabled")){
return true; return true;
} }
var options = { var fieldNames = /*<% if(isNotBlank(p.fieldNames!)){ %>*/"#{p.fieldNames!}"/*<% }else{ %>*/{}/*<% } %>*/, options = {
type: 2, type: 2,
maxmin: true, maxmin: true,
shadeClose: true, shadeClose: true,
@@ -106,6 +107,7 @@ $("#${p.id}Button${p.allowInput?'':',#'+p.id+'Name'}").click(function(){
url: $('#${p.id}Div').attr('data-url'), url: $('#${p.id}Div').attr('data-url'),
checkbox: '${p.checkbox}', checkbox: '${p.checkbox}',
chkboxType: "${p.chkboxType}", chkboxType: "${p.chkboxType}",
fieldNames: "${p.fieldNames}",
expandLevel: '${p.expandLevel}', expandLevel: '${p.expandLevel}',
selectCodes: $("#${p.id}Code").val(), selectCodes: $("#${p.id}Code").val(),
isReturnValue: '${p.isReturnValue}', isReturnValue: '${p.isReturnValue}',
@@ -136,22 +138,23 @@ $("#${p.id}Button${p.allowInput?'':',#'+p.id+'Name'}").click(function(){
//# } // 不允许选择跟节点 //# } // 不允许选择跟节点
//# if (!p.canSelectRoot){ //# if (!p.canSelectRoot){
if (nodes[i].level == 0 && nodes[i].isParent){ if (nodes[i].level == 0 && nodes[i].isParent){
js.showMessage("${text('不能选择根节点')}"+nodes[i].name+"${text('请重新选择')}。"); js.showMessage("${text('不能选择根节点')}"+nodes[i][fieldNames.name||'name']+"${text('请重新选择')}。");
return false; return false;
} }
//# } // 不允许选择父节点 //# } // 不允许选择父节点
//# if (!p.canSelectParent){ //# if (!p.canSelectParent){
if (nodes[i].isParent){ if (nodes[i].isParent){
js.showMessage("${text('不能选择父节点')}"+nodes[i].name+"${text('请重新选择')}。"); js.showMessage("${text('不能选择父节点')}"+nodes[i][fieldNames.name||'name']+"${text('请重新选择')}。");
return false; return false;
} }
//# } //# }
var code = nodes[i]['${p.isReturnValue!}'=='true'?'value':'id'], name = nodes[i]['name']; var code = nodes[i][fieldNames.id||('${p.isReturnValue!}'=='true'?'value':'id')],
name = nodes[i][fieldNames.name||'name'];
//# // 如果是返回全部路径的名称,则读取名称路径 //# // 如果是返回全部路径的名称,则读取名称路径
//# if (p.returnFullName){ //# if (p.returnFullName){
var pNode = nodes[i].getParentNode(); var pNode = nodes[i].getParentNode();
while(!!pNode) { while(!!pNode) {
name = pNode.name + '${p.returnFullNameSplit}' + name; name = pNode[fieldNames.name||'name'] + '${p.returnFullNameSplit}' + name;
pNode = pNode.getParentNode(); pNode = pNode.getParentNode();
} }
//# } //# }

View File

@@ -17,14 +17,16 @@
<div id="tree" class="ztree treeselect"></div> <div id="tree" class="ztree treeselect"></div>
<% } %> <% } %>
<script> <script>
var selectCodes = "${selectCodes!}".split(","), setting = { var selectCodes = "${selectCodes!}".split(","), fieldNames = /*<% if(isNotBlank(fieldNames!)){
view:{selectedMulti:false,dblClickExpand:false}, fieldNames = toJson(fromJson(fieldNames!, 'map')); // 转换一遍防止XSS注入
} if(isNotBlank(fieldNames!)){ %>*/"#{fieldNames!}"/*<% }else{ %>*/{}/*<% } %>*/, setting = {
check:{enable:"${checkbox!}"=="true",nocheckInherit:true/*<% if(isNotBlank(chkboxType!)){ check:{enable:"${checkbox!}"=="true",nocheckInherit:true/*<% if(isNotBlank(chkboxType!)){
chkboxType = toJson(fromJson(chkboxType!, 'map')); // 转换一遍防止XSS注入 chkboxType = toJson(fromJson(chkboxType!, 'map')); // 转换一遍防止XSS注入
if(isNotBlank(chkboxType!)){ %>*/,chkboxType:"#{chkboxType!}"/*<% } } %>*/}, } if(isNotBlank(chkboxType!)){ %>*/,chkboxType:"#{chkboxType!}"/*<% } %>*/},
async:{enable:true,autoParam:["id=parentCode"], async:{enable:true,autoParam:["id=parentCode"], url:js.removeParam('parentCode', "${url!}")},
url:js.removeParam('parentCode', "${url!}")}, data:{simpleData:{enable:true,idKey:fieldNames.id||'id',pIdKey:fieldNames.pId||'pId'},
data:{simpleData:{enable:true}},callback:{ key:{name:fieldNames.name||'name',title:fieldNames.title||'title'}},
view:{selectedMulti:false,dblClickExpand:false}, callback:{
onClick:function(event, treeId, treeNode){ onClick:function(event, treeId, treeNode){
tree.expandNode(treeNode); tree.expandNode(treeNode);
}, },