NewEMIS.Comm.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. function alertMsg(message) {
  2. window.top.$.messager.alert("系统消息", message, "info");
  3. }
  4. function redirect(url) {
  5. window.location.href = url;
  6. }
  7. function confirmMsg(message, handler) {
  8. window.top.$.messager.confirm("系统提示", message, handler);
  9. }
  10. //删除数据方法
  11. //url:删除方法url
  12. //paramName:删除方法参数名称
  13. //key:主键列
  14. $.fn.deleteRows = function (url, paramName, key) {
  15. this.deleteRows(url, paramName, key, "datagrid");
  16. }
  17. $.fn.deleteRows = function (url, paramName, key, control) {
  18. control = control || "datagrid";
  19. var me = this;
  20. var selrows = me[control]("getChecked")
  21. if (selrows.length > 0) {
  22. confirmMsg("确定删除吗?", function (r) {
  23. var ids = new Array();
  24. $(selrows).each(function (i, row) {
  25. ids.push(row[key]);
  26. })
  27. if (r) {
  28. var param = JSON.parse("{ \"" + paramName + "\":\"\"}");
  29. param[paramName] = JSON.stringify(ids);
  30. $.post(url, param, function (responseJson) {
  31. alertMsg(responseJson.msg);
  32. $('.pagination-load').click(); // [control]('reload');
  33. }, "json");
  34. }
  35. })
  36. } else {
  37. alertMsg('请选择需要删除的数据!');
  38. }
  39. }
  40. //验证datagrid是否只选择一行数据
  41. $.fn.isSingle = function () {
  42. var rows = this.datagrid("getChecked");
  43. if (rows.length != 1) {
  44. alertMsg('请选择一行数据!');
  45. return false;
  46. }
  47. return true;
  48. }
  49. function isNumber(value) {
  50. return (/^[1-9]\d*$/gi).test(value);
  51. }
  52. function topDialogIframe() {
  53. var id = $('div.easyui-topDialog').attr("id");
  54. if (window[id + "_iframe"]) return window[id + "_iframe"];
  55. else return window;
  56. }
  57. //json转字符串
  58. function json2str(o) {
  59. var arr = [];
  60. var fmt = function (s) {
  61. if (typeof s == 'object' && s != null) return json2str(s);
  62. return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
  63. }
  64. for (var i in o) arr.push("'" + i + "':" + fmt(o[i]));
  65. return '{' + arr.join(',') + '}';
  66. }
  67. //同步-ajax
  68. function Invoke(url, param, dataType) {
  69. dataType = dataType | "json";
  70. var result;
  71. $.ajax({
  72. type: "POST",
  73. url: url,
  74. async: false,
  75. data: param,
  76. dataType: "json",
  77. success: function (msg) {
  78. result = msg;
  79. },
  80. error: function (r, s, e) {
  81. $.messager.alert("系统提示", s);
  82. }
  83. });
  84. return result;
  85. }
  86. //异步-ajax
  87. function beginInvoke(url, param, endInvoike) {
  88. endInvoike = endInvoike || function () { };
  89. $.ajax({
  90. type: "POST",
  91. url: url,
  92. async: true,
  93. data: param,
  94. dataType: "json",
  95. beforeSend: function () {
  96. var top = ($(window).height() - 26) / 2;
  97. var left = ($(window).width() - 26) / 2;
  98. var stop = $(document).scrollTop();
  99. var sleft = $(document).scrollLeft();
  100. $('<img></img>', {
  101. id: 'img-loading',
  102. css: {
  103. width: 26,
  104. height: 26,
  105. position: 'absolute',
  106. background: '#fff',
  107. left: left + sleft,
  108. top: top + stop
  109. },
  110. src: CMS_SystemConfig.VirtualDirectoryPath + '/Content/themes/bootstrap/images/wait.gif'
  111. }).appendTo('body').fadeTo('fast', 0.8);
  112. return true;
  113. },
  114. success: function (datas) {
  115. endInvoike(datas);
  116. },
  117. error: function (r, s, e) {
  118. $.messager.alert("系统提示", s);
  119. },
  120. complete: function () {
  121. $('body').find('#img-loading').remove();
  122. }
  123. });
  124. }
  125. //生成GUID
  126. function Guid() {
  127. var guid = "";
  128. for (var i = 1; i <= 32; i++) {
  129. var n = Math.floor(Math.random() * 16.0).toString(16);
  130. guid += n;
  131. if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
  132. guid += "-";
  133. }
  134. return guid;
  135. }