Merge remote-tracking branch 'origin/group5-dictTag'

pull/64/head
fengshuonan 2021-01-17 14:46:56 +08:00
commit 236670e72a
15 changed files with 609 additions and 19 deletions

View File

@ -68,6 +68,7 @@ public class BeetlConfiguration {
Properties properties = new Properties();
properties.setProperty("DELIMITER_STATEMENT_START", BeetlConfigExpander.getDelimiterStatementStart());
properties.setProperty("DELIMITER_STATEMENT_END", BeetlConfigExpander.getDelimiterStatementEnd());
properties.setProperty("HTML_TAG_FLAG", BeetlConfigExpander.getHtmlTagFlag());
properties.setProperty("RESOURCE.tagRoot", BeetlConfigExpander.getResourceTagRoot());
properties.setProperty("RESOURCE.tagSuffix", BeetlConfigExpander.getResourceTagSuffix());
properties.setProperty("RESOURCE.autoCheck", BeetlConfigExpander.getResourceAutoCheck());

View File

@ -1,6 +1,9 @@
package cn.stylefeng.guns.core.beetl;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.core.beetl.tag.SysDictCheckBoxTag;
import cn.stylefeng.guns.core.beetl.tag.SysDictRadioTag;
import cn.stylefeng.guns.core.beetl.tag.SysDictSelectTag;
import cn.stylefeng.roses.kernel.auth.api.LoginUserApi;
import cn.stylefeng.roses.kernel.system.expander.SystemConfigExpander;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
@ -31,6 +34,13 @@ public class CustomBeetlGroupUtilConfiguration extends BeetlGroupUtilConfigurati
// 获取基本信息的工具
groupTemplate.registerFunctionPackage("constants", SystemConfigExpander.class);
// 下拉选字典
groupTemplate.registerTag("dict_select", SysDictSelectTag.class);
// 单选字典
groupTemplate.registerTag("dict_radio", SysDictRadioTag.class);
// 多选字典
groupTemplate.registerTag("dict_checkbox", SysDictCheckBoxTag.class);
// todo 多语言
// groupTemplate.registerFunctionPackage("lang", new UserTranslationContext());
}

View File

@ -37,4 +37,10 @@ public interface BeetlConstants {
*/
String DEFAULT_RESOURCE_AUTO_CHECK = "false";
/**
* beetl HTML
* <p>
* beetl '#'
*/
String DEFAULT_HTML_TAG_FLAG = "tag:";
}

View File

@ -0,0 +1,78 @@
package cn.stylefeng.guns.core.beetl.consts;
/**
* html
*
* @author liuhanqing
* @date 2021/1/16 21:06
*/
public interface DictTagConstants {
/**
* html id
*/
String ID = "id";
/**
* html name
*/
String NAME = "name";
/**
* html type
*/
String TYPE = "type";
/**
*
*/
String DICT_TYPE_CODE = "dictTypeCode";
/**
* layui
*/
String LAY_SKIN = "laySkin";
/**
* layui
*/
String LAY_FILTER = "layFilter";
/**
* layui
*/
String LAY_VERIFY = "layVerify";
/**
* selectname
*/
String HEAD_NAME = "headName";
/**
* selectvalue
*/
String HEAD_VALUE = "headValue";
/**
* select1-2-
*/
String HEAD_TYPE = "headType";
/**
*
*/
String DEFAULT_VALUE = "defaultValue";
/**
*
*/
String WORKFLOW_FORM = "workflowForm";
/**
*
*/
String ITEM_NAME = "itemName";
}

View File

@ -0,0 +1,67 @@
package cn.stylefeng.guns.core.beetl.enums;
import lombok.Getter;
/**
*
*
* @author liuhanqing
* @date 2021/1/16 20:36
*/
@Getter
public enum SelectTagHeadTypeEnum {
/**
*
*/
ALL("1", "全部"),
/**
*
*/
SELECT("2", "请选择");
private final String code;
private final String name;
SelectTagHeadTypeEnum(String code, String name) {
this.code = code;
this.name = name;
}
/**
* code
*
* @author liuhanqing
* @date 2021/1/16 20:36
*/
public static SelectTagHeadTypeEnum codeToEnum(String code) {
if (null != code) {
for (SelectTagHeadTypeEnum e : SelectTagHeadTypeEnum.values()) {
if (e.getCode().equals(code)) {
return e;
}
}
}
return null;
}
/**
*
*
* @author liuhanqing
* @date 2021/1/16 20:36
*/
public static String codeToName(String code) {
if (null != code) {
for (SelectTagHeadTypeEnum e : SelectTagHeadTypeEnum.values()) {
if (e.getCode().equals(code)) {
return e.getName();
}
}
}
return "未知";
}
}

View File

@ -60,5 +60,14 @@ public class BeetlConfigExpander {
public static String getResourceAutoCheck() {
return ConfigContext.me().getSysConfigValueWithDefault("RESOURCE_AUTO_CHECK", String.class, BeetlConstants.DEFAULT_RESOURCE_AUTO_CHECK);
}
/**
* HTML
*
* @author liuhanqing
* @date 2021/1/16 21:06
*/
public static String getHtmlTagFlag() {
return ConfigContext.me().getSysConfigValueWithDefault("HTML_TAG_FLAG", String.class, BeetlConstants.DEFAULT_HTML_TAG_FLAG);
}
}

View File

@ -0,0 +1,165 @@
package cn.stylefeng.guns.core.beetl.tag;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.stylefeng.guns.core.beetl.consts.DictTagConstants;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
import cn.stylefeng.roses.kernel.dict.modular.service.DictService;
import cn.stylefeng.roses.kernel.dict.modular.service.DictTypeService;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.Data;
import org.beetl.core.tag.GeneralVarTagBinding;
import java.util.List;
import java.util.Map;
/**
* beetl
*
* @author liuhanqing
* @date 2021/1/16 18:45
*/
@Data
public class SysDictBaseTag extends GeneralVarTagBinding {
public DictService dictService = SpringUtil.getBean(DictService.class);
public DictTypeService dictTypeService = SpringUtil.getBean(DictTypeService.class);
/**
* html id
*/
public String id;
/**
* html name
*/
public String name;
/**
* html type
*/
public String type;
/**
*
*/
public String dictTypeCode;
/**
* layui
*/
public String laySkin;
/**
* layui
*/
public String layFilter;
/**
* layui
*/
public String layVerify;
/**
* selectname
*/
public String headName;
/**
* selectvalue
*/
public String headValue;
/**
* select1-2-
*/
public String headType;
/**
*
*/
public String defaultValue;
/**
*
*/
public String workflowForm;
/**
*
*/
public String itemName;
/**
*
*
* @author liuhanqing
* @date 2021/1/16 23:49
*/
public void initAttr() {
Map<String, Object> attrs = this.getAttributes();
if (attrs.size() > 0) {
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.ID))) {
this.setId(attrs.get(DictTagConstants.ID).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.NAME))) {
this.setName(attrs.get(DictTagConstants.NAME).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.TYPE))) {
this.setType(attrs.get(DictTagConstants.TYPE).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.DICT_TYPE_CODE))) {
this.setDictTypeCode(attrs.get(DictTagConstants.DICT_TYPE_CODE).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.LAY_SKIN))) {
this.setLaySkin(attrs.get(DictTagConstants.LAY_SKIN).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.LAY_FILTER))) {
this.setLayFilter(attrs.get(DictTagConstants.LAY_FILTER).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.LAY_VERIFY))) {
this.setLayVerify(attrs.get(DictTagConstants.LAY_VERIFY).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.HEAD_NAME))) {
this.setHeadName(attrs.get(DictTagConstants.HEAD_NAME).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.HEAD_VALUE))) {
this.setHeadValue(attrs.get(DictTagConstants.HEAD_VALUE).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.HEAD_TYPE))) {
this.setHeadType(attrs.get(DictTagConstants.HEAD_TYPE).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.DEFAULT_VALUE))) {
this.setDefaultValue(attrs.get(DictTagConstants.DEFAULT_VALUE).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.WORKFLOW_FORM))) {
this.setWorkflowForm(attrs.get(DictTagConstants.WORKFLOW_FORM).toString());
}
if (ObjectUtil.isNotNull(attrs.get(DictTagConstants.ITEM_NAME))) {
this.setItemName(attrs.get(DictTagConstants.ITEM_NAME).toString());
}
}
}
@Override
public void render() {
}
/**
*
* @return
* @author liuhanqing
* @date 2021/1/16 23:46
*/
public SysDictType getDictType(){
// 根据字典类型编码去查询字典类型
LambdaQueryWrapper<SysDictType> dictTypeQueryWrapper = new LambdaQueryWrapper<>();
dictTypeQueryWrapper.eq(SysDictType::getDictTypeCode, this.getDictTypeCode());
dictTypeQueryWrapper.ne(SysDictType::getDelFlag, YesOrNotEnum.Y.getCode());
return dictTypeService.getOne(dictTypeQueryWrapper);
}
/**
*
*
* @return
* @author liuhanqing
* @date 2021/1/16 23:46
*/
public List<SysDict> getDictList(){
// 查询字典列表
LambdaQueryWrapper<SysDict> dictQueryWrapper = new LambdaQueryWrapper<>();
dictQueryWrapper.eq(SysDict::getDictTypeCode, this.getDictTypeCode());
dictQueryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode());
dictQueryWrapper.orderByAsc(SysDict::getDictSort);
return dictService.list(dictQueryWrapper);
}
}

View File

@ -0,0 +1,72 @@
package cn.stylefeng.guns.core.beetl.tag;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.List;
/**
* checkbox
*
* @author liuhanqing
* @date 2021/1/16 19:06
*/
@Slf4j
public class SysDictCheckBoxTag extends SysDictBaseTag {
@Override
public void render() {
// 初始属性
initAttr();
StringBuilder sb = new StringBuilder();
// 当字典类型编码不为空
if (StrUtil.isNotBlank(this.getDictTypeCode())) {
// 根据字典类型编码去查询字典类型
SysDictType dictType = getDictType();
// 判断字典类型不为空
if (dictType != null) {
List<SysDict> lst = getDictList();
// 默认选中值
String defaultValue = this.getDefaultValue();
// 循环字典列表
for (SysDict option : lst) {
// 生成input的id
String id = this.getType() + "_" + this.getName() + "_" + option.getDictCode();
// 拼接html
sb.append(" <input type='checkbox' name='").append(this.getName())
.append("' id='").append(id)
.append("' title='").append(option.getDictName())
.append("' value='").append(option.getDictCode())
.append("'");
// layui 元素的风格
if (StrUtil.isNotBlank(this.getLaySkin())) {
sb.append(" lay-skin='").append(this.getLaySkin()).append("'");
}
// layui 事件过滤器
if (StrUtil.isNotBlank(this.getLayFilter())) {
sb.append(" lay-filter='").append(this.getLayFilter()).append("'");
}
// layui 表单验证
if (StrUtil.isNotBlank(this.getLayVerify())) {
sb.append(" lay-verify='").append(this.getLayVerify()).append("'");
}
// 默认选中值
if (StrUtil.isNotBlank(defaultValue) && defaultValue.equals(option.getDictCode())) {
sb.append(" checked ");
}
sb.append(" /> ");
}
}
}
try {
this.ctx.byteWriter.writeString(sb.toString());
} catch (IOException e) {
log.error("checkbox字典初始化异常",e);
}
}
}

View File

@ -0,0 +1,79 @@
package cn.stylefeng.guns.core.beetl.tag;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.List;
/**
* radio
*
* @author liuhanqing
* @date 2021/1/16 19:59
*/
@Slf4j
public class SysDictRadioTag extends SysDictBaseTag {
@Override
public void render() {
// 初始属性
initAttr();
StringBuilder sb = new StringBuilder();
// 当字典类型编码不为空
if (StrUtil.isNotBlank(this.getDictTypeCode())) {
// 根据字典类型编码去查询字典类型
SysDictType dictType = getDictType();
// 判断字典类型不为空
if (dictType != null) {
List<SysDict> lst = getDictList();
// 默认选中值
String defaultValue = this.getDefaultValue();
int index = 0;
for (SysDict option : lst) {
// 生成input的id
String id = this.getType() + "_" + this.getName() + "_" + option.getDictCode();
// 拼接html
sb.append(" <input type='radio' name='").append(this.getName())
.append("' id='").append(id)
.append("' title='").append(option.getDictName())
.append("' value='").append(option.getDictCode())
.append("'");
// layui 元素的风格
if (StrUtil.isNotBlank(this.getLaySkin())) {
sb.append(" lay-skin='").append(this.getLaySkin()).append("'");
}
// layui 事件过滤器
if (StrUtil.isNotBlank(this.getLayFilter())) {
sb.append(" lay-filter='").append(this.getLayFilter()).append("'");
}
// layui 表单验证
if (StrUtil.isNotBlank(this.getLayVerify())) {
sb.append(" lay-verify='").append(this.getLayVerify()).append("'");
}
// 默认选中值
if (StrUtil.isNotBlank(defaultValue) && defaultValue.equals(option.getDictCode())) {
sb.append(" checked ");
} else {
// 无默认值选中第一个(忘了为什么设计先保留逻辑)
if (index == 0) {
sb.append(" checked ");
}
}
sb.append(" /> ");
index++;
}
}
}
try {
this.ctx.byteWriter.writeString(sb.toString());
} catch (IOException e) {
log.error("select字典初始化异常", e);
}
}
}

View File

@ -0,0 +1,98 @@
package cn.stylefeng.guns.core.beetl.tag;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.guns.core.beetl.enums.SelectTagHeadTypeEnum;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDict;
import cn.stylefeng.roses.kernel.dict.modular.entity.SysDictType;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.util.List;
/**
* select
*
* @author liuhanqing
* @date 2021/1/16 19:37
*/
@Slf4j
public class SysDictSelectTag extends SysDictBaseTag {
@Override
public void render() {
// 初始属性
initAttr();
StringBuilder sb = new StringBuilder();
// 当字典类型编码不为空
if (StrUtil.isNotBlank(this.getDictTypeCode())) {
sb.append("<select name='").append(this.getName())
.append("' id='").append(this.getId())
.append("'");
// layui 事件过滤器
if (StrUtil.isNotBlank(this.getLayFilter())) {
sb.append(" lay-filter='").append(this.getLayFilter()).append("' ");
}
// layui 表单验证
if (StrUtil.isNotBlank(this.getLayVerify())) {
sb.append(" lay-verify='").append(this.getLayVerify()).append("' ");
}
// 原有工作流用到
if (StrUtil.isNotBlank(this.getWorkflowForm())) {
sb.append(" workFlowForm='").append(this.getWorkflowForm()).append("' ");
}
if (StrUtil.isNotBlank(this.getItemName())) {
sb.append(" itemName='").append(this.getItemName()).append("' ");
}
sb.append(" >");
if (StrUtil.isNotBlank(this.getHeadName())) {
sb.append("<option value='").append(this.getHeadValue()).append("' selected>")
.append(this.getHeadName()).append("</option>");
} else {
if (StrUtil.isNotBlank(this.getHeadType())) {
if (SelectTagHeadTypeEnum.ALL.getCode().equals(this.getHeadType())) {
sb.append("<option value='").append(this.getHeadValue()).append("' selected>")
.append(" - 全部 - ").append("</option>");
}
if (SelectTagHeadTypeEnum.SELECT.getCode().equals(this.getHeadType())) {
sb.append("<option value='").append(this.getHeadValue()).append("' selected>")
.append(" - 请选择 - ").append("</option>");
}
}
}
// 根据字典类型编码去查询字典类型
SysDictType dictType = getDictType();
// 判断字典类型不为空
if (dictType != null) {
List<SysDict> lst = getDictList();
// 默认选中值
String defaultValue = this.getDefaultValue();
// 循环字典列表,添加下拉选项
int index = 0;
for (SysDict option : lst) {
sb.append("<option value='").append(option.getDictCode()).append("'");
// 设置默认选中值
if (StrUtil.isNotBlank(defaultValue) && defaultValue.equals(option.getDictCode())) {
sb.append(" selected ");
} else {
// 未设置headName和headType 默认选中第一个
if (index == 0 && StrUtil.isNotBlank(this.getHeadName()) && StrUtil.isNotBlank(this.getHeadType())) {
sb.append(" selected ");
}
}
sb.append(">").append(option.getDictName()).append("</option>");
index++;
}
}
sb.append("</select>");
}
try {
this.ctx.byteWriter.writeString(sb.toString());
} catch (IOException e) {
log.error("select字典初始化异常",e);
}
}
}

View File

@ -21,6 +21,9 @@ spring:
serialization:
indent_output: false
beetl:
html-tag-flag: 'tag:'
scanner:
open: true

View File

@ -40,11 +40,12 @@ layui.use(['layer', 'form', 'admin', 'laydate', 'HttpRequest', 'xmSelect'], func
plugins: 'code print preview fullscreen paste searchreplace save autosave link autolink image imagetools media table codesample lists advlist hr charmap emoticons anchor directionality pagebreak quickbars nonbreaking visualblocks visualchars wordcount',
toolbar: 'fullscreen preview code | undo redo | forecolor backcolor | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | formatselect fontselect fontsizeselect | link image media emoticons charmap anchor pagebreak codesample | ltr rtl',
toolbar_drawer: 'sliding',
images_upload_url: '../../../json/tinymce-upload-ok.json',
file_picker_types: 'media',
file_picker_callback: function (callback, value, meta) {
layer.msg('演示环境不允许上传', {anim: 6});
},
images_upload_url: Feng.ctxPath + '/sysFileInfo/tinymceUpload',
images_upload_base_path: Feng.ctxPath,
file_picker_types: 'file image media',
// file_picker_callback: function (callback, value, meta) {
// layer.msg('演示环境不允许上传', {anim: 6});
// },
init_instance_callback: function (editor) {
console.log(editor);
}

View File

@ -19,11 +19,12 @@ layui.use(['layer', 'form', 'admin', 'laydate', 'HttpRequest', 'xmSelect'], func
plugins: 'code print preview fullscreen paste searchreplace save autosave link autolink image imagetools media table codesample lists advlist hr charmap emoticons anchor directionality pagebreak quickbars nonbreaking visualblocks visualchars wordcount',
toolbar: 'fullscreen preview code | undo redo | forecolor backcolor | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | formatselect fontselect fontsizeselect | link image media emoticons charmap anchor pagebreak codesample | ltr rtl',
toolbar_drawer: 'sliding',
images_upload_url: '../../../json/tinymce-upload-ok.json',
file_picker_types: 'media',
file_picker_callback: function (callback, value, meta) {
layer.msg('演示环境不允许上传', {anim: 6});
},
images_upload_url: Feng.ctxPath + '/sysFileInfo/tinymceUpload',
images_upload_base_path: Feng.ctxPath,
file_picker_types: 'file image media',
// file_picker_callback: function (callback, value, meta) {
// layer.msg('演示环境不允许上传', {anim: 6});
// },
init_instance_callback: function (editor) {
tinymce.get('noticeContent').setContent(data.noticeContent);
}
@ -128,9 +129,11 @@ layui.use(['layer', 'form', 'admin', 'laydate', 'HttpRequest', 'xmSelect'], func
Feng.error("修改失败!" + data.message);
});
data.field.noticeContent = tinymce.get('noticeContent').getContent();
console.log(data.field.noticeContent)
if (data.field.noticeScope !== "all") {
data.field.noticeScope = userSelect.getValue('valueStr');
}
// request.setContentType("multipart/form-data");
request.set(data.field);
request.start(true);
//添加 return false 可成功跳转页面

View File

@ -22,12 +22,15 @@
<div class="layui-inline layui-col-md12">
<label class="layui-form-label">优先级<span style="color: red;">*</span></label>
<div class="layui-input-block">
<select id="priorityLevel" name="priorityLevel" lay-filter="">
<tag:dict_select id="priorityLevel" name="priorityLevel" type="select" head-type="2" head-name="" head-value="" default-value="" dict-type-code="priority_level" lay-verify="required" >
</tag:dict_select>
<!-- <select id="priorityLevel" name="priorityLevel" lay-filter="">
<option value="">请选择通知优先级</option>
<option value="low"></option>
<option value="middle"></option>
<option value="high"></option>
</select>
</select>-->
<!-- <input name="priorityLevel" placeholder="请输入通知优先级" type="text" class="layui-input" lay-verify="required" required autocomplete="off"/>-->
</div>
</div>

View File

@ -22,13 +22,8 @@
<div class="layui-inline layui-col-md12">
<label class="layui-form-label">优先级<span style="color: red;">*</span></label>
<div class="layui-input-block">
<select id="priorityLevel" name="priorityLevel" lay-filter="">
<option value="">请选择通知优先级</option>
<option value="low"></option>
<option value="middle"></option>
<option value="high"></option>
</select>
<!-- <input name="priorityLevel" placeholder="请输入通知优先级" type="text" class="layui-input" lay-verify="required" required autocomplete="off"/>-->
<tag:dict_select id="priorityLevel" name="priorityLevel" type="select" head-type="2" head-name="" head-value="" default-value="" dict-type-code="priority_level" lay-verify="required" >
</tag:dict_select>
</div>
</div>
<div class="layui-inline layui-col-md12">