open beetl functions form

This commit is contained in:
thinkgem
2024-07-22 15:39:44 +08:00
parent ccc3ea6894
commit 7ce1f84866
3 changed files with 124 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<%/* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law. */
/**
* 编译控件属性
* @author ThinkGem
* @version 2019-3-5
*/
var p = para0;
// 编译除内置属性以外的属性到元素。
p.attrs = p.attrs!'';
for (var attr in p.thisTag.attrs){
if (attr.key != '$cols' && !@ListUtils.inString(attr.key, p.exclAttrs)){
if(attr.key == 'readonly' && !toBoolean(attr.value)){
continue;
}
var s = {
%> ${attr.key}="${attr.value}"<%
};
p.attrs = p.attrs + s;
}
}
%>

View File

@@ -0,0 +1,27 @@
<%/* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law. */
/**
* 编译items属性
* @author ThinkGem
* @version 2017-3-5
*/
var p = para0;
// 如果设置了字典,则使用字典数据
if (isNotEmpty(p.dictType) && type.name(dictType) == 'String'){
p.items = @DictUtils.getDictList(p.dictType);
if (isBlank(p.itemLabel)){
p.itemLabel = 'dictLabel';
}
if (isBlank(p.itemValue)){
p.itemValue = 'dictValue';
}
}
// 如果为空,则赋一个空数组
if (isEmpty(p.items!)){
p.items = [];
}
%>

View File

@@ -0,0 +1,72 @@
<%/* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
* No deletion without permission, or be held responsible to law. */
/**
* 编译path属性当设置path属性时自动根据model获取value
* @author ThinkGem
* @version 2017-3-5
*/
var p = para0, tag = p.thisTag;
if (tag != null) {
var parent = @tag.getParentByTagName('form');
var readonly = parent.attrs.readonly!;
if (isNotEmpty(readonly) && toBoolean(readonly)) {
p.readonly = toBoolean(readonly!false);
p.attrs = p.attrs!'' + 'readonly="'+p.readonly+'"';
}
// path 优先级高于 name
if (isNotEmpty(p.path) || isNotEmpty(p.labelPath)) {
var model = parent.attrs.model!;
if (isNotEmpty(p.path)){
p.name = p.path;
if (isNotEmpty(model)){
p.value = @ReflectUtils.invokeGetter(model, p.name);
if (toBoolean(xss!false) && type.name(p.value) == 'String'){
p.value = @EncodeUtils.xssFilter(p.value);
}else if (toBoolean(encodeHtml!false) && type.name(p.value) == 'String'){
p.value = @EncodeUtils.encodeHtml(p.value);
}
}
}
if (isNotEmpty(p.labelPath)){
p.labelName = p.labelPath;
if (isNotEmpty(model)){
p.labelValue = @ReflectUtils.invokeGetter(model, p.labelName);
if (toBoolean(xss!false) && type.name(p.value) == 'String'){
p.labelValue = @EncodeUtils.xssFilter(p.labelValue);
}if (toBoolean(encodeHtml!false) && type.name(p.value) == 'String'){
p.labelValue = @EncodeUtils.encodeHtml(p.labelValue);
}
}
}
}
}
// defaultValue 默认值
if (isNotBlank(p.name)){
if (p.defaultValue != null && isBlank(p.value)){
p.value = p.defaultValue;
}
}
if (isNotBlank(p.labelName)) {
if (p.defaultLabel != null && isBlank(p.labelValue)){
p.labelValue = p.defaultLabel;
}
if (isBlank(p.labelValue)) {
p.labelValue = p.value;
}
}
// 如果没有设置id则与name相同
if (isBlank(p.id)){
p.id = p.name;
// 替换id中的非法字符
p.id = @StringUtils.replace(p.id, '.', '_');
p.id = @StringUtils.replace(p.id, '\'', '_');
p.id = @StringUtils.replace(p.id, '\"', '_');
p.id = @StringUtils.replace(p.id, '[', '_');
p.id = @StringUtils.replace(p.id, ']', '_');
}
%>