index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. var tablist = {
  2. newTab: function (item) {
  3. var dataId = item.id;
  4. var dataUrl = item.url;
  5. var menuName = '<i class="' + item.icon + '"></i>' + item.title;
  6. var flag = true;
  7. if (dataUrl == undefined || $.trim(dataUrl).length == 0) {
  8. return false;
  9. }
  10. $('.menuTab').each(function () {
  11. if ($(this).data('id') == dataUrl) {
  12. if (!$(this).hasClass('active')) {
  13. $(this).addClass('active').siblings('.menuTab').removeClass('active');
  14. $.learuntab.scrollToTab(this);
  15. $('#mainContent .LRADMS_iframe').each(function () {
  16. if ($(this).data('id') == dataUrl) {
  17. $(this).show().siblings('.LRADMS_iframe').hide();
  18. return false;
  19. }
  20. });
  21. }
  22. flag = false;
  23. return false;
  24. }
  25. });
  26. if (flag) {
  27. var str = '<a href="javascript:;" class="active menuTab" data-id="' + dataUrl + '">' + menuName + ' <div class="tab_close "></div></a>';
  28. $('.menuTab').removeClass('active');
  29. var str1 = '<iframe class="LRADMS_iframe" id="iframe' + dataId + '" name="iframe' + dataId + '" width="100%" height="100%" src="' + dataUrl + '" frameborder="0" data-id="' + dataUrl + '" seamless></iframe>';
  30. $('#mainContent').find('iframe.LRADMS_iframe').hide();
  31. $('#mainContent').append(str1);
  32. Loading(true);
  33. $('#mainContent iframe:visible').load(function () {
  34. Loading(false);
  35. });
  36. $('.menuTabs .page-tabs-content').append(str);
  37. $.learuntab.scrollToTab($('.menuTab.active'));
  38. }
  39. }
  40. };
  41. (function ($) {
  42. "use strict";
  43. $.learuntab = {
  44. requestFullScreen: function () {
  45. var de = document.documentElement;
  46. if (de.requestFullscreen) {
  47. de.requestFullscreen();
  48. } else if (de.mozRequestFullScreen) {
  49. de.mozRequestFullScreen();
  50. } else if (de.webkitRequestFullScreen) {
  51. de.webkitRequestFullScreen();
  52. }
  53. },
  54. exitFullscreen: function () {
  55. var de = document;
  56. if (de.exitFullscreen) {
  57. de.exitFullscreen();
  58. } else if (de.mozCancelFullScreen) {
  59. de.mozCancelFullScreen();
  60. } else if (de.webkitCancelFullScreen) {
  61. de.webkitCancelFullScreen();
  62. }
  63. },
  64. refreshTab: function () {
  65. var currentId = $('.page-tabs-content').find('.active').attr('data-id');
  66. var target = $('.LRADMS_iframe[data-id="' + currentId + '"]');
  67. var url = target.attr('src');
  68. Loading(true);
  69. target.attr('src', url).load(function () {
  70. Loading(false);
  71. });
  72. },
  73. activeTab: function () {
  74. var currentId = $(this).data('id');
  75. if (!$(this).hasClass('active')) {
  76. $('#mainContent .LRADMS_iframe').each(function () {
  77. if ($(this).data('id') == currentId) {
  78. $(this).show().siblings('.LRADMS_iframe').hide();
  79. return false;
  80. }
  81. });
  82. $(this).addClass('active').siblings('.menuTab').removeClass('active');
  83. $.learuntab.scrollToTab(this);
  84. }
  85. var dataId = $(this).attr('data-value');
  86. if (dataId != "") {
  87. top.$.cookie('currentmoduleId', dataId, { path: "/" });
  88. }
  89. },
  90. closeOtherTabs: function () {
  91. $('.page-tabs-content').children("[data-id]").find('.tab_close').parents('a').not(".active").each(function () {
  92. $('.LRADMS_iframe[data-id="' + $(this).data('id') + '"]').remove();
  93. $(this).remove();
  94. });
  95. $('.page-tabs-content').css("margin-left", "0");
  96. },
  97. closeTab: function () {
  98. var closeTabId = $(this).parents('.menuTab').data('id');
  99. var currentWidth = $(this).parents('.menuTab').width();
  100. if ($(this).parents('.menuTab').hasClass('active')) {
  101. if ($(this).parents('.menuTab').next('.menuTab').size()) {
  102. var activeId = $(this).parents('.menuTab').next('.menuTab:eq(0)').data('id');
  103. $(this).parents('.menuTab').next('.menuTab:eq(0)').addClass('active');
  104. $('#mainContent .LRADMS_iframe').each(function () {
  105. if ($(this).data('id') == activeId) {
  106. $(this).show().siblings('.LRADMS_iframe').hide();
  107. return false;
  108. }
  109. });
  110. var marginLeftVal = parseInt($('.page-tabs-content').css('margin-left'));
  111. if (marginLeftVal < 0) {
  112. $('.page-tabs-content').animate({
  113. marginLeft: (marginLeftVal + currentWidth) + 'px'
  114. }, "fast");
  115. }
  116. $(this).parents('.menuTab').remove();
  117. $('#mainContent .LRADMS_iframe').each(function () {
  118. if ($(this).data('id') == closeTabId) {
  119. $(this).remove();
  120. return false;
  121. }
  122. });
  123. }
  124. if ($(this).parents('.menuTab').prev('.menuTab').size()) {
  125. var activeId = $(this).parents('.menuTab').prev('.menuTab:last').data('id');
  126. $(this).parents('.menuTab').prev('.menuTab:last').addClass('active');
  127. $('#mainContent .LRADMS_iframe').each(function () {
  128. if ($(this).data('id') == activeId) {
  129. $(this).show().siblings('.LRADMS_iframe').hide();
  130. return false;
  131. }
  132. });
  133. $(this).parents('.menuTab').remove();
  134. $('#mainContent .LRADMS_iframe').each(function () {
  135. if ($(this).data('id') == closeTabId) {
  136. $(this).remove();
  137. return false;
  138. }
  139. });
  140. }
  141. }
  142. else {
  143. $(this).parents('.menuTab').remove();
  144. $('#mainContent .LRADMS_iframe').each(function () {
  145. if ($(this).data('id') == closeTabId) {
  146. $(this).remove();
  147. return false;
  148. }
  149. });
  150. $.learuntab.scrollToTab($('.menuTab.active'));
  151. }
  152. var dataId = $('.menuTab.active').attr('data-value');
  153. if (dataId != "") {
  154. top.$.cookie('currentmoduleId', dataId, { path: "/" });
  155. }
  156. return false;
  157. },
  158. addTab: function () {
  159. var dataId = $(this).attr('data-id');
  160. if (dataId != "") {
  161. top.$.cookie('currentmoduleId', dataId, { path: "/" });
  162. }
  163. var dataUrl = $(this).attr('href');
  164. var menuName = $.trim($(this).html());
  165. if (dataUrl == undefined || $.trim(dataUrl).length == 0) {
  166. return false;
  167. }
  168. var flag = true;
  169. $('.menuTab').each(function () {
  170. if ($(this).data('id') == dataUrl) {
  171. if (!$(this).hasClass('active')) {
  172. $(this).addClass('active').siblings('.menuTab').removeClass('active');
  173. $.learuntab.scrollToTab(this);
  174. $('#mainContent .LRADMS_iframe').each(function () {
  175. if ($(this).data('id') == dataUrl) {
  176. $(this).show().siblings('.LRADMS_iframe').hide();
  177. return false;
  178. }
  179. });
  180. }
  181. flag = false;
  182. return false;
  183. }
  184. });
  185. if (flag) {
  186. var str = '<a href="javascript:;" class="active menuTab" data-value=' + dataId + ' data-id="' + dataUrl + '">' + menuName + '<div class="tab_close "></div></a>';
  187. $('.menuTab').removeClass('active');
  188. var str1 = '<iframe class="LRADMS_iframe" id="iframe' + dataId + '" name="iframe' + dataId + '" width="100%" height="100%" src="' + dataUrl + '" frameborder="0" data-id="' + dataUrl + '" seamless></iframe>';
  189. $('#mainContent').find('iframe.LRADMS_iframe').hide();
  190. $('#mainContent').append(str1);
  191. Loading(true);
  192. $('#mainContent iframe:visible').load(function () {
  193. Loading(false);
  194. });
  195. $('.menuTabs .page-tabs-content').append(str);
  196. $.learuntab.scrollToTab($('.menuTab.active'));
  197. }
  198. $(this).parents('.popover-moreMenu').hide();
  199. $(this).parents('.popover-menu').hide();
  200. $(this).parents('.popover-menu-sub').hide();
  201. return false;
  202. },
  203. scrollTabRight: function () {
  204. var marginLeftVal = Math.abs(parseInt($('.page-tabs-content').css('margin-left')));
  205. var tabOuterWidth = $.learuntab.calSumWidth($(".lea-tabs").children().not(".menuTabs"));
  206. var visibleWidth = $(".lea-tabs").outerWidth(true) - tabOuterWidth;
  207. var scrollVal = 0;
  208. if ($(".page-tabs-content").width() < visibleWidth) {
  209. return false;
  210. } else {
  211. var tabElement = $(".menuTab:first");
  212. var offsetVal = 0;
  213. while ((offsetVal + $(tabElement).outerWidth(true)) <= marginLeftVal) {
  214. offsetVal += $(tabElement).outerWidth(true);
  215. tabElement = $(tabElement).next();
  216. }
  217. offsetVal = 0;
  218. while ((offsetVal + $(tabElement).outerWidth(true)) < (visibleWidth) && tabElement.length > 0) {
  219. offsetVal += $(tabElement).outerWidth(true);
  220. tabElement = $(tabElement).next();
  221. }
  222. scrollVal = $.learuntab.calSumWidth($(tabElement).prevAll());
  223. if (scrollVal > 0) {
  224. $('.page-tabs-content').animate({
  225. marginLeft: 0 - scrollVal + 'px'
  226. }, "fast");
  227. }
  228. }
  229. },
  230. scrollTabLeft: function () {
  231. var marginLeftVal = Math.abs(parseInt($('.page-tabs-content').css('margin-left')));
  232. var tabOuterWidth = $.learuntab.calSumWidth($(".lea-tabs").children().not(".menuTabs"));
  233. var visibleWidth = $(".lea-tabs").outerWidth(true) - tabOuterWidth;
  234. var scrollVal = 0;
  235. if ($(".page-tabs-content").width() < visibleWidth) {
  236. return false;
  237. } else {
  238. var tabElement = $(".menuTab:first");
  239. var offsetVal = 0;
  240. while ((offsetVal + $(tabElement).outerWidth(true)) <= marginLeftVal) {
  241. offsetVal += $(tabElement).outerWidth(true);
  242. tabElement = $(tabElement).next();
  243. }
  244. offsetVal = 0;
  245. if ($.learuntab.calSumWidth($(tabElement).prevAll()) > visibleWidth) {
  246. while ((offsetVal + $(tabElement).outerWidth(true)) < (visibleWidth) && tabElement.length > 0) {
  247. offsetVal += $(tabElement).outerWidth(true);
  248. tabElement = $(tabElement).prev();
  249. }
  250. scrollVal = $.learuntab.calSumWidth($(tabElement).prevAll());
  251. }
  252. }
  253. $('.page-tabs-content').animate({
  254. marginLeft: 0 - scrollVal + 'px'
  255. }, "fast");
  256. },
  257. scrollToTab: function (element) {
  258. var marginLeftVal = $.learuntab.calSumWidth($(element).prevAll()), marginRightVal = $.learuntab.calSumWidth($(element).nextAll());
  259. var tabOuterWidth = $.learuntab.calSumWidth($(".lea-tabs").children().not(".menuTabs"));
  260. var visibleWidth = $(".lea-tabs").outerWidth(true) - tabOuterWidth;
  261. var scrollVal = 0;
  262. if ($(".page-tabs-content").outerWidth() < visibleWidth) {
  263. scrollVal = 0;
  264. } else if (marginRightVal <= (visibleWidth - $(element).outerWidth(true) - $(element).next().outerWidth(true))) {
  265. if ((visibleWidth - $(element).next().outerWidth(true)) > marginRightVal) {
  266. scrollVal = marginLeftVal;
  267. var tabElement = element;
  268. while ((scrollVal - $(tabElement).outerWidth()) > ($(".page-tabs-content").outerWidth() - visibleWidth)) {
  269. scrollVal -= $(tabElement).prev().outerWidth();
  270. tabElement = $(tabElement).prev();
  271. }
  272. }
  273. } else if (marginLeftVal > (visibleWidth - $(element).outerWidth(true) - $(element).prev().outerWidth(true))) {
  274. scrollVal = marginLeftVal - $(element).prev().outerWidth(true);
  275. }
  276. $('.page-tabs-content').animate({
  277. marginLeft: 0 - scrollVal + 'px'
  278. }, "fast");
  279. },
  280. calSumWidth: function (element) {
  281. var width = 0;
  282. $(element).each(function () {
  283. width += $(this).outerWidth(true);
  284. });
  285. return width;
  286. },
  287. init: function () {
  288. $('.menuTabs').on('click', '.menuTab .tab_close', $.learuntab.closeTab);
  289. $('.menuTabs').on('click', '.menuTab', $.learuntab.activeTab);
  290. $('.tabLeft').on('click', $.learuntab.scrollTabLeft);
  291. $('.tabRight').on('click', $.learuntab.scrollTabRight);
  292. $('.tabReload').on('click', $.learuntab.refreshTab);
  293. $('.tabCloseCurrent').on('click', function () {
  294. $('.page-tabs-content').find('.active .tab_close').trigger("click");
  295. });
  296. $('.tabCloseAll').on('click', function () {
  297. $('.page-tabs-content').children("[data-id]").find('.tab_close').each(function () {
  298. $(this).parents('a').remove();
  299. });
  300. $('.page-tabs-content').children("[data-id]:first").each(function () {
  301. $('.LRADMS_iframe[data-id="' + $(this).data('id') + '"]').show();
  302. $(this).addClass("active");
  303. });
  304. $('.page-tabs-content').css("margin-left", "0");
  305. });
  306. $('.tabCloseOther').on('click', $.learuntab.closeOtherTabs);
  307. $('.fullscreen').on('click', function () {
  308. if (!$(this).attr('fullscreen')) {
  309. $(this).attr('fullscreen', 'true');
  310. $.learuntab.requestFullScreen();
  311. } else {
  312. $(this).removeAttr('fullscreen');
  313. $.learuntab.exitFullscreen();
  314. }
  315. });
  316. }
  317. };
  318. $.learunindex = {
  319. load: function () {
  320. $("#mainContent").height($(window).height() - 128);
  321. $(window).resize(function (e) {
  322. $("#mainContent").height($(window).height() - 128);
  323. $.learunindex.loadMenu(true);
  324. });
  325. //个人中心
  326. $("#UserSetting").click(function () {
  327. tablist.newTab({ id: "UserSetting", title: "个人中心", closed: true, icon: "fa fa fa-user", url: contentPath + "/PersonCenter/Index" });
  328. });
  329. $(window).load(function () {
  330. window.setTimeout(function () {
  331. $('#ajax-loader').fadeOut();
  332. Loading(false);
  333. }, 300);
  334. });
  335. },
  336. jsonWhere: function (data, action) {
  337. if (action == null) return;
  338. var reval = new Array();
  339. $(data).each(function (i, v) {
  340. if (action(v)) {
  341. reval.push(v);
  342. }
  343. })
  344. return reval;
  345. },
  346. loadMenu: function (isInit) {
  347. var flag = false;
  348. var topMenuWidth = $('.lea-Head').width() - $.learuntab.calSumWidth($(".lea-Head").children().not(".left-bar"));
  349. var data = authorizeMenuData;
  350. var _html = "";
  351. var menuWidth = 0;
  352. var _html1 = "", _html2 = "";
  353. $.each(data, function (i) {
  354. var row = data[i];
  355. if (row.ParentId == "0") {
  356. var _itemHtml = "";
  357. _itemHtml += '<li class="treeview">';
  358. _itemHtml += '<a>';
  359. _itemHtml += '<i class="' + row.Icon + '"></i><span>' + row.FullName + '</span>';
  360. _itemHtml += '</a>';
  361. var childNodes = $.learunindex.jsonWhere(data, function (v) { return v.ParentId == row.ModuleId });
  362. if (childNodes.length > 0) {
  363. _itemHtml += '<div class="popover-menu"><div class="arrow"><em></em><span></span></div><ul class="treeview-menu">';
  364. $.each(childNodes, function (i) {
  365. var subrow = childNodes[i];
  366. var subchildNodes = $.learunindex.jsonWhere(data, function (v) { return v.ParentId == subrow.ModuleId });
  367. _itemHtml += '<li>';
  368. if (subchildNodes.length > 0) {
  369. _itemHtml += '<a class="menuTreeItem menuItem" href="#"><i class="' + subrow.Icon + ' firstIcon"></i>' + subrow.FullName + '';
  370. _itemHtml += '<i class="fa fa-angle-right pull-right"></i></a>';
  371. _itemHtml += '<div class="popover-menu-sub"><ul class="treeview-menu">';
  372. $.each(subchildNodes, function (i) {
  373. var subchildNodesrow = subchildNodes[i];
  374. _itemHtml += '<li><a class="menuItem menuiframe" data-id="' + subchildNodesrow.ModuleId + '" href="' + subchildNodesrow.UrlAddress + '"><i class="' + subchildNodesrow.Icon + ' firstIcon"></i>' + subchildNodesrow.FullName + '</a></li>';
  375. });
  376. _itemHtml += '</ul></div>';
  377. } else {
  378. _itemHtml += '<a class="menuItem menuiframe" data-id="' + subrow.ModuleId + '" href="' + subrow.UrlAddress + '"><i class="' + subrow.Icon + ' firstIcon"></i>' + subrow.FullName + '</a>';
  379. }
  380. _itemHtml += '</li>';
  381. });
  382. _itemHtml += '</ul></div>';
  383. }
  384. _itemHtml += '</li>';
  385. menuWidth += 88;
  386. if (menuWidth > topMenuWidth) {
  387. _html2 += _itemHtml;
  388. }
  389. else if ((menuWidth + 88) > topMenuWidth) {
  390. _html1 = _itemHtml;
  391. }
  392. else {
  393. _html += _itemHtml;
  394. }
  395. }
  396. });
  397. if (menuWidth > topMenuWidth) {
  398. _html2 = _html1 + _html2;
  399. _html += ' <li class="treeview" id="moreMenu"><a ><i class="fa fa-reorder"></i><span>更多应用</span></a></li>';
  400. flag = true;
  401. }
  402. else {
  403. _html += _html1;
  404. }
  405. if (isInit || flag) {
  406. $("#top-menu").html(_html);
  407. if (flag) {
  408. $('#moreMenu').append('<div class="popover-moreMenu"><div class="arrow"><em></em><span></span></div><div class="title">更多应用</div><div class="moresubmenu"></div></div>');
  409. $('.moresubmenu').html(_html2);
  410. //更多应用菜单点击事件
  411. $('.moresubmenu > .treeview > a').unbind();
  412. $('.moresubmenu > .treeview > a').on('click', function () {
  413. $('.moresubmenu > .treeview > a.active').parent().find('.popover-menu').hide();
  414. $('.moresubmenu > .treeview > a.active').removeClass('active');
  415. var $li = $(this);
  416. $li.addClass('active');
  417. $li.parent().find('.popover-menu').show();
  418. });
  419. }
  420. $("#top-menu>.treeview").unbind();
  421. $('.popover-menu>ul>li').unbind();
  422. $("#top-menu>.treeview").hover(
  423. function () {
  424. var $li = $(this);
  425. var $moreMenuPopover = $li.find('.popover-moreMenu');
  426. $li.addClass('active');
  427. if ($moreMenuPopover.length > 0) {
  428. $moreMenuPopover.slideDown(150);
  429. $($moreMenuPopover.find('.treeview>a')[0]).trigger('click');
  430. }
  431. else {
  432. var $popover = $li.find('.popover-menu');
  433. $popover.slideDown(150);
  434. }
  435. },
  436. function () {
  437. var $li = $(this);
  438. var $popover = $li.find('.popover-menu');
  439. var $moreMenuPopover = $li.find('.popover-moreMenu');
  440. if ($moreMenuPopover.length == 0) {
  441. $popover.slideUp(50);
  442. }
  443. else {
  444. $moreMenuPopover.hide();
  445. }
  446. $li.removeClass('active');
  447. });
  448. $('.popover-menu>ul>li').hover(
  449. function () {
  450. var $li = $(this);
  451. if ($li.parents('.moresubmenu').length == 0) {
  452. var windowWidth = $(window).width();
  453. var windowHeight = $(window).height();
  454. var $popover = $li.find('.popover-menu-sub');
  455. var subHeight = $popover.height();
  456. if ((windowWidth - $li.offset().left - 154) < 152) {
  457. $popover.css("left", "-156px");
  458. }
  459. if ((subHeight - 10 + $li.offset().top) > windowHeight) {
  460. var marginTop = subHeight - 10 + $li.offset().top - windowHeight + 46;
  461. $popover.css('margin-top', '-' + marginTop + 'px');
  462. }
  463. $li.addClass('active');
  464. $popover.slideDown(150);
  465. }
  466. },
  467. function () {
  468. var $li = $(this);
  469. if ($li.parents('.moresubmenu').length == 0) {
  470. var $popover = $li.find('.popover-menu-sub');
  471. $li.removeClass('active');
  472. $popover.css('margin-top', '-46px');
  473. $popover.slideUp(50);
  474. }
  475. });
  476. $('.menuiframe').unbind();
  477. $('.menuiframe').on('click', $.learuntab.addTab);
  478. $('.moresubmenu .menuTreeItem ').unbind();
  479. $('.menuTreeItem ').on('click', function () {
  480. $('.moresubmenu .popover-menu-sub').slideUp(300);
  481. var $this = $(this);
  482. if (!$this.hasClass('active')) {
  483. var $sub = $(this).parent().find('.popover-menu-sub');
  484. $this.addClass('active');
  485. $sub.slideDown(300);
  486. }
  487. else {
  488. $this.removeClass('active');
  489. }
  490. });
  491. }
  492. },
  493. indexOut: function () {
  494. dialogConfirm("注:您确定要安全退出本次登录吗?", function (r) {
  495. if (r) {
  496. Loading(true, "正在安全退出...");
  497. window.setTimeout(function () {
  498. $.ajax({
  499. url: contentPath + "/Login/OutLogin",
  500. type: "post",
  501. dataType: "json",
  502. success: function (data) {
  503. window.location.href = contentPath + "/Login/Index";
  504. }
  505. });
  506. }, 500);
  507. }
  508. });
  509. }
  510. };
  511. $(function () {
  512. $.learunindex.loadMenu(true);
  513. $.learuntab.init();
  514. $.learunindex.load();
  515. });
  516. })(jQuery);
  517. //安全退出
  518. function IndexOut() {
  519. dialogConfirm("注:您确定要安全退出本次登录吗?", function (r) {
  520. if (r) {
  521. Loading(true, "正在安全退出...");
  522. window.setTimeout(function () {
  523. $.ajax({
  524. url: contentPath + "/Login/OutLogin",
  525. type: "post",
  526. dataType: "json",
  527. success: function (data) {
  528. window.location.href = contentPath + "/Login/Index";
  529. }
  530. });
  531. }, 500);
  532. }
  533. });
  534. }