diff --git a/src/main/java/cn/stylefeng/guns/config/web/BeetlConfiguration.java b/src/main/java/cn/stylefeng/guns/config/web/BeetlConfiguration.java index ec136ee4..0fbb4f98 100644 --- a/src/main/java/cn/stylefeng/guns/config/web/BeetlConfiguration.java +++ b/src/main/java/cn/stylefeng/guns/config/web/BeetlConfiguration.java @@ -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()); diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/CustomBeetlGroupUtilConfiguration.java b/src/main/java/cn/stylefeng/guns/core/beetl/CustomBeetlGroupUtilConfiguration.java index 34cc0f38..4a35fd8c 100644 --- a/src/main/java/cn/stylefeng/guns/core/beetl/CustomBeetlGroupUtilConfiguration.java +++ b/src/main/java/cn/stylefeng/guns/core/beetl/CustomBeetlGroupUtilConfiguration.java @@ -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()); } diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/consts/BeetlConstants.java b/src/main/java/cn/stylefeng/guns/core/beetl/consts/BeetlConstants.java index 14316a8f..13f7dc7a 100644 --- a/src/main/java/cn/stylefeng/guns/core/beetl/consts/BeetlConstants.java +++ b/src/main/java/cn/stylefeng/guns/core/beetl/consts/BeetlConstants.java @@ -37,4 +37,10 @@ public interface BeetlConstants { */ String DEFAULT_RESOURCE_AUTO_CHECK = "false"; + /** + * 默认beetl 支持HTML标签 + *

+ * beetl默认的是 '#' + */ + String DEFAULT_HTML_TAG_FLAG = "tag:"; } diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/consts/DictTagConstants.java b/src/main/java/cn/stylefeng/guns/core/beetl/consts/DictTagConstants.java new file mode 100644 index 00000000..75b0da28 --- /dev/null +++ b/src/main/java/cn/stylefeng/guns/core/beetl/consts/DictTagConstants.java @@ -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"; + + /** + * select控件提示name + */ + String HEAD_NAME = "headName"; + + /** + * select控件提示value + */ + String HEAD_VALUE = "headValue"; + + /** + * select控件提示类型::1-全部,2-请选择 + */ + String HEAD_TYPE = "headType"; + + /** + * 默认值 + */ + String DEFAULT_VALUE = "defaultValue"; + + /** + * 工作流相关 + */ + String WORKFLOW_FORM = "workflowForm"; + + /** + * 工作流相关 + */ + String ITEM_NAME = "itemName"; + + +} diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/enums/SelectTagHeadTypeEnum.java b/src/main/java/cn/stylefeng/guns/core/beetl/enums/SelectTagHeadTypeEnum.java new file mode 100644 index 00000000..e16f4178 --- /dev/null +++ b/src/main/java/cn/stylefeng/guns/core/beetl/enums/SelectTagHeadTypeEnum.java @@ -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 "未知"; + } + +} diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/expander/BeetlConfigExpander.java b/src/main/java/cn/stylefeng/guns/core/beetl/expander/BeetlConfigExpander.java index 812d0e7f..82a96ab3 100644 --- a/src/main/java/cn/stylefeng/guns/core/beetl/expander/BeetlConfigExpander.java +++ b/src/main/java/cn/stylefeng/guns/core/beetl/expander/BeetlConfigExpander.java @@ -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); + } } diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictBaseTag.java b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictBaseTag.java new file mode 100644 index 00000000..04dd7354 --- /dev/null +++ b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictBaseTag.java @@ -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; + /** + * select控件提示name + */ + public String headName; + /** + * select控件提示value + */ + public String headValue; + /** + * select控件提示类型::1-全部,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 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 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 getDictList(){ + // 查询字典列表 + LambdaQueryWrapper dictQueryWrapper = new LambdaQueryWrapper<>(); + dictQueryWrapper.eq(SysDict::getDictTypeCode, this.getDictTypeCode()); + dictQueryWrapper.ne(SysDict::getDelFlag, YesOrNotEnum.Y.getCode()); + dictQueryWrapper.orderByAsc(SysDict::getDictSort); + return dictService.list(dictQueryWrapper); + } +} diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictCheckBoxTag.java b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictCheckBoxTag.java new file mode 100644 index 00000000..45482975 --- /dev/null +++ b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictCheckBoxTag.java @@ -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 lst = getDictList(); + // 默认选中值 + String defaultValue = this.getDefaultValue(); + // 循环字典列表 + for (SysDict option : lst) { + // 生成input的id + String id = this.getType() + "_" + this.getName() + "_" + option.getDictCode(); + // 拼接html + sb.append(" "); + } + } + } + try { + this.ctx.byteWriter.writeString(sb.toString()); + } catch (IOException e) { + log.error("checkbox字典初始化异常:",e); + } + } +} diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictRadioTag.java b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictRadioTag.java new file mode 100644 index 00000000..3b1f75e7 --- /dev/null +++ b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictRadioTag.java @@ -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 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(" "); + index++; + } + } + } + try { + this.ctx.byteWriter.writeString(sb.toString()); + } catch (IOException e) { + log.error("select字典初始化异常:", e); + } + } +} diff --git a/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictSelectTag.java b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictSelectTag.java new file mode 100644 index 00000000..cb10795e --- /dev/null +++ b/src/main/java/cn/stylefeng/guns/core/beetl/tag/SysDictSelectTag.java @@ -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(""); + } + try { + this.ctx.byteWriter.writeString(sb.toString()); + } catch (IOException e) { + log.error("select字典初始化异常:",e); + } + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 87f7b662..b5d0634f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,6 +21,9 @@ spring: serialization: indent_output: false +beetl: + html-tag-flag: 'tag:' + scanner: open: true diff --git a/src/main/webapp/assets/modular/system/notice/notice_add.js b/src/main/webapp/assets/modular/system/notice/notice_add.js index 612f8410..9156590d 100644 --- a/src/main/webapp/assets/modular/system/notice/notice_add.js +++ b/src/main/webapp/assets/modular/system/notice/notice_add.js @@ -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); } diff --git a/src/main/webapp/assets/modular/system/notice/notice_edit.js b/src/main/webapp/assets/modular/system/notice/notice_edit.js index c1fa3642..5fa3d0a9 100644 --- a/src/main/webapp/assets/modular/system/notice/notice_edit.js +++ b/src/main/webapp/assets/modular/system/notice/notice_edit.js @@ -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 可成功跳转页面 diff --git a/src/main/webapp/pages/modular/system/notice/notice_add.html b/src/main/webapp/pages/modular/system/notice/notice_add.html index eaa810ea..4308f919 100644 --- a/src/main/webapp/pages/modular/system/notice/notice_add.html +++ b/src/main/webapp/pages/modular/system/notice/notice_add.html @@ -22,12 +22,15 @@

- - - - - - - + +