You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

229 lines
9.2 KiB

  1. /*
  2. * 版 本 Learun-ADMS V7.0.3 力软敏 捷开发框架(http://www.learun.cn)
  3. * Copyright (c) 2013-2018 上海力软信息技术有限公司
  4. * 创建人:力软-前端 开发组
  5. * 日 期:2017.03.16
  6. * 描 述:tab窗口操作方法
  7. */
  8. (function ($, learun) {
  9. "use strict";
  10. //初始化菜单和tab页的属性Id
  11. var iframeIdList = {};
  12. learun.frameTab = {
  13. iframeId: '',
  14. init: function () {
  15. learun.frameTab.bind();
  16. },
  17. bind: function () {
  18. $(".lr-frame-tabs-wrap").lrscroll();
  19. },
  20. setCurrentIframeId: function (iframeId) {
  21. learun.iframeId = iframeId;
  22. },
  23. open: function (module, notAllowClosed) {
  24. var $tabsUl = $('#lr_frame_tabs_ul');
  25. var $frameMain = $('#lr_frame_main');
  26. if (iframeIdList[module.F_ModuleId] == undefined || iframeIdList[module.F_ModuleId] == null) {
  27. // 隐藏之前的tab和窗口
  28. if (learun.frameTab.iframeId != '') {
  29. $tabsUl.find('#lr_tab_' + learun.frameTab.iframeId).removeClass('active');
  30. $frameMain.find('#lr_iframe_' + learun.frameTab.iframeId).removeClass('active');
  31. iframeIdList[learun.frameTab.iframeId] = 0;
  32. }
  33. var parentId = learun.frameTab.iframeId;
  34. learun.frameTab.iframeId = module.F_ModuleId;
  35. iframeIdList[learun.frameTab.iframeId] = 1;
  36. // 打开一个功能模块tab_iframe页面
  37. var $tabItem = $('<li class="lr-frame-tabItem active" id="lr_tab_' + module.F_ModuleId + '" parent-id="' + parentId + '" ><span>' + module.F_FullName + '</span></li>');
  38. // 翻译
  39. learun.language.get(module.F_FullName, function (text) {
  40. $tabItem.find('span').text(text);
  41. if (!notAllowClosed) {
  42. $tabItem.append('<span class="reomve" title="关闭窗口"></span>');
  43. }
  44. });
  45. var $iframe = $('<iframe class="lr-frame-iframe active" id="lr_iframe_' + module.F_ModuleId + '" frameborder="0" src="' + $.rootUrl + module.F_UrlAddress + '"></iframe>');
  46. $tabsUl.append($tabItem);
  47. $frameMain.append($iframe);
  48. var w = 0;
  49. var width = $tabsUl.children().each(function () {
  50. w += $(this).outerWidth();
  51. });
  52. $tabsUl.css({ 'width': w });
  53. $tabsUl.parent().css({ 'width': w });
  54. $(".lr-frame-tabs-wrap").lrscrollSet('moveRight');
  55. //绑定一个点击事件
  56. $tabItem.on('click', function () {
  57. var id = $(this).attr('id').replace('lr_tab_', '');
  58. learun.frameTab.focus(id);
  59. });
  60. $tabItem.find('.reomve').on('click', function () {
  61. var id = $(this).parent().attr('id').replace('lr_tab_', '');
  62. learun.frameTab.close(id);
  63. return false;
  64. });
  65. if (!!learun.frameTab.opencallback) {
  66. learun.frameTab.opencallback();
  67. }
  68. if (!notAllowClosed) {
  69. var loginInfo = learun.clientdata.get(['userinfo']);
  70. var account = '';
  71. if (loginInfo) {
  72. account = loginInfo.account;
  73. }
  74. $.ajax({
  75. url: top.$.rootUrl + "/Home/VisitModule",
  76. headers: { account: account },
  77. data: { moduleName: module.F_FullName, moduleUrl: module.F_UrlAddress },
  78. type: "post",
  79. dataType: "json",
  80. success: function (res) {
  81. if (res.code == learun.httpCode.nologin) {
  82. var _topUrl = top.$.rootUrl + '/Login/Index';
  83. switch (res.info) {
  84. case 'nologin':
  85. break;
  86. case 'noip':
  87. _topUrl += '?error=ip';
  88. break;
  89. case 'notime':
  90. _topUrl += '?error=time';
  91. break;
  92. case 'other':
  93. _topUrl += '?error=other';
  94. break;
  95. }
  96. top.window.location.href = _topUrl;
  97. return;
  98. }
  99. },
  100. error: function (XMLHttpRequest, textStatus, errorThrown) {
  101. top.window.location.href = top.$.rootUrl + '/Login/Index';
  102. },
  103. beforeSend: function () {
  104. },
  105. complete: function () {
  106. }
  107. });
  108. }
  109. }
  110. else {
  111. learun.frameTab.focus(module.F_ModuleId);
  112. }
  113. },
  114. focus: function (moduleId) {
  115. if (iframeIdList[moduleId] == 0) {
  116. // 定位焦点tab页
  117. $('#lr_tab_' + learun.frameTab.iframeId).removeClass('active');
  118. $('#lr_iframe_' + learun.frameTab.iframeId).removeClass('active');
  119. iframeIdList[learun.frameTab.iframeId] = 0;
  120. $('#lr_tab_' + moduleId).addClass('active');
  121. $('#lr_iframe_' + moduleId).addClass('active');
  122. learun.frameTab.iframeId = moduleId;
  123. iframeIdList[moduleId] = 1;
  124. if (!!learun.frameTab.opencallback) {
  125. learun.frameTab.opencallback();
  126. }
  127. }
  128. },
  129. leaveFocus: function () {
  130. $('#lr_tab_' + learun.frameTab.iframeId).removeClass('active');
  131. $('#lr_iframe_' + learun.frameTab.iframeId).removeClass('active');
  132. iframeIdList[learun.frameTab.iframeId] = 0;
  133. learun.frameTab.iframeId = '';
  134. },
  135. close: function (moduleId) {
  136. delete iframeIdList[moduleId];
  137. var $this = $('#lr_tab_' + moduleId);
  138. var $prev = $this.prev();// 获取它的上一个节点数据;
  139. if ($prev.length < 1) {
  140. $prev = $this.next();
  141. }
  142. $this.remove();
  143. $('#lr_iframe_' + moduleId).remove();
  144. if (moduleId == learun.frameTab.iframeId && $prev.length > 0) {
  145. var prevId = $prev.attr('id').replace('lr_tab_', '');
  146. $prev.addClass('active');
  147. $('#lr_iframe_' + prevId).addClass('active');
  148. learun.frameTab.iframeId = prevId;
  149. iframeIdList[prevId] = 1;
  150. }
  151. else {
  152. if ($prev.length < 1) {
  153. learun.frameTab.iframeId = "";
  154. }
  155. }
  156. var $tabsUl = $('#lr_frame_tabs_ul');
  157. var w = 0;
  158. var width = $tabsUl.children().each(function () {
  159. w += $(this).outerWidth();
  160. });
  161. $tabsUl.css({ 'width': w });
  162. $tabsUl.parent().css({ 'width': w });
  163. if (!!learun.frameTab.closecallback) {
  164. learun.frameTab.closecallback();
  165. }
  166. }
  167. // 获取当前窗口
  168. ,currentIframe: function () {
  169. var ifameId = 'lr_iframe_' + learun.frameTab.iframeId;
  170. if (top.frames[ifameId].contentWindow != undefined) {
  171. return top.frames[ifameId].contentWindow;
  172. }
  173. else {
  174. return top.frames[ifameId];
  175. }
  176. }
  177. ,parentIframe: function () {
  178. var ifameId = 'lr_iframe_' + top.$('#lr_tab_'+learun.frameTab.iframeId).attr('parent-id');
  179. if (top.frames[ifameId].contentWindow != undefined) {
  180. return top.frames[ifameId].contentWindow;
  181. }
  182. else {
  183. return top.frames[ifameId];
  184. }
  185. }
  186. , wfFormIframe: function () {
  187. var currentIframe = learun.frameTab.currentIframe();
  188. var iframeId = currentIframe.$('#form_list_iframes .form-list-iframe.active').attr('id');
  189. return learun.iframe(iframeId, currentIframe.frames);
  190. }
  191. , closeByParam: function (name, value) {
  192. $('#lr_frame_tabs_ul li').each(function () {
  193. var id = $(this).attr('id').replace('lr_tab_', '');
  194. var frameObj = top.frames[ 'lr_iframe_' + id];
  195. if (frameObj.contentWindow != undefined) {
  196. frameObj = frameObj.contentWindow;
  197. }
  198. if (frameObj[name] == value) {
  199. learun.frameTab.close(id);
  200. return false;
  201. }
  202. });
  203. }
  204. , opencallback: false
  205. , closecallback: false
  206. };
  207. learun.frameTab.init();
  208. })(window.jQuery, top.learun);