function alertMsg(message) { window.top.$.messager.alert("系统消息", message, "info"); } function redirect(url) { window.location.href = url; } function confirmMsg(message, handler) { window.top.$.messager.confirm("系统提示", message, handler); } //删除数据方法 //url:删除方法url //paramName:删除方法参数名称 //key:主键列 $.fn.deleteRows = function (url, paramName, key) { this.deleteRows(url, paramName, key, "datagrid"); } $.fn.deleteRows = function (url, paramName, key, control) { control = control || "datagrid"; var me = this; var selrows = me[control]("getChecked") if (selrows.length > 0) { confirmMsg("确定删除吗?", function (r) { var ids = new Array(); $(selrows).each(function (i, row) { ids.push(row[key]); }) if (r) { var param = JSON.parse("{ \"" + paramName + "\":\"\"}"); param[paramName] = JSON.stringify(ids); $.post(url, param, function (responseJson) { alertMsg(responseJson.msg); $('.pagination-load').click(); // [control]('reload'); }, "json"); } }) } else { alertMsg('请选择需要删除的数据!'); } } //验证datagrid是否只选择一行数据 $.fn.isSingle = function () { var rows = this.datagrid("getChecked"); if (rows.length != 1) { alertMsg('请选择一行数据!'); return false; } return true; } //提交表单 //formID:提交的表单ID //postUrl:处理方法 //handler:处理完成后执行方法 function submitForm(formID, postUrl, handler, target) { options = { formID: formID, postUrl: postUrl, handler: handler, target: target, isShowMsg: true, isValidate: false }; submitFormJson(options); } function submitFormJson(options) { options = options || {}; options.target = options.target || $(event ? event.srcElement : options.target); var button = options.target.closest('[class*=button]'); var enabled = button.attr('isopera') != 'true'; if (($("#" + options.formID).form('validate') && enabled) || options.isValidate) { button.attr('isopera', true); button.attr('disabled', true); try { $.post(options.postUrl, $("#" + options.formID).getFormData(), function (data) { if (options.isShowMsg) alertMsg(data.msg); //if (data.result) { } if ($.isFunction(options.handler)) options.handler(data); if (typeof (jQuery) != "unknown" && typeof (button.attr('isopera')) != "undefined") { button.attr('isopera', false); button.attr('disabled', false); } }); } catch (e) { $.messager.alert("系统提示", e.toString()); } } } //提交表单 //formID:提交的表单ID //postUrl:处理方法 //handler:处理完成后执行方法 function submitFormNoShow(formID, postUrl, handler, target) { options = { formID: formID, postUrl: postUrl, handler: handler, target: target, isShowMsg: false }; submitFormJson(options); } function isNumber(value) { return (/^[1-9]\d*$/gi).test(value); } function topDialogIframe() { var id = $('div.easyui-topDialog').attr("id"); if (window[id + "_iframe"]) return window[id + "_iframe"]; else return window; } //json转字符串 function json2str(o) { var arr = []; var fmt = function (s) { if (typeof s == 'object' && s != null) return json2str(s); return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s; } for (var i in o) arr.push("'" + i + "':" + fmt(o[i])); return '{' + arr.join(',') + '}'; } //同步-ajax function Invoke(url, param, dataType) { dataType = dataType | "json"; var result; $.ajax({ type: "POST", url: url, async: false, data: param, dataType: "json", success: function (msg) { result = msg; }, error: function (r, s, e) { $.messager.alert("系统提示", s); } }); return result; } //异步-ajax function beginInvoke(url, param, endInvoike) { endInvoike = endInvoike || function () { }; $.ajax({ type: "POST", url: url, async: true, data: param, dataType: "json", beforeSend: function () { var top = ($(window).height() - 26) / 2; var left = ($(window).width() - 26) / 2; var stop = $(document).scrollTop(); var sleft = $(document).scrollLeft(); $('', { id: 'img-loading', css: { width: 26, height: 26, position: 'absolute', background: '#fff', left: left + sleft, top: top + stop }, src: CMS_SystemConfig.VirtualDirectoryPath + '/Content/themes/bootstrap/images/wait.gif' }).appendTo('body').fadeTo('fast', 0.8); return true; }, success: function (datas) { endInvoike(datas); }, error: function (r, s, e) { $.messager.alert("系统提示", s); }, complete: function () { $('body').find('#img-loading').remove(); } }); } //生成GUID function Guid() { var guid = ""; for (var i = 1; i <= 32; i++) { var n = Math.floor(Math.random() * 16.0).toString(16); guid += n; if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) guid += "-"; } return guid; } //把View数据模型没使用到的属性加到form里面 //model:json格式的model //form:加到的容器 function InitPropertyValue(model, form) { for (var property in model) { if (form.find("[name=" + property + "]").length == 0) form.append(""); }; }