| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- $(function () {
- //document.body.className = localStorage.getItem('config-skin');
- $("[data-toggle='tooltip']").tooltip();
- })
- $.reload = function () {
- location.reload();
- return false;
- }
- $.loading = function (bool, text) {
- var $loadingpage = top.$("#loadingPage");
- var $loadingtext = $loadingpage.find('.loading-content');
- if (bool) {
- $loadingpage.show();
- } else {
- if ($loadingtext.attr('istableloading') == undefined) {
- $loadingpage.hide();
- }
- }
- if (!!text) {
- $loadingtext.html(text);
- } else {
- $loadingtext.html("数据加载中,请稍后…");
- }
- $loadingtext.css("left", (top.$('body').width() - $loadingtext.width()) / 2 - 50);
- $loadingtext.css("top", (top.$('body').height() - $loadingtext.height()) / 2);
- }
- $.request = function (name) {
- var search = location.search.slice(1);
- var arr = search.split("&");
- for (var i = 0; i < arr.length; i++) {
- var ar = arr[i].split("=");
- if (ar[0] == name) {
- if (unescape(ar[1]) == 'undefined') {
- return "";
- } else {
- return unescape(ar[1]);
- }
- }
- }
- return "";
- }
- $.currentWindow = function () {
- var iframeId = top.$(".NFine_iframe:visible").attr("id");
- return top.frames[iframeId];
- }
- $.browser = function () {
- var userAgent = navigator.userAgent;
- var isOpera = userAgent.indexOf("Opera") > -1;
- if (isOpera) {
- return "Opera"
- };
- if (userAgent.indexOf("Firefox") > -1) {
- return "FF";
- }
- if (userAgent.indexOf("Chrome") > -1) {
- if (window.navigator.webkitPersistentStorage.toString().indexOf('DeprecatedStorageQuota') > -1) {
- return "Chrome";
- } else {
- return "360";
- }
- }
- if (userAgent.indexOf("Safari") > -1) {
- return "Safari";
- }
- if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
- return "IE";
- };
- }
- $.download = function (url, data, method) {
- if (url && data) {
- data = typeof data == 'string' ? data : jQuery.param(data);
- var inputs = '';
- $.each(data.split('&'), function () {
- var pair = this.split('=');
- inputs += '<input type="hidden" name="' + pair[0] + '" value="' + pair[1] + '" />';
- });
- $('<form action="' + url + '" method="' + (method || 'post') + '">' + inputs + '</form>').appendTo('body').submit().remove();
- };
- };
- $.modalOpen = function (options) {
- var defaults = {
- id: null,
- title: '系统窗口',
- width: "100px",
- height: "100px",
- url: '',
- shade: 0.3,
- btn: ['确认', '关闭'],
- btnclass: ['btn btn-primary', 'btn btn-danger'],
- callBack: null
- };
- var options = $.extend(defaults, options);
- var _width = top.$(window).width() > parseInt(options.width.replace('px', '')) ? options.width : top.$(window).width() + 'px';
- var _height = top.$(window).height() > parseInt(options.height.replace('px', '')) ? options.height : top.$(window).height() + 'px';
- top.layer.open({
- id: options.id,
- type: 2,
- shade: options.shade,
- title: options.title,
- fix: false,
- area: [_width, _height],
- content: options.url,
- btn: options.btn,
- btnclass: options.btnclass,
- yes: function () {
- options.callBack(options.id)
- }, cancel: function () {
- return true;
- }
- });
- }
- $.modalConfirm = function (content, callBack) {
- top.layer.confirm(content, {
- icon: "fa-exclamation-circle",
- title: "系统提示",
- btn: ['确认', '取消'],
- btnclass: ['btn btn-primary', 'btn btn-danger'],
- }, function () {
- callBack(true);
- }, function () {
- callBack(false)
- });
- }
- $.modalAlert = function (content, type) {
- var icon = "";
- if (type == 'success') {
- icon = "fa-check-circle";
- }
- if (type == 'error') {
- icon = "fa-times-circle";
- }
- if (type == 'warning') {
- icon = "fa-exclamation-circle";
- }
- top.layer.alert(content, {
- icon: icon,
- title: "系统提示",
- btn: ['确认'],
- btnclass: ['btn btn-primary'],
- });
- }
- $.modalMsg = function (content, type) {
- if (type != undefined) {
- var icon = "";
- if (type == 'success') {
- icon = "fa-check-circle";
- }
- if (type == 'error') {
- icon = "fa-times-circle";
- }
- if (type == 'warning') {
- icon = "fa-exclamation-circle";
- }
- top.layer.msg(content, { icon: icon, time: 4000, shift: 5 });
- top.$(".layui-layer-msg").find('i.' + icon).parents('.layui-layer-msg').addClass('layui-layer-msg-' + type);
- } else {
- top.layer.msg(content);
- }
- }
- $.modalClose = function () {
- var index = top.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
- var $IsdialogClose = top.$("#layui-layer" + index).find('.layui-layer-btn').find("#IsdialogClose");
- var IsClose = $IsdialogClose.is(":checked");
- if ($IsdialogClose.length == 0) {
- IsClose = true;
- }
- if (IsClose) {
- top.layer.close(index);
- } else {
- location.reload();
- }
- }
- $.submitForm = function (options) {
- var defaults = {
- url: "",
- param: [],
- loading: "正在提交数据...",
- success: null,
- close: true
- };
- var options = $.extend(defaults, options);
- $.loading(true, options.loading);
- window.setTimeout(function () {
- if ($('[name=__RequestVerificationToken]').length > 0) {
- options.param["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
- }
- $.ajax({
- url: options.url,
- data: options.param,
- type: "post",
- dataType: "json",
- success: function (data) {
- if (data.state == "success") {
- options.success(data);
- $.modalMsg(data.message, data.state);
- if (options.close == true) {
- $.modalClose();
- }
- } else {
- $.modalAlert(data.message, data.state);
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- $.loading(false);
- $.modalMsg(errorThrown, "error");
- },
- beforeSend: function () {
- $.loading(true, options.loading);
- },
- complete: function () {
- $.loading(false);
- }
- });
- }, 500);
- }
- $.deleteForm = function (options) {
- var defaults = {
- prompt: "注:您确定要删除该项数据吗?",
- url: "",
- param: [],
- loading: "正在删除数据...",
- success: null,
- close: true
- };
- var options = $.extend(defaults, options);
- if ($('[name=__RequestVerificationToken]').length > 0) {
- options.param["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
- }
- $.modalConfirm(options.prompt, function (r) {
- if (r) {
- $.loading(true, options.loading);
- window.setTimeout(function () {
- $.ajax({
- url: options.url,
- data: options.param,
- type: "post",
- dataType: "json",
- success: function (data) {
- if (data.state == "success") {
- options.success(data);
- $.modalMsg(data.message, data.state);
- } else {
- $.modalAlert(data.message, data.state);
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- $.loading(false);
- $.modalMsg(errorThrown, "error");
- },
- beforeSend: function () {
- $.loading(true, options.loading);
- },
- complete: function () {
- $.loading(false);
- }
- });
- }, 500);
- }
- });
- }
- $.jsonWhere = function (data, action) {
- if (action == null) return;
- var reval = new Array();
- $(data).each(function (i, v) {
- if (action(v)) {
- reval.push(v);
- }
- })
- return reval;
- }
- $.fn.jqGridRowValue = function () {
- var $grid = $(this);
- var selectedRowIds = $grid.jqGrid("getGridParam", "selarrrow");
- if (selectedRowIds != "") {
- var json = [];
- var len = selectedRowIds.length;
- for (var i = 0; i < len ; i++) {
- var rowData = $grid.jqGrid('getRowData', selectedRowIds[i]);
- json.push(rowData);
- }
- return json;
- } else {
- return $grid.jqGrid('getRowData', $grid.jqGrid('getGridParam', 'selrow'));
- }
- }
- $.fn.formValid = function () {
- return $(this).valid({
- errorPlacement: function (error, element) {
- element.parents('.formValue').addClass('has-error');
- element.parents('.has-error').find('i.error').remove();
- element.parents('.has-error').append('<i class="form-control-feedback fa fa-exclamation-circle error" data-placement="left" data-toggle="tooltip" title="' + error + '"></i>');
- $("[data-toggle='tooltip']").tooltip();
- if (element.parents('.input-group').hasClass('input-group')) {
- element.parents('.has-error').find('i.error').css('right', '33px')
- }
- },
- success: function (element) {
- element.parents('.has-error').find('i.error').remove();
- element.parent().removeClass('has-error');
- }
- });
- }
- $.fn.formSerialize = function (formdate) {
- var element = $(this);
- if (!!formdate) {
- for (var key in formdate) {
- var $id = element.find('#' + key);
- var value = $.trim(formdate[key]).replace(/ /g, '');
- var type = $id.attr('type');
- if ($id.hasClass("select2-hidden-accessible")) {
- type = "select";
- }
- switch (type) {
- case "checkbox":
- if (value == "true") {
- $id.attr("checked", 'checked');
- } else {
- $id.removeAttr("checked");
- }
- break;
- case "select":
- $id.val(value).trigger("change");
- break;
- default:
- $id.val(value);
- break;
- }
- };
- return false;
- }
- var postdata = {};
- element.find('input,select,textarea').each(function (r) {
- var $this = $(this);
- var id = $this.attr('id');
- var type = $this.attr('type');
- switch (type) {
- case "checkbox":
- postdata[id] = $this.is(":checked");
- break;
- default:
- var value = $this.val() == "" ? " " : $this.val();
- if (!$.request("keyValue")) {
- value = value.replace(/ /g, '');
- }
- postdata[id] = value;
- break;
- }
- });
- if ($('[name=__RequestVerificationToken]').length > 0) {
- postdata["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
- }
- return postdata;
- };
- $.fn.bindSelect = function (options) {
- var defaults = {
- id: "id",
- text: "text",
- search: false,
- url: "",
- param: [],
- change: null
- };
- var options = $.extend(defaults, options);
- var $element = $(this);
- if (options.url != "") {
- $.ajax({
- url: options.url,
- data: options.param,
- dataType: "json",
- //async: false,
- success: function (data) {
- $.each(data, function (i) {
- $element.append($("<option></option>").val(data[i][options.id]).html(data[i][options.text]));
- });
- $element.select2({
- minimumResultsForSearch: options.search == true ? 0 : -1
- });
- $element.on("change", function (e) {
- if (options.change != null) {
- options.change(data[$(this).find("option:selected").index()]);
- }
- $("#select2-" + $element.attr('id') + "-container").html($(this).find("option:selected").text().replace(/ /g, ''));
- });
- }
- });
- } else {
- $element.select2({
- minimumResultsForSearch: -1
- });
- }
- }
- $.fn.authorizeButton = function () {
- var moduleId = top.$(".J_iframe:visible").attr("id") && top.$(".J_iframe:visible").attr("id").substr(5);
- var dataJson = top.clients.authorizeButton[moduleId];
- var $element = $(this);
- $element.find('[authorize=yes]').attr('authorize', 'no');
- console.log("authorizeButton===="+moduleId);
- console.log(dataJson);
- if (dataJson != undefined) {
- $.each(dataJson, function (i) {
- $element.find("#" + dataJson[i].encode).attr('authorize', 'yes');
- });
- }
- $element.find("[authorize=no]").remove();
- }
- $.fn.authorizeOperateButton = function () {
- var moduleId = top.$(".J_iframe:visible").attr("id") && top.$(".J_iframe:visible").attr("id").substr(5);
- var dataJson = top.clients.authorizeButton[moduleId];
- console.log("authorizeOperateButton===="+moduleId);
- console.log(dataJson);
- var $element = $(this);
- $element.find('[authorize=yes]').attr('authorize', 'no');
- if (dataJson != undefined) {
- $.each(dataJson, function (i) {
- $element.find("[id*='" + dataJson[i].encode + "']").attr('authorize', 'yes');
- });
- }
- if(dataJson && dataJson.length == 0){
- $element.find("[authorize=no]").parents('.task_tools').html('-');
- $element.find("[authorize=no]").parents('ul').html('-');
- }
- //行内编辑的情况去掉编辑(注意类名为 editValue)
- if($element.find('a[authorize=no]').hasClass('editValue')){
- $element.find('a[authorize=no]').removeClass('editValue');
- $element.find('a[authorize=no]').attr('title', '');
- }else{
- $element.find('a[authorize=no]').parents('li').remove();
- $element.find('a[authorize=no]').remove();
- }
- }
- $.fn.dataGrid = function (options) {
- var defaults = {
- datatype: "json",
- autowidth: true,
- rownumbers: true,
- shrinkToFit: false,
- gridview: true
- };
- var options = $.extend(defaults, options);
- var $element = $(this);
- options["onSelectRow"] = function (rowid) {
- var length = $(this).jqGrid("getGridParam", "selrow").length;
- var $operate = $(".operate");
- if (length > 0) {
- $operate.animate({ "left": 0 }, 200);
- } else {
- $operate.animate({ "left": '-100.1%' }, 200);
- }
- $operate.find('.close').click(function () {
- $operate.animate({ "left": '-100.1%' }, 200);
- })
- };
- $element.jqGrid(options);
- };
|