/** * 閫氱敤js鏂规硶灏佽澶勭悊 * Copyright (c) 2019 ruoyi */ // 褰撳墠table鐩稿叧淇℃伅 var table = { config: {}, // 褰撳墠瀹炰緥閰嶇疆 options: {}, // 璁剧疆瀹炰緥閰嶇疆 set: function(id) { if($.common.getLength(table.config) > 1) { var tableId = $.common.isEmpty(id) ? $(event.currentTarget).parents(".bootstrap-table").find(".table").attr("id") : id; if ($.common.isNotEmpty(tableId)) { table.options = table.get(tableId); } } }, // 鑾峰彇瀹炰緥閰嶇疆 get: function(id) { return table.config[id]; }, // 璁颁綇閫夋嫨瀹炰緥缁 rememberSelecteds: {}, // 璁颁綇閫夋嫨ID缁 rememberSelectedIds: {} }; (function ($) { $.extend({ _tree: {}, bttTable: {}, // 琛ㄦ牸灏佽澶勭悊 table: { // 鍒濆鍖栬〃鏍煎弬鏁 init: function(options) { var defaults = { id: "bootstrap-table", type: 0, // 0 浠h〃bootstrapTable 1浠h〃bootstrapTreeTable height: undefined, sidePagination: "server", sortName: "", sortOrder: "asc", pagination: true, pageSize: 10, pageList: [10, 25, 50], toolbar: "toolbar", striped: false, escape: false, firstLoad: true, showFooter: false, search: false, showSearch: true, showPageGo: false, showRefresh: true, showColumns: true, showToggle: true, showExport: false, clickToSelect: false, mobileResponsive: true, rememberSelected: false, fixedColumns: false, fixedNumber: 0, rightFixedColumns: false, rightFixedNumber: 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, url: options.url, // 璇锋眰鍚庡彴鐨刄RL锛?锛 contentType: "application/x-www-form-urlencoded", // 缂栫爜绫诲瀷 method: 'post', // 璇锋眰鏂瑰紡锛?锛 cache: false, // 鏄惁浣跨敤缂撳瓨 height: options.height, // 琛ㄦ牸鐨勯珮搴 striped: options.striped, // 鏄惁鏄剧ず琛岄棿闅旇壊 sortable: true, // 鏄惁鍚敤鎺掑簭 sortStable: true, // 璁剧疆涓 true 灏嗚幏寰楃ǔ瀹氱殑鎺掑簭 sortName: options.sortName, // 鎺掑簭鍒楀悕绉 sortOrder: options.sortOrder, // 鎺掑簭鏂瑰紡 asc 鎴栬€ desc pagination: options.pagination, // 鏄惁鏄剧ず鍒嗛〉锛?锛 pageNumber: 1, // 鍒濆鍖栧姞杞界涓€椤碉紝榛樿绗竴椤 pageSize: options.pageSize, // 姣忛〉鐨勮褰曡鏁帮紙*锛 pageList: options.pageList, // 鍙緵閫夋嫨鐨勬瘡椤电殑琛屾暟锛?锛 firstLoad: options.firstLoad, // 鏄惁棣栨璇锋眰鍔犺浇鏁版嵁锛屽浜庢暟鎹緝澶у彲浠ラ厤缃甪alse escape: options.escape, // 杞箟HTML瀛楃涓 showFooter: options.showFooter, // 鏄惁鏄剧ず琛ㄥ熬 iconSize: 'outline', // 鍥炬爣澶у皬锛歶ndefined榛樿鐨勬寜閽昂瀵 xs瓒呭皬鎸夐挳sm灏忔寜閽甽g澶ф寜閽 toolbar: '#' + options.toolbar, // 鎸囧畾宸ヤ綔鏍 sidePagination: options.sidePagination, // server鍚敤鏈嶅姟绔垎椤礳lient瀹㈡埛绔垎椤 search: options.search, // 鏄惁鏄剧ず鎼滅储妗嗗姛鑳 searchText: options.searchText, // 鎼滅储妗嗗垵濮嬫樉绀虹殑鍐呭锛岄粯璁や负绌 showSearch: options.showSearch, // 鏄惁鏄剧ず妫€绱俊鎭 showPageGo: options.showPageGo, // 鏄惁鏄剧ず璺宠浆椤 showRefresh: options.showRefresh, // 鏄惁鏄剧ず鍒锋柊鎸夐挳 showColumns: options.showColumns, // 鏄惁鏄剧ず闅愯棌鏌愬垪涓嬫媺妗 showToggle: options.showToggle, // 鏄惁鏄剧ず璇︾粏瑙嗗浘鍜屽垪琛ㄨ鍥剧殑鍒囨崲鎸夐挳 showExport: options.showExport, // 鏄惁鏀寔瀵煎嚭鏂囦欢 uniqueId: options.uniqueId, // 鍞 涓€鐨勬爣璇嗙 clickToSelect: options.clickToSelect, // 鏄惁鍚敤鐐瑰嚮閫変腑琛 mobileResponsive: options.mobileResponsive, // 鏄惁鏀寔绉诲姩绔€傞厤 detailView: options.detailView, // 鏄惁鍚敤鏄剧ず缁嗚妭瑙嗗浘 onClickRow: options.onClickRow, // 鐐瑰嚮鏌愯瑙﹀彂鐨勪簨浠 onDblClickRow: options.onDblClickRow, // 鍙屽嚮鏌愯瑙﹀彂鐨勪簨浠 onClickCell: options.onClickCell, // 鍗曞嚮鏌愭牸瑙﹀彂鐨勪簨浠 onDblClickCell: options.onDblClickCell, // 鍙屽嚮鏌愭牸瑙﹀彂鐨勪簨浠 onEditableSave: options.onEditableSave, // 琛屽唴缂栬緫淇濆瓨鐨勪簨浠 onExpandRow: options.onExpandRow, // 鐐瑰嚮璇︾粏瑙嗗浘鐨勪簨浠 rememberSelected: options.rememberSelected, // 鍚敤缈婚〉璁颁綇鍓嶉潰鐨勯€夋嫨 fixedColumns: options.fixedColumns, // 鏄惁鍚敤鍐荤粨鍒楋紙宸︿晶锛 fixedNumber: options.fixedNumber, // 鍒楀喕缁撶殑涓暟锛堝乏渚э級 rightFixedColumns: options.rightFixedColumns, // 鏄惁鍚敤鍐荤粨鍒楋紙鍙充晶锛 rightFixedNumber: options.rightFixedNumber, // 鍒楀喕缁撶殑涓暟锛堝彸渚э級 onReorderRow: options.onReorderRow, // 褰撴嫋鎷界粨鏉熷悗澶勭悊鍑芥暟 queryParams: options.queryParams, // 浼犻€掑弬鏁帮紙*锛 rowStyle: options.rowStyle, // 閫氳繃鑷畾涔夊嚱鏁拌缃鏍峰紡 columns: options.columns, // 鏄剧ず鍒椾俊鎭紙*锛 responseHandler: $.table.responseHandler, // 鍦ㄥ姞杞芥湇鍔″櫒鍙戦€佹潵鐨勬暟鎹箣鍓嶅鐞嗗嚱鏁 onLoadSuccess: $.table.onLoadSuccess, // 褰撴墍鏈夋暟鎹鍔犺浇鏃惰Е鍙戝鐞嗗嚱鏁 exportOptions: options.exportOptions, // 鍓嶇瀵煎嚭蹇界暐鍒楃储寮 detailFormatter: options.detailFormatter, // 鍦ㄨ涓嬮潰灞曠ず鍏朵粬鏁版嵁鍒楄〃 }); }, // 鑾峰彇瀹炰緥ID锛屽瀛樺湪澶氫釜杩斿洖#id1,#id2 delimeter鍒嗛殧绗 getOptionsIds: function(separator) { var _separator = $.common.isEmpty(separator) ? "," : separator; var optionsIds = ""; $.each(table.config, function(key, value){ optionsIds += "#" + key + _separator; }); return optionsIds.substring(0, optionsIds.length - 1); }, initHead:function(options){ $('#bootstrap-table').bootstrapTable({ cache: false, // 鏄惁浣跨敤缂撳瓨 sortable: false, // 鏄惁鍚敤鎺掑簭 sortStable: false, // 璁剧疆涓 true 灏嗚幏寰楃ǔ瀹氱殑鎺掑簭 pagination: false, // 鏄惁鏄剧ず鍒嗛〉锛?锛 iconSize: 'outline', // 鍥炬爣澶у皬锛歶ndefined榛樿鐨勬寜閽昂瀵 xs瓒呭皬鎸夐挳sm灏忔寜閽甽g澶ф寜閽 toolbar: '#toolbar', // 鎸囧畾宸ヤ綔鏍 height:options.height, columns: options.columns // 鏄剧ず鍒椾俊鎭紙*锛 }); }, loadData:function(data){ $('#bootstrap-table').bootstrapTable('load',data); }, // 鏌ヨ鏉′欢 queryParams: function(params) { 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.options.responseHandler == "function") { table.options.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; }) } return { rows: res.rows, total: res.total }; } } else { $.modal.alertWarning(res.msg); return { rows: [], total: 0 }; } }, // 鍒濆鍖栦簨浠 initEvent: function() { // 瀹炰緥ID淇℃伅 var optionsIds = $.table.getOptionsIds(); // 鐩戝惉浜嬩欢澶勭悊 $(optionsIds).on(TABLE_EVENTS, function () { table.set($(this).attr("id")); }); // 閫変腑銆佸彇娑堛€佸叏閮ㄩ€変腑銆佸叏閮ㄥ彇娑堬紙浜嬩欢锛 $(optionsIds).on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table", function (e, rows) { // 澶嶉€夋鍒嗛〉淇濈暀淇濆瓨閫変腑鏁扮粍 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); }); // 鍥剧墖棰勮浜嬩欢 $(optionsIds).off("click").on("click", '.img-circle', function() { /*var src = $(this).attr('src'); var target = $(this).data('target'); var height = $(this).data('height'); var width = $(this).data('width'); if($.common.equals("self", target)) { layer.open({ title: false, type: 1, closeBtn: true, shadeClose: true, area: ['auto', 'auto'], content: "" }); } else if ($.common.equals("blank", target)) { window.open(src); }*/ var html="
\n" + "
\n" + " \n" + "
\n" + "
"; $("body").append(html); var outerdiv="#outerdiv"; var innerdiv="#innerdiv"; var bigimg="#bigimg"; var url = $(this).attr('src'); $(bigimg).attr("src", url); $("").attr("src", url).load(function(){ var windowW = $(window).width(); var windowH = $(window).height(); var realWidth = this.width; var realHeight = this.height; var imgWidth, imgHeight; var scale = 0.8; if(realHeight>windowH*scale) { imgHeight = windowH*scale; imgWidth = imgHeight/realHeight*realWidth; if(imgWidth>windowW*scale) { imgWidth = windowW*scale; } } else if(realWidth>windowW*scale) { imgWidth = windowW*scale; imgHeight = imgWidth/realWidth*realHeight; } else { imgWidth = realWidth; imgHeight = realHeight; } $(bigimg).css("width",imgWidth); var w = (windowW-imgWidth)/2; var h = (windowH-imgHeight)/2; $(innerdiv).css({"top":h, "left":w}); $(outerdiv).fadeIn("fast"); }); $(outerdiv).click(function(){ $(this).fadeOut("fast"); }); }); // 鍗曞嚮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'], }); } }); }, // 褰撴墍鏈夋暟鎹鍔犺浇鏃惰Е鍙 onLoadSuccess: function(data) { if (typeof table.options.onLoadSuccess == "function") { table.options.onLoadSuccess(data); } // 娴姩鎻愮ず妗嗙壒鏁 $("[data-toggle='tooltip']").tooltip(); }, // 琛ㄦ牸閿€姣 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 = tableParams.pageSize; var pageNumber = tableParams.pageNumber; return pageSize * (pageNumber - 1) + index + 1; }, // 鍒楄秴鍑烘寚瀹氶暱搴︽诞鍔ㄦ彁绀 target锛坈opy鍗曞嚮澶嶅埗鏂囨湰 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,"鈥?); 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'; } // 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); } }, // 鎼滅储-榛樿绗竴涓猣orm search: function(formId, tableId, data) { table.set(tableId); var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; var params = $.common.isEmpty(tableId) ? $("#" + table.options.id).bootstrapTable('getOptions') : $("#" + tableId).bootstrapTable('getOptions'); params.queryParams = function(params) { var search = $.common.formToJSON(currentId); if($.common.isNotEmpty(data)){ $.each(data, function(key) { search[key] = data[key]; }); } search.pageSize = params.limit; search.pageNum = params.offset / params.limit + 1; search.searchValue = params.search; search.orderByColumn = params.sort; search.isAsc = params.order; return search; } if($.common.isNotEmpty(tableId)){ $("#" + tableId).bootstrapTable('refresh', params); } else{ $("#" + table.options.id).bootstrapTable('refresh', params); } }, // 瀵煎嚭鏁版嵁 exportExcel: function(formId,url) { var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; $.modal.loading("姝e湪瀵煎嚭鏁版嵁锛岃绋嶅悗..."); if($.common.isEmpty(url)){ url = table.options.exportUrl; } $.post(url, $("#" + currentId).serializeArray(), function(result) { if (result.code === web_status.SUCCESS) { window.location.href = ctx + "common/download?fileName=" + result.msg + "&delete=" + true; } 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); } }); }, // 瀵煎叆鏁版嵁 importExcel: function(formId) { table.set(); var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId; layer.open({ type: 1, area: ['400px', '230px'], 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("璇烽€夋嫨鍚庣紑涓 鈥渪ls鈥濇垨鈥渪lsx鈥濈殑鏂囦欢銆?); return false; } var index = layer.load(2, {shade: false}); $.modal.disable(); var formData = new FormData(); formData.append("file", $('#file')[0].files[0]); formData.append("updateSupport", $("input[name='updateSupport']").is(':checked')); $.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 { $.modal.closeAll(); $.modal.alertError(result.msg); $.table.refresh(); } } }); } }); }, // 鍒锋柊琛ㄦ牸 refresh: function(tableId) { var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; $("#" + currentId).bootstrapTable('refresh', { silent: true }); }, // 鏌ヨ琛ㄦ牸鎸囧畾鍒楀€ selectColumns: function(column) { var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) { return 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 row[column]; }); } } return $.common.uniqueFn(rows); }, // 鑾峰彇褰撳墠椤甸€変腑鎴栬€呭彇娑堢殑琛孖D affectedRowIds: function(rows) { var column = $.common.isEmpty(table.options.uniqueId) ? table.options.columns[1].field : table.options.uniqueId; var rowIds; if ($.isArray(rows)) { rowIds = $.map(rows, function(row) { return row[column]; }); } else { rowIds = [rows[column]]; } return rowIds; }, // 鏌ヨ琛ㄦ牸棣栧垪鍊 selectFirstColumns: function() { var rows = $.map($("#" + table.options.id).bootstrapTable('getSelections'), function (row) { return 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) { return row[table.options.columns[1].field]; }); } } return $.common.uniqueFn(rows); }, // 鍥炴樉鏁版嵁瀛楀吀 selectDictLabel: function(datas, value) { var actions = []; $.each(datas, function(index, dict) { if (dict.dictValue == ('' + value)) { var listClass = $.common.equals("default", dict.listClass) || $.common.isEmpty(dict.listClass) ? "" : "badge badge-" + dict.listClass; actions.push($.common.sprintf("%s", listClass, dict.dictLabel)); return false; } }); return actions.join(''); }, // 鏄剧ず琛ㄦ牸鎸囧畾鍒 showColumn: function(column, tableId) { var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; $("#" + currentId).bootstrapTable('showColumn', column); }, // 闅愯棌琛ㄦ牸鎸囧畾鍒 hideColumn: function(column, tableId) { var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId; $("#" + currentId).bootstrapTable('hideColumn', column); } }, // 琛ㄦ牸鏍戝皝瑁呭鐞 treeTable: { // 鍒濆鍖栬〃鏍 init: function(options) { var defaults = { id: "bootstrap-tree-table", type: 1, // 0 浠h〃bootstrapTable 1浠h〃bootstrapTreeTable 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; $.bttTable = $('#' + options.id).bootstrapTreeTable({ code: options.code, // 鐢ㄤ簬璁剧疆鐖跺瓙鍏崇郴 parentCode: options.parentCode, // 鐢ㄤ簬璁剧疆鐖跺瓙鍏崇郴 type: 'post', // 璇锋眰鏂瑰紡锛?锛 url: options.url, // 璇锋眰鍚庡彴鐨刄RL锛?锛 data: options.data, // 鏃爑rl鏃剁敤浜庢覆鏌撶殑鏁版嵁 ajaxParams: options.ajaxParams, // 璇锋眰鏁版嵁鐨刟jax鐨刣ata灞炴€ rootIdValue: options.rootIdValue, // 璁剧疆鎸囧畾鏍硅妭鐐筰d鍊 height: options.height, // 琛ㄦ牸鏍戠殑楂樺害 expandColumn: options.expandColumn, // 鍦ㄥ摢涓€鍒椾笂闈㈡樉绀哄睍寮€鎸夐挳 striped: options.striped, // 鏄惁鏄剧ず琛岄棿闅旇壊 bordered: true, // 鏄惁鏄剧ず杈规 toolbar: '#' + options.toolbar, // 鎸囧畾宸ヤ綔鏍 showSearch: options.showSearch, // 鏄惁鏄剧ず妫€绱俊鎭 showRefresh: options.showRefresh, // 鏄惁鏄剧ず鍒锋柊鎸夐挳 showColumns: options.showColumns, // 鏄惁鏄剧ず闅愯棌鏌愬垪涓嬫媺妗 expandAll: options.expandAll, // 鏄惁鍏ㄩ儴灞曞紑 expandFirst: options.expandFirst, // 鏄惁榛樿绗竴绾у睍寮€--expandAll涓篺alse鏃剁敓鏁 columns: options.columns, // 鏄剧ず鍒椾俊鎭紙*锛 responseHandler: $.treeTable.responseHandler // 褰撴墍鏈夋暟鎹鍔犺浇鏃惰Е鍙戝鐞嗗嚱鏁 }); }, // 鏉′欢鏌ヨ search: function(formId) { var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; var params = $.common.formToJSON(currentId); $.bttTable.bootstrapTreeTable('refresh', params); }, // 鍒锋柊 refresh: function() { $.bttTable.bootstrapTreeTable('refresh'); }, // 鏌ヨ琛ㄦ牸鏍戞寚瀹氬垪鍊 selectColumns: function(column) { var rows = $.map($.bttTable.bootstrapTreeTable('getSelections'), function (row) { return row[column]; }); return $.common.uniqueFn(rows); }, // 璇锋眰鑾峰彇鏁版嵁鍚庡鐞嗗洖璋冨嚱鏁帮紝鏍¢獙寮傚父鐘舵€佹彁閱 responseHandler: function(data) { if (data.code != undefined && data.code != 0) { $.modal.alertWarning(data.msg); return []; } else { return data; } }, }, // 琛ㄥ崟灏佽澶勭悊 form: { // 琛ㄥ崟閲嶇疆 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'); } } }, // 鑾峰彇閫変腑澶嶉€夋椤 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; }, // 鑾峰彇閫変腑涓嬫媺妗嗛」 selectSelects: function(name) { var 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; }, // 娑堟伅鎻愮ず msg: function(content, type) { if (type != undefined) { layer.msg(content, { icon: $.modal.icon(type), time: 1000, shift: 5 }); } else { layer.msg(content); } }, // 閿欒娑堟伅 msgError: function(content) { $.modal.msg(content, modal_status.FAIL); }, // 鎴愬姛娑堟伅 msgSuccess: function(content) { $.modal.msg(content, modal_status.SUCCESS); }, // 璀﹀憡娑堟伅 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'], }); }, // 娑堟伅鎻愮ず骞跺埛鏂扮埗绐椾綋 msgReload: function(msg, type) { layer.msg(msg, { icon: $.modal.icon(type), time: 500, shade: [0.1, '#8F8F8F'] }, function() { $.modal.reload(); }); }, // 閿欒鎻愮ず alertError: function(content) { $.modal.alert(content, modal_status.FAIL); }, // 鎴愬姛鎻愮ず alertSuccess: function(content) { $.modal.alert(content, modal_status.SUCCESS); }, // 璀﹀憡鎻愮ず alertWarning: function(content) { $.modal.alert(content, modal_status.WARNING); }, // 鍏抽棴绐椾綋 close: function () { var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); }, // 鍏抽棴鍏ㄩ儴绐椾綋 closeAll: function () { layer.closeAll(); }, // 纭绐椾綋 confirm: function (content, callBack) { layer.confirm(content, { icon: 3, title: "绯荤粺鎻愮ず", btn: ['纭', '鍙栨秷'] }, function (index) { layer.close(index); callBack(true); }); }, // 寮瑰嚭灞傛寚瀹氬搴 open: function (title, url, width, height, callback) { //濡傛灉鏄Щ鍔ㄧ锛屽氨浣跨敤鑷€傚簲澶у皬寮圭獥 if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) { width = 'auto'; height = 'auto'; } if ($.common.isEmpty(title)) { title = false; } if ($.common.isEmpty(url)) { url = "/404.html"; } if ($.common.isEmpty(width)) { width = 800; } if ($.common.isEmpty(height)) { height = ($(window).height() - 50); } if ($.common.isEmpty(callback)) { callback = function(index, layero) { var iframeWin = layero.find('iframe')[0]; iframeWin.contentWindow.submitHandler(index, layero); } } layer.open({ type: 2, area: [width + 'px', height + 'px'], fix: false, //涓嶅浐瀹 maxmin: true, shade: 0.3, title: title, content: url, btn: ['纭畾', '鍏抽棴'], // 寮瑰眰澶栧尯鍩熷叧闂 shadeClose: true, yes: callback, cancel: function(index) { return true; } }); }, // 寮瑰嚭灞傛寚瀹氬弬鏁伴€夐」 openOptions: function (options) { var _url = $.common.isEmpty(options.url) ? "/404.html" : options.url; var _title = $.common.isEmpty(options.title) ? "绯荤粺绐楀彛" : options.title; var _width = $.common.isEmpty(options.width) ? "800" : options.width; var _height = $.common.isEmpty(options.height) ? ($(window).height() - 50) : options.height; var _btn = [' 纭', ' 鍏抽棴']; if ($.common.isEmpty(options.yes)) { options.yes = function(index, layero) { options.callBack(index, layero); } } layer.open({ type: 2, maxmin: true, 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; } }); }, // 寮瑰嚭灞傚叏灞 openFull: function (title, url, width, height) { //濡傛灉鏄Щ鍔ㄧ锛屽氨浣跨敤鑷€傚簲澶у皬寮圭獥 if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) { width = 'auto'; height = 'auto'; } if ($.common.isEmpty(title)) { title = false; } if ($.common.isEmpty(url)) { url = "/404.html"; } if ($.common.isEmpty(width)) { width = 800; } if ($.common.isEmpty(height)) { 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; } }); layer.full(index); }, // 閫夊崱椤垫柟寮忔墦寮€ openTab: function (title, url) { createMenuItem(url, title); }, // 閫夊崱椤靛悓涓€椤电鎵撳紑 parentTab: function (title, url) { var dataId = window.frameElement.getAttribute('data-id'); createMenuItem(url, title); closeItem(dataId); }, // 鍏抽棴閫夐」鍗 closeTab: function (dataId) { closeItem(dataId); }, // 绂佺敤鎸夐挳 disable: function() { var doc = window.top == window.parent ? window.document : window.parent.document; $("a[class*=layui-layer-btn]", doc).addClass("layer-disabled"); }, // 鍚敤鎸夐挳 enable: function() { var doc = window.top == window.parent ? window.document : window.parent.document; $("a[class*=layui-layer-btn]", doc).removeClass("layer-disabled"); }, // 鎵撳紑閬僵灞 loading: function (message) { $.blockUI({ message: '
' + message + '
' }); }, // 鍏抽棴閬僵灞 closeLoading: function () { setTimeout(function(){ $.unblockUI(); }, 50); }, // 閲嶆柊鍔犺浇 reload: function () { parent.location.reload(); } }, // 鎿嶄綔灏佽澶勭悊 operate: { // 鎻愪氦鏁版嵁 submit: function(url, type, dataType, data, callback) { var config = { url: url, type: type, dataType: dataType, data: data, beforeSend: function () { $.modal.loading("姝e湪澶勭悊涓紝璇风◢鍚?.."); }, success: function(result) { if (typeof callback == "function") { callback(result); } $.operate.ajaxSuccess(result); } }; $.ajax(config) }, // post璇锋眰浼犺緭 post: function(url, data, callback) { $.operate.submit(url, "post", "json", data, callback); }, // get璇锋眰浼犺緭 get: function(url, callback) { $.operate.submit(url, "get", "json", "", callback); }, ajaxGet: function(url, callback) { var config = { url: url, type: "get", dataType: "json", data: data, beforeSend: function () { $.modal.loading("姝e湪澶勭悊涓紝璇风◢鍚?.."); }, success: function(result) { $.modal.closeLoading(); if (typeof callback == "function") { callback(result); } } }; $.ajax(config) }, // 璇︾粏淇℃伅 detail: function(id, width, height) { table.set(); var _url = $.operate.detailUrl(id); var _width = $.common.isEmpty(width) ? "800" : width; var _height = $.common.isEmpty(height) ? ($(window).height() - 50) : height; //濡傛灉鏄Щ鍔ㄧ锛屽氨浣跨敤鑷€傚簲澶у皬寮圭獥 if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) { _width = 'auto'; _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); } }; $.modal.openOptions(options); }, // 璇︾粏璁块棶鍦板潃 detailUrl: function(id) { var url = "/404.html"; if ($.common.isNotEmpty(id)) { url = table.options.detailUrl.replace("{id}", id); } else { var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); if (id.length == 0) { $.modal.alertWarning("璇疯嚦灏戦€夋嫨涓€鏉¤褰?); return; } url = table.options.detailUrl.replace("{id}", id); } return url; }, // 鍒犻櫎淇℃伅 remove: function(id) { table.set(); $.modal.confirm("纭畾鍒犻櫎璇ユ潯" + table.options.modalName + "淇℃伅鍚楋紵", function() { var url = $.common.isEmpty(id) ? table.options.removeUrl : table.options.removeUrl.replace("{id}", id); if(table.options.type == table_type.bootstrapTreeTable) { $.operate.get(url); } else { 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); }); }, // 娓呯┖淇℃伅 clean: function() { table.set(); $.modal.confirm("纭畾娓呯┖鎵€鏈? + table.options.modalName + "鍚楋紵", function() { var url = table.options.cleanUrl; $.operate.submit(url, "post", "json", ""); }); }, // 娣诲姞淇℃伅 add: function(id) { table.set(); $.modal.open("娣诲姞" + table.options.modalName, $.operate.addUrl(id)); }, // 娣诲姞淇℃伅锛屼互tab椤靛睍鐜 addTab: function (id) { table.set(); $.modal.openTab("娣诲姞" + table.options.modalName, $.operate.addUrl(id)); }, // 娣诲姞淇℃伅 鍏ㄥ睆 addFull: function(id) { table.set(); var url = $.common.isEmpty(id) ? table.options.createUrl : table.options.createUrl.replace("{id}", id); $.modal.openFull("娣诲姞" + table.options.modalName, url); }, // 娣诲姞璁块棶鍦板潃 addUrl: function(id) { var url = $.common.isEmpty(id) ? table.options.createUrl.replace("{id}", "") : table.options.createUrl.replace("{id}", id); return url; }, // 淇敼淇℃伅 edit: function(id) { table.set(); if($.common.isEmpty(id) && table.options.type == table_type.bootstrapTreeTable) { var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0]; if ($.common.isEmpty(row)) { $.modal.alertWarning("璇疯嚦灏戦€夋嫨涓€鏉¤褰?); return; } var url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]); $.modal.open("淇敼" + table.options.modalName, url); } else { $.modal.open("淇敼" + table.options.modalName, $.operate.editUrl(id)); } }, // 淇敼淇℃伅锛屼互tab椤靛睍鐜 editTab: function(id) { table.set(); $.modal.openTab("淇敼" + table.options.modalName, $.operate.editUrl(id)); }, // 淇敼淇℃伅 鍏ㄥ睆 editFull: function(id) { table.set(); var url = "/404.html"; if ($.common.isNotEmpty(id)) { url = table.options.updateUrl.replace("{id}", id); } else { var row = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); url = table.options.updateUrl.replace("{id}", row); } $.modal.openFull("淇敼" + table.options.modalName, url); }, // 淇敼璁块棶鍦板潃 editUrl: function(id) { var url = "/404.html"; if ($.common.isNotEmpty(id)) { url = table.options.updateUrl.replace("{id}", id); } else { var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId); if (id.length == 0) { $.modal.alertWarning("璇疯嚦灏戦€夋嫨涓€鏉¤褰?); return; } url = table.options.updateUrl.replace("{id}", id); } return url; }, // 淇濆瓨淇℃伅 鍒锋柊琛ㄦ牸 save: function(url, data, callback) { var config = { url: url, type: "post", dataType: "json", data: data, beforeSend: function () { $.modal.loading("姝e湪澶勭悊涓紝璇风◢鍚?.."); $.modal.disable(); }, success: function(result) { if (typeof callback == "function") { callback(result); } $.operate.successCallback(result); } }; $.ajax(config) }, // 淇濆瓨淇℃伅 寮瑰嚭鎻愮ず妗 saveModal: function(url, data, callback) { var config = { url: url, type: "post", dataType: "json", data: data, beforeSend: function () { $.modal.loading("姝e湪澶勭悊涓紝璇风◢鍚?.."); }, success: function(result) { if (typeof callback == "function") { callback(result); } if (result.code == web_status.SUCCESS) { $.modal.alertSuccess(result.msg) } else if (result.code == web_status.WARNING) { $.modal.alertWarning(result.msg) } else { $.modal.alertError(result.msg); } $.modal.closeLoading(); } }; $.ajax(config) }, // 淇濆瓨閫夐」鍗′俊鎭 saveTab: function(url, data, callback) { var config = { url: url, type: "post", dataType: "json", data: data, beforeSend: function () { $.modal.loading("姝e湪澶勭悊涓紝璇风◢鍚?.."); }, 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(); } else if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTreeTable) { $.modal.msgSuccess(result.msg); $.treeTable.refresh(); } else if (result.code == web_status.WARNING) { $.modal.alertWarning(result.msg) } else if (result.code == web_status.SUCCESS && table.option.type == undefined) { $.modal.msgSuccess(result.msg); } else { $.modal.alertError(result.msg); } $.modal.closeLoading(); }, // 鎴愬姛缁撴灉鎻愮ずmsg锛堢埗绐椾綋鍏ㄥ眬鏇存柊锛 saveSuccess: function (result) { if (result.code == web_status.SUCCESS) { $.modal.msgReload("淇濆瓨鎴愬姛,姝e湪鍒锋柊鏁版嵁璇风◢鍚庘€︹€?, modal_status.SUCCESS); } else if (result.code == web_status.WARNING) { $.modal.alertWarning(result.msg) } else { $.modal.alertError(result.msg); } $.modal.closeLoading(); }, // 鎴愬姛鍥炶皟鎵ц浜嬩欢锛堢埗绐椾綋闈欓粯鏇存柊锛 successCallback: function(result) { if (result.code == web_status.SUCCESS) { var parent = window.parent; if (parent.table.options.type == table_type.bootstrapTable) { $.modal.close(); parent.$.modal.msgSuccess(result.msg); parent.$.table.refresh(); } else if (parent.table.options.type == table_type.bootstrapTreeTable) { $.modal.close(); parent.$.modal.msgSuccess(result.msg); parent.$.treeTable.refresh(); } else { $.modal.msgReload("淇濆瓨鎴愬姛,姝e湪鍒锋柊鏁版嵁璇风◢鍚庘€︹€?, modal_status.SUCCESS); } } else if (result.code == web_status.WARNING) { $.modal.alertWarning(result.msg) } else { $.modal.alertError(result.msg); } $.modal.closeLoading(); $.modal.enable(); }, // 閫夐」鍗℃垚鍔熷洖璋冩墽琛屼簨浠讹紙鐖剁獥浣撻潤榛樻洿鏂帮級 successTabCallback: function(result) { if (result.code == web_status.SUCCESS) { var topWindow = $(window.parent.document); var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-panel'); var $contentWindow = $('.RuoYi_iframe[data-id="' + currentId + '"]', topWindow)[0].contentWindow; $.modal.close(); $contentWindow.$.modal.msgSuccess(result.msg); $contentWindow.$(".layui-layer-padding").removeAttr("style"); if ($contentWindow.table.options.type == table_type.bootstrapTable) { $contentWindow.$.table.refresh(); } else if ($contentWindow.table.options.type == table_type.bootstrapTreeTable) { $contentWindow.$.treeTable.refresh(); } $.modal.closeTab(); } else if (result.code == web_status.WARNING) { $.modal.alertWarning(result.msg) } else { $.modal.alertError(result.msg); } $.modal.closeLoading(); } }, // 鏍¢獙灏佽澶勭悊 validate: { // 鍒ゆ柇杩斿洖鏍囪瘑鏄惁鍞竴 false 涓嶅瓨鍦 true 瀛樺湪 unique: function (value) { if (value == "0") { return true; } return false; }, // 琛ㄥ崟楠岃瘉 form: function (formId) { var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; return $("#" + currentId).validate().form(); }, // 閲嶇疆琛ㄥ崟楠岃瘉锛堟竻闄ゆ彁绀轰俊鎭級 reset: function (formId) { var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId; return $("#" + currentId).validate().resetForm(); } }, // 鏍戞彃浠跺皝瑁呭鐞 tree: { _option: {}, _lastValue: {}, // 鍒濆鍖栨爲缁撴瀯 init: function(options) { var defaults = { id: "tree", // 灞炴€D expandLevel: 0, // 灞曞紑绛夌骇鑺傜偣 view: { selectedMulti: false, // 璁剧疆鏄惁鍏佽鍚屾椂閫変腑澶氫釜鑺傜偣 nameIsHTML: true // 璁剧疆 name 灞炴€ф槸鍚︽敮鎸 HTML 鑴氭湰 }, check: { enable: false, // 缃 zTree 鐨勮妭鐐逛笂鏄惁鏄剧ず checkbox / radio nocheckInherit: true, // 璁剧疆瀛愯妭鐐规槸鍚﹁嚜鍔ㄧ户鎵 }, 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; var nodes = tree.getNodesByParam("level", options.expandLevel - 1); for (var i = 0; i < nodes.length; i++) { tree.expandNode(nodes[i], true, false, false); } var node = tree.getNodesByParam("id", treeId, null)[0]; $.tree.selectByIdName(treeId, node); }); }, // 鎼滅储鑺傜偣 searchNode: function() { // 鍙栧緱杈撳叆鐨勫叧閿瓧鐨勫€ var value = $.common.trim($("#keyword").val()); if ($.tree._lastValue == value) { return; } // 淇濆瓨鏈€鍚庝竴娆℃悳绱㈠悕绉 $.tree._lastValue = value; var nodes = $._tree.getNodes(); // 濡傛灉瑕佹煡绌哄瓧涓诧紝灏遍€€鍑轰笉鏌ヤ簡銆 if (value == "") { $.tree.showAllNode(nodes); return; } $.tree.hideAllNode(nodes); // 鏍规嵁鎼滅储鍊兼ā绯婂尮閰 $.tree.updateNodes($._tree.getNodesByParamFuzzy("name", value)); }, // 鏍规嵁Id鍜孨ame閫変腑鎸囧畾鑺傜偣 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); } }, // 闅愯棌鎵€鏈夎妭鐐 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){ $.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++) { 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); } }, // 閫氱敤鏂规硶灏佽澶勭悊 common: { // 鍒ゆ柇瀛楃涓叉槸鍚︿负绌 isEmpty: function (value) { if (value == null || this.trim(value) == "") { return true; } return false; }, // 鍒ゆ柇涓€涓瓧绗︿覆鏄惁涓洪潪绌轰覆 isNotEmpty: function (value) { return !$.common.isEmpty(value); }, // 绌哄璞¤浆瀛楃涓 nullToStr: function(value) { if ($.common.isEmpty(value)) { return "-"; } return value; }, // 鏄惁鏄剧ず鏁版嵁 涓虹┖榛樿涓烘樉绀 visible: function (value) { if ($.common.isEmpty(value) || value == true) { return true; } return false; }, // 绌烘牸鎴彇 trim: function (value) { if (value == null) { return ""; } return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, ""); }, // 姣旇緝涓や釜瀛楃涓诧紙澶у皬鍐欐晱鎰燂級 equals: function (str, that) { return str == that; }, // 姣旇緝涓や釜瀛楃涓诧紙澶у皬鍐欎笉鏁忔劅锛 equalsIgnoreCase: function (str, that) { return String(str).toUpperCase() === String(that).toUpperCase(); }, // 灏嗗瓧绗︿覆鎸夋寚瀹氬瓧绗﹀垎鍓 split: function (str, sep, maxLen) { if ($.common.isEmpty(str)) { return null; } var value = String(str).split(sep); return maxLen ? value.slice(0, maxLen - 1) : value; }, // 瀛楃涓叉牸寮忓寲(%s ) sprintf: function (str) { var args = arguments, flag = true, i = 1; str = str.replace(/%s/g, function () { var arg = args[i++]; if (typeof arg === 'undefined') { flag = false; return ''; } return arg; }); return flag ? str : ''; }, // 鎸囧畾闅忔満鏁拌繑鍥 random: function (min, max) { return Math.floor((Math.random() * max) + min); }, // 鍒ゆ柇瀛楃涓叉槸鍚︽槸浠tart寮€澶 startWith: function(value, start) { var reg = new RegExp("^" + start); return reg.test(value) }, // 鍒ゆ柇瀛楃涓叉槸鍚︽槸浠nd缁撳熬 endWith: function(value, end) { var reg = new RegExp(end + "$"); return reg.test(value) }, // 鏁扮粍鍘婚噸 uniqueFn: function(array) { var result = []; var hashObj = {}; for (var i = 0; i < array.length; i++) { if (!hashObj[array[i]]) { hashObj[array[i]] = true; result.push(array[i]); } } return result; }, // 鏁扮粍涓殑鎵€鏈夊厓绱犳斁鍏ヤ竴涓瓧绗︿覆 join: function(array, separator) { if ($.common.isEmpty(array)) { return null; } return array.join(separator); }, // 鑾峰彇form涓嬫墍鏈夌殑瀛楁骞惰浆鎹负json瀵硅薄 formToJSON: function(formId) { var json = {}; $.each($("#" + formId).serializeArray(), function(i, field) { if(json[field.name]) { json[field.name] += ("," + field.value); } else { json[field.name] = field.value; } }); return json; }, // 鑾峰彇obj瀵硅薄闀垮害 getLength: function(obj) { var count = 0;銆€銆€ for (var i in obj) { if (obj.hasOwnProperty(i)) { count++; }銆€銆€ } return count; } } }); })(jQuery); /** 琛ㄦ牸绫诲瀷 */ table_type = { bootstrapTable: 0, bootstrapTreeTable: 1 }; /** 娑堟伅鐘舵€佺爜 */ web_status = { SUCCESS: 0, FAIL: 500, WARNING: 301 }; /** 寮圭獥鐘舵€佺爜 */ modal_status = { SUCCESS: "success", FAIL: "error", WARNING: "warning" }; /*灏嗗悗鍙拌繑鍥炵殑鏃堕棿鎴砳d杞崲鎴愭棩鏈熷瓧绗︿覆*/ function convertTimeUuidToDateStr(id){ id = id+""; var year = "20"+id.substring(0,2); var month = id.substring(2,4); var day = id.substring(4,6); var hour = id.substring(6,8); var min = id.substring(8,10); var sec = id.substring(10,12); return year+"-"+month+"-"+day+" "+hour+":"+min+":"+sec; }