common.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * 通用方法封装处理
  3. * Copyright (c) 2018 ruoyi
  4. */
  5. /*
  6. 参数解释:
  7. title 标题
  8. url 请求的url
  9. w 弹出层宽度(缺省调默认值)
  10. h 弹出层高度(缺省调默认值)
  11. */
  12. function layer_show(title, url, w, h) {
  13. if (title == null || title == '') {
  14. title = false;
  15. };
  16. if (url == null || url == '') {
  17. url = "404.html";
  18. };
  19. if (w == null || w == '') {
  20. w = 800;
  21. };
  22. if (h == null || h == '') {
  23. h = ($(window).height() - 50);
  24. };
  25. layer.open({
  26. type: 2,
  27. area: [w + 'px', h + 'px'],
  28. fix: false,
  29. //不固定
  30. maxmin: true,
  31. shade: 0.4,
  32. title: title,
  33. content: url
  34. });
  35. }
  36. function layer_showAuto(title, url) {
  37. layer_show(title, url, '', '');
  38. }
  39. /*关闭弹出框口*/
  40. function layer_close() {
  41. var index = parent.layer.getFrameIndex(window.name);
  42. parent.layer.close(index);
  43. }
  44. //状态码
  45. web_status = {
  46. SUCCESS: 0,
  47. FAIL: 500
  48. };
  49. //对ajax的post方法再次封装
  50. _ajax_save = function(url, data) {
  51. var config = {
  52. url: url,
  53. type: "post",
  54. dataType: "json",
  55. data: data,
  56. success: function(result) {
  57. handleSuccess(result);
  58. }
  59. };
  60. $.ajax(config)
  61. };
  62. //对jquery的ajax方法再次封装
  63. _ajax = function(url, data, type) {
  64. var config = {
  65. url: url,
  66. type: type,
  67. dataType: "json",
  68. data: data,
  69. success: function(result) {
  70. simpleSuccess(result);
  71. }
  72. };
  73. $.ajax(config)
  74. };
  75. /** 返回结果处理 */
  76. function simpleSuccess(result) {
  77. if (result.code == web_status.SUCCESS) {
  78. $.modalMsg(result.msg, "success");
  79. $.refreshTable();
  80. } else {
  81. $.modalAlert(result.msg, "error");
  82. }
  83. }
  84. /** 操作结果处理 */
  85. function handleSuccess(result) {
  86. if (result.code == web_status.SUCCESS) {
  87. parent.layer.msg("新增成功,正在刷新数据请稍后……",{icon:1,time: 500,shade: [0.1,'#fff']},function(){
  88. $.parentReload();
  89. });
  90. } else {
  91. $.modalAlert(result.msg, "error");
  92. }
  93. }
  94. /** 时间格式化 */
  95. function formatDate(_date, _pattern) {
  96. var date = new Date(_date);
  97. var newDate = date.format(_pattern);
  98. return newDate;
  99. }
  100. Date.prototype.format = function(format) {
  101. var date = {
  102. "M+" : this.getMonth() + 1,
  103. "d+" : this.getDate(),
  104. "h+" : this.getHours(),
  105. "m+" : this.getMinutes(),
  106. "s+" : this.getSeconds(),
  107. "q+" : Math.floor((this.getMonth() + 3) / 3),
  108. "S+" : this.getMilliseconds()
  109. };
  110. if (/(y+)/i.test(format)) {
  111. format = format.replace(RegExp.$1, (this.getFullYear() + '')
  112. .substr(4 - RegExp.$1.length));
  113. }
  114. for ( var k in date) {
  115. if (new RegExp("(" + k + ")").test(format)) {
  116. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? date[k]
  117. : ("00" + date[k]).substr(("" + date[k]).length));
  118. }
  119. }
  120. return format;
  121. }
  122. // 创建选项卡
  123. function createMenuItem(dataUrl, menuName) {
  124. dataIndex = Math.floor(Math.random()*100),
  125. flag = true;
  126. if (dataUrl == undefined || $.trim(dataUrl).length == 0) return false;
  127. // 选项卡菜单已存在
  128. $('.menuTab', window.parent.document).each(function() {
  129. if ($(this).data('id') == dataUrl) {
  130. if (!$(this).hasClass('active')) {
  131. $(this).addClass('active').siblings('.menuTab').removeClass('active');
  132. scrollToTab(this);
  133. // 显示tab对应的内容区
  134. $('.mainContent .RuoYi_iframe', window.parent.document).each(function() {
  135. if ($(this).data('id') == dataUrl) {
  136. $(this).show().siblings('.RuoYi_iframe').hide();
  137. return false;
  138. }
  139. });
  140. }
  141. flag = false;
  142. return false;
  143. }
  144. });
  145. // 选项卡菜单不存在
  146. if (flag) {
  147. var str = '<a href="javascript:;" class="active menuTab" data-id="' + dataUrl + '">' + menuName + ' <i class="fa fa-times-circle"></i></a>';
  148. $('.menuTab', window.parent.document).removeClass('active');
  149. // 添加选项卡对应的iframe
  150. var str1 = '<iframe class="RuoYi_iframe" name="iframe' + dataIndex + '" width="100%" height="100%" src="' + dataUrl + '" frameborder="0" data-id="' + dataUrl + '" seamless></iframe>';
  151. $('.mainContent', window.parent.document).find('iframe.RuoYi_iframe').hide().parents('.mainContent').append(str1);
  152. // 添加选项卡
  153. $('.menuTabs .page-tabs-content', window.parent.document).append(str);
  154. scrollToTab($('.menuTab.active'));
  155. }
  156. return false;
  157. }