common.js 11 KB

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