From 707b51b2473312528221786aeef7dca1aba333a2 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sun, 18 Oct 2020 12:05:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/static/ruoyi/index.js | 81 +- .../main/resources/static/ruoyi/js/common.js | 438 ++--- .../main/resources/static/ruoyi/js/ry-ui.js | 1454 ++++++++--------- .../src/main/resources/static/ruoyi/login.js | 56 +- .../main/resources/static/ruoyi/register.js | 28 +- 5 files changed, 1028 insertions(+), 1029 deletions(-) diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/index.js b/ruoyi-admin/src/main/resources/static/ruoyi/index.js index a4ff28f1..29f21242 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/index.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/index.js @@ -24,9 +24,9 @@ $(function() { // 菜单切换 $('.navbar-minimalize').click(function() { if (isMobile) { - $("body").toggleClass("canvas-menu"); + $("body").toggleClass("canvas-menu"); } else { - $("body").toggleClass("mini-navbar"); + $("body").toggleClass("mini-navbar"); } SmoothlyMenu(); }); @@ -62,12 +62,12 @@ $(window).bind("load resize", function() { $('.navbar-static-side').fadeOut(); } else { if($('body').hasClass('canvas-menu')) { - $('body').addClass('fixed-sidebar'); - $('body').removeClass('canvas-menu'); - $("body").removeClass("mini-navbar"); - $("nav .logo").removeClass("hide"); - $(".slimScrollDiv").css({ "overflow": "visible" }); - $('.navbar-static-side').fadeIn(); + $('body').addClass('fixed-sidebar'); + $('body').removeClass('canvas-menu'); + $("body").removeClass("mini-navbar"); + $("nav .logo").removeClass("hide"); + $(".slimScrollDiv").css({ "overflow": "visible" }); + $('.navbar-static-side').fadeIn(); } } }); @@ -89,7 +89,7 @@ function syncMenuTab(dataId) { $("#tab_" + menuId + " a").click(); } } - } + } } function NavToggle() { @@ -97,12 +97,11 @@ function NavToggle() { } function fixedSidebar() { - $('#side-menu').hide(); - $("nav .logo").addClass("hide"); + $('#side-menu').hide(); + $("nav .logo").addClass("hide"); setTimeout(function() { $('#side-menu').fadeIn(500); - }, - 100); + }, 100); } function SmoothlyMenu() { @@ -263,8 +262,8 @@ $(function() { var $dataObj = $('a[href$="' + decodeURI(dataUrl) + '"]'); if (!$dataObj.hasClass("noactive")) { - $('.tab-pane li').removeClass("active"); - $('.nav ul').removeClass("in"); + $('.tab-pane li').removeClass("active"); + $('.nav ul').removeClass("in"); $dataObj.parents("ul").addClass("in") $dataObj.parents("li").addClass("active").siblings().removeClass("active").find('li').removeClass("active"); $dataObj.parents("ul").css('height', 'auto').height(); @@ -395,7 +394,7 @@ $(function() { $(this).show().siblings('.RuoYi_iframe').hide(); return false; } - }); + }); } } } @@ -450,14 +449,14 @@ $(function() { var currentId = $('.page-tabs-content').find('.active').attr('data-id'); var target = $('.RuoYi_iframe[data-id="' + currentId + '"]'); var url = target.attr('src'); - target.attr('src', url).ready(); + target.attr('src', url).ready(); } // 页签全屏 function fullScreenTab() { var currentId = $('.page-tabs-content').find('.active').attr('data-id'); var target = $('.RuoYi_iframe[data-id="' + currentId + '"]'); - target.fullScreen(true); + target.fullScreen(true); } // 关闭当前选项卡 @@ -538,11 +537,11 @@ $(function() { // 设置锚点 function setIframeUrl(href) { if($.common.equals("history", mode)) { - storage.set('publicPath', href); + storage.set('publicPath', href); } else { - var nowUrl = window.location.href; - var newUrl = nowUrl.substring(0, nowUrl.indexOf("#")); - window.location.href = newUrl + "#" + href; + var nowUrl = window.location.href; + var newUrl = nowUrl.substring(0, nowUrl.indexOf("#")); + window.location.href = newUrl + "#" + href; } } @@ -569,14 +568,14 @@ $(function() { name: "关闭当前", icon: "fa-close", callback: function(key, opt) { - opt.$trigger.find('i').trigger("click"); + opt.$trigger.find('i').trigger("click"); } }, "close_other": { name: "关闭其他", icon: "fa-window-close-o", callback: function(key, opt) { - setActiveTab(this); + setActiveTab(this); tabCloseOther(); } }, @@ -584,23 +583,23 @@ $(function() { name: "关闭左侧", icon: "fa-reply", callback: function(key, opt) { - setActiveTab(this); - this.prevAll('.menuTab').not(":last").each(function() { - if ($(this).hasClass('active')) { - setActiveTab(this); - } - $('.RuoYi_iframe[data-id="' + $(this).data('id') + '"]').remove(); - $(this).remove(); - }); - $('.page-tabs-content').css("margin-left", "0"); + setActiveTab(this); + this.prevAll('.menuTab').not(":last").each(function() { + if ($(this).hasClass('active')) { + setActiveTab(this); + } + $('.RuoYi_iframe[data-id="' + $(this).data('id') + '"]').remove(); + $(this).remove(); + }); + $('.page-tabs-content').css("margin-left", "0"); } }, "close_right": { name: "关闭右侧", icon: "fa-share", callback: function(key, opt) { - setActiveTab(this); - this.nextAll('.menuTab').each(function() { + setActiveTab(this); + this.nextAll('.menuTab').each(function() { $('.menuTab[data-id="' + $(this).data('id') + '"]').remove(); $(this).remove(); }); @@ -618,18 +617,18 @@ $(function() { name: "全屏显示", icon: "fa-arrows-alt", callback: function(key, opt) { - setActiveTab(this); + setActiveTab(this); var target = $('.RuoYi_iframe[data-id="' + this.data('id') + '"]'); - target.fullScreen(true); + target.fullScreen(true); } }, "refresh": { name: "刷新页面", icon: "fa-refresh", callback: function(key, opt) { - setActiveTab(this); - var target = $('.RuoYi_iframe[data-id="' + this.data('id') + '"]'); - var url = target.attr('src'); + setActiveTab(this); + var target = $('.RuoYi_iframe[data-id="' + this.data('id') + '"]'); + var url = target.attr('src'); $.modal.loading("数据加载中,请稍后..."); target.attr('src', url).load(function () { $.modal.closeLoading(); @@ -640,7 +639,7 @@ $(function() { name: "新窗口打开", icon: "fa-link", callback: function(key, opt) { - var target = $('.RuoYi_iframe[data-id="' + this.data('id') + '"]'); + var target = $('.RuoYi_iframe[data-id="' + this.data('id') + '"]'); window.open(target.attr('src')); } }, diff --git a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js index 163d2ce6..bc810834 100644 --- a/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js +++ b/ruoyi-admin/src/main/resources/static/ruoyi/js/common.js @@ -4,187 +4,187 @@ */ $(function() { - // layer扩展皮肤 - if (window.layer !== undefined) { - layer.config({ - extend: 'moon/style.css', - skin: 'layer-ext-moon' - }); - } + // layer扩展皮肤 + if (window.layer !== undefined) { + layer.config({ + extend: 'moon/style.css', + skin: 'layer-ext-moon' + }); + } - // 回到顶部绑定 - if ($.fn.toTop !== undefined) { - $('#scroll-up').toTop(); - } + // 回到顶部绑定 + if ($.fn.toTop !== undefined) { + $('#scroll-up').toTop(); + } - // select2复选框事件绑定 - if ($.fn.select2 !== undefined) { + // select2复选框事件绑定 + if ($.fn.select2 !== undefined) { $.fn.select2.defaults.set( "theme", "bootstrap" ); - $("select.form-control:not(.noselect2)").each(function () { - $(this).select2().on("change", function () { - $(this).valid(); - }) - }) - } + $("select.form-control:not(.noselect2)").each(function () { + $(this).select2().on("change", function () { + $(this).valid(); + }) + }) + } - // iCheck单选框及复选框事件绑定 - if ($.fn.iCheck !== undefined) { - $(".check-box:not(.noicheck),.radio-box:not(.noicheck)").each(function() { + // iCheck单选框及复选框事件绑定 + if ($.fn.iCheck !== undefined) { + $(".check-box:not(.noicheck),.radio-box:not(.noicheck)").each(function() { $(this).iCheck({ checkboxClass: 'icheckbox-blue', radioClass: 'iradio-blue', }) }) - } + } - // 气泡弹出框特效(移到元素时) - $(document).on("mouseenter", '.table [data-toggle="popover"]', function() { - var _this = this; - $(this).popover("show"); - $(".popover").on("mouseleave", function() { - $(_this).popover('hide'); - }); - }) + // 气泡弹出框特效(移到元素时) + $(document).on("mouseenter", '.table [data-toggle="popover"]', function() { + var _this = this; + $(this).popover("show"); + $(".popover").on("mouseleave", function() { + $(_this).popover('hide'); + }); + }) - // 气泡弹出框特效(离开元素时) - $(document).on("mouseleave", '.table [data-toggle="popover"]', function() { - var _this = this; - setTimeout(function() { - if (!$(".popover:hover").length) $(_this).popover("hide"); - }, 100); - }); + // 气泡弹出框特效(离开元素时) + $(document).on("mouseleave", '.table [data-toggle="popover"]', function() { + var _this = this; + setTimeout(function() { + if (!$(".popover:hover").length) $(_this).popover("hide"); + }, 100); + }); - // 取消回车自动提交表单 - $(document).on("keypress", ":input:not(textarea):not([type=submit])", function(event) { + // 取消回车自动提交表单 + $(document).on("keypress", ":input:not(textarea):not([type=submit])", function(event) { if (event.keyCode == 13) { event.preventDefault(); } }); - // laydate 时间控件绑定 - if ($(".select-time").length > 0) { - layui.use('laydate', function() { - var laydate = layui.laydate; - var startDate = laydate.render({ - elem: '#startTime', - max: $('#endTime').val(), - theme: 'molv', - trigger: 'click', - done: function(value, date) { - // 结束时间大于开始时间 - if (value !== '') { - endDate.config.min.year = date.year; - endDate.config.min.month = date.month - 1; - endDate.config.min.date = date.date; - } else { - endDate.config.min.year = ''; - endDate.config.min.month = ''; - endDate.config.min.date = ''; - } - } - }); - var endDate = laydate.render({ - elem: '#endTime', - min: $('#startTime').val(), - theme: 'molv', - trigger: 'click', - done: function(value, date) { - // 开始时间小于结束时间 - if (value !== '') { - startDate.config.max.year = date.year; - startDate.config.max.month = date.month - 1; - startDate.config.max.date = date.date; - } else { - startDate.config.max.year = '2099'; - startDate.config.max.month = '12'; - startDate.config.max.date = '31'; - } - } - }); - }); - } + // laydate 时间控件绑定 + if ($(".select-time").length > 0) { + layui.use('laydate', function() { + var laydate = layui.laydate; + var startDate = laydate.render({ + elem: '#startTime', + max: $('#endTime').val(), + theme: 'molv', + trigger: 'click', + done: function(value, date) { + // 结束时间大于开始时间 + if (value !== '') { + endDate.config.min.year = date.year; + endDate.config.min.month = date.month - 1; + endDate.config.min.date = date.date; + } else { + endDate.config.min.year = ''; + endDate.config.min.month = ''; + endDate.config.min.date = ''; + } + } + }); + var endDate = laydate.render({ + elem: '#endTime', + min: $('#startTime').val(), + theme: 'molv', + trigger: 'click', + done: function(value, date) { + // 开始时间小于结束时间 + if (value !== '') { + startDate.config.max.year = date.year; + startDate.config.max.month = date.month - 1; + startDate.config.max.date = date.date; + } else { + startDate.config.max.year = '2099'; + startDate.config.max.month = '12'; + startDate.config.max.date = '31'; + } + } + }); + }); + } - // laydate time-input 时间控件绑定 - if ($(".time-input").length > 0) { - layui.use('laydate', function () { - var com = layui.laydate; - $(".time-input").each(function (index, item) { - var time = $(item); - // 控制控件外观 - var type = time.attr("data-type") || 'date'; - // 控制回显格式 - var format = time.attr("data-format") || 'yyyy-MM-dd'; - // 控制日期控件按钮 - var buttons = time.attr("data-btn") || 'clear|now|confirm', newBtnArr = []; - // 日期控件选择完成后回调处理 - var callback = time.attr("data-callback") || {}; - if (buttons) { - if (buttons.indexOf("|") > 0) { - var btnArr = buttons.split("|"), btnLen = btnArr.length; - for (var j = 0; j < btnLen; j++) { - if ("clear" === btnArr[j] || "now" === btnArr[j] || "confirm" === btnArr[j]) { - newBtnArr.push(btnArr[j]); - } - } - } else { - if ("clear" === buttons || "now" === buttons || "confirm" === buttons) { - newBtnArr.push(buttons); - } - } - } else { - newBtnArr = ['clear', 'now', 'confirm']; - } - com.render({ - elem: item, - theme: 'molv', - trigger: 'click', - type: type, - format: format, - btns: newBtnArr, - done: function (value, data) { - if (typeof window[callback] != 'undefined' - && window[callback] instanceof Function) { - window[callback](value, data); - } - } - }); - }); - }); - } + // laydate time-input 时间控件绑定 + if ($(".time-input").length > 0) { + layui.use('laydate', function () { + var com = layui.laydate; + $(".time-input").each(function (index, item) { + var time = $(item); + // 控制控件外观 + var type = time.attr("data-type") || 'date'; + // 控制回显格式 + var format = time.attr("data-format") || 'yyyy-MM-dd'; + // 控制日期控件按钮 + var buttons = time.attr("data-btn") || 'clear|now|confirm', newBtnArr = []; + // 日期控件选择完成后回调处理 + var callback = time.attr("data-callback") || {}; + if (buttons) { + if (buttons.indexOf("|") > 0) { + var btnArr = buttons.split("|"), btnLen = btnArr.length; + for (var j = 0; j < btnLen; j++) { + if ("clear" === btnArr[j] || "now" === btnArr[j] || "confirm" === btnArr[j]) { + newBtnArr.push(btnArr[j]); + } + } + } else { + if ("clear" === buttons || "now" === buttons || "confirm" === buttons) { + newBtnArr.push(buttons); + } + } + } else { + newBtnArr = ['clear', 'now', 'confirm']; + } + com.render({ + elem: item, + theme: 'molv', + trigger: 'click', + type: type, + format: format, + btns: newBtnArr, + done: function (value, data) { + if (typeof window[callback] != 'undefined' + && window[callback] instanceof Function) { + window[callback](value, data); + } + } + }); + }); + }); + } - // tree 关键字搜索绑定 - if ($("#keyword").length > 0) { - $("#keyword").bind("focus", function focusKey(e) { - if ($("#keyword").hasClass("empty")) { - $("#keyword").removeClass("empty"); - } - }).bind("blur", function blurKey(e) { - if ($("#keyword").val() === "") { - $("#keyword").addClass("empty"); - } - $.tree.searchNode(e); - }).bind("input propertychange", $.tree.searchNode); - } + // tree 关键字搜索绑定 + if ($("#keyword").length > 0) { + $("#keyword").bind("focus", function focusKey(e) { + if ($("#keyword").hasClass("empty")) { + $("#keyword").removeClass("empty"); + } + }).bind("blur", function blurKey(e) { + if ($("#keyword").val() === "") { + $("#keyword").addClass("empty"); + } + $.tree.searchNode(e); + }).bind("input propertychange", $.tree.searchNode); + } - // tree表格树 展开/折叠 - var expandFlag; - $("#expandAllBtn").click(function() { - var dataExpand = $.common.isEmpty(table.options.expandAll) ? true : table.options.expandAll; - expandFlag = $.common.isEmpty(expandFlag) ? dataExpand : expandFlag; - if (!expandFlag) { - $.bttTable.bootstrapTreeTable('expandAll'); - } else { - $.bttTable.bootstrapTreeTable('collapseAll'); - } - expandFlag = expandFlag ? false: true; - }) + // tree表格树 展开/折叠 + var expandFlag; + $("#expandAllBtn").click(function() { + var dataExpand = $.common.isEmpty(table.options.expandAll) ? true : table.options.expandAll; + expandFlag = $.common.isEmpty(expandFlag) ? dataExpand : expandFlag; + if (!expandFlag) { + $.bttTable.bootstrapTreeTable('expandAll'); + } else { + $.bttTable.bootstrapTreeTable('collapseAll'); + } + expandFlag = expandFlag ? false: true; + }) - // 按下ESC按钮关闭弹层 - $('body', document).on('keyup', function(e) { - if (e.which === 27) { - $.modal.closeAll(); - } - }); + // 按下ESC按钮关闭弹层 + $('body', document).on('keyup', function(e) { + if (e.which === 27) { + $.modal.closeAll(); + } + }); }); (function ($) { @@ -233,8 +233,8 @@ $(function() { /** 刷新选项卡 */ var refreshItem = function(){ var topWindow = $(window.parent.document); - var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-id'); - var target = $('.RuoYi_iframe[data-id="' + currentId + '"]', topWindow); + var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-id'); + var target = $('.RuoYi_iframe[data-id="' + currentId + '"]', topWindow); var url = target.attr('src'); target.attr('src', url).ready(); } @@ -243,29 +243,29 @@ var refreshItem = function(){ var closeItem = function(dataId){ var topWindow = $(window.parent.document); if($.common.isNotEmpty(dataId)){ - window.parent.$.modal.closeLoading(); - // 根据dataId关闭指定选项卡 - $('.menuTab[data-id="' + dataId + '"]', topWindow).remove(); - // 移除相应tab对应的内容区 - $('.mainContent .RuoYi_iframe[data-id="' + dataId + '"]', topWindow).remove(); - return; + window.parent.$.modal.closeLoading(); + // 根据dataId关闭指定选项卡 + $('.menuTab[data-id="' + dataId + '"]', topWindow).remove(); + // 移除相应tab对应的内容区 + $('.mainContent .RuoYi_iframe[data-id="' + dataId + '"]', topWindow).remove(); + return; } var panelUrl = window.frameElement.getAttribute('data-panel'); $('.page-tabs-content .active i', topWindow).click(); if($.common.isNotEmpty(panelUrl)){ - $('.menuTab[data-id="' + panelUrl + '"]', topWindow).addClass('active').siblings('.menuTab').removeClass('active'); - $('.mainContent .RuoYi_iframe', topWindow).each(function() { - if ($(this).data('id') == panelUrl) { - $(this).show().siblings('.RuoYi_iframe').hide(); - return false; + $('.menuTab[data-id="' + panelUrl + '"]', topWindow).addClass('active').siblings('.menuTab').removeClass('active'); + $('.mainContent .RuoYi_iframe', topWindow).each(function() { + if ($(this).data('id') == panelUrl) { + $(this).show().siblings('.RuoYi_iframe').hide(); + return false; } - }); - } + }); + } } /** 创建选项卡 */ function createMenuItem(dataUrl, menuName) { - var panelUrl = window.frameElement.getAttribute('data-id'); + var panelUrl = window.frameElement.getAttribute('data-id'); dataIndex = $.common.random(1, 100), flag = true; if (dataUrl == undefined || $.trim(dataUrl).length == 0) return false; @@ -300,7 +300,7 @@ function createMenuItem(dataUrl, menuName) { window.parent.$.modal.loading("数据加载中,请稍后..."); $('.mainContent iframe:visible', topWindow).load(function () { - window.parent.$.modal.closeLoading(); + window.parent.$.modal.closeLoading(); }); // 添加选项卡 @@ -312,7 +312,7 @@ function createMenuItem(dataUrl, menuName) { // 滚动到指定选项卡 function scrollToTab(element) { - var topWindow = $(window.parent.document); + var topWindow = $(window.parent.document); var marginLeftVal = calSumWidth($(element).prevAll()), marginRightVal = calSumWidth($(element).nextAll()); // 可视区域非tab宽度 @@ -349,28 +349,28 @@ function calSumWidth(elements) { /** 密码规则范围验证 */ function checkpwd(chrtype, password) { - if (chrtype == 1) { - if(!$.common.numValid(password)){ - $.modal.alertWarning("密码只能为0-9数字"); - return false; - } - } else if (chrtype == 2) { - if(!$.common.enValid(password)){ - $.modal.alertWarning("密码只能为a-z和A-Z字母"); - return false; - } - } else if (chrtype == 3) { - if(!$.common.enNumValid(password)){ - $.modal.alertWarning("密码必须包含字母以及数字"); - return false; - } - } else if (chrtype == 4) { - if(!$.common.charValid(password)){ - $.modal.alertWarning("密码必须包含字母、数字、以及特殊符号~!@#$%^&*()-=_+"); - return false; - } - } - return true; + if (chrtype == 1) { + if(!$.common.numValid(password)){ + $.modal.alertWarning("密码只能为0-9数字"); + return false; + } + } else if (chrtype == 2) { + if(!$.common.enValid(password)){ + $.modal.alertWarning("密码只能为a-z和A-Z字母"); + return false; + } + } else if (chrtype == 3) { + if(!$.common.enNumValid(password)){ + $.modal.alertWarning("密码必须包含字母以及数字"); + return false; + } + } else if (chrtype == 4) { + if(!$.common.charValid(password)){ + $.modal.alertWarning("密码必须包含字母、数字、以及特殊符号~!@#$%^&*()-=_+"); + return false; + } + } + return true; } // 日志打印封装处理 @@ -411,21 +411,21 @@ var sub = { var count = $("#" + table.options.id).bootstrapTable('getData').length; var params = new Array(); for (var dataIndex = 0; dataIndex <= count; dataIndex++) { - var columns = $('#' + table.options.id + ' tr[data-index="' + dataIndex + '"] td'); - var obj = new Object(); - for (var i = 0; i < columns.length; i++) { - var inputValue = $(columns[i]).find('input'); - var selectValue = $(columns[i]).find('select'); - var key = table.options.columns[i].field; - if ($.common.isNotEmpty(inputValue.val())) { - obj[key] = inputValue.val(); - } else if ($.common.isNotEmpty(selectValue.val())) { - obj[key] = selectValue.val(); - } else { - obj[key] = ""; - } - } - params.push({ index: dataIndex, row: obj }); + var columns = $('#' + table.options.id + ' tr[data-index="' + dataIndex + '"] td'); + var obj = new Object(); + for (var i = 0; i < columns.length; i++) { + var inputValue = $(columns[i]).find('input'); + var selectValue = $(columns[i]).find('select'); + var key = table.options.columns[i].field; + if ($.common.isNotEmpty(inputValue.val())) { + obj[key] = inputValue.val(); + } else if ($.common.isNotEmpty(selectValue.val())) { + obj[key] = selectValue.val(); + } else { + obj[key] = ""; + } + } + params.push({ index: dataIndex, row: obj }); } $("#" + table.options.id).bootstrapTable("updateRow", params); }, @@ -445,12 +445,12 @@ var sub = { $.ajaxSetup({ complete: function(XMLHttpRequest, textStatus) { if (textStatus == 'timeout') { - $.modal.alertWarning("服务器超时,请稍后再试!"); - $.modal.enable(); + $.modal.alertWarning("服务器超时,请稍后再试!"); + $.modal.enable(); $.modal.closeLoading(); } else if (textStatus == "parsererror" || textStatus == "error") { - $.modal.alertWarning("服务器错误,请联系管理员!"); - $.modal.enable(); + $.modal.alertWarning("服务器错误,请联系管理员!"); + $.modal.enable(); $.modal.closeLoading(); } } 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 4807f06a..d7fd933b 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 @@ -11,7 +11,7 @@ var table = { // 设置实例配置 set: function(id) { if($.common.getLength(table.config) > 1) { - var tableId = $.common.isEmpty(id) ? $(event.currentTarget).parents(".bootstrap-table").find("table.table").attr("id") : id; + 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); } @@ -36,25 +36,25 @@ var table = { // 初始化表格参数 init: function(options) { var defaults = { - id: "bootstrap-table", - type: 0, // 0 代表bootstrapTable 1代表bootstrapTreeTable - method: 'post', - height: undefined, - sidePagination: "server", - sortName: "", - sortOrder: "asc", - pagination: true, - paginationLoop: false, - pageSize: 10, - pageNumber: 1, - pageList: [10, 25, 50], - toolbar: "toolbar", - loadingFontSize: 13, - striped: false, - escape: false, - firstLoad: true, - showFooter: false, - search: false, + id: "bootstrap-table", + type: 0, // 0 代表bootstrapTable 1代表bootstrapTreeTable + method: 'post', + height: undefined, + sidePagination: "server", + sortName: "", + sortOrder: "asc", + pagination: true, + paginationLoop: false, + pageSize: 10, + pageNumber: 1, + pageList: [10, 25, 50], + toolbar: "toolbar", + loadingFontSize: 13, + striped: false, + escape: false, + firstLoad: true, + showFooter: false, + search: false, showSearch: true, showPageGo: false, showRefresh: true, @@ -66,18 +66,18 @@ var table = { mobileResponsive: true, maintainSelected: false, rememberSelected: false, - fixedColumns: false, - fixedNumber: 0, - fixedRightNumber: 0, - queryParams: $.table.queryParams, - rowStyle: {}, - }; + fixedColumns: false, + fixedNumber: 0, + fixedRightNumber: 0, + queryParams: $.table.queryParams, + rowStyle: {}, + }; var options = $.extend(defaults, options); table.options = options; table.config[options.id] = options; $.table.initEvent(); $('#' + options.id).bootstrapTable({ - id: options.id, + id: options.id, url: options.url, // 请求后台的URL(*) contentType: "application/x-www-form-urlencoded", // 编码类型 method: options.method, // 请求方式(*) @@ -103,7 +103,7 @@ var table = { search: options.search, // 是否显示搜索框功能 searchText: options.searchText, // 搜索框初始显示的内容,默认为空 showSearch: options.showSearch, // 是否显示检索信息 - showPageGo: options.showPageGo, // 是否显示跳转页 + showPageGo: options.showPageGo, // 是否显示跳转页 showRefresh: options.showRefresh, // 是否显示刷新按钮 showColumns: options.showColumns, // 是否显示隐藏某列下拉框 showToggle: options.showToggle, // 是否显示详细视图和列表视图的切换按钮 @@ -111,7 +111,7 @@ var table = { showHeader: options.showHeader, // 是否显示表头 showFullscreen: options.showFullscreen, // 是否显示全屏按钮 uniqueId: options.uniqueId, // 唯一的标识符 - clickToSelect: options.clickToSelect, // 是否启用点击选中行 + clickToSelect: options.clickToSelect, // 是否启用点击选中行 singleSelect: options.singleSelect, // 是否单选checkbox mobileResponsive: options.mobileResponsive, // 是否支持移动端适配 cardView: options.cardView, // 是否启用显示卡片视图 @@ -145,36 +145,36 @@ var table = { var _separator = $.common.isEmpty(separator) ? "," : separator; var optionsIds = ""; $.each(table.config, function(key, value){ - optionsIds += "#" + key + _separator; + optionsIds += "#" + key + _separator; }); return optionsIds.substring(0, optionsIds.length - 1); }, // 查询条件 queryParams: function(params) { - var curParams = { - // 传递参数查询参数 - pageSize: params.limit, - pageNum: params.offset / params.limit + 1, - searchValue: params.search, - orderByColumn: params.sort, - isAsc: params.order - }; + var curParams = { + // 传递参数查询参数 + pageSize: params.limit, + pageNum: params.offset / params.limit + 1, + searchValue: params.search, + 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)); }, // 请求获取数据后处理回调函数 responseHandler: function(res) { if (typeof table.get(this.id).responseHandler == "function") { - table.get(this.id).responseHandler(res); + table.get(this.id).responseHandler(res); } if (res.code == 0) { if ($.common.isNotEmpty(table.options.sidePagination) && table.options.sidePagination == 'client') { return res.rows; } else { 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; + 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 }; @@ -190,197 +190,197 @@ var table = { var optionsIds = $.table.getOptionsIds(); // 监听事件处理 $(optionsIds).on(TABLE_EVENTS, function () { - table.set($(this).attr("id")); + table.set($(this).attr("id")); }); // 在表格体渲染完成,并在 DOM 中可见后触发(事件) $(optionsIds).on("post-body.bs.table", function (e, args) { - // 浮动提示框特效 - $(".table [data-toggle='tooltip']").tooltip(); + // 浮动提示框特效 + $(".table [data-toggle='tooltip']").tooltip(); }); // 选中、取消、全部选中、全部取消(事件) $(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); - if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) { - func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference'; - var selectedIds = table.rememberSelectedIds[table.options.id]; - if($.common.isNotEmpty(selectedIds)) { - table.rememberSelectedIds[table.options.id] = _[func](selectedIds, rowIds); - } else { - table.rememberSelectedIds[table.options.id] = _[func]([], rowIds); - } - var selectedRows = table.rememberSelecteds[table.options.id]; - if($.common.isNotEmpty(selectedRows)) { - table.rememberSelecteds[table.options.id] = _[func](selectedRows, rows); - } else { - table.rememberSelecteds[table.options.id] = _[func]([], rows); - } - } + // 复选框分页保留保存选中数组 + var rows = $.common.equals("uncheck-all", e.type) ? rowsBefore : rowsAfter; + var rowIds = $.table.affectedRowIds(rows); + if ($.common.isNotEmpty(table.options.rememberSelected) && table.options.rememberSelected) { + func = $.inArray(e.type, ['check', 'check-all']) > -1 ? 'union' : 'difference'; + var selectedIds = table.rememberSelectedIds[table.options.id]; + if($.common.isNotEmpty(selectedIds)) { + table.rememberSelectedIds[table.options.id] = _[func](selectedIds, rowIds); + } else { + table.rememberSelectedIds[table.options.id] = _[func]([], rowIds); + } + var selectedRows = table.rememberSelecteds[table.options.id]; + if($.common.isNotEmpty(selectedRows)) { + table.rememberSelecteds[table.options.id] = _[func](selectedRows, rows); + } else { + 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 () { - var toolbar = table.options.toolbar; - var uniqueId = table.options.uniqueId; - // 工具栏按钮控制 - var rows = $.common.isEmpty(uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(uniqueId); - // 非多个禁用 - $('#' + toolbar + ' .multiple').toggleClass('disabled', !rows.length); - // 非单个禁用 - $('#' + toolbar + ' .single').toggleClass('disabled', rows.length!=1); + var toolbar = table.options.toolbar; + var uniqueId = table.options.uniqueId; + // 工具栏按钮控制 + var rows = $.common.isEmpty(uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(uniqueId); + // 非多个禁用 + $('#' + toolbar + ' .multiple').toggleClass('disabled', !rows.length); + // 非单个禁用 + $('#' + toolbar + ' .single').toggleClass('disabled', rows.length!=1); }); // 图片预览事件 $(optionsIds).off("click").on("click", '.img-circle', function() { - var src = $(this).attr('src'); - var target = $(this).data('target'); - if($.common.equals("self", target)) { - var height = $(this).data('height'); - var width = $(this).data('width'); - // 如果是移动端,就使用自适应大小弹窗 - if ($.common.isMobile()) { - width = 'auto'; - height = 'auto'; - } - layer.open({ - title: false, - type: 1, - closeBtn: true, - shadeClose: true, - area: ['auto', 'auto'], - content: "" - }); - } else if ($.common.equals("blank", target)) { - window.open(src); - } - }); + var src = $(this).attr('src'); + var target = $(this).data('target'); + if($.common.equals("self", target)) { + var height = $(this).data('height'); + var width = $(this).data('width'); + // 如果是移动端,就使用自适应大小弹窗 + if ($.common.isMobile()) { + width = 'auto'; + height = 'auto'; + } + layer.open({ + title: false, + type: 1, + closeBtn: true, + shadeClose: true, + area: ['auto', 'auto'], + content: "" + }); + } else if ($.common.equals("blank", target)) { + window.open(src); + } + }); // 单击tooltip事件 $(optionsIds).on("click", '.tooltip-show', function() { - var target = $(this).data('target'); - var input = $(this).prev(); - if ($.common.equals("copy", target)) { - input.select(); - document.execCommand("copy"); - } else if ($.common.equals("open", target)) { - parent.layer.alert(input.val(), { - title: "信息内容", - shadeClose: true, - btn: ['确认'], - btnclass: ['btn btn-primary'], - }); - } + var target = $(this).data('target'); + var input = $(this).prev(); + if ($.common.equals("copy", target)) { + input.select(); + document.execCommand("copy"); + } else if ($.common.equals("open", target)) { + parent.layer.alert(input.val(), { + title: "信息内容", + shadeClose: true, + btn: ['确认'], + btnclass: ['btn btn-primary'], + }); + } }); }, // 当所有数据被加载时触发 onLoadSuccess: function(data) { if (typeof table.options.onLoadSuccess == "function") { - table.options.onLoadSuccess(data); + table.options.onLoadSuccess(data); } }, // 表格销毁 destroy: function (tableId) { var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; $("#" + currentId).bootstrapTable('destroy'); - }, + }, // 序列号生成 serialNumber: function (index, tableId) { - var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; - var tableParams = $("#" + currentId).bootstrapTable('getOptions'); - var pageSize = $.common.isNotEmpty(tableParams.pageSize) ? tableParams.pageSize: table.options.pageSize; - var pageNumber = $.common.isNotEmpty(tableParams.pageNumber) ? tableParams.pageNumber: table.options.pageNumber; - return pageSize * (pageNumber - 1) + index + 1; - }, - // 列超出指定长度浮动提示 target(copy单击复制文本 open弹窗打开文本) - tooltip: function (value, length, target) { - var _length = $.common.isEmpty(length) ? 20 : length; - var _text = ""; - var _value = $.common.nullToStr(value); - var _target = $.common.isEmpty(target) ? 'copy' : target; - if (_value.length > _length) { - _text = _value.substr(0, _length) + "..."; - _value = _value.replace(/\'/g,"'"); - _value = _value.replace(/\"/g,"""); - var actions = []; - actions.push($.common.sprintf('', _value)); - actions.push($.common.sprintf('%s', _target, _value, _text)); - return actions.join(''); - } else { - _text = _value; - return _text; - } - }, - // 下拉按钮切换 - dropdownToggle: function (value) { - var actions = []; - actions.push('
'); - actions.push(''); - actions.push(''); - actions.push('
'); - return actions.join(''); - }, - // 图片预览 - imageView: function (value, height, width, target) { - if ($.common.isEmpty(width)) { - width = 'auto'; + var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; + var tableParams = $("#" + currentId).bootstrapTable('getOptions'); + var pageSize = $.common.isNotEmpty(tableParams.pageSize) ? tableParams.pageSize: table.options.pageSize; + var pageNumber = $.common.isNotEmpty(tableParams.pageNumber) ? tableParams.pageNumber: table.options.pageNumber; + return pageSize * (pageNumber - 1) + index + 1; + }, + // 列超出指定长度浮动提示 target(copy单击复制文本 open弹窗打开文本) + tooltip: function (value, length, target) { + var _length = $.common.isEmpty(length) ? 20 : length; + var _text = ""; + var _value = $.common.nullToStr(value); + var _target = $.common.isEmpty(target) ? 'copy' : target; + if (_value.length > _length) { + _text = _value.substr(0, _length) + "..."; + _value = _value.replace(/\'/g,"'"); + _value = _value.replace(/\"/g,"""); + var actions = []; + actions.push($.common.sprintf('', _value)); + actions.push($.common.sprintf('%s', _target, _value, _text)); + return actions.join(''); + } else { + _text = _value; + return _text; + } + }, + // 下拉按钮切换 + dropdownToggle: function (value) { + var actions = []; + actions.push('
'); + actions.push(''); + actions.push(''); + actions.push('
'); + return actions.join(''); + }, + // 图片预览 + imageView: function (value, height, width, target) { + if ($.common.isEmpty(width)) { + width = 'auto'; } if ($.common.isEmpty(height)) { - height = 'auto'; + height = 'auto'; } - // blank or self - var _target = $.common.isEmpty(target) ? 'self' : target; - if ($.common.isNotEmpty(value)) { - return $.common.sprintf("", height, width, _target, value); - } else { - return $.common.nullToStr(value); - } - }, + // blank or self + var _target = $.common.isEmpty(target) ? 'self' : target; + if ($.common.isNotEmpty(value)) { + return $.common.sprintf("", height, width, _target, value); + } else { + return $.common.nullToStr(value); + } + }, // 搜索-默认第一个form search: function(formId, tableId) { - table.set(tableId); - 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(tableId)){ - $("#" + tableId).bootstrapTable('refresh', params); - } else{ - $("#" + table.options.id).bootstrapTable('refresh', params); - } - }, - // 导出数据 - exportExcel: function(formId) { - table.set(); - $.modal.confirm("确定导出所有" + table.options.modalName + "吗?", function() { - var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; - var params = $("#" + table.options.id).bootstrapTable('getOptions'); - var dataParam = $("#" + currentId).serializeArray(); - dataParam.push({ "name": "orderByColumn", "value": params.sortName }); - dataParam.push({ "name": "isAsc", "value": params.sortOrder }); - $.modal.loading("正在导出数据,请稍后..."); - $.post(table.options.exportUrl, dataParam, function(result) { - if (result.code == web_status.SUCCESS) { - window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true; - } else if (result.code == web_status.WARNING) { - $.modal.alertWarning(result.msg) - } else { - $.modal.alertError(result.msg); - } - $.modal.closeLoading(); - }); - }); - }, - // 下载模板 - importTemplate: function() { - table.set(); - $.get(table.options.importTemplateUrl, function(result) { - if (result.code == web_status.SUCCESS) { - window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true; - } else if (result.code == web_status.WARNING) { + table.set(tableId); + 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(tableId)){ + $("#" + tableId).bootstrapTable('refresh', params); + } else{ + $("#" + table.options.id).bootstrapTable('refresh', params); + } + }, + // 导出数据 + exportExcel: function(formId) { + table.set(); + $.modal.confirm("确定导出所有" + table.options.modalName + "吗?", function() { + var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; + var params = $("#" + table.options.id).bootstrapTable('getOptions'); + var dataParam = $("#" + currentId).serializeArray(); + dataParam.push({ "name": "orderByColumn", "value": params.sortName }); + dataParam.push({ "name": "isAsc", "value": params.sortOrder }); + $.modal.loading("正在导出数据,请稍后..."); + $.post(table.options.exportUrl, dataParam, function(result) { + if (result.code == web_status.SUCCESS) { + window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true; + } else if (result.code == web_status.WARNING) { + $.modal.alertWarning(result.msg) + } else { + $.modal.alertError(result.msg); + } + $.modal.closeLoading(); + }); + }); + }, + // 下载模板 + importTemplate: function() { + table.set(); + $.get(table.options.importTemplateUrl, function(result) { + if (result.code == web_status.SUCCESS) { + window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true; + } else if (result.code == web_status.WARNING) { $.modal.alertWarning(result.msg) } else { - $.modal.alertError(result.msg); - } - }); + $.modal.alertError(result.msg); + } + }); }, // 导入数据 importExcel: function(formId, width, height) { @@ -389,50 +389,50 @@ var table = { var _width = $.common.isEmpty(width) ? "400" : width; var _height = $.common.isEmpty(height) ? "230" : height; layer.open({ - type: 1, - area: [_width + 'px', _height + 'px'], - fix: false, - //不固定 - maxmin: true, - shade: 0.3, - title: '导入' + table.options.modalName + '数据', - content: $('#' + currentId).html(), - btn: [' 导入', ' 取消'], - // 弹层外区域关闭 - shadeClose: true, - btn1: function(index, layero){ - var file = layero.find('#file').val(); - if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))){ - $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。"); - return false; - } - var index = layer.load(2, {shade: false}); - $.modal.disable(); - var formData = new FormData(layero.find('form')[0]); - $.ajax({ - url: table.options.importUrl, - data: formData, - cache: false, - contentType: false, - processData: false, - type: 'POST', - success: function (result) { - if (result.code == web_status.SUCCESS) { - $.modal.closeAll(); - $.modal.alertSuccess(result.msg); - $.table.refresh(); - } else if (result.code == web_status.WARNING) { - layer.close(index); - $.modal.enable(); - $.modal.alertWarning(result.msg) - } else { - layer.close(index); - $.modal.enable(); - $.modal.alertError(result.msg); - } - } - }); - } + type: 1, + area: [_width + 'px', _height + 'px'], + fix: false, + //不固定 + maxmin: true, + shade: 0.3, + title: '导入' + table.options.modalName + '数据', + content: $('#' + currentId).html(), + btn: [' 导入', ' 取消'], + // 弹层外区域关闭 + shadeClose: true, + btn1: function(index, layero){ + var file = layero.find('#file').val(); + if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx'))){ + $.modal.msgWarning("请选择后缀为 “xls”或“xlsx”的文件。"); + return false; + } + var index = layer.load(2, {shade: false}); + $.modal.disable(); + var formData = new FormData(layero.find('form')[0]); + $.ajax({ + url: table.options.importUrl, + data: formData, + cache: false, + contentType: false, + processData: false, + type: 'POST', + success: function (result) { + if (result.code == web_status.SUCCESS) { + $.modal.closeAll(); + $.modal.alertSuccess(result.msg); + $.table.refresh(); + } else if (result.code == web_status.WARNING) { + layer.close(index); + $.modal.enable(); + $.modal.alertWarning(result.msg) + } else { + layer.close(index); + $.modal.enable(); + $.modal.alertError(result.msg); + } + } + }); + } }); }, // 刷新表格 @@ -445,15 +445,15 @@ var table = { // 查询表格指定列值 selectColumns: function(column) { var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) { - return $.common.getItemField(row, column); - }); + 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); - }); - } + 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); }, @@ -473,15 +473,15 @@ var table = { // 查询表格首列值 selectFirstColumns: function() { var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) { - return $.common.getItemField(row, table.options.columns[1].field); - }); + return $.common.getItemField(row, table.options.columns[1].field); + }); 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) { + 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); }, @@ -505,13 +505,13 @@ var table = { var currentSeparator = $.common.isEmpty(separator) ? "," : separator; var actions = []; $.each(value.split(currentSeparator), function(i, val) { - $.each(datas, function(index, dict) { - if (dict.dictValue == ('' + val)) { - var listClass = $.common.equals("default", dict.listClass) || $.common.isEmpty(dict.listClass) ? "" : "badge badge-" + dict.listClass; - actions.push($.common.sprintf("%s ", listClass, dict.dictLabel)); + $.each(datas, function(index, dict) { + if (dict.dictValue == ('' + val)) { + 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; } - }); + }); }); return actions.join(''); }, @@ -541,46 +541,46 @@ var table = { // 初始化表格 init: function(options) { var defaults = { - id: "bootstrap-tree-table", + id: "bootstrap-tree-table", type: 1, // 0 代表bootstrapTable 1代表bootstrapTreeTable - height: 0, - rootIdValue: null, - ajaxParams: {}, - toolbar: "toolbar", - striped: false, - expandColumn: 1, - showSearch: true, - showRefresh: true, - showColumns: true, - expandAll: true, - expandFirst: true - }; + height: 0, + rootIdValue: null, + ajaxParams: {}, + toolbar: "toolbar", + striped: false, + expandColumn: 1, + showSearch: true, + showRefresh: true, + showColumns: true, + expandAll: true, + expandFirst: true + }; 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, // 用于设置父子关系 - type: 'post', // 请求方式(*) - url: options.url, // 请求后台的URL(*) - data: options.data, // 无url时用于渲染的数据 - ajaxParams: options.ajaxParams, // 请求数据的ajax的data属性 - rootIdValue: options.rootIdValue, // 设置指定根节点id值 - height: options.height, // 表格树的高度 - expandColumn: options.expandColumn, // 在哪一列上面显示展开按钮 - striped: options.striped, // 是否显示行间隔色 - bordered: false, // 是否显示边框 - toolbar: '#' + options.toolbar, // 指定工作栏 - showSearch: options.showSearch, // 是否显示检索信息 - showRefresh: options.showRefresh, // 是否显示刷新按钮 - showColumns: options.showColumns, // 是否显示隐藏某列下拉框 - expandAll: options.expandAll, // 是否全部展开 - expandFirst: options.expandFirst, // 是否默认第一级展开--expandAll为false时生效 - columns: options.columns, // 显示列信息(*) - responseHandler: $.treeTable.responseHandler, // 在加载服务器发送来的数据之前处理函数 - onLoadSuccess: $.table.onLoadSuccess // 当所有数据被加载时触发处理函数 - }); + code: options.code, // 用于设置父子关系 + parentCode: options.parentCode, // 用于设置父子关系 + type: 'post', // 请求方式(*) + url: options.url, // 请求后台的URL(*) + data: options.data, // 无url时用于渲染的数据 + ajaxParams: options.ajaxParams, // 请求数据的ajax的data属性 + rootIdValue: options.rootIdValue, // 设置指定根节点id值 + height: options.height, // 表格树的高度 + expandColumn: options.expandColumn, // 在哪一列上面显示展开按钮 + striped: options.striped, // 是否显示行间隔色 + bordered: false, // 是否显示边框 + toolbar: '#' + options.toolbar, // 指定工作栏 + showSearch: options.showSearch, // 是否显示检索信息 + showRefresh: options.showRefresh, // 是否显示刷新按钮 + showColumns: options.showColumns, // 是否显示隐藏某列下拉框 + expandAll: options.expandAll, // 是否全部展开 + expandFirst: options.expandFirst, // 是否默认第一级展开--expandAll为false时生效 + columns: options.columns, // 显示列信息(*) + responseHandler: $.treeTable.responseHandler, // 在加载服务器发送来的数据之前处理函数 + onLoadSuccess: $.table.onLoadSuccess // 当所有数据被加载时触发处理函数 + }); }, // 条件查询 search: function(formId) { @@ -594,19 +594,19 @@ var table = { }, // 查询表格树指定列值 selectColumns: function(column) { - var rows = $.map($.bttTable.bootstrapTreeTable('getSelections'), function (row) { - return $.common.getItemField(row, column); - }); - return $.common.uniqueFn(rows); + var rows = $.map($.bttTable.bootstrapTreeTable('getSelections'), function (row) { + return $.common.getItemField(row, column); + }); + return $.common.uniqueFn(rows); }, // 请求获取数据后处理回调函数,校验异常状态提醒 responseHandler: function(res) { if (typeof table.options.responseHandler == "function") { - table.options.responseHandler(res); + table.options.responseHandler(res); } if (res.code != undefined && res.code != 0) { - $.modal.alertWarning(res.msg); - return []; + $.modal.alertWarning(res.msg); + return []; } else { return res; } @@ -614,67 +614,67 @@ var table = { }, // 表单封装处理 form: { - // 表单重置 - reset: function(formId, tableId) { - table.set(tableId); + // 表单重置 + reset: function(formId, tableId) { + table.set(tableId); var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; $("#" + currentId)[0].reset(); if (table.options.type == table_type.bootstrapTable) { - if($.common.isEmpty(tableId)){ - $("#" + table.options.id).bootstrapTable('refresh'); - } else{ - $("#" + tableId).bootstrapTable('refresh'); - } + if($.common.isEmpty(tableId)){ + $("#" + table.options.id).bootstrapTable('refresh'); + } else{ + $("#" + tableId).bootstrapTable('refresh'); + } } else if (table.options.type == table_type.bootstrapTreeTable) { - if($.common.isEmpty(tableId)){ - $("#" + table.options.id).bootstrapTreeTable('refresh', []); - } else{ - $("#" + tableId).bootstrapTreeTable('refresh', []); - } + if($.common.isEmpty(tableId)){ + $("#" + table.options.id).bootstrapTreeTable('refresh', []); + } else{ + $("#" + tableId).bootstrapTreeTable('refresh', []); + } } }, // 获取选中复选框项 selectCheckeds: function(name) { var checkeds = ""; - $('input:checkbox[name="' + name + '"]:checked').each(function(i) { - if (0 == i) { - checkeds = $(this).val(); - } else { - checkeds += ("," + $(this).val()); - } - }); - return checkeds; + $('input:checkbox[name="' + name + '"]:checked').each(function(i) { + if (0 == i) { + checkeds = $(this).val(); + } else { + checkeds += ("," + $(this).val()); + } + }); + return checkeds; }, // 获取选中下拉框项 selectSelects: function(name) { var selects = ""; - $('#' + name + ' option:selected').each(function (i) { - if (0 == i) { - selects = $(this).val(); - } else { - selects += ("," + $(this).val()); - } - }); - return selects; + $('#' + name + ' option:selected').each(function (i) { + if (0 == i) { + selects = $(this).val(); + } else { + selects += ("," + $(this).val()); + } + }); + return selects; } }, // 弹出层封装处理 modal: { - // 显示图标 - icon: function(type) { - var icon = ""; - if (type == modal_status.WARNING) { - icon = 0; - } else if (type == modal_status.SUCCESS) { - icon = 1; - } else if (type == modal_status.FAIL) { - icon = 2; - } else { - icon = 3; - } - return icon; + // 显示图标 + icon: function(type) { + var icon = ""; + if (type == modal_status.WARNING) { + icon = 0; + } else if (type == modal_status.SUCCESS) { + icon = 1; + } else if (type == modal_status.FAIL) { + icon = 2; + } else { + icon = 3; + } + return icon; }, - // 消息提示 + // 消息提示 msg: function(content, type) { if (type != undefined) { layer.msg(content, { icon: $.modal.icon(type), time: 1000, shift: 5 }); @@ -694,14 +694,14 @@ var table = { msgWarning: function(content) { $.modal.msg(content, modal_status.WARNING); }, - // 弹出提示 + // 弹出提示 alert: function(content, type) { - layer.alert(content, { - icon: $.modal.icon(type), - title: "系统提示", - btn: ['确认'], - btnclass: ['btn btn-primary'], - }); + layer.alert(content, { + icon: $.modal.icon(type), + title: "系统提示", + btn: ['确认'], + btnclass: ['btn btn-primary'], + }); }, // 消息提示并刷新父窗体 msgReload: function(msg, type) { @@ -728,12 +728,12 @@ var table = { }, // 关闭窗体 close: function (index) { - if($.common.isEmpty(index)){ - var index = parent.layer.getFrameIndex(window.name); + if($.common.isEmpty(index)){ + var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); - } else { - layer.close(index); - } + } else { + layer.close(index); + } }, // 关闭全部窗体 closeAll: function () { @@ -741,14 +741,14 @@ var table = { }, // 确认窗体 confirm: function (content, callBack) { - layer.confirm(content, { - icon: 3, - title: "系统提示", - btn: ['确认', '取消'] - }, function (index) { - layer.close(index); - callBack(true); - }); + layer.confirm(content, { + icon: 3, + title: "系统提示", + btn: ['确认', '取消'] + }, function (index) { + layer.close(index); + callBack(true); + }); }, // 弹出层指定宽度 open: function (title, url, width, height, callback) { @@ -761,13 +761,13 @@ var table = { 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) { @@ -776,18 +776,18 @@ var table = { } } layer.open({ - type: 2, - area: [width + 'px', height + 'px'], - fix: false, - //不固定 - maxmin: true, - shade: 0.3, - title: title, - content: url, - btn: ['确定', '关闭'], + type: 2, + area: [width + 'px', height + 'px'], + fix: false, + //不固定 + maxmin: true, + shade: 0.3, + title: title, + content: url, + btn: ['确定', '关闭'], // 弹层外区域关闭 - shadeClose: true, - yes: callback, + shadeClose: true, + yes: callback, cancel: function(index) { return true; } @@ -801,38 +801,38 @@ var table = { var _height = $.common.isEmpty(options.height) ? ($(window).height() - 50) : options.height; var _btn = [' 确认', ' 关闭']; if ($.common.isEmpty(options.yes)) { - options.yes = function(index, layero) { - options.callBack(index, layero); + options.yes = function(index, layero) { + options.callBack(index, layero); } } var btnCallback = {}; - if(options.btn instanceof Array){ - for (var i = 1, len = options.btn.length; i < len; i++) { - var btn = options["btn" + (i + 1)]; - if (btn) { - btnCallback["btn" + (i + 1)] = btn; - } - } - } - var index = layer.open($.extend({ - type: 2, - maxmin: $.common.isEmpty(options.maxmin) ? true : options.maxmin, - shade: 0.3, - title: _title, - fix: false, - area: [_width + 'px', _height + 'px'], - content: _url, - shadeClose: $.common.isEmpty(options.shadeClose) ? true : options.shadeClose, - skin: options.skin, - btn: $.common.isEmpty(options.btn) ? _btn : options.btn, - yes: options.yes, - cancel: function () { - return true; - } - }, btnCallback)); - if ($.common.isNotEmpty(options.full) && options.full === true) { - layer.full(index); - } + if(options.btn instanceof Array){ + for (var i = 1, len = options.btn.length; i < len; i++) { + var btn = options["btn" + (i + 1)]; + if (btn) { + btnCallback["btn" + (i + 1)] = btn; + } + } + } + var index = layer.open($.extend({ + type: 2, + maxmin: $.common.isEmpty(options.maxmin) ? true : options.maxmin, + shade: 0.3, + title: _title, + fix: false, + area: [_width + 'px', _height + 'px'], + content: _url, + shadeClose: $.common.isEmpty(options.shadeClose) ? true : options.shadeClose, + skin: options.skin, + btn: $.common.isEmpty(options.btn) ? _btn : options.btn, + yes: options.yes, + cancel: function () { + return true; + } + }, btnCallback)); + if ($.common.isNotEmpty(options.full) && options.full === true) { + layer.full(index); + } }, // 弹出层全屏 openFull: function (title, url, width, height) { @@ -854,24 +854,24 @@ var table = { height = ($(window).height() - 50); } var index = layer.open({ - type: 2, - area: [width + 'px', height + 'px'], - fix: false, - //不固定 - maxmin: true, - shade: 0.3, - title: title, - content: url, - btn: ['确定', '关闭'], - // 弹层外区域关闭 - shadeClose: true, - yes: function(index, layero) { - var iframeWin = layero.find('iframe')[0]; - iframeWin.contentWindow.submitHandler(index, layero); - }, - cancel: function(index) { - return true; - } + type: 2, + area: [width + 'px', height + 'px'], + fix: false, + //不固定 + maxmin: true, + shade: 0.3, + title: title, + content: url, + btn: ['确定', '关闭'], + // 弹层外区域关闭 + shadeClose: true, + yes: function(index, layero) { + var iframeWin = layero.find('iframe')[0]; + iframeWin.contentWindow.submitHandler(index, layero); + }, + cancel: function(index) { + return true; + } }); layer.full(index); }, @@ -892,7 +892,7 @@ var table = { // 禁用按钮 disable: function() { var doc = window.top == window.parent ? window.document : window.parent.document; - $("a[class*=layui-layer-btn]", doc).addClass("layer-disabled"); + $("a[class*=layui-layer-btn]", doc).addClass("layer-disabled"); }, // 启用按钮 enable: function() { @@ -906,7 +906,7 @@ var table = { // 关闭遮罩层 closeLoading: function () { setTimeout(function(){ - $.unblockUI(); + $.unblockUI(); }, 50); }, // 重新加载 @@ -916,24 +916,24 @@ var table = { }, // 操作封装处理 operate: { - // 提交数据 - submit: function(url, type, dataType, data, callback) { - var config = { - url: url, - type: type, - dataType: dataType, - data: data, - beforeSend: function () { - $.modal.loading("正在处理中,请稍后..."); - }, - success: function(result) { - if (typeof callback == "function") { - callback(result); - } - $.operate.ajaxSuccess(result); - } - }; - $.ajax(config) + // 提交数据 + submit: function(url, type, dataType, data, callback) { + var config = { + url: url, + type: type, + dataType: dataType, + data: data, + beforeSend: function () { + $.modal.loading("正在处理中,请稍后..."); + }, + success: function(result) { + if (typeof callback == "function") { + callback(result); + } + $.operate.ajaxSuccess(result); + } + }; + $.ajax(config) }, // post请求传输 post: function(url, data, callback) { @@ -955,16 +955,16 @@ var table = { _height = 'auto'; } var options = { - title: table.options.modalName + "详细", - width: _width, - height: _height, - url: _url, - skin: 'layui-layer-gray', - btn: ['关闭'], - yes: function (index, layero) { - layer.close(index); + title: table.options.modalName + "详细", + width: _width, + height: _height, + url: _url, + skin: 'layui-layer-gray', + btn: ['关闭'], + yes: function (index, layero) { + layer.close(index); } - }; + }; $.modal.openOptions(options); }, // 详细访问地址 @@ -975,9 +975,9 @@ var table = { } else { var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); if (id.length == 0) { - $.modal.alertWarning("请至少选择一条记录"); - return; - } + $.modal.alertWarning("请至少选择一条记录"); + return; + } url = table.options.detailUrl.replace("{id}", id); } return url; @@ -990,31 +990,31 @@ var table = { if(table.options.type == table_type.bootstrapTreeTable) { $.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); - }); + 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", ""); + var url = table.options.cleanUrl; + $.operate.submit(url, "post", "json", ""); }); }, // 添加信息 @@ -1042,13 +1042,13 @@ var table = { 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); + 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)); } @@ -1065,17 +1065,17 @@ var table = { 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); - } + 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); }, @@ -1087,9 +1087,9 @@ var table = { } else { var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); if (id.length == 0) { - $.modal.alertWarning("请至少选择一条记录"); - return; - } + $.modal.alertWarning("请至少选择一条记录"); + return; + } url = table.options.updateUrl.replace("{id}", id); } return url; @@ -1102,14 +1102,14 @@ var table = { dataType: "json", data: data, beforeSend: function () { - $.modal.loading("正在处理中,请稍后..."); - $.modal.disable(); + $.modal.loading("正在处理中,请稍后..."); + $.modal.disable(); }, success: function(result) { - if (typeof callback == "function") { - callback(result); - } - $.operate.successCallback(result); + if (typeof callback == "function") { + callback(result); + } + $.operate.successCallback(result); } }; $.ajax(config) @@ -1122,20 +1122,20 @@ var table = { dataType: "json", data: data, beforeSend: function () { - $.modal.loading("正在处理中,请稍后..."); + $.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) { + 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 { + } else { $.modal.alertError(result.msg); } - $.modal.closeLoading(); + $.modal.closeLoading(); } }; $.ajax(config) @@ -1143,54 +1143,54 @@ var table = { // 保存选项卡信息 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) + 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(); + $.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(); }, // 成功结果提示msg(父窗体全局更新) saveSuccess: function (result) { if (result.code == web_status.SUCCESS) { - $.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_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(); }, // 成功回调执行事件(父窗体静默更新) successCallback: function(result) { if (result.code == web_status.SUCCESS) { - var parent = window.parent; + var parent = window.parent; if (parent.table.options.type == table_type.bootstrapTable) { $.modal.close(); parent.$.modal.msgSuccess(result.msg); @@ -1213,17 +1213,17 @@ var table = { // 选项卡成功回调执行事件(父窗体静默更新) successTabCallback: function(result) { if (result.code == web_status.SUCCESS) { - var topWindow = $(window.parent.document); + 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(); - } + $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) @@ -1235,9 +1235,9 @@ var table = { }, // 校验封装处理 validate: { - // 判断返回标识是否唯一 false 不存在 true 存在 - unique: function (value) { - if (value == "0") { + // 判断返回标识是否唯一 false 不存在 true 存在 + unique: function (value) { + if (value == "0") { return true; } return false; @@ -1255,64 +1255,64 @@ var table = { }, // 树插件封装处理 tree: { - _option: {}, - _lastValue: {}, - // 初始化树结构 - init: function(options) { - var defaults = { - id: "tree", // 属性ID - expandLevel: 0, // 展开等级节点 - view: { - selectedMulti: false, // 设置是否允许同时选中多个节点 - nameIsHTML: true // 设置 name 属性是否支持 HTML 脚本 - }, - check: { - enable: false, // 置 zTree 的节点上是否显示 checkbox / radio - nocheckInherit: true, // 设置子节点是否自动继承 - chkboxType: { "Y": "ps", "N": "ps" } // 父子节点的关联关系 - }, - data: { - key: { - title: "title" // 节点数据保存节点提示信息的属性名称 - }, - simpleData: { - enable: true // true / false 分别表示 使用 / 不使用 简单数据模式 - } - }, - }; - var options = $.extend(defaults, options); - $.tree._option = options; - // 树结构初始化加载 - var setting = { - callback: { - onClick: options.onClick, // 用于捕获节点被点击的事件回调函数 - onCheck: options.onCheck, // 用于捕获 checkbox / radio 被勾选 或 取消勾选的事件回调函数 - onDblClick: options.onDblClick // 用于捕获鼠标双击之后的事件回调函数 - }, - check: options.check, - view: options.view, - data: options.data - }; - $.get(options.url, function(data) { - var treeId = $("#treeId").val(); - tree = $.fn.zTree.init($("#" + options.id), setting, data); - $._tree = tree; - for (var i = 0; i < options.expandLevel; i++) { - var nodes = tree.getNodesByParam("level", i); - for (var j = 0; j < nodes.length; j++) { - tree.expandNode(nodes[j], true, false, false); - } - } - var node = tree.getNodesByParam("id", treeId, null)[0]; - $.tree.selectByIdName(treeId, node); - // 回调tree方法 + _option: {}, + _lastValue: {}, + // 初始化树结构 + init: function(options) { + var defaults = { + id: "tree", // 属性ID + expandLevel: 0, // 展开等级节点 + view: { + selectedMulti: false, // 设置是否允许同时选中多个节点 + nameIsHTML: true // 设置 name 属性是否支持 HTML 脚本 + }, + check: { + enable: false, // 置 zTree 的节点上是否显示 checkbox / radio + nocheckInherit: true, // 设置子节点是否自动继承 + chkboxType: { "Y": "ps", "N": "ps" } // 父子节点的关联关系 + }, + data: { + key: { + title: "title" // 节点数据保存节点提示信息的属性名称 + }, + simpleData: { + enable: true // true / false 分别表示 使用 / 不使用 简单数据模式 + } + }, + }; + var options = $.extend(defaults, options); + $.tree._option = options; + // 树结构初始化加载 + var setting = { + callback: { + onClick: options.onClick, // 用于捕获节点被点击的事件回调函数 + onCheck: options.onCheck, // 用于捕获 checkbox / radio 被勾选 或 取消勾选的事件回调函数 + onDblClick: options.onDblClick // 用于捕获鼠标双击之后的事件回调函数 + }, + check: options.check, + view: options.view, + data: options.data + }; + $.get(options.url, function(data) { + var treeId = $("#treeId").val(); + tree = $.fn.zTree.init($("#" + options.id), setting, data); + $._tree = tree; + for (var i = 0; i < options.expandLevel; i++) { + var nodes = tree.getNodesByParam("level", i); + for (var j = 0; j < nodes.length; j++) { + tree.expandNode(nodes[j], true, false, false); + } + } + var node = tree.getNodesByParam("id", treeId, null)[0]; + $.tree.selectByIdName(treeId, node); + // 回调tree方法 if(typeof(options.callBack) === "function"){ options.callBack(tree); } - }); - }, - // 搜索节点 - searchNode: function() { + }); + }, + // 搜索节点 + searchNode: function() { // 取得输入的关键字的值 var value = $.common.trim($("#keyword").val()); if ($.tree._lastValue == value) { @@ -1329,119 +1329,119 @@ var table = { $.tree.hideAllNode(nodes); // 根据搜索值模糊匹配 $.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value)); - }, - // 根据Id和Name选中指定节点 - selectByIdName: function(treeId, node) { + }, + // 根据Id和Name选中指定节点 + selectByIdName: function(treeId, node) { if ($.common.isNotEmpty(treeId) && treeId == node.id) { $._tree.selectNode(node, true); } + }, + // 显示所有节点 + showAllNode: function(nodes) { + nodes = $._tree.transformToArray(nodes); + for (var i = nodes.length - 1; i >= 0; i--) { + if (nodes[i].getParentNode() != null) { + $._tree.expandNode(nodes[i], true, false, false, false); + } else { + $._tree.expandNode(nodes[i], true, true, false, false); + } + $._tree.showNode(nodes[i]); + $.tree.showAllNode(nodes[i].children); + } }, - // 显示所有节点 - showAllNode: function(nodes) { - nodes = $._tree.transformToArray(nodes); - for (var i = nodes.length - 1; i >= 0; i--) { - if (nodes[i].getParentNode() != null) { - $._tree.expandNode(nodes[i], true, false, false, false); - } else { - $._tree.expandNode(nodes[i], true, true, false, false); - } - $._tree.showNode(nodes[i]); - $.tree.showAllNode(nodes[i].children); - } + // 隐藏所有节点 + hideAllNode: function(nodes) { + var tree = $.fn.zTree.getZTreeObj("tree"); + var nodes = $._tree.transformToArray(nodes); + for (var i = nodes.length - 1; i >= 0; i--) { + $._tree.hideNode(nodes[i]); + } + }, + // 显示所有父节点 + showParent: function(treeNode) { + var parentNode; + while ((parentNode = treeNode.getParentNode()) != null) { + $._tree.showNode(parentNode); + $._tree.expandNode(parentNode, true, false, false); + treeNode = parentNode; + } + }, + // 显示所有孩子节点 + showChildren: function(treeNode) { + if (treeNode.isParent) { + for (var idx in treeNode.children) { + var node = treeNode.children[idx]; + $._tree.showNode(node); + $.tree.showChildren(node); + } + } + }, + // 更新节点状态 + updateNodes: function(nodeList) { + $._tree.showNodes(nodeList); + for (var i = 0, l = nodeList.length; i < l; i++) { + var treeNode = nodeList[i]; + $.tree.showChildren(treeNode); + $.tree.showParent(treeNode) + } + }, + // 获取当前被勾选集合 + getCheckedNodes: function(column) { + var _column = $.common.isEmpty(column) ? "id" : column; + var nodes = $._tree.getCheckedNodes(true); + return $.map(nodes, function (row) { + return row[_column]; + }).join(); }, - // 隐藏所有节点 - hideAllNode: function(nodes) { - var tree = $.fn.zTree.getZTreeObj("tree"); - var nodes = $._tree.transformToArray(nodes); - for (var i = nodes.length - 1; i >= 0; i--) { - $._tree.hideNode(nodes[i]); - } - }, - // 显示所有父节点 - showParent: function(treeNode) { - var parentNode; - while ((parentNode = treeNode.getParentNode()) != null) { - $._tree.showNode(parentNode); - $._tree.expandNode(parentNode, true, false, false); - treeNode = parentNode; - } - }, - // 显示所有孩子节点 - showChildren: function(treeNode) { - if (treeNode.isParent) { - for (var idx in treeNode.children) { - var node = treeNode.children[idx]; - $._tree.showNode(node); - $.tree.showChildren(node); - } - } - }, - // 更新节点状态 - updateNodes: function(nodeList) { - $._tree.showNodes(nodeList); - for (var i = 0, l = nodeList.length; i < l; i++) { - var treeNode = nodeList[i]; - $.tree.showChildren(treeNode); - $.tree.showParent(treeNode) - } - }, - // 获取当前被勾选集合 - getCheckedNodes: function(column) { - var _column = $.common.isEmpty(column) ? "id" : column; - var nodes = $._tree.getCheckedNodes(true); - return $.map(nodes, function (row) { - return row[_column]; - }).join(); - }, - // 不允许根父节点选择 - notAllowParents: function(_tree) { - var nodes = _tree.getSelectedNodes(); - if(nodes.length == 0){ + // 不允许根父节点选择 + notAllowParents: function(_tree) { + var nodes = _tree.getSelectedNodes(); + if(nodes.length == 0){ $.modal.msgError("请选择节点后提交"); return false; - } - for (var i = 0; i < nodes.length; i++) { - if (nodes[i].level == 0) { - $.modal.msgError("不能选择根节点(" + nodes[i].name + ")"); - return false; - } - if (nodes[i].isParent) { - $.modal.msgError("不能选择父节点(" + nodes[i].name + ")"); - return false; - } - } - return true; - }, - // 不允许最后层级节点选择 - notAllowLastLevel: function(_tree) { - var nodes = _tree.getSelectedNodes(); - for (var i = 0; i < nodes.length; i++) { + } + for (var i = 0; i < nodes.length; i++) { + if (nodes[i].level == 0) { + $.modal.msgError("不能选择根节点(" + nodes[i].name + ")"); + return false; + } + if (nodes[i].isParent) { + $.modal.msgError("不能选择父节点(" + nodes[i].name + ")"); + return false; + } + } + return true; + }, + // 不允许最后层级节点选择 + notAllowLastLevel: function(_tree) { + var nodes = _tree.getSelectedNodes(); + for (var i = 0; i < nodes.length; i++) { if (!nodes[i].isParent) { - $.modal.msgError("不能选择最后层级节点(" + nodes[i].name + ")"); - return false; - } - } - return true; - }, - // 隐藏/显示搜索栏 - toggleSearch: function() { - $('#search').slideToggle(200); - $('#btnShow').toggle(); - $('#btnHide').toggle(); - $('#keyword').focus(); - }, - // 折叠 - collapse: function() { - $._tree.expandAll(false); - }, - // 展开 - expand: function() { - $._tree.expandAll(true); - } + $.modal.msgError("不能选择最后层级节点(" + nodes[i].name + ")"); + return false; + } + } + return true; + }, + // 隐藏/显示搜索栏 + toggleSearch: function() { + $('#search').slideToggle(200); + $('#btnShow').toggle(); + $('#btnHide').toggle(); + $('#keyword').focus(); + }, + // 折叠 + collapse: function() { + $._tree.expandAll(false); + }, + // 展开 + expand: function() { + $._tree.expandAll(true); + } }, // 通用方法封装处理 common: { - // 判断字符串是否为空 + // 判断字符串是否为空 isEmpty: function (value) { if (value == null || this.trim(value) == "") { return true; @@ -1582,14 +1582,14 @@ var table = { }, // 获取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; - } - }); + 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; }, // 数据字典转下拉框 @@ -1597,7 +1597,7 @@ var table = { var actions = []; actions.push($.common.sprintf("