From 57da9f7ffea6a9960984af0dc5e2aadd990e396a Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 23 Jul 2021 18:54:16 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=8D=87=E7=BA=A7oshi=E5=88=B0=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=ACv5.8.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7279a36d1..62467346f 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 2.1.4 1.3.1 1.2.76 - 5.7.5 + 5.8.0 5.8.0 2.10.0 1.4 From 15c75786929375814044dc26804d7dffb72408eb Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 25 Jul 2021 10:36:42 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=90=88=E7=90=86=E5=8C=96=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/src/main/resources/application.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index e66fe68e4..b79e9b30f 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -82,7 +82,6 @@ mybatis: # PageHelper分页插件 pagehelper: helperDialect: mysql - reasonable: true supportMethodsArguments: true params: count=countSql From 27277b51d7deb0ac33a96af660005c73ecb66c3b Mon Sep 17 00:00:00 2001 From: RuoYi Date: Wed, 28 Jul 2021 16:37:56 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BC=98=E5=8C=96XSS=E8=B7=A8=E7=AB=99?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/constant/Constants.java | 10 ++ .../com/ruoyi/common/utils/StringUtils.java | 110 +++++++++++++++++- .../java/com/ruoyi/common/xss/XssFilter.java | 33 +----- .../ruoyi/framework/config/FilterConfig.java | 8 +- 4 files changed, 127 insertions(+), 34 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java index 869997cda..64664e06e 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java @@ -17,6 +17,16 @@ public class Constants */ public static final String GBK = "GBK"; + /** + * http请求 + */ + public static final String HTTP = "http://"; + + /** + * https请求 + */ + public static final String HTTPS = "https://"; + /** * 通用成功标识 */ diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java index 882e94a64..806e4ad9c 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java @@ -1,7 +1,13 @@ package com.ruoyi.common.utils; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.Set; +import org.springframework.util.AntPathMatcher; +import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.text.StrFormatter; /** @@ -256,6 +262,68 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils return StrFormatter.format(template, params); } + /** + * 是否为http(s)://开头 + * + * @param link 链接 + * @return 结果 + */ + public static boolean ishttp(String link) + { + return StringUtils.startsWithAny(link, Constants.HTTP, Constants.HTTPS); + } + + /** + * 字符串转set + * + * @param str 字符串 + * @param sep 分隔符 + * @return set集合 + */ + public static final Set str2Set(String str, String sep) + { + return new HashSet(str2List(str, sep, true, false)); + } + + /** + * 字符串转list + * + * @param str 字符串 + * @param sep 分隔符 + * @param filterBlank 过滤纯空白 + * @param trim 去掉首尾空白 + * @return list集合 + */ + public static final List str2List(String str, String sep, boolean filterBlank, boolean trim) + { + List list = new ArrayList(); + if (StringUtils.isEmpty(str)) + { + return list; + } + + // 过滤空白字符串 + if (filterBlank && StringUtils.isBlank(str)) + { + return list; + } + String[] split = str.split(sep); + for (String string : split) + { + if (filterBlank && StringUtils.isBlank(string)) + { + continue; + } + if (trim) + { + string = string.trim(); + } + list.add(string); + } + + return list; + } + /** * 驼峰转下划线命名 */ @@ -301,6 +369,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils } sb.append(Character.toLowerCase(c)); } + return sb.toString(); } @@ -400,9 +469,48 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils return sb.toString(); } + /** + * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 + * + * @param str 指定字符串 + * @param strs 需要检查的字符串数组 + * @return 是否匹配 + */ + public static boolean matches(String str, List strs) + { + if (isEmpty(str) || isEmpty(strs)) + { + return false; + } + for (String pattern : strs) + { + if (isMatch(pattern, str)) + { + return true; + } + } + return false; + } + + /** + * 判断url是否与规则配置: + * ? 表示单个字符; + * * 表示一层路径内的任意字符串,不可跨层级; + * ** 表示任意层路径; + * + * @param pattern 匹配规则 + * @param url 需要匹配的url + * @return + */ + public static boolean isMatch(String pattern, String url) + { + AntPathMatcher matcher = new AntPathMatcher(); + return matcher.match(pattern, url); + } + @SuppressWarnings("unchecked") public static T cast(Object obj) { return (T) obj; } -} +} \ No newline at end of file diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/xss/XssFilter.java b/ruoyi-common/src/main/java/com/ruoyi/common/xss/XssFilter.java index d307fbc9f..30fd69ce8 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/xss/XssFilter.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/xss/XssFilter.java @@ -3,8 +3,6 @@ package com.ruoyi.common.xss; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -27,16 +25,10 @@ public class XssFilter implements Filter */ public List excludes = new ArrayList<>(); - /** - * xss过滤开关 - */ - public boolean enabled = false; - @Override public void init(FilterConfig filterConfig) throws ServletException { String tempExcludes = filterConfig.getInitParameter("excludes"); - String tempEnabled = filterConfig.getInitParameter("enabled"); if (StringUtils.isNotEmpty(tempExcludes)) { String[] url = tempExcludes.split(","); @@ -45,10 +37,6 @@ public class XssFilter implements Filter excludes.add(url[i]); } } - if (StringUtils.isNotEmpty(tempEnabled)) - { - enabled = Boolean.valueOf(tempEnabled); - } } @Override @@ -68,25 +56,14 @@ public class XssFilter implements Filter private boolean handleExcludeURL(HttpServletRequest request, HttpServletResponse response) { - if (!enabled) + String url = request.getServletPath(); + String method = request.getMethod(); + // GET DELETE 不过滤 + if (method == null || method.matches("GET") || method.matches("DELETE")) { return true; } - if (excludes == null || excludes.isEmpty()) - { - return false; - } - String url = request.getServletPath(); - for (String pattern : excludes) - { - Pattern p = Pattern.compile("^" + pattern); - Matcher m = p.matcher(url); - if (m.find()) - { - return true; - } - } - return false; + return StringUtils.matches(url, excludes); } @Override diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java index 92d010e80..b7d10b8f9 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import javax.servlet.DispatcherType; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -16,11 +17,9 @@ import com.ruoyi.common.xss.XssFilter; * @author ruoyi */ @Configuration +@ConditionalOnProperty(value = "xss.enabled", havingValue = "true") public class FilterConfig { - @Value("${xss.enabled}") - private String enabled; - @Value("${xss.excludes}") private String excludes; @@ -36,10 +35,9 @@ public class FilterConfig registration.setFilter(new XssFilter()); registration.addUrlPatterns(StringUtils.split(urlPatterns, ",")); registration.setName("xssFilter"); - registration.setOrder(Integer.MAX_VALUE); + registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); Map initParameters = new HashMap(); initParameters.put("excludes", excludes); - initParameters.put("enabled", enabled); registration.setInitParameters(initParameters); return registration; } From eed4caa44f3238bfb33336b853c221615e8a1bac Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 30 Jul 2021 10:18:37 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E9=A1=B6=E7=BA=A7=E8=8A=82=E7=82=B9=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index e7035fc8d..98f44bea5 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -227,7 +227,7 @@ public class SysDeptServiceImpl implements ISysDeptService updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); } int result = deptMapper.updateDept(dept); - if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) + if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())) { // 如果该部门是启用状态,则启用该部门的所有上级部门 updateParentDeptStatusNormal(dept); From 9d83ffab2adb668164308e4dbe1f32c5629ac0d9 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 30 Jul 2021 10:19:26 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E9=BB=98=E8=AE=A4dialogsInBody?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-generator/src/main/resources/vm/html/add.html.vm | 1 + ruoyi-generator/src/main/resources/vm/html/edit.html.vm | 1 + 2 files changed, 2 insertions(+) diff --git a/ruoyi-generator/src/main/resources/vm/html/add.html.vm b/ruoyi-generator/src/main/resources/vm/html/add.html.vm index 85fd47c48..b228b34ee 100644 --- a/ruoyi-generator/src/main/resources/vm/html/add.html.vm +++ b/ruoyi-generator/src/main/resources/vm/html/add.html.vm @@ -238,6 +238,7 @@ $(function() { $('.summernote').summernote({ lang: 'zh-CN', + dialogsInBody: true, callbacks: { onChange: function(contents, $edittable) { $("input[name='" + this.id + "']").val(contents); diff --git a/ruoyi-generator/src/main/resources/vm/html/edit.html.vm b/ruoyi-generator/src/main/resources/vm/html/edit.html.vm index 0d1f8b7cb..174cc0823 100644 --- a/ruoyi-generator/src/main/resources/vm/html/edit.html.vm +++ b/ruoyi-generator/src/main/resources/vm/html/edit.html.vm @@ -245,6 +245,7 @@ $('.summernote').each(function(i) { $('#' + this.id).summernote({ lang: 'zh-CN', + dialogsInBody: true, callbacks: { onChange: function(contents, $edittable) { $("input[name='" + this.id + "']").val(contents); From c7e0292da30bc51b15166826385de78c6dc80774 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 30 Jul 2021 10:19:46 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E5=88=97=E5=80=BC=E5=A2=9E=E5=8A=A0deDuplica?= =?UTF-8?q?tion=E6=98=AF=E5=90=A6=E5=8E=BB=E9=87=8D=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/static/ruoyi/js/ry-ui.js | 881 +++++++++--------- 1 file changed, 442 insertions(+), 439 deletions(-) diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js index 82759721b..2c38d8f24 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js @@ -10,12 +10,12 @@ var table = { options: {}, // 设置实例配置 set: function(id) { - if($.common.getLength(table.config) > 1) { + if($.common.getLength(table.config) > 1) { var tableId = $.common.isEmpty(id) ? $(event.currentTarget).parents(".bootstrap-table").find("table.table").attr("id") : id; if ($.common.isNotEmpty(tableId)) { table.options = table.get(tableId); } - } + } }, // 获取实例配置 get: function(id) { @@ -29,13 +29,13 @@ var table = { (function ($) { $.extend({ - _tree: {}, - bttTable: {}, - // 表格封装处理 - table: { + _tree: {}, + bttTable: {}, + // 表格封装处理 + table: { // 初始化表格参数 init: function(options) { - var defaults = { + var defaults = { id: "bootstrap-table", type: 0, // 0 代表bootstrapTable 1代表bootstrapTreeTable method: 'post', @@ -75,9 +75,9 @@ var table = { queryParams: $.table.queryParams, rowStyle: undefined, }; - var options = $.extend(defaults, options); - table.options = options; - table.config[options.id] = options; + var options = $.extend(defaults, options); + table.options = options; + table.config[options.id] = options; $.table.initEvent(); $('#' + options.id).bootstrapTable({ id: options.id, @@ -154,12 +154,12 @@ var table = { }, // 获取实例ID,如存在多个返回#id1,#id2 delimeter分隔符 getOptionsIds: function(separator) { - var _separator = $.common.isEmpty(separator) ? "," : separator; - var optionsIds = ""; - $.each(table.config, function(key, value){ + var _separator = $.common.isEmpty(separator) ? "," : separator; + var optionsIds = ""; + $.each(table.config, function(key, value){ optionsIds += "#" + key + _separator; - }); - return optionsIds.substring(0, optionsIds.length - 1); + }); + return optionsIds.substring(0, optionsIds.length - 1); }, // 查询条件 queryParams: function(params) { @@ -171,24 +171,24 @@ var table = { orderByColumn: params.sort, isAsc: params.order }; - var currentId = $.common.isEmpty(table.options.formId) ? $('form').attr('id') : table.options.formId; - return $.extend(curParams, $.common.formToJSON(currentId)); + var currentId = $.common.isEmpty(table.options.formId) ? $('form').attr('id') : table.options.formId; + return $.extend(curParams, $.common.formToJSON(currentId)); }, // 请求获取数据后处理回调函数 responseHandler: function(res) { - if (typeof table.get(this.id).responseHandler == "function") { + if (typeof table.get(this.id).responseHandler == "function") { table.get(this.id).responseHandler(res); } if (res.code == web_status.SUCCESS) { if ($.common.isNotEmpty(table.options.sidePagination) && table.options.sidePagination == 'client') { - return res.rows; + return res.rows; } else { - if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) { + if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) { var column = $.common.isEmpty(table.options.uniqueId) ? table.options.columns[1].field : table.options.uniqueId; $.each(res.rows, function(i, row) { row.state = $.inArray(row[column], table.rememberSelectedIds[table.options.id]) !== -1; }) - } + } return { rows: res.rows, total: res.total }; } } else { @@ -198,21 +198,21 @@ var table = { }, // 初始化事件 initEvent: function() { - // 实例ID信息 - var optionsIds = $.table.getOptionsIds(); - // 监听事件处理 - $(optionsIds).on(TABLE_EVENTS, function () { + // 实例ID信息 + var optionsIds = $.table.getOptionsIds(); + // 监听事件处理 + $(optionsIds).on(TABLE_EVENTS, function () { table.set($(this).attr("id")); - }); - // 在表格体渲染完成,并在 DOM 中可见后触发(事件) - $(optionsIds).on("post-body.bs.table", function (e, args) { + }); + // 在表格体渲染完成,并在 DOM 中可见后触发(事件) + $(optionsIds).on("post-body.bs.table", function (e, args) { // 浮动提示框特效 $(".table [data-toggle='tooltip']").tooltip(); // 气泡弹出框特效 $('.table [data-toggle="popover"]').popover(); - }); - // 选中、取消、全部选中、全部取消(事件) - $(optionsIds).on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", function (e, rowsAfter, rowsBefore) { + }); + // 选中、取消、全部选中、全部取消(事件) + $(optionsIds).on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", function (e, rowsAfter, rowsBefore) { // 复选框分页保留保存选中数组 var rows = $.common.equals("uncheck-all", e.type) ? rowsBefore : rowsAfter; var rowIds = $.table.affectedRowIds(rows); @@ -231,9 +231,9 @@ var table = { table.rememberSelecteds[table.options.id] = _[func]([], rows); } } - }); - // 加载成功、选中、取消、全部选中、全部取消(事件) - $(optionsIds).on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table load-success.bs.table", function () { + }); + // 加载成功、选中、取消、全部选中、全部取消(事件) + $(optionsIds).on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table load-success.bs.table", function () { var toolbar = table.options.toolbar; var uniqueId = table.options.uniqueId; // 工具栏按钮控制 @@ -242,9 +242,9 @@ var table = { $('#' + toolbar + ' .multiple').toggleClass('disabled', !rows.length); // 非单个禁用 $('#' + toolbar + ' .single').toggleClass('disabled', rows.length!=1); - }); - // 图片预览事件 - $(optionsIds).off("click").on("click", '.img-circle', function() { + }); + // 图片预览事件 + $(optionsIds).off("click").on("click", '.img-circle', function() { var src = $(this).attr('src'); var target = $(this).data('target'); if($.common.equals("self", target)) { @@ -262,8 +262,8 @@ var table = { window.open(src); } }); - // 单击tooltip事件 - $(optionsIds).on("click", '.tooltip-show', function() { + // 单击tooltip事件 + $(optionsIds).on("click", '.tooltip-show', function() { var target = $(this).data('target'); var input = $(this).prev(); if ($.common.equals("copy", target)) { @@ -277,20 +277,20 @@ var table = { btnclass: ['btn btn-primary'], }); } - }); + }); }, // 当所有数据被加载时触发 onLoadSuccess: function(data) { - if (typeof table.options.onLoadSuccess == "function") { + if (typeof table.options.onLoadSuccess == "function") { table.options.onLoadSuccess(data); - } + } }, // 表格销毁 destroy: function (tableId) { - var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; - $("#" + currentId).bootstrapTable('destroy'); - delete table.rememberSelectedIds[currentId]; - delete table.rememberSelecteds[currentId]; + var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; + $("#" + currentId).bootstrapTable('destroy'); + delete table.rememberSelectedIds[currentId]; + delete table.rememberSelecteds[currentId]; }, // 序列号生成 serialNumber: function (index, tableId) { @@ -353,10 +353,10 @@ var table = { table.options.formId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; var params = $.common.isEmpty(tableId) ? $("#" + table.options.id).bootstrapTable('getOptions') : $("#" + tableId).bootstrapTable('getOptions'); if ($.common.isNotEmpty(pageNumber)) { - params.pageNumber = pageNumber; + params.pageNumber = pageNumber; } if ($.common.isNotEmpty(pageSize)) { - params.pageSize = pageSize; + params.pageSize = pageSize; } if($.common.isNotEmpty(tableId)){ $("#" + tableId).bootstrapTable('refresh', params); @@ -401,11 +401,11 @@ var table = { }, // 导入数据 importExcel: function(formId, width, height) { - table.set(); - var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId; - var _width = $.common.isEmpty(width) ? "400" : width; + table.set(); + var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId; + var _width = $.common.isEmpty(width) ? "400" : width; var _height = $.common.isEmpty(height) ? "230" : height; - layer.open({ + layer.open({ type: 1, area: [_width + 'px', _height + 'px'], fix: false, @@ -450,22 +450,22 @@ var table = { } }); } - }); + }); }, // 刷新表格 refresh: function(tableId, pageNumber, pageSize, url) { - var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; - var params = $("#" + currentId).bootstrapTable('getOptions'); - if ($.common.isEmpty(pageNumber)) { - pageNumber = params.pageNumber; - } - if ($.common.isEmpty(pageSize)) { - pageSize = params.pageSize; - } - if ($.common.isEmpty(url)) { - url = $.common.isEmpty(url) ? params.url : url; - } - $("#" + currentId).bootstrapTable('refresh', { + var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; + var params = $("#" + currentId).bootstrapTable('getOptions'); + if ($.common.isEmpty(pageNumber)) { + pageNumber = params.pageNumber; + } + if ($.common.isEmpty(pageSize)) { + pageSize = params.pageSize; + } + if ($.common.isEmpty(url)) { + url = $.common.isEmpty(url) ? params.url : url; + } + $("#" + currentId).bootstrapTable('refresh', { silent: true, url: url, pageNumber: pageNumber, @@ -477,59 +477,61 @@ var table = { var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; $("#" + currentId).bootstrapTable('refreshOptions', options); }, - // 查询表格指定列值 - selectColumns: function(column) { - var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) { + // 查询表格指定列值 deDuplication( true去重、false不去重) + selectColumns: function(column, deDuplication) { + var distinct = $.common.isEmpty(deDuplication) ? true : deDuplication; + var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) { return $.common.getItemField(row, column); - }); - if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) { - var selectedRows = table.rememberSelecteds[table.options.id]; - if($.common.isNotEmpty(selectedRows)) { - rows = $.map(table.rememberSelecteds[table.options.id], function (row) { - return $.common.getItemField(row, column); - }); - } - } - return $.common.uniqueFn(rows); + }); + if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) { + var selectedRows = table.rememberSelecteds[table.options.id]; + if($.common.isNotEmpty(selectedRows)) { + rows = $.map(table.rememberSelecteds[table.options.id], function (row) { + return $.common.getItemField(row, column); + }); + } + } + return distinct ? $.common.uniqueFn(rows) : rows; }, // 获取当前页选中或者取消的行ID affectedRowIds: function(rows) { - var column = $.common.isEmpty(table.options.uniqueId) ? table.options.columns[1].field : table.options.uniqueId; - var rowIds; - if ($.isArray(rows)) { - rowIds = $.map(rows, function(row) { - return $.common.getItemField(row, column); - }); - } else { - rowIds = [rows[column]]; - } - return rowIds; + var column = $.common.isEmpty(table.options.uniqueId) ? table.options.columns[1].field : table.options.uniqueId; + var rowIds; + if ($.isArray(rows)) { + rowIds = $.map(rows, function(row) { + return $.common.getItemField(row, column); + }); + } else { + rowIds = [rows[column]]; + } + return rowIds; }, - // 查询表格首列值 - selectFirstColumns: function() { - var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) { + // 查询表格首列值deDuplication( true去重、false不去重) + selectFirstColumns: function(deDuplication) { + var distinct = $.common.isEmpty(deDuplication) ? true : deDuplication; + var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) { return $.common.getItemField(row, table.options.columns[1].field); }); - if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) { + if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) { var selectedRows = table.rememberSelecteds[table.options.id]; if($.common.isNotEmpty(selectedRows)) { rows = $.map(selectedRows, function (row) { return $.common.getItemField(row, table.options.columns[1].field); }); } - } - return $.common.uniqueFn(rows); + } + return distinct ? $.common.uniqueFn(rows) : rows; }, // 回显数据字典 selectDictLabel: function(datas, value) { - if ($.common.isEmpty(datas) || $.common.isEmpty(value)) { - return ''; - } - var actions = []; + if ($.common.isEmpty(datas) || $.common.isEmpty(value)) { + return ''; + } + var actions = []; $.each(datas, function(index, dict) { if (dict.dictValue == ('' + value)) { - var listClass = $.common.equals("default", dict.listClass) || $.common.isEmpty(dict.listClass) ? "" : "badge badge-" + dict.listClass; - actions.push($.common.sprintf("%s", listClass, dict.dictLabel)); + var listClass = $.common.equals("default", dict.listClass) || $.common.isEmpty(dict.listClass) ? "" : "badge badge-" + dict.listClass; + actions.push($.common.sprintf("%s", listClass, dict.dictLabel)); return false; } }); @@ -537,11 +539,11 @@ var table = { }, // 回显数据字典(字符串数组) selectDictLabels: function(datas, value, separator) { - if ($.common.isEmpty(datas) || $.common.isEmpty(value)) { - return ''; - } - var currentSeparator = $.common.isEmpty(separator) ? "," : separator; - var actions = []; + if ($.common.isEmpty(datas) || $.common.isEmpty(value)) { + return ''; + } + var currentSeparator = $.common.isEmpty(separator) ? "," : separator; + var actions = []; $.each(value.split(currentSeparator), function(i, val) { $.each(datas, function(index, dict) { if (dict.dictValue == ('' + val)) { @@ -555,30 +557,30 @@ var table = { }, // 显示表格指定列 showColumn: function(column, tableId) { - var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; - $("#" + currentId).bootstrapTable('showColumn', column); + var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; + $("#" + currentId).bootstrapTable('showColumn', column); }, // 隐藏表格指定列 hideColumn: function(column, tableId) { - var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; - $("#" + currentId).bootstrapTable('hideColumn', column); + var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; + $("#" + currentId).bootstrapTable('hideColumn', column); }, // 显示所有表格列 showAllColumns: function(tableId) { - var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; - $("#" + currentId).bootstrapTable('showAllColumns'); + var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; + $("#" + currentId).bootstrapTable('showAllColumns'); }, // 隐藏所有表格列 hideAllColumns: function(tableId) { - var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; - $("#" + currentId).bootstrapTable('hideAllColumns'); + var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; + $("#" + currentId).bootstrapTable('hideAllColumns'); } }, // 表格树封装处理 treeTable: { // 初始化表格 init: function(options) { - var defaults = { + var defaults = { id: "bootstrap-tree-table", type: 1, // 0 代表bootstrapTable 1代表bootstrapTreeTable height: 0, @@ -593,10 +595,10 @@ var table = { expandAll: true, expandFirst: true }; - var options = $.extend(defaults, options); - table.options = options; - table.config[options.id] = options; - $.table.initEvent(); + var options = $.extend(defaults, options); + table.options = options; + table.config[options.id] = options; + $.table.initEvent(); $.bttTable = $('#' + options.id).bootstrapTreeTable({ code: options.code, // 用于设置父子关系 parentCode: options.parentCode, // 用于设置父子关系 @@ -622,27 +624,28 @@ var table = { }, // 条件查询 search: function(formId) { - var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; - var params = $.common.formToJSON(currentId); + var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; + var params = $.common.formToJSON(currentId); $.bttTable.bootstrapTreeTable('refresh', params); }, // 刷新 refresh: function() { - $.bttTable.bootstrapTreeTable('refresh'); + $.bttTable.bootstrapTreeTable('refresh'); }, - // 查询表格树指定列值 - selectColumns: function(column) { + // 查询表格树指定列值deDuplication( true去重、false不去重) + selectColumns: function(column, deDuplication) { + var distinct = $.common.isEmpty(deDuplication) ? true : deDuplication; var rows = $.map($.bttTable.bootstrapTreeTable('getSelections'), function (row) { return $.common.getItemField(row, column); }); - return $.common.uniqueFn(rows); + return distinct ? $.common.uniqueFn(rows) : rows; }, // 请求获取数据后处理回调函数,校验异常状态提醒 responseHandler: function(res) { - if (typeof table.options.responseHandler == "function") { + if (typeof table.options.responseHandler == "function") { table.options.responseHandler(res); } - if (res.code != undefined && res.code != web_status.SUCCESS) { + if (res.code != undefined && res.code != web_status.SUCCESS) { $.modal.alertWarning(res.msg); return []; } else { @@ -651,36 +654,36 @@ var table = { }, // 当所有数据被加载时触发 onLoadSuccess: function(data) { - if (typeof table.options.onLoadSuccess == "function") { + if (typeof table.options.onLoadSuccess == "function") { table.options.onLoadSuccess(data); - } - $(".table [data-toggle='tooltip']").tooltip(); + } + $(".table [data-toggle='tooltip']").tooltip(); }, }, // 表单封装处理 - form: { + form: { // 表单重置 reset: function(formId, tableId, pageNumber, pageSize) { table.set(tableId); - formId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; - $("#" + formId)[0].reset(); - var tableId = $.common.isEmpty(tableId) ? table.options.id : tableId; - if (table.options.type == table_type.bootstrapTable) { - var params = $("#" + tableId).bootstrapTable('getOptions'); + formId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; + $("#" + formId)[0].reset(); + var tableId = $.common.isEmpty(tableId) ? table.options.id : tableId; + if (table.options.type == table_type.bootstrapTable) { + var params = $("#" + tableId).bootstrapTable('getOptions'); if ($.common.isNotEmpty(pageNumber)) { - params.pageNumber = pageNumber; + params.pageNumber = pageNumber; } if ($.common.isNotEmpty(pageSize)) { - params.pageSize = pageSize; + params.pageSize = pageSize; } $("#" + tableId).bootstrapTable('refresh', params); - } else if (table.options.type == table_type.bootstrapTreeTable) { - $("#" + tableId).bootstrapTreeTable('refresh', []); - } + } else if (table.options.type == table_type.bootstrapTreeTable) { + $("#" + tableId).bootstrapTreeTable('refresh', []); + } }, // 获取选中复选框项 selectCheckeds: function(name) { - var checkeds = ""; + var checkeds = ""; $('input:checkbox[name="' + name + '"]:checked').each(function(i) { if (0 == i) { checkeds = $(this).val(); @@ -692,19 +695,19 @@ var table = { }, // 获取选中下拉框项 selectSelects: function(name) { - var selects = ""; - $('#' + name + ' option:selected').each(function (i) { - if (0 == i) { - selects = $(this).val(); - } else { - selects += ("," + $(this).val()); - } - }); - return selects; + var selects = ""; + $('#' + name + ' option:selected').each(function (i) { + if (0 == i) { + selects = $(this).val(); + } else { + selects += ("," + $(this).val()); + } + }); + return selects; } }, // 弹出层封装处理 - modal: { + modal: { // 显示图标 icon: function(type) { var icon = ""; @@ -721,7 +724,7 @@ var table = { }, // 消息提示 msg: function(content, type) { - if (type != undefined) { + if (type != undefined) { layer.msg(content, { icon: $.modal.icon(type), time: 1000, shift: 5 }); } else { layer.msg(content); @@ -729,15 +732,15 @@ var table = { }, // 错误消息 msgError: function(content) { - $.modal.msg(content, modal_status.FAIL); + $.modal.msg(content, modal_status.FAIL); }, // 成功消息 msgSuccess: function(content) { - $.modal.msg(content, modal_status.SUCCESS); + $.modal.msg(content, modal_status.SUCCESS); }, // 警告消息 msgWarning: function(content) { - $.modal.msg(content, modal_status.WARNING); + $.modal.msg(content, modal_status.WARNING); }, // 弹出提示 alert: function(content, type) { @@ -750,26 +753,26 @@ var table = { }, // 消息提示并刷新父窗体 msgReload: function(msg, type) { - layer.msg(msg, { - icon: $.modal.icon(type), - time: 500, - shade: [0.1, '#8F8F8F'] - }, - function() { - $.modal.reload(); - }); + layer.msg(msg, { + icon: $.modal.icon(type), + time: 500, + shade: [0.1, '#8F8F8F'] + }, + function() { + $.modal.reload(); + }); }, // 错误提示 alertError: function(content) { - $.modal.alert(content, modal_status.FAIL); + $.modal.alert(content, modal_status.FAIL); }, // 成功提示 alertSuccess: function(content) { - $.modal.alert(content, modal_status.SUCCESS); + $.modal.alert(content, modal_status.SUCCESS); }, // 警告提示 alertWarning: function(content) { - $.modal.alert(content, modal_status.WARNING); + $.modal.alert(content, modal_status.WARNING); }, // 关闭窗体 close: function (index) { @@ -797,22 +800,22 @@ var table = { }, // 弹出层指定宽度 open: function (title, url, width, height, callback) { - // 如果是移动端,就使用自适应大小弹窗 - if ($.common.isMobile()) { - width = 'auto'; - height = 'auto'; - } - if ($.common.isEmpty(title)) { + // 如果是移动端,就使用自适应大小弹窗 + if ($.common.isMobile()) { + width = 'auto'; + height = 'auto'; + } + if ($.common.isEmpty(title)) { title = false; } if ($.common.isEmpty(url)) { - url = "/404.html"; + url = "/404.html"; } if ($.common.isEmpty(width)) { - width = 800; + width = 800; } if ($.common.isEmpty(height)) { - height = ($(window).height() - 50); + height = ($(window).height() - 50); } if ($.common.isEmpty(callback)) { callback = function(index, layero) { @@ -820,36 +823,36 @@ var table = { iframeWin.contentWindow.submitHandler(index, layero); } } - layer.open({ - type: 2, - area: [width + 'px', height + 'px'], - fix: false, - //不固定 - maxmin: true, - shade: 0.3, - title: title, - content: url, - btn: ['确定', '关闭'], - // 弹层外区域关闭 - shadeClose: true, - yes: callback, - cancel: function(index) { - return true; - } - }); + layer.open({ + type: 2, + area: [width + 'px', height + 'px'], + fix: false, + //不固定 + maxmin: true, + shade: 0.3, + title: title, + content: url, + btn: ['确定', '关闭'], + // 弹层外区域关闭 + shadeClose: true, + yes: callback, + cancel: function(index) { + return true; + } + }); }, // 弹出层指定参数选项 openOptions: function (options) { - var _url = $.common.isEmpty(options.url) ? "/404.html" : options.url; - var _title = $.common.isEmpty(options.title) ? "系统窗口" : options.title; + var _url = $.common.isEmpty(options.url) ? "/404.html" : options.url; + var _title = $.common.isEmpty(options.title) ? "系统窗口" : options.title; var _width = $.common.isEmpty(options.width) ? "800" : options.width; var _height = $.common.isEmpty(options.height) ? ($(window).height() - 50) : options.height; var _btn = [' 确认', ' 关闭']; - // 如果是移动端,就使用自适应大小弹窗 - if ($.common.isMobile()) { - _width = 'auto'; - _height = 'auto'; - } + // 如果是移动端,就使用自适应大小弹窗 + if ($.common.isMobile()) { + _width = 'auto'; + _height = 'auto'; + } if ($.common.isEmpty(options.yes)) { options.yes = function(index, layero) { options.callBack(index, layero); @@ -886,22 +889,22 @@ var table = { }, // 弹出层全屏 openFull: function (title, url, width, height) { - // 如果是移动端,就使用自适应大小弹窗 - if ($.common.isMobile()) { - width = 'auto'; - height = 'auto'; - } - if ($.common.isEmpty(title)) { + // 如果是移动端,就使用自适应大小弹窗 + if ($.common.isMobile()) { + width = 'auto'; + height = 'auto'; + } + if ($.common.isEmpty(title)) { title = false; } if ($.common.isEmpty(url)) { url = "/404.html"; } if ($.common.isEmpty(width)) { - width = 800; + width = 800; } if ($.common.isEmpty(height)) { - height = ($(window).height() - 50); + height = ($(window).height() - 50); } var index = layer.open({ type: 2, @@ -922,46 +925,46 @@ var table = { cancel: function(index) { return true; } - }); + }); layer.full(index); }, // 选卡页方式打开 openTab: function (title, url, isRefresh) { - createMenuItem(url, title, isRefresh); + createMenuItem(url, title, isRefresh); }, // 选卡页同一页签打开 parentTab: function (title, url) { - var dataId = window.frameElement.getAttribute('data-id'); - createMenuItem(url, title); - closeItem(dataId); + var dataId = window.frameElement.getAttribute('data-id'); + createMenuItem(url, title); + closeItem(dataId); }, // 关闭选项卡 closeTab: function (dataId) { - closeItem(dataId); + closeItem(dataId); }, // 禁用按钮 disable: function() { - var doc = window.top == window.parent ? window.document : window.parent.document; - $("a[class*=layui-layer-btn]", doc).addClass("layer-disabled"); + var doc = window.top == window.parent ? window.document : window.parent.document; + $("a[class*=layui-layer-btn]", doc).addClass("layer-disabled"); }, // 启用按钮 enable: function() { - var doc = window.top == window.parent ? window.document : window.parent.document; - $("a[class*=layui-layer-btn]", doc).removeClass("layer-disabled"); + var doc = window.top == window.parent ? window.document : window.parent.document; + $("a[class*=layui-layer-btn]", doc).removeClass("layer-disabled"); }, // 打开遮罩层 loading: function (message) { - $.blockUI({ message: '
' + message + '
' }); + $.blockUI({ message: '
' + message + '
' }); }, // 关闭遮罩层 closeLoading: function () { - setTimeout(function(){ - $.unblockUI(); - }, 50); + setTimeout(function(){ + $.unblockUI(); + }, 50); }, // 重新加载 reload: function () { - parent.location.reload(); + parent.location.reload(); } }, // 操作封装处理 @@ -987,17 +990,17 @@ var table = { }, // post请求传输 post: function(url, data, callback) { - $.operate.submit(url, "post", "json", data, callback); + $.operate.submit(url, "post", "json", data, callback); }, // get请求传输 get: function(url, callback) { - $.operate.submit(url, "get", "json", "", callback); + $.operate.submit(url, "get", "json", "", callback); }, // 详细信息 detail: function(id, width, height) { - table.set(); - var _url = $.operate.detailUrl(id); - var options = { + table.set(); + var _url = $.operate.detailUrl(id); + var options = { title: table.options.modalName + "详细", width: width, height: height, @@ -1008,231 +1011,231 @@ var table = { layer.close(index); } }; - $.modal.openOptions(options); + $.modal.openOptions(options); }, // 详细信息,以tab页展现 detailTab: function(id) { - table.set(); - $.modal.openTab("详细" + table.options.modalName, $.operate.detailUrl(id)); + table.set(); + $.modal.openTab("详细" + table.options.modalName, $.operate.detailUrl(id)); }, // 详细访问地址 detailUrl: function(id) { - var url = "/404.html"; - if ($.common.isNotEmpty(id)) { - url = table.options.detailUrl.replace("{id}", id); - } else { - var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); - if (id.length == 0) { + var url = "/404.html"; + if ($.common.isNotEmpty(id)) { + url = table.options.detailUrl.replace("{id}", id); + } else { + var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); + if (id.length == 0) { $.modal.alertWarning("请至少选择一条记录"); return; - } - url = table.options.detailUrl.replace("{id}", id); - } + } + url = table.options.detailUrl.replace("{id}", id); + } return url; }, // 删除信息 remove: function(id) { - table.set(); - $.modal.confirm("确定删除该条" + table.options.modalName + "信息吗?", function() { + table.set(); + $.modal.confirm("确定删除该条" + table.options.modalName + "信息吗?", function() { var url = $.common.isEmpty(id) ? table.options.removeUrl : table.options.removeUrl.replace("{id}", id); if(table.options.type == table_type.bootstrapTreeTable) { - $.operate.get(url); + $.operate.get(url); } else { - var data = { "ids": id }; - $.operate.submit(url, "post", "json", data); + var data = { "ids": id }; + $.operate.submit(url, "post", "json", data); } - }); + }); }, // 批量删除信息 removeAll: function() { - table.set(); - var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); - if (rows.length == 0) { - $.modal.alertWarning("请至少选择一条记录"); - return; - } - $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() { - var url = table.options.removeUrl; - var data = { "ids": rows.join() }; - $.operate.submit(url, "post", "json", data); - }); + table.set(); + var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); + if (rows.length == 0) { + $.modal.alertWarning("请至少选择一条记录"); + return; + } + $.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() { + var url = table.options.removeUrl; + var data = { "ids": rows.join() }; + $.operate.submit(url, "post", "json", data); + }); }, // 清空信息 clean: function() { - table.set(); - $.modal.confirm("确定清空所有" + table.options.modalName + "吗?", function() { - var url = table.options.cleanUrl; - $.operate.submit(url, "post", "json", ""); - }); + table.set(); + $.modal.confirm("确定清空所有" + table.options.modalName + "吗?", function() { + var url = table.options.cleanUrl; + $.operate.submit(url, "post", "json", ""); + }); }, // 添加信息 add: function(id) { - table.set(); - $.modal.open("添加" + table.options.modalName, $.operate.addUrl(id)); + table.set(); + $.modal.open("添加" + table.options.modalName, $.operate.addUrl(id)); }, // 添加信息,以tab页展现 addTab: function (id) { - table.set(); + table.set(); $.modal.openTab("添加" + table.options.modalName, $.operate.addUrl(id)); }, // 添加信息 全屏 addFull: function(id) { - table.set(); + table.set(); $.modal.openFull("添加" + table.options.modalName, $.operate.addUrl(id)); }, // 添加访问地址 addUrl: function(id) { - var url = $.common.isEmpty(id) ? table.options.createUrl.replace("{id}", "") : table.options.createUrl.replace("{id}", id); + var url = $.common.isEmpty(id) ? table.options.createUrl.replace("{id}", "") : table.options.createUrl.replace("{id}", id); return url; }, // 修改信息 edit: function(id) { - table.set(); - if($.common.isEmpty(id) && table.options.type == table_type.bootstrapTreeTable) { - var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0]; - if ($.common.isEmpty(row)) { - $.modal.alertWarning("请至少选择一条记录"); - return; - } - var url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]); - $.modal.open("修改" + table.options.modalName, url); - } else { - $.modal.open("修改" + table.options.modalName, $.operate.editUrl(id)); - } + table.set(); + if($.common.isEmpty(id) && table.options.type == table_type.bootstrapTreeTable) { + var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0]; + if ($.common.isEmpty(row)) { + $.modal.alertWarning("请至少选择一条记录"); + return; + } + var url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]); + $.modal.open("修改" + table.options.modalName, url); + } else { + $.modal.open("修改" + table.options.modalName, $.operate.editUrl(id)); + } }, // 修改信息,以tab页展现 editTab: function(id) { - table.set(); - $.modal.openTab("修改" + table.options.modalName, $.operate.editUrl(id)); + table.set(); + $.modal.openTab("修改" + table.options.modalName, $.operate.editUrl(id)); }, // 修改信息 全屏 editFull: function(id) { - table.set(); - var url = "/404.html"; - if ($.common.isNotEmpty(id)) { - url = table.options.updateUrl.replace("{id}", id); - } else { - if(table.options.type == table_type.bootstrapTreeTable) { - var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0]; - if ($.common.isEmpty(row)) { - $.modal.alertWarning("请至少选择一条记录"); - return; - } - url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]); - } else { - var row = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); - url = table.options.updateUrl.replace("{id}", row); - } - } - $.modal.openFull("修改" + table.options.modalName, url); + table.set(); + var url = "/404.html"; + if ($.common.isNotEmpty(id)) { + url = table.options.updateUrl.replace("{id}", id); + } else { + if(table.options.type == table_type.bootstrapTreeTable) { + var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0]; + if ($.common.isEmpty(row)) { + $.modal.alertWarning("请至少选择一条记录"); + return; + } + url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]); + } else { + var row = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); + url = table.options.updateUrl.replace("{id}", row); + } + } + $.modal.openFull("修改" + table.options.modalName, url); }, // 修改访问地址 editUrl: function(id) { - var url = "/404.html"; - if ($.common.isNotEmpty(id)) { - url = table.options.updateUrl.replace("{id}", id); - } else { - var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); - if (id.length == 0) { - $.modal.alertWarning("请至少选择一条记录"); - return; - } - url = table.options.updateUrl.replace("{id}", id); - } + var url = "/404.html"; + if ($.common.isNotEmpty(id)) { + url = table.options.updateUrl.replace("{id}", id); + } else { + var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); + if (id.length == 0) { + $.modal.alertWarning("请至少选择一条记录"); + return; + } + url = table.options.updateUrl.replace("{id}", id); + } return url; }, // 保存信息 刷新表格 save: function(url, data, callback) { - var config = { - url: url, - type: "post", - dataType: "json", - data: data, - beforeSend: function () { - $.modal.loading("正在处理中,请稍后..."); - $.modal.disable(); - }, - success: function(result) { - if (typeof callback == "function") { - callback(result); - } - $.operate.successCallback(result); - } - }; - $.ajax(config) + var config = { + url: url, + type: "post", + dataType: "json", + data: data, + beforeSend: function () { + $.modal.loading("正在处理中,请稍后..."); + $.modal.disable(); + }, + success: function(result) { + if (typeof callback == "function") { + callback(result); + } + $.operate.successCallback(result); + } + }; + $.ajax(config) }, // 保存信息 弹出提示框 saveModal: function(url, data, callback) { - var config = { - url: url, - type: "post", - dataType: "json", - data: data, - beforeSend: function () { - $.modal.loading("正在处理中,请稍后..."); - }, - success: function(result) { - if (typeof callback == "function") { - callback(result); - } - if (result.code == web_status.SUCCESS) { - $.modal.alertSuccess(result.msg) - } else if (result.code == web_status.WARNING) { - $.modal.alertWarning(result.msg) - } else { - $.modal.alertError(result.msg); - } - $.modal.closeLoading(); - } - }; - $.ajax(config) + var config = { + url: url, + type: "post", + dataType: "json", + data: data, + beforeSend: function () { + $.modal.loading("正在处理中,请稍后..."); + }, + success: function(result) { + if (typeof callback == "function") { + callback(result); + } + if (result.code == web_status.SUCCESS) { + $.modal.alertSuccess(result.msg) + } else if (result.code == web_status.WARNING) { + $.modal.alertWarning(result.msg) + } else { + $.modal.alertError(result.msg); + } + $.modal.closeLoading(); + } + }; + $.ajax(config) }, // 保存选项卡信息 saveTab: function(url, data, callback) { - var config = { - url: url, - type: "post", - dataType: "json", - data: data, - beforeSend: function () { - $.modal.loading("正在处理中,请稍后..."); - }, - success: function(result) { - if (typeof callback == "function") { - callback(result); - } - $.operate.successTabCallback(result); - } - }; - $.ajax(config) + var config = { + url: url, + type: "post", + dataType: "json", + data: data, + beforeSend: function () { + $.modal.loading("正在处理中,请稍后..."); + }, + success: function(result) { + if (typeof callback == "function") { + callback(result); + } + $.operate.successTabCallback(result); + } + }; + $.ajax(config) }, // 保存结果弹出msg刷新table表格 ajaxSuccess: function (result) { - if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTable) { - $.modal.msgSuccess(result.msg); - $.table.refresh(); + if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTable) { + $.modal.msgSuccess(result.msg); + $.table.refresh(); } else if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTreeTable) { - $.modal.msgSuccess(result.msg); - $.treeTable.refresh(); + $.modal.msgSuccess(result.msg); + $.treeTable.refresh(); } else if (result.code == web_status.SUCCESS && $.common.isEmpty(table.options.type)) { - $.modal.msgSuccess(result.msg) + $.modal.msgSuccess(result.msg) } else if (result.code == web_status.WARNING) { - $.modal.alertWarning(result.msg) + $.modal.alertWarning(result.msg) } else { - $.modal.alertError(result.msg); + $.modal.alertError(result.msg); } - $.modal.closeLoading(); + $.modal.closeLoading(); }, // 成功结果提示msg(父窗体全局更新) saveSuccess: function (result) { - if (result.code == web_status.SUCCESS) { - $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS); + if (result.code == web_status.SUCCESS) { + $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS); } else if (result.code == web_status.WARNING) { - $.modal.alertWarning(result.msg) + $.modal.alertWarning(result.msg) } else { - $.modal.alertError(result.msg); + $.modal.alertError(result.msg); } - $.modal.closeLoading(); + $.modal.closeLoading(); }, // 成功回调执行事件(父窗体静默更新) successCallback: function(result) { @@ -1260,18 +1263,18 @@ var table = { // 选项卡成功回调执行事件(父窗体静默更新) successTabCallback: function(result) { if (result.code == web_status.SUCCESS) { - var topWindow = $(window.parent.document); - var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-panel'); - var $contentWindow = $('.RuoYi_iframe[data-id="' + currentId + '"]', topWindow)[0].contentWindow; - $.modal.close(); - $contentWindow.$.modal.msgSuccess(result.msg); - $contentWindow.$(".layui-layer-padding").removeAttr("style"); - if ($contentWindow.table.options.type == table_type.bootstrapTable) { - $contentWindow.$.table.refresh(); - } else if ($contentWindow.table.options.type == table_type.bootstrapTreeTable) { - $contentWindow.$.treeTable.refresh(); - } - $.modal.closeTab(); + var topWindow = $(window.parent.document); + var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-panel'); + var $contentWindow = $('.RuoYi_iframe[data-id="' + currentId + '"]', topWindow)[0].contentWindow; + $.modal.close(); + $contentWindow.$.modal.msgSuccess(result.msg); + $contentWindow.$(".layui-layer-padding").removeAttr("style"); + if ($contentWindow.table.options.type == table_type.bootstrapTable) { + $contentWindow.$.table.refresh(); + } else if ($contentWindow.table.options.type == table_type.bootstrapTreeTable) { + $contentWindow.$.treeTable.refresh(); + } + $.modal.closeTab(); } else if (result.code == web_status.WARNING) { $.modal.alertWarning(result.msg) } else { @@ -1291,12 +1294,12 @@ var table = { }, // 表单验证 form: function (formId) { - var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; + var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; return $("#" + currentId).validate().form(); }, // 重置表单验证(清除提示信息) reset: function (formId) { - var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; + var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; return $("#" + currentId).validate().resetForm(); } }, @@ -1360,28 +1363,28 @@ var table = { }, // 搜索节点 searchNode: function() { - // 取得输入的关键字的值 - var value = $.common.trim($("#keyword").val()); - if ($.tree._lastValue == value) { - return; - } - // 保存最后一次搜索名称 - $.tree._lastValue = value; - var nodes = $._tree.getNodes(); - // 如果要查空字串,就退出不查了。 - if (value == "") { - $.tree.showAllNode(nodes); - return; - } - $.tree.hideAllNode(nodes); - // 根据搜索值模糊匹配 - $.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value)); + // 取得输入的关键字的值 + var value = $.common.trim($("#keyword").val()); + if ($.tree._lastValue == value) { + return; + } + // 保存最后一次搜索名称 + $.tree._lastValue = value; + var nodes = $._tree.getNodes(); + // 如果要查空字串,就退出不查了。 + if (value == "") { + $.tree.showAllNode(nodes); + return; + } + $.tree.hideAllNode(nodes); + // 根据搜索值模糊匹配 + $.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value)); }, // 根据Id和Name选中指定节点 selectByIdName: function(treeId, node) { - if ($.common.isNotEmpty(treeId) && node && treeId == node.id) { - $._tree.selectNode(node, true); - } + if ($.common.isNotEmpty(treeId) && node && treeId == node.id) { + $._tree.selectNode(node, true); + } }, // 显示所有节点 showAllNode: function(nodes) { @@ -1395,7 +1398,7 @@ var table = { $._tree.showNode(nodes[i]); $.tree.showAllNode(nodes[i].children); } - }, + }, // 隐藏所有节点 hideAllNode: function(nodes) { var tree = $.fn.zTree.getZTreeObj("tree"); @@ -1439,7 +1442,7 @@ var table = { return $.map(nodes, function (row) { return row[_column]; }).join(); - }, + }, // 不允许根父节点选择 notAllowParents: function(_tree) { var nodes = _tree.getSelectedNodes(); @@ -1487,8 +1490,8 @@ var table = { } }, // 通用方法封装处理 - common: { - // 判断字符串是否为空 + common: { + // 判断字符串是否为空 isEmpty: function (value) { if (value == null || this.trim(value) == "") { return true; @@ -1497,7 +1500,7 @@ var table = { }, // 判断一个字符串是否为非空串 isNotEmpty: function (value) { - return !$.common.isEmpty(value); + return !$.common.isEmpty(value); }, // 空对象转字符串 nullToStr: function(value) { @@ -1522,19 +1525,19 @@ var table = { }, // 比较两个字符串(大小写敏感) equals: function (str, that) { - return str == that; + return str == that; }, // 比较两个字符串(大小写不敏感) equalsIgnoreCase: function (str, that) { - return String(str).toUpperCase() === String(that).toUpperCase(); + return String(str).toUpperCase() === String(that).toUpperCase(); }, // 将字符串按指定字符分割 split: function (str, sep, maxLen) { - if ($.common.isEmpty(str)) { - return null; - } - var value = String(str).split(sep); - return maxLen ? value.slice(0, maxLen - 1) : value; + if ($.common.isEmpty(str)) { + return null; + } + var value = String(str).split(sep); + return maxLen ? value.slice(0, maxLen - 1) : value; }, // 字符串格式化(%s ) sprintf: function (str) { @@ -1622,31 +1625,31 @@ var table = { }, // 数组中的所有元素放入一个字符串 join: function(array, separator) { - if ($.common.isEmpty(array)) { - return null; - } + if ($.common.isEmpty(array)) { + return null; + } return array.join(separator); }, // 获取form下所有的字段并转换为json对象 formToJSON: function(formId) { - var json = {}; - $.each($("#" + formId).serializeArray(), function(i, field) { - if(json[field.name]) { - json[field.name] += ("," + field.value); - } else { - json[field.name] = field.value; - } - }); - return json; + var json = {}; + $.each($("#" + formId).serializeArray(), function(i, field) { + if(json[field.name]) { + json[field.name] += ("," + field.value); + } else { + json[field.name] = field.value; + } + }); + return json; }, // 数据字典转下拉框 dictToSelect: function(datas, value, name) { - var actions = []; - actions.push($.common.sprintf("", name)); $.each(datas, function(index, dict) { actions.push($.common.sprintf("", dict.dictLabel)); }); From 42c7c4fdc664830d97b240765c65199cc926323d Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 30 Jul 2021 10:20:01 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=B1=8F=E8=94=BDhttp(s)=E8=BF=9C=E7=A8=8B=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/StringUtils.java | 23 +++++++++++++++++++ .../quartz/controller/SysJobController.java | 12 ++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java index 806e4ad9c..73a40cf07 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java @@ -324,6 +324,29 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils return list; } + /** + * 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写 + * + * @param cs 指定字符串 + * @param searchCharSequences 需要检查的字符串数组 + * @return 是否包含任意一个字符串 + */ + public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences) + { + if (isEmpty(cs) || isEmpty(searchCharSequences)) + { + return false; + } + for (CharSequence testStr : searchCharSequences) + { + if (containsIgnoreCase(cs, testStr)) + { + return true; + } + } + return false; + } + /** * 驼峰转下划线命名 */ diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java index 6803c96fa..3fbfb252d 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/controller/SysJobController.java @@ -137,7 +137,11 @@ public class SysJobController extends BaseController } else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI)) { - return AjaxResult.error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用"); + return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用"); + } + else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS })) + { + return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)//'调用"); } return toAjax(jobService.insertJob(job)); } @@ -167,7 +171,11 @@ public class SysJobController extends BaseController } else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI)) { - return AjaxResult.error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用"); + return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi://'调用"); + } + else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS })) + { + return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)//'调用"); } return toAjax(jobService.updateJob(job)); }