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.
 
 
 
 
 
 

244 lines
10 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. if (module.F_UrlAddress != null && module.F_UrlAddress != "" && module.F_UrlAddress != undefined) {
  28. // 隐藏之前的tab和窗口
  29. if (learun.frameTab.iframeId != '') {
  30. $tabsUl.find('#lr_tab_' + learun.frameTab.iframeId).removeClass('active');
  31. $frameMain.find('#lr_iframe_' + learun.frameTab.iframeId).removeClass('active');
  32. iframeIdList[learun.frameTab.iframeId] = 0;
  33. }
  34. var parentId = learun.frameTab.iframeId;
  35. learun.frameTab.iframeId = module.F_ModuleId;
  36. iframeIdList[learun.frameTab.iframeId] = 1;
  37. // 打开一个功能模块tab_iframe页面
  38. var $tabItem = $('<li class="lr-frame-tabItem active" id="lr_tab_' +
  39. module.F_ModuleId +
  40. '" parent-id="' +
  41. parentId +
  42. '" ><span>' +
  43. module.F_FullName +
  44. '</span></li>');
  45. // 翻译
  46. learun.language.get(module.F_FullName,
  47. function (text) {
  48. $tabItem.find('span').text(text);
  49. if (!notAllowClosed) {
  50. $tabItem.append('<span class="reomve" title="关闭窗口"></span>');
  51. }
  52. });
  53. var $iframe = $('<iframe class="lr-frame-iframe active" id="lr_iframe_' +
  54. module.F_ModuleId +
  55. '" frameborder="0" src="' +
  56. $.rootUrl +
  57. module.F_UrlAddress +
  58. '"></iframe>');
  59. $tabsUl.append($tabItem);
  60. $frameMain.append($iframe);
  61. var w = 0;
  62. var width = $tabsUl.children().each(function () {
  63. w += $(this).outerWidth();
  64. });
  65. $tabsUl.css({ 'width': w });
  66. $tabsUl.parent().css({ 'width': w });
  67. $(".lr-frame-tabs-wrap").lrscrollSet('moveRight');
  68. //绑定一个点击事件
  69. $tabItem.on('click',
  70. function () {
  71. var id = $(this).attr('id').replace('lr_tab_', '');
  72. learun.frameTab.focus(id);
  73. });
  74. $tabItem.find('.reomve').on('click',
  75. function () {
  76. var id = $(this).parent().attr('id').replace('lr_tab_', '');
  77. learun.frameTab.close(id);
  78. return false;
  79. });
  80. if (!!learun.frameTab.opencallback) {
  81. learun.frameTab.opencallback();
  82. }
  83. if (!notAllowClosed) {
  84. var loginInfo = learun.clientdata.get(['userinfo']);
  85. var account = '';
  86. if (loginInfo) {
  87. account = loginInfo.account;
  88. }
  89. $.ajax({
  90. url: top.$.rootUrl + "/Home/VisitModule",
  91. headers: { account: account },
  92. data: { moduleName: module.F_FullName, moduleUrl: module.F_UrlAddress },
  93. type: "post",
  94. dataType: "json",
  95. success: function (res) {
  96. if (res.code == learun.httpCode.nologin) {
  97. var _topUrl = top.$.rootUrl + '/Login/Index';
  98. switch (res.info) {
  99. case 'nologin':
  100. break;
  101. case 'noip':
  102. _topUrl += '?error=ip';
  103. break;
  104. case 'notime':
  105. _topUrl += '?error=time';
  106. break;
  107. case 'other':
  108. _topUrl += '?error=other';
  109. break;
  110. }
  111. top.window.location.href = _topUrl;
  112. return;
  113. }
  114. },
  115. error: function (XMLHttpRequest, textStatus, errorThrown) {
  116. top.window.location.href = top.$.rootUrl + '/Login/Index';
  117. },
  118. beforeSend: function () {
  119. },
  120. complete: function () {
  121. }
  122. });
  123. }
  124. }
  125. }
  126. else {
  127. learun.frameTab.focus(module.F_ModuleId);
  128. }
  129. },
  130. focus: function (moduleId) {
  131. if (iframeIdList[moduleId] == 0) {
  132. // 定位焦点tab页
  133. $('#lr_tab_' + learun.frameTab.iframeId).removeClass('active');
  134. $('#lr_iframe_' + learun.frameTab.iframeId).removeClass('active');
  135. iframeIdList[learun.frameTab.iframeId] = 0;
  136. $('#lr_tab_' + moduleId).addClass('active');
  137. $('#lr_iframe_' + moduleId).addClass('active');
  138. learun.frameTab.iframeId = moduleId;
  139. iframeIdList[moduleId] = 1;
  140. if (!!learun.frameTab.opencallback) {
  141. learun.frameTab.opencallback();
  142. }
  143. }
  144. },
  145. leaveFocus: function () {
  146. $('#lr_tab_' + learun.frameTab.iframeId).removeClass('active');
  147. $('#lr_iframe_' + learun.frameTab.iframeId).removeClass('active');
  148. iframeIdList[learun.frameTab.iframeId] = 0;
  149. learun.frameTab.iframeId = '';
  150. },
  151. close: function (moduleId) {
  152. delete iframeIdList[moduleId];
  153. var $this = $('#lr_tab_' + moduleId);
  154. var $prev = $this.prev();// 获取它的上一个节点数据;
  155. if ($prev.length < 1) {
  156. $prev = $this.next();
  157. }
  158. $this.remove();
  159. $('#lr_iframe_' + moduleId).remove();
  160. if (moduleId == learun.frameTab.iframeId && $prev.length > 0) {
  161. var prevId = $prev.attr('id').replace('lr_tab_', '');
  162. $prev.addClass('active');
  163. $('#lr_iframe_' + prevId).addClass('active');
  164. learun.frameTab.iframeId = prevId;
  165. iframeIdList[prevId] = 1;
  166. }
  167. else {
  168. if ($prev.length < 1) {
  169. learun.frameTab.iframeId = "";
  170. }
  171. }
  172. var $tabsUl = $('#lr_frame_tabs_ul');
  173. var w = 0;
  174. var width = $tabsUl.children().each(function () {
  175. w += $(this).outerWidth();
  176. });
  177. $tabsUl.css({ 'width': w });
  178. $tabsUl.parent().css({ 'width': w });
  179. if (!!learun.frameTab.closecallback) {
  180. learun.frameTab.closecallback();
  181. }
  182. }
  183. // 获取当前窗口
  184. , currentIframe: function () {
  185. var ifameId = 'lr_iframe_' + learun.frameTab.iframeId;
  186. if (top.frames[ifameId].contentWindow != undefined) {
  187. return top.frames[ifameId].contentWindow;
  188. }
  189. else {
  190. return top.frames[ifameId];
  191. }
  192. }
  193. , parentIframe: function () {
  194. var ifameId = 'lr_iframe_' + top.$('#lr_tab_' + learun.frameTab.iframeId).attr('parent-id');
  195. if (top.frames[ifameId].contentWindow != undefined) {
  196. return top.frames[ifameId].contentWindow;
  197. }
  198. else {
  199. return top.frames[ifameId];
  200. }
  201. }
  202. , wfFormIframe: function () {
  203. var currentIframe = learun.frameTab.currentIframe();
  204. var iframeId = currentIframe.$('#form_list_iframes .form-list-iframe.active').attr('id');
  205. return learun.iframe(iframeId, currentIframe.frames);
  206. }
  207. , closeByParam: function (name, value) {
  208. $('#lr_frame_tabs_ul li').each(function () {
  209. var id = $(this).attr('id').replace('lr_tab_', '');
  210. var frameObj = top.frames['lr_iframe_' + id];
  211. if (frameObj.contentWindow != undefined) {
  212. frameObj = frameObj.contentWindow;
  213. }
  214. if (frameObj[name] == value) {
  215. learun.frameTab.close(id);
  216. return false;
  217. }
  218. });
  219. }
  220. , opencallback: false
  221. , closecallback: false
  222. };
  223. learun.frameTab.init();
  224. })(window.jQuery, top.learun);