index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. $.fn.Tab = function (options) {
  2. var cfg = {
  3. items: [],
  4. width: 500,
  5. height: 500,
  6. tabcontentWidth: 498,
  7. tabWidth: 100,
  8. tabHeight: 32,
  9. tabScroll: true,
  10. tabScrollWidth: 19,
  11. tabClass: 'tab',
  12. tabContentClass: 'tab-div-content',
  13. tabClassOn: 'on',
  14. tabClassOff: 'off',
  15. tabClassClose: 'tab_close',
  16. tabClassInner: 'inner',
  17. tabClassInnerLeft: 'innerLeft',
  18. tabClassInnerMiddle: 'innerMiddle',
  19. tabClassInnerRight: 'innerRight',
  20. tabClassText: 'text',
  21. tabClassScrollLeft: 'scroll-left',
  22. tabClassScrollRight: 'scroll-right',
  23. tabClassDiv: 'tab-div',
  24. addEvent: null,
  25. currentEvent: null
  26. };
  27. //默认显示第一个li
  28. var displayLINum = 0;
  29. $.extend(cfg, options);
  30. //判断是不是有隐藏的tab
  31. var tW = cfg.tabWidth * cfg.items.length;
  32. cfg.tabScroll ? tW -= cfg.tabScrollWidth * 2 : null;
  33. //tabDiv,该div是自动增加的
  34. var tab = $('<div />').attr('id', 'jquery_tab_div').height(cfg.tabHeight).addClass(cfg.tabClass).append('<ul />');
  35. //tab target content
  36. var tabContent = $('<div />').attr('id', 'jquery_tab_div_content').width(cfg.tabcontentWidth).height(cfg.height - cfg.tabHeight).addClass(cfg.tabContentClass);
  37. var ccW = (cfg.items.length * cfg.tabWidth) - cfg.width;
  38. var tabH = '';
  39. //增加一个tab下的li得模板
  40. var tabTemplate = '';
  41. tabTemplate = '<table class="' + cfg.tabClassInner + '" id="{0}" data-value="{3}" border="0" cellpadding="0" cellspacing="0"><tr>' + '<td class="' + cfg.tabClassInnerLeft + '"></td>'
  42. + '<td class="' + cfg.tabClassInnerMiddle + '"><span class="' + cfg.tabClassText + '"><i class="fa {2}"></i>&nbsp;{1}</span></td>' + '<td class="' + cfg.tabClassInnerMiddle + '"><div class="' + cfg.tabClassClose + ' ' + cfg.tabClassClose + '_noselected"></div></td>' + '<td class="' + cfg.tabClassInnerRight + '"></td>'
  43. + '</tr></table>';
  44. var scrollTab = function (o, flag) {
  45. //当前的left
  46. var displayWidth = Number(tab.css('left').replace('px', ''));
  47. !displayWidth ? displayWidth = 0 : null;
  48. //显示第几个LI
  49. var displayNum = 0;
  50. var DW = 0;
  51. var left = 0;
  52. if (flag && displayWidth == 0) {
  53. return;
  54. }
  55. if (flag) {
  56. displayLINum--;
  57. left = displayWidth + tab.find('li').eq(displayLINum).width();
  58. left > 0 ? left = 0 : null;
  59. } else {
  60. var _rigth = $(".tab ul").width() - parseInt(tab.offset().left) * -1 - cfg.tabcontentWidth - 82;
  61. var _step = tab.find('li').eq(displayLINum).width();
  62. if (_rigth > 0) {
  63. if (_rigth < _step) {
  64. _step = _rigth;
  65. }
  66. } else {
  67. return;
  68. }
  69. left = displayWidth - _step;
  70. displayLINum++;
  71. }
  72. if (left == 0) {
  73. tab.animate({ 'left': parseInt(-19) });
  74. } else {
  75. tab.animate({ 'left': parseInt(left) });
  76. }
  77. }
  78. function removeTab(item) {
  79. tab.find("#" + item.id).parents('li').remove();
  80. tabContent.find('#iframe' + item.id).remove();
  81. }
  82. function addTab(item) {
  83. if (item.replace == true) {
  84. removeTab(item);
  85. }
  86. if (tab.find("#" + item.id).length == 0) {
  87. Loading(true);
  88. var innerString = tabTemplate.replace("{0}", item.id).replace("{1}", item.title).replace("{2}", item.icon).replace("{3}", item.dataValue);
  89. var liObj = $('<li class="off"></li>');
  90. liObj.append(innerString).appendTo(tab.find('ul')).find('table td:eq(1)').click(function () {
  91. liObj.Contextmenu();
  92. //判断当前是不是处于激活状态
  93. if (liObj.hasClass(cfg.tabClassOn)) return;
  94. var activeLi = liObj.parent().find('li.' + cfg.tabClassOn);
  95. activeLi.removeClass().addClass(cfg.tabClassOff);
  96. $(this).next().find('div').removeClass().addClass(cfg.tabClassClose);
  97. liObj.removeClass().addClass(cfg.tabClassOn);
  98. tabContent.find('iframe').hide().removeClass(cfg.tabClassOn);
  99. tabContent.find('#iframe' + liObj.find('table').attr('id')).show().addClass(cfg.tabClassOn);
  100. cfg.currentEvent(liObj.find('.inner').attr('data-value'));
  101. })
  102. if (item.url) {
  103. var $iframe = $("<iframe class=\"LRADMS_iframe\" id=\"iframe" + item.id + "\" height=\"100%\" width=\"100%\" src=\"" + item.url + "\" frameBorder=\"0\"></iframe>")
  104. tabContent.append($iframe);
  105. $iframe.load(function () {
  106. window.setTimeout(function () {
  107. Loading(false);
  108. }, 200);
  109. });
  110. }
  111. if (item.closed) {
  112. liObj.find('td:eq(2)').find('div').click(function () {
  113. var li_index = tab.find('li').length;
  114. removeTab(item);
  115. tab.find('li:eq(' + (li_index - 2) + ')').find('table td:eq(1)').trigger("click");
  116. }).hover(function () {
  117. if (liObj.hasClass(cfg.tabClassOn)) return;
  118. $(this).removeClass().addClass(cfg.tabClassClose);
  119. }, function () {
  120. if (liObj.hasClass(cfg.tabClassOn)) return;
  121. $(this).addClass(cfg.tabClassClose + '_noselected');
  122. });
  123. }
  124. else {
  125. liObj.find('td:eq(2)').html('');
  126. }
  127. tab.find('li:eq(' + (tab.find('li').length - 1) + ')').find('table td:eq(1)').trigger("click");
  128. cfg.addEvent(item);
  129. } else {
  130. tab.find('li').removeClass('on').addClass('off');
  131. tab.find("#" + item.id).parent().removeClass('off').addClass('on');
  132. tabContent.find('iframe').hide().removeClass('on');
  133. tabContent.find('#iframe' + item.id).show().addClass('on');
  134. }
  135. }
  136. function newTab(item) {
  137. if ($(".tab ul>li").length >= 10) {
  138. dialogAlert("为保证系统效率,只允许同时运行10个功能窗口,请关闭一些窗口后重试!", 0)
  139. return false;
  140. }
  141. if (item.moduleIdCookie == true) {
  142. top.$.cookie('currentmoduleId', item.id, { path: "/" });
  143. item.dataValue = item.id;
  144. }
  145. else {
  146. item.dataValue = top.$.cookie('currentmoduleId');
  147. }
  148. addTab(item);
  149. var nW = $(".tab ul").width() - 4;
  150. if (nW > cfg.width) {
  151. if (!cfg.tabScroll) {
  152. cfg.tabScroll = true;
  153. scrollLeft = $('<div class="' + cfg.tabClassScrollLeft + '"><i></i></div>').click(function () {
  154. scrollTab(scrollLeft, true);
  155. });
  156. srcollRight = $('<div class="' + cfg.tabClassScrollRight + '"><i></i></div>').click(function () {
  157. scrollTab(srcollRight, false);
  158. });
  159. cW -= cfg.tabScrollWidth * 2;
  160. tabContenter.width(cW);
  161. scrollLeft.insertBefore(tabContenter);
  162. srcollRight.insertBefore(tabContenter);
  163. }
  164. var _left = cfg.width - nW;
  165. tab.animate({ 'left': _left - 43 });
  166. displaylicount = tab.find('li').length;
  167. }
  168. }
  169. $.each(cfg.items, function (i, item) {
  170. addTab(item);
  171. });
  172. var scrollLeft, srcollRight;
  173. if (cfg.tabScroll) {
  174. scrollLeft = $('<div class="' + cfg.tabClassScrollLeft + '"><i></i></div>').click(function () {
  175. scrollTab($(this), true);
  176. });
  177. srcollRight = $('<div class="' + cfg.tabClassScrollRight + '"><i></i></div>').click(function () {
  178. scrollTab($(this), false);
  179. });
  180. cfg.width -= cfg.tabScrollWidth * 2;
  181. }
  182. var container = $('<div />').css({
  183. 'position': 'relative',
  184. 'width': cfg.width,
  185. 'height': cfg.tabHeight
  186. }).append(scrollLeft).append(srcollRight).addClass(cfg.tabClassDiv);
  187. var tabContenter = $('<div />').css({
  188. 'width': cfg.width,
  189. 'height': cfg.tabHeight,
  190. 'float': 'left'
  191. }).append(tab);
  192. var obj = $(this).append(tabH).append(container.append(tabContenter)).append(tabContent);
  193. $(window).resize(function () {
  194. cfg.width = $(window).width() - 100;
  195. cfg.height = $(window).height() - 56;
  196. cfg.tabcontentWidth = $(window).width() - 80;
  197. container.width(cfg.width);
  198. tabContent.width(cfg.tabcontentWidth).height(cfg.height - cfg.tabHeight);
  199. });
  200. //点击第一
  201. tab.find('li:first td:eq(1)').click();
  202. return obj.extend({ 'addTab': addTab, 'newTab': newTab });
  203. };
  204. //初始化导航
  205. var tablist;
  206. loadnav = function () {
  207. var navJson = {};
  208. tablist = $("#tab_list_add").Tab({
  209. items: [
  210. { id: 'desktop', title: '欢迎首页', closed: false, icon: 'fa fa fa-desktop', url: contentPath + '/Home/AdminDefaultDesktop' },
  211. ],
  212. tabScroll: false,
  213. width: $(window).width() - 100,
  214. height: $(window).height() - 56,
  215. tabcontentWidth: $(window).width() - 80,
  216. addEvent: function (item) {
  217. if (item.closed && item.isNoLog != true) {
  218. $.ajax({
  219. url: contentPath + "/Home/VisitModule",
  220. data: { moduleId: item.id, moduleName: item.title, moduleUrl: item.url },
  221. type: "post",
  222. dataType: "text"
  223. });
  224. }
  225. },
  226. currentEvent: function (moduleId) {
  227. top.$.cookie('currentmoduleId', moduleId, { path: "/" });
  228. }
  229. });
  230. //个人中心
  231. $("#UserSetting").click(function () {
  232. tablist.newTab({ id: "UserSetting", title: "个人中心", closed: true, icon: "fa fa fa-user", url: contentPath + "/PersonCenter/Index" });
  233. });
  234. //动态加载导航菜单
  235. var _html = "";
  236. var index = 0;
  237. $.each(authorizeMenuData, function (i) {
  238. var row = authorizeMenuData[i];
  239. if (row.ParentId == '0') {
  240. index++;
  241. _html += '<li class="item">';
  242. _html += ' <a id=' + row.ModuleId + ' href="javascript:void(0);" class="main-nav">';
  243. _html += ' <div class="main-nav-icon"><i class="fa ' + row.Icon + '"></i></div>';
  244. _html += ' <div class="main-nav-text">' + row.FullName + '</div>';
  245. _html += ' <span class="arrow"></span>';
  246. _html += ' </a>';
  247. _html += getsubnav(row.ModuleId);
  248. _html += '</li>';
  249. navJson[row.ModuleId] = row;
  250. }
  251. });
  252. $("#nav").append(_html);
  253. $('#nav li a').click(function () {
  254. var id = $(this).attr('id');
  255. var data = navJson[id];
  256. if (data.Target == "iframe") {
  257. tablist.newTab({
  258. moduleIdCookie: true,
  259. id: id,
  260. title: data.FullName,
  261. closed: true,
  262. icon: data.Icon,
  263. url: contentPath + data.UrlAddress
  264. });
  265. }
  266. });
  267. //一级菜单鼠标hover
  268. $("#nav li.item").hover(function (e) {
  269. var $sub = $(this).find('.sub-nav-wrap');
  270. var length = $sub.find('.sub-nav').find('li').length;
  271. if (length > 0) {
  272. $(this).addClass('on');
  273. $sub.show();
  274. var sub_top = $sub.offset().top + $sub.height();
  275. var body_height = $(window).height();
  276. if (sub_top > body_height) {
  277. $sub.css('bottom', '0px');
  278. }
  279. }
  280. }, function (e) {
  281. $(this).removeClass('on');
  282. $(this).find('.sub-nav-wrap').hide();
  283. });
  284. //二级菜单鼠标hover
  285. $("#nav li.sub").hover(function (e) {
  286. var $ul = $(this).find('.sub-nav');
  287. $ul.show();
  288. var top = $(this).find('ul').offset().top;
  289. var height = $ul.height();
  290. var wheight = $(window).height();
  291. if (top + height > wheight) {
  292. $ul.css('top', parseInt('-' + (height - 180))).css('left', '130px');
  293. } else {
  294. $ul.css('top', '0px').css('left', '130px');
  295. }
  296. }, function (e) {
  297. $(this).find('ul').hide();
  298. $(this).find('ul').css('top', '0px');
  299. });
  300. //三级菜单鼠标hover
  301. $("#nav ul.sub-nav.sub2 li").hover(function (e) {
  302. var $sub = $(this).find('.sub-child ul');
  303. $sub.show();
  304. var top = $(this).find('.sub-child ul').offset().top;
  305. var height = $sub.height();
  306. var wheight = $(window).height();
  307. if (top + height > wheight) {
  308. $sub.css('top', parseInt('-' + (height - 200))).css('left', '130px');
  309. } else {
  310. $sub.css('top', '0px').css('left', '130px');
  311. }
  312. }, function (e) {
  313. $(this).find('.sub-child ul').hide();
  314. $(this).find('.sub-child ul').css('top', '0px');
  315. });
  316. //导航二菜单
  317. function getsubnav(moduleId) {
  318. var _html = '<div class="sub-nav-wrap">';
  319. _html += '<ul class="sub-nav sub1">';
  320. $.each(authorizeMenuData, function (i) {
  321. var row = authorizeMenuData[i];
  322. if (row.ParentId == moduleId) {
  323. if (isbelowmenu(row.ModuleId) == 0) {
  324. _html += '<li><a id=' + row.ModuleId + '><i class="fa ' + row.Icon + '"></i>' + row.FullName + '</a></li>';
  325. } else {
  326. _html += '<li class="sub" title=' + (row.Description == null ? "" : row.Description) + '><a id=' + row.ModuleId + '><i class="fa ' + row.Icon + '"></i>' + row.FullName + '</a>';
  327. _html += getsubchildnav(row.ModuleId);
  328. _html += '</li>'; //sub
  329. }
  330. navJson[row.ModuleId] = row;
  331. }
  332. });
  333. _html += '</ul>';
  334. _html += '</div>';
  335. return _html;
  336. }
  337. //导航三级菜单
  338. function getsubchildnav(moduleId) {
  339. var _html = '';//<div class="sub-nav-wrap">
  340. _html += '<ul class="sub-nav sub2">';
  341. $.each(authorizeMenuData, function (i) {
  342. var row = authorizeMenuData[i];
  343. if (row.ParentId == moduleId) {
  344. if (isbelowmenu(row.ModuleId) == 0) {
  345. _html += '<li><a id=' + row.ModuleId + '><i class="fa ' + row.Icon + '"></i>' + row.FullName + '</a></li>';
  346. } else {
  347. _html += '<li class="sub" title=' + (row.Description == null ? "" : row.Description) + '><a id=' + row.ModuleId + '><i class="fa ' + row.Icon + '"></i>' + row.FullName + '</a>';
  348. _html += getchildnav(row.ModuleId);
  349. _html += '</li>'; //sub
  350. }
  351. navJson[row.ModuleId] = row;
  352. }
  353. });
  354. _html += '</ul>';
  355. //_html += '</div>';
  356. return _html;
  357. }
  358. //导航四级菜单
  359. function getchildnav(moduleId) {
  360. var _html = '<div class="sub-child"><ul>';
  361. $.each(authorizeMenuData, function (i) {
  362. var row = authorizeMenuData[i];
  363. if (row.ParentId == moduleId) {
  364. _html += '<li title=' + (row.Description == null ? "" : row.Description) + '><a id=' + row.ModuleId + '><i class="fa ' + row.Icon + '"></i>' + row.FullName + '</a></li>';
  365. navJson[row.ModuleId] = row;
  366. }
  367. });
  368. _html += '</ul></div>';
  369. return _html;
  370. }
  371. //判断是否有子节点
  372. function isbelowmenu(moduleId) {
  373. var count = 0;
  374. $.each(authorizeMenuData, function (i) {
  375. if (authorizeMenuData[i].ParentId == moduleId) {
  376. count++;
  377. return false;
  378. }
  379. });
  380. return count;
  381. }
  382. }
  383. //安全退出
  384. function IndexOut() {
  385. dialogConfirm("注:您确定要安全退出本次登录吗?", function (r) {
  386. if (r) {
  387. Loading(true, "正在安全退出...");
  388. window.setTimeout(function () {
  389. $.ajax({
  390. url: contentPath + "/Login/OutLogin",
  391. type: "post",
  392. dataType: "json",
  393. success: function (data) {
  394. window.location.href = contentPath + "/Login/Index";
  395. }
  396. });
  397. }, 500);
  398. }
  399. });
  400. }
  401. //移除Tab
  402. $.removeTab = function (type) {
  403. var Id = tabiframeId();
  404. var $tab = $(".tab-div");
  405. var $tabContent = $(".tab-div-content");
  406. switch (type) {
  407. case "reloadCurrent":
  408. $.currentIframe().reload();
  409. break;
  410. case "closeCurrent":
  411. remove(Id);
  412. break;
  413. case "closeAll":
  414. $tab.find("div.tab_close").each(function () {
  415. var id = $(this).parents('.inner').attr('id');
  416. remove(id);
  417. });
  418. break;
  419. case "closeOther":
  420. $tab.find("div.tab_close").each(function () {
  421. var id = $(this).parents('.inner').attr('id');
  422. if (Id != id) {
  423. remove(id);
  424. }
  425. });
  426. break;
  427. default:
  428. break;
  429. }
  430. function remove(id) {
  431. var li_index = $tab.find('li').length;
  432. $tab.find("#" + id).parents('li').remove();
  433. $tabContent.find('#iframe' + id).remove();
  434. $tab.find('li:eq(' + (li_index - 2) + ')').find('table td:eq(1)').trigger("click");
  435. }
  436. }