common.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /**
  2. * 通用方法封装处理
  3. * Copyright (c) 2019 ruoyi
  4. */
  5. $(function() {
  6. // select2复选框事件绑定
  7. if ($.fn.select2 !== undefined) {
  8. $("select.form-control:not(.noselect2)").each(function () {
  9. $(this).select2().on("change", function () {
  10. $(this).valid();
  11. })
  12. })
  13. }
  14. // checkbox 事件绑定
  15. if ($(".check-box").length > 0) {
  16. $(".check-box").iCheck({
  17. checkboxClass: 'icheckbox-blue',
  18. radioClass: 'iradio-blue',
  19. })
  20. }
  21. // radio 事件绑定
  22. if ($(".radio-box").length > 0) {
  23. $(".radio-box").iCheck({
  24. checkboxClass: 'icheckbox-blue',
  25. radioClass: 'iradio-blue',
  26. })
  27. }
  28. // laydate 时间控件绑定
  29. if ($(".select-time").length > 0) {
  30. layui.use('laydate', function() {
  31. var laydate = layui.laydate;
  32. var startDate = laydate.render({
  33. elem: '#startTime',
  34. max: $('#endTime').val(),
  35. theme: 'molv',
  36. trigger: 'click',
  37. done: function(value, date) {
  38. // 结束时间大于开始时间
  39. if (value !== '') {
  40. endDate.config.min.year = date.year;
  41. endDate.config.min.month = date.month - 1;
  42. endDate.config.min.date = date.date;
  43. } else {
  44. endDate.config.min.year = '';
  45. endDate.config.min.month = '';
  46. endDate.config.min.date = '';
  47. }
  48. }
  49. });
  50. var endDate = laydate.render({
  51. elem: '#endTime',
  52. min: $('#startTime').val(),
  53. theme: 'molv',
  54. trigger: 'click',
  55. done: function(value, date) {
  56. // 开始时间小于结束时间
  57. if (value !== '') {
  58. startDate.config.max.year = date.year;
  59. startDate.config.max.month = date.month - 1;
  60. startDate.config.max.date = date.date;
  61. } else {
  62. startDate.config.max.year = '';
  63. startDate.config.max.month = '';
  64. startDate.config.max.date = '';
  65. }
  66. }
  67. });
  68. });
  69. }
  70. // laydate time-input 时间控件绑定
  71. if ($(".time-input").length > 0) {
  72. layui.use('laydate', function () {
  73. var com = layui.laydate;
  74. $(".time-input").each(function (index, item) {
  75. var time = $(item);
  76. // 控制控件外观
  77. var type = time.attr("data-type") || 'date';
  78. // 控制回显格式
  79. var format = time.attr("data-format") || 'yyyy-MM-dd';
  80. // 控制日期控件按钮
  81. var buttons = time.attr("data-btn") || 'clear|now|confirm', newBtnArr = [];
  82. // 日期控件选择完成后回调处理
  83. var callback = time.attr("data-callback") || {};
  84. if (buttons) {
  85. if (buttons.indexOf("|") > 0) {
  86. var btnArr = buttons.split("|"), btnLen = btnArr.length;
  87. for (var j = 0; j < btnLen; j++) {
  88. if ("clear" === btnArr[j] || "now" === btnArr[j] || "confirm" === btnArr[j]) {
  89. newBtnArr.push(btnArr[j]);
  90. }
  91. }
  92. } else {
  93. if ("clear" === buttons || "now" === buttons || "confirm" === buttons) {
  94. newBtnArr.push(buttons);
  95. }
  96. }
  97. } else {
  98. newBtnArr = ['clear', 'now', 'confirm'];
  99. }
  100. com.render({
  101. elem: item,
  102. theme: 'molv',
  103. trigger: 'click',
  104. type: type,
  105. format: format,
  106. btns: newBtnArr,
  107. done: function (value, data) {
  108. if (typeof window[callback] != 'undefined'
  109. && window[callback] instanceof Function) {
  110. window[callback](value, data);
  111. }
  112. }
  113. });
  114. });
  115. });
  116. }
  117. // tree 关键字搜索绑定
  118. if ($("#keyword").length > 0) {
  119. $("#keyword").bind("focus", function focusKey(e) {
  120. if ($("#keyword").hasClass("empty")) {
  121. $("#keyword").removeClass("empty");
  122. }
  123. }).bind("blur", function blurKey(e) {
  124. if ($("#keyword").val() === "") {
  125. $("#keyword").addClass("empty");
  126. }
  127. $.tree.searchNode(e);
  128. }).bind("input propertychange", $.tree.searchNode);
  129. }
  130. // tree表格树 展开/折叠
  131. var expandFlag;
  132. $("#expandAllBtn").click(function() {
  133. var dataExpand = $.common.isEmpty($.table._option.expandAll) ? true : $.table._option.expandAll;
  134. expandFlag = $.common.isEmpty(expandFlag) ? dataExpand : expandFlag;
  135. if (!expandFlag) {
  136. $('#' + $.table._option.id).bootstrapTreeTable('expandAll');
  137. } else {
  138. $('#' + $.table._option.id).bootstrapTreeTable('collapseAll');
  139. }
  140. expandFlag = expandFlag ? false: true;
  141. })
  142. // 按下ESC按钮关闭弹层
  143. $('body', document).on('keyup', function(e) {
  144. if (e.which === 27) {
  145. $.modal.closeAll();
  146. }
  147. });
  148. });
  149. /** 刷新选项卡 */
  150. var refreshItem = function(){
  151. var topWindow = $(window.parent.document);
  152. var currentId = $('.page-tabs-content', topWindow).find('.active').attr('data-id');
  153. var target = $('.RuoYi_iframe[data-id="' + currentId + '"]', topWindow);
  154. var url = target.attr('src');
  155. target.attr('src', url).ready();
  156. }
  157. /** 关闭选项卡 */
  158. var closeItem = function(){
  159. var topWindow = $(window.parent.document);
  160. var panelUrl = window.frameElement.getAttribute('data-panel');
  161. $('.page-tabs-content .active i', topWindow).click();
  162. if($.common.isNotEmpty(panelUrl)){
  163. $('.menuTab[data-id="' + panelUrl + '"]', topWindow).addClass('active').siblings('.menuTab').removeClass('active');
  164. $('.mainContent .RuoYi_iframe', topWindow).each(function() {
  165. if ($(this).data('id') == panelUrl) {
  166. $(this).show().siblings('.RuoYi_iframe').hide();
  167. return false;
  168. }
  169. });
  170. }
  171. }
  172. /** 创建选项卡 */
  173. function createMenuItem(dataUrl, menuName) {
  174. var panelUrl = window.frameElement.getAttribute('data-id');
  175. dataIndex = $.common.random(1,100),
  176. flag = true;
  177. if (dataUrl == undefined || $.trim(dataUrl).length == 0) return false;
  178. var topWindow = $(window.parent.document);
  179. // 选项卡菜单已存在
  180. $('.menuTab', topWindow).each(function() {
  181. if ($(this).data('id') == dataUrl) {
  182. if (!$(this).hasClass('active')) {
  183. $(this).addClass('active').siblings('.menuTab').removeClass('active');
  184. $('.page-tabs-content').animate({ marginLeft: ""}, "fast");
  185. // 显示tab对应的内容区
  186. $('.mainContent .RuoYi_iframe', topWindow).each(function() {
  187. if ($(this).data('id') == dataUrl) {
  188. $(this).show().siblings('.RuoYi_iframe').hide();
  189. return false;
  190. }
  191. });
  192. }
  193. flag = false;
  194. return false;
  195. }
  196. });
  197. // 选项卡菜单不存在
  198. if (flag) {
  199. var str = '<a href="javascript:;" class="active menuTab" data-id="' + dataUrl + '" data-panel="' + panelUrl + '">' + menuName + ' <i class="fa fa-times-circle"></i></a>';
  200. $('.menuTab', topWindow).removeClass('active');
  201. // 添加选项卡对应的iframe
  202. var str1 = '<iframe class="RuoYi_iframe" name="iframe' + dataIndex + '" width="100%" height="100%" src="' + dataUrl + '" frameborder="0" data-id="' + dataUrl + '" data-panel="' + panelUrl + '" seamless></iframe>';
  203. $('.mainContent', topWindow).find('iframe.RuoYi_iframe').hide().parents('.mainContent').append(str1);
  204. window.parent.$.modal.loading("数据加载中,请稍后...");
  205. $('.mainContent iframe:visible', topWindow).load(function () {
  206. window.parent.$.modal.closeLoading();
  207. });
  208. // 添加选项卡
  209. $('.menuTabs .page-tabs-content', topWindow).append(str);
  210. }
  211. return false;
  212. }
  213. //日志打印封装处理
  214. var log = {
  215. log: function (msg) {
  216. console.log(msg);
  217. },
  218. info: function(msg) {
  219. console.info(msg);
  220. },
  221. warn: function(msg) {
  222. console.warn(msg);
  223. },
  224. error: function(msg) {
  225. console.error(msg);
  226. }
  227. };
  228. /** 设置全局ajax处理 */
  229. $.ajaxSetup({
  230. complete: function(XMLHttpRequest, textStatus) {
  231. if (textStatus == 'timeout') {
  232. $.modal.alertWarning("服务器超时,请稍后再试!");
  233. $.modal.closeLoading();
  234. } else if (textStatus == "parsererror") {
  235. $.modal.alertWarning("服务器错误,请联系管理员!");
  236. $.modal.closeLoading();
  237. }
  238. }
  239. });
  240. layer.config({
  241. extend: 'moon/style.css',
  242. skin: 'layer-ext-moon'
  243. });