From 33f205244bf16ccf47b0d112699c9c1c742acdc1 Mon Sep 17 00:00:00 2001 From: smallchill Date: Fri, 16 Jun 2017 09:24:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 +- .../system/controller/UserController.java | 20 +- .../webapp/static/blade/js/blade-combotree.js | 397 ++++++++++++++++++ src/main/webapp/static/blade/js/blade-grid.js | 328 +++++++++++++++ 4 files changed, 739 insertions(+), 14 deletions(-) create mode 100644 src/main/webapp/static/blade/js/blade-combotree.js create mode 100644 src/main/webapp/static/blade/js/blade-grid.js diff --git a/pom.xml b/pom.xml index dcc86cd9..19244a0c 100644 --- a/pom.xml +++ b/pom.xml @@ -15,10 +15,10 @@ 1.7 - 4.3.7.RELEASE + 4.3.9.RELEASE 1.3.2 2.7 - 2.8.6 + 2.8.18 @@ -154,7 +154,7 @@ com.alibaba druid - 1.0.29 + 1.0.31 @@ -183,7 +183,7 @@ com.alibaba fastjson - 1.2.28 + 1.2.33 diff --git a/src/main/java/com/smallchill/system/controller/UserController.java b/src/main/java/com/smallchill/system/controller/UserController.java index e146fb90..11a81cbd 100644 --- a/src/main/java/com/smallchill/system/controller/UserController.java +++ b/src/main/java/com/smallchill/system/controller/UserController.java @@ -15,16 +15,6 @@ */ package com.smallchill.system.controller; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; - import com.smallchill.common.base.BaseController; import com.smallchill.common.tool.SysCache; import com.smallchill.core.annotation.Before; @@ -49,6 +39,15 @@ import com.smallchill.system.meta.intercept.UserIntercept; import com.smallchill.system.meta.intercept.UserValidator; import com.smallchill.system.model.RoleExt; import com.smallchill.system.model.User; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; @Controller @RequestMapping("/user") @@ -187,6 +186,7 @@ public class UserController extends BaseController implements ConstShiro{ boolean temp = Blade.create(User.class).update(user); if (temp) { CacheKit.removeAll(SYS_CACHE); + ShiroKit.clearCachedAuthenticationInfo(user.getAccount()); return success(UPDATE_SUCCESS_MSG); } else { return error(UPDATE_FAIL_MSG); diff --git a/src/main/webapp/static/blade/js/blade-combotree.js b/src/main/webapp/static/blade/js/blade-combotree.js new file mode 100644 index 00000000..22564c4a --- /dev/null +++ b/src/main/webapp/static/blade/js/blade-combotree.js @@ -0,0 +1,397 @@ +(function () { + var BladeComboTree = function () { + this.id = ""; + this.search = ""; + this.type = "combotree"; + this.source = ""; + this.where = ""; + this.val = ""; + this.treeId = "id"; + this.intercept = ""; + this.check = ""; + this.width = "180px"; + this.height = "250px"; + this.fix = true; + this.ext = ""; + } + + BladeComboTree.prototype = { + setId : function (id) { + this.id = id; + }, + setType : function (type) { + this.type = type; + }, + setSource : function (source) { + this.source = source; + }, + setWhere : function (where) { + this.where = where; + }, + setVal : function (val) { + this.val = val; + }, + setTreeId : function (treeId) { + this.treeId = treeId; + }, + setIntercept : function (intercept) { + this.intercept = intercept; + }, + setCheck : function (check) { + this.check = check; + }, + setWidth : function (width) { + this.width = width; + }, + setHeight : function (height) { + this.height = height; + }, + setExt : function (ext) { + this.ext = ext; + }, + beforeClick : function (treeId, treeNode) { + var zTree = $.fn.zTree.getZTreeObj(treeId); + zTree.checkNode(treeNode, !treeNode.checked, null, true); + return false; + }, + onCheck : function (e, treeId, treeNode) { + var zTree = $.fn.zTree.getZTreeObj(treeId), + nodes = zTree.getCheckedNodes(true), + ids = "", + v = ""; + for (var i = 0, l = nodes.length; i < l; i++) { + ids += nodes[i].id + ","; + v += nodes[i].name + ","; + } + if (v.length > 0 ) v = v.substring(0, v.length - 1); + if (ids.length > 0 ) ids = ids.substring(0, ids.length - 1); + var _id = treeId.replace("tree_", "").replace("_ipt", ""); + var treeInput = $("#" + _id + "_ipt"); + var treeHidden = $("#" + _id + ""); + treeInput.val(v); + treeHidden.val(ids); + $("#form_token").val(1); + + //用于点击后的回调 + if (typeof comboTreeCallBack == 'function') { + comboTreeCallBack(_id, ids); + } + + }, + showMenu : function () { + var _id = this.id; + var _me = this; + var $ipt = $("#" + _id + "_ipt"); + $("#tree_" + _id + "_ipt").css({"width": $ipt.css("width")}); + var top = $ipt.outerHeight(); + if (this.fix) { + top = top + $ipt.offset().top - 1; + } + $("#treeContent_" + _id + "_ipt").css({top:top + "px"}).slideDown("fast"); + $("body").bind("mousedown", function (event) { + if (!(event.target.id == "menuBtn" || event.target.id == ""+_id+"_ipt" || event.target.id == "treeContent_"+_id+"_ipt" || $(event.target).parents("#treeContent_"+_id+"_ipt").length>0)) { + _me.hideMenu(); + } + }); + }, + hideMenu : function () { + var _id = this.id; + var _me = this; + $("#treeContent_" + _id + "_ipt").fadeOut("fast"); + $("body").unbind("mousedown", function (event) { + if (!(event.target.id == "menuBtn" || event.target.id == ""+id+"_ipt" || event.target.id == "treeContent_"+id+"_ipt" || $(event.target).parents("#treeContent_"+id+"_ipt").length>0)) { + _me.showMenu(); + } + }); + }, + searchMenu : function () { + var setting; + + if (this.check == "radio") { + setting = { + check: { + enable: true, + chkStyle: "radio", + radioType : "all" + }, + view: { + dblClickExpand: false, + fontCss: getFont, + nameIsHTML: true + }, + data: { + simpleData: { + enable: true + } + }, + callback: { + beforeClick: this.beforeClick, + onCheck: this.onCheck + } + } + } else { + setting = { + check: { + enable: true, + chkboxType :{ "Y" : "", "N" : "" } + }, + view: { + dblClickExpand: false, + fontCss: getFont, + nameIsHTML: true + }, + data: { + simpleData: { + enable: true + } + }, + callback: { + beforeClick: this.beforeClick, + onCheck: this.onCheck + } + } + } + + function getFont(treeId, node) { + return node.font ? node.font : {}; + } + + var _id = this.id; + var _node_data; + var treeList = new Ajax(BladeApp.getCtx() + "/combotree/getTreeList", function(data){ + if (data.code === 0) { + _node_data = data.data; + $.fn.zTree.init($("#tree_" + _id + "_ipt"), setting, _node_data); + match(); + } else { + layer.alert(data.message, {icon: 2,title:"发生错误"}); + } + }); + treeList.set("search", $("#" + _id + "_ipt").val()); + treeList.set("type", this.type); + treeList.set("source", this.source); + treeList.set("where", this.where); + treeList.set("intercept", this.intercept); + treeList.set("ext", this.ext); + treeList.set("val", 0); + treeList.set("treeId", this.treeId); + treeList.start(); + + + function match() { + var search = $("#" + _id + "_ipt").val(); + if (BladeTool.isEmpty(search)) { + //layer.msg("请输入关键字", {shift: 6,time:2000}); + return false; + } + var zTree = $.fn.zTree.getZTreeObj("tree_" + _id + "_ipt"); + for (var i = 0; i < _node_data.length; i++) { + var name = _node_data[i].name; + if (name.contains(search)) { + var node = zTree.getNodeByParam("name", name); + node.font = {'font-weight':'bold', 'color':'#009688'}; + zTree.updateNode(node); + zTree.expandNode(node, true, false);//指定选中ID节点展开 + expandParentNode(node, zTree); + } + + } + } + + //递归打开ztree节点 + function expandParentNode(_node, zTree) { + var _pNode = _node.getParentNode();//获得父节点 + if (null != _pNode) { + if (!_pNode.open) { + zTree.expandNode(_pNode, true, false);//指定选中ID节点展开 + } + expandParentNode(_pNode, zTree); + } + } + + }, + initComboTree : function () { + var setting; + + if (this.check == "radio") { + setting = { + check: { + enable: true, + chkStyle: "radio", + radioType : "all" + }, + view: { + dblClickExpand: false + }, + data: { + simpleData: { + enable: true + } + }, + callback: { + beforeClick: this.beforeClick, + onCheck: this.onCheck + } + } + } else { + setting = { + check: { + enable: true, + chkboxType :{ "Y" : "", "N" : "" } + }, + view: { + dblClickExpand: false + }, + data: { + simpleData: { + enable: true + } + }, + callback: { + beforeClick: this.beforeClick, + onCheck: this.onCheck + } + } + } + + var _id = this.id; + var _val = $("#" + this.id).val(); + + var treeList = new Ajax(BladeApp.getCtx() + "/combotree/getTreeList", function(data){ + if (data.code === 0) { + $.fn.zTree.init($("#tree_" + _id + "_ipt"), setting, data.data); + } else { + layer.alert(data.message, {icon: 2,title:"发生错误"}); + } + }); + treeList.set("search", ""); + treeList.set("val", _val); + treeList.set("type", this.type); + treeList.set("source", this.source); + treeList.set("where", this.where); + treeList.set("intercept", this.intercept); + treeList.set("ext", this.ext); + treeList.set("treeId", this.treeId); + treeList.start(); + + + var treeName = new Ajax(BladeApp.getCtx() + "/combotree/getTreeListName", function(data){ + if (data.code === 0) { + $("#" + _id + "_ipt").val(data.data); + } else { + layer.alert(data.message, {icon: 2,title:"发生错误"}); + } + }); + treeName.set("type", this.type); + treeName.set("source", this.source); + treeName.set("where", this.where); + treeName.set("val", _val); + treeName.set("treeId", this.treeId); + treeName.start(); + + }, + reset: function () { + var setting; + + if (this.check == "radio") { + setting = { + check: { + enable: true, + chkStyle: "radio", + radioType : "all" + }, + view: { + dblClickExpand: false + }, + data: { + simpleData: { + enable: true + } + }, + callback: { + beforeClick: this.beforeClick, + onCheck: this.onCheck + } + } + } else { + setting = { + check: { + enable: true, + chkboxType :{ "Y" : "", "N" : "" } + }, + view: { + dblClickExpand: false + }, + data: { + simpleData: { + enable: true + } + }, + callback: { + beforeClick: this.beforeClick, + onCheck: this.onCheck + } + } + } + + var _id = this.id; + var _val = $("#" + this.id).val(); + + var treeList = new Ajax(BladeApp.getCtx() + "/combotree/getTreeList", function(data){ + if (data.code === 0) { + $.fn.zTree.init($("#tree_" + _id + "_ipt"), setting, data.data); + } else { + layer.alert(data.message, {icon: 2,title:"发生错误"}); + } + }); + treeList.set("search", ""); + treeList.set("val", _val); + treeList.set("type", this.type); + treeList.set("source", this.source); + treeList.set("where", this.where); + treeList.set("intercept", this.intercept); + treeList.set("ext", this.ext); + treeList.set("treeId", this.treeId); + treeList.start(); + }, + init : function () { + + var _me = this; + + var $ipt = $("#" + this.id); + + var _val = $ipt.val(); + + $ipt.attr("id", this.id + "_ipt"); + + var html = []; + html.push(''); + html.push(''); + $ipt.after(html.join("")); + + if (BladeTool.isEmpty(this.val)) { + this.val = _val; + } + + this.initComboTree(); + + $ipt.bind("click", function(){ + _me.showMenu(); + }); + $ipt.bind("keydown", function(e){ + if (e.keyCode == 13) { + _me.searchMenu(); + } + }); + } + } + + window.BladeComboTree = BladeComboTree; + + document.write(''); + document.write(''); + document.write(''); + +}()); \ No newline at end of file diff --git a/src/main/webapp/static/blade/js/blade-grid.js b/src/main/webapp/static/blade/js/blade-grid.js new file mode 100644 index 00000000..a63d0ba3 --- /dev/null +++ b/src/main/webapp/static/blade/js/blade-grid.js @@ -0,0 +1,328 @@ +(function () { + var CacheGrid = function () { + this.title = []; + this.field = []; + this.pk = "id"; + this.table = ""; + this.data = new JMap(); + this.keys = new Array(); + this.checkBox = true; + this.count = 0; + this.noWidth = 3.5; + this.pageDetail = ""; + }; + + CacheGrid.prototype = { + setPk: function (pk) { + this.pk = pk; + }, + setNoWidth: function (width) { + this.noWidth = width; + }, + setCheckBox: function (checkBox) { + this.checkBox = checkBox; + }, + setTable: function (table) { + this.table = table; + }, + setTitle: function (title) { + this.title = title; + }, + setField: function (field) { + this.field = field; + }, + setData: function (data) { + this.count = 0; + this.data = new JMap(); + var keys = data.keys().sortNumber(); + for (var k = 0; k < keys.length; k++) { + var _key = keys[k]; + var _map = data.get(_key); + this.count++; + this.data.put(this.count, _map); + } + }, + setDataByKey: function (data) { + this.count = 0; + this.data = new JMap(); + var keys = data.keys().sortNumber(); + for (var k = 0; k < keys.length; k++) { + var _key = keys[k]; + var _map = data.get(_key); + this.count = _key; + this.data.put(_key, _map); + } + }, + setPageDetail:function (pageDetail) { + this.pageDetail = pageDetail; + }, + getData: function () { + return this.data; + }, + getSelectKey: function () { + return this.keys[0]; + }, + getSelectKeys: function () { + return this.keys.unique(); + }, + getSelectRow: function () { + var selectKey = this.keys[0]; + return this.data.get(selectKey); + }, + getSelectRows: function () { + var selectRows = new JMap(); + var selectKeys = this.keys.unique(); + for (var i = 0; i < selectKeys.length; i++) { + var key = selectKeys[i]; + selectRows.put(key, this.data.get(key)); + } + return selectRows; + }, + zero: function () { + return (this.getSelectKeys().length == 0); + }, + one: function () { + return (this.getSelectKeys().length == 1); + }, + multi: function () { + return (this.getSelectKeys().length > 1); + }, + rowId: function () { + return this.count; + }, + select: function (key) { + debugger; + $("#" + this.table + "_body_tr_" + key).click(); + }, + add: function (_map) { + var me = this; + //如果没有数据则清空 + if (this.data.size() == 0) { + $("#" + this.table + "_body").html(""); + } + this.count++; + var _key = this.count; + this.data.put(_key, _map); + clickCheckbox(me, _key, _map); + }, + update: function (_key, _map) { + this.data.remove(_key); + this.data.put(_key, _map); + this.keys.remove(_key); + var field = []; + if (this.checkBox) { + field.push(""); + field.push("
"); + field.push(" "); + field.push("
"); + field.push("
"); + field.push(""); + } + field.push(""); + field.push(_key); + field.push(""); + for (var f = 0; f < this.field.length; f++) { + var _value = _map.get(this.field[f].name); + var _style = ""; + if (this.field[f].hidden) { + _style += "display: none;"; + } + if (typeof this.field[f].align === "string") { + _style += "text-align: " + this.field[f].align + ";"; + } + field.push(""); + if (typeof this.field[f].format === 'function') { + field.push(this.field[f].format(_map, _key)); + } else { + field.push(_value); + } + field.push(""); + } + $("#" + this.table + "_body_tr_" + _key).html(field.join("")); + $("#" + this.table + "_body_tr_" + _key).removeAttr("style"); + }, + remove: function (_key) { + this.data.remove(_key); + this.keys.remove(_key); + $("#" + this.table + "_body_tr_" + _key).remove(); + if (this.data.size() == 0) { + $("#" + this.table + "_body").html("暂无数据"); + } + }, + removeMulti: function (_keys) { + for (var i = 0; i < _keys.length; i++) { + var key = _keys[i]; + this.remove(key); + } + }, + init: function () { + this.keys = new Array(); + var me = this; + var $table = $("#" + this.table); + $table.html(""); + var thead = []; + thead.push(""); + thead.push(""); + if (this.checkBox) { + thead.push(""); + } + thead.push("序号"); + for (var i = 0; i < this.title.length; i++) { + var _display = ""; + if (this.field[i].hidden) { + _display = "style='display:none;'"; + } + thead.push(""); + thead.push(this.title[i]); + thead.push(""); + } + thead.push(""); + thead.push(""); + $table.append(thead.join("")); + var $tbody = $("").appendTo($table); + + //加载分页信息 + if (BladeTool.isNotEmpty(this.pageDetail) && this.pageDetail.total > 0) { + var html = []; + html.push(''); + html.push('每页显示:'); + html.push(''); + html.push(''); + $("#grid_pages").html(html.join("")); + $("#sel_page").val(this.pageDetail.pageSize); + var rowEnd = (this.pageDetail.rowEnd == 100000000) ? "∞" : this.pageDetail.rowEnd; + $("#sp_grid").html("显示第" + this.pageDetail.rowBegin + "到第" + rowEnd + "条记录,共" + this.pageDetail.records + "条记录,"); + } + + if (this.data.size() === 0) { + $tbody.html("暂无数据"); + $("#" + this.table + "_chb").bind("click", function () { + var checked = $(this).is(":checked"); + $("input[name='" + me.table + "_grid_checkbox']").each(function () { + var data_key = $(this).attr("data-key"); + $(this).prop("checked", checked); + if (checked) { + $(this).closest("tr").css("background-color", "#f5f5f5"); + me.keys.push(data_key); + } else { + $(this).closest("tr").removeAttr("style"); + me.keys.remove(data_key); + } + }); + me.keys = me.keys.unique(); + }); + return false; + } + //传入的data参数为一个ListMap + var keys = this.data.keys().sortNumber(); + for (var k = 0; k < keys.length; k++) { + //取到每一行的map对象 + var _key = keys[k]; + var _map = this.data.get(_key); + clickCheckbox(me, _key, _map); + } + + $("#" + this.table + "_chb").bind("click", function () { + var checked = $(this).is(":checked"); + $("input[name='" + me.table + "_grid_checkbox']").each(function () { + var data_key = $(this).attr("data-key"); + $(this).prop("checked", checked); + if (checked) { + $(this).closest("tr").css("background-color", "#f5f5f5"); + me.keys.push(data_key); + } else { + $(this).closest("tr").removeAttr("style"); + me.keys.remove(data_key); + } + }); + me.keys = me.keys.unique(); + }); + } + }; + window.CacheGrid = CacheGrid; + + function clickCheckbox(me, _key, _map) { + var field = []; + field.push(""); + if (me.checkBox) { + field.push(""); + field.push("
"); + field.push(" "); + field.push("
"); + field.push("
"); + field.push(""); + } + field.push(""); + field.push(_key); + field.push(""); + for (var f = 0; f < me.field.length; f++) { + var _value = _map.get(me.field[f].name); + var _style = ""; + if (me.field[f].hidden) { + _style += "display: none;"; + } + if (typeof me.field[f].align === "string") { + _style += "text-align: " + me.field[f].align + ";"; + } + field.push(""); + if (typeof me.field[f].format === 'function') { + field.push(me.field[f].format(_map, _key)); + } else { + field.push(_value); + } + field.push(""); + } + field.push(""); + $("#" + me.table + "_body").append(field.join("")); + if (me.checkBox) { + $("#" + me.table + "_body_tr_" + _key).bind("click", function () { + var par = $(this).parent(); + var _key = $(this).find("input[type='checkbox']").attr("data-key"); + var $chb = $("#" + me.table + "_grid_checkbox_" + _key); + if ($chb.hasClass('multiple-check')) { + if ($chb.is(":checked")) { + me.keys.remove(_key); + $chb.prop("checked", false); + $(this).removeAttr("style"); + $("#" + me.table + "_chb").prop("checked", false); + } else { + me.keys.push(_key); + $chb.prop("checked", true); + $(this).css("background-color", "#f5f5f5"); + } + return; + } + let checkBoxes = par.find("input[name='" + me.table + "_grid_checkbox']"); + for (let i = 0; i < checkBoxes.length; i++) { + let check_key = $(checkBoxes[i]).attr("data-key"); + me.keys.remove(check_key); + $(checkBoxes[i]).prop("checked", false); + $(checkBoxes[i]).closest('tr').removeAttr("style"); + } + $("#" + me.table + "_chb").prop("checked", false); + if ($chb.is(":checked")) { + // me.keys.remove(_key); + // $chb.prop("checked", false); + // $(this).removeAttr("style"); + } else { + me.keys = []; + me.keys.push(_key); + $chb.prop("checked", true); + $(this).css("background-color", "#f5f5f5"); + } + }); + $('.cover-checkbox').on('mouseover', function () { + $(this).find("input[type='checkbox']").addClass("multiple-check"); + }) + $('.cover-checkbox').on('mouseout', function () { + $(this).find("input[type='checkbox']").removeClass("multiple-check"); + }) + } + + } +}()); \ No newline at end of file