adminindex.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. var $taskContentInner = null;
  2. var $mainIframe = null;
  3. var tabwidth = 118;
  4. var $loading = null;
  5. var $navWraper = $("#nav-wrapper");
  6. var $content;
  7. var topMenuWidth = [];
  8. var headerHeight = 80;
  9. var openMenuHeight = 43;
  10. $(function () {
  11. // 各模块高度计算
  12. $mainIframe = $("#mainiframe");
  13. $content = $("#content");
  14. $loading = $("#loading");
  15. $content.height($(window).height() - headerHeight);
  16. $navWraper.height($(window).height() - headerHeight);
  17. $('.nav-list').css({"max-height": $(window).height() - headerHeight - 70, overflowY: 'auto'});
  18. $(window).resize(function () {
  19. $navWraper.height($(window).height() - headerHeight);
  20. var h = 0;
  21. if ($('.admin-tab:visible').length) {
  22. h = openMenuHeight;
  23. }
  24. $content.height($(window).height() - headerHeight - h);
  25. $('.nav-list').css({"max-height": $(window).height() - headerHeight - 70, overflowY: 'auto'});
  26. });
  27. // iframe 加载状态改变
  28. $("#content iframe").load(function () {
  29. $loading.hide();
  30. });
  31. // 多页面标签控制
  32. $taskContentInner = $(".admin-tab_inner");
  33. /*$(".admin-tab_inner").on("click", "li", function () {
  34. openapp($(this).attr("app-url"), $(this).attr("app-id"), $(this).attr("app-name"));
  35. return false;
  36. });
  37. $(".admin-tab_inner").on("dblclick", "li", function () {
  38. closeapp($(this));
  39. return false;
  40. });
  41. $(".admin-tab_inner").on("click", ".admin-tab_close", function () {
  42. closeapp($(this).parents('li'));
  43. return false;
  44. });
  45. $(".admin-tab_next").click(function () {
  46. var marginLeft = $taskContentInner.css("margin-left");
  47. marginLeft = marginLeft.replace("px", "");
  48. var contentInner = $(".admin-tab_inner").width();
  49. var contentWidth = $(".admin-tab").width();
  50. if (contentInner < contentWidth) {
  51. return false;
  52. }
  53. var lessWidth = contentWidth - contentInner;
  54. marginLeft = marginLeft - tabwidth <= lessWidth ? lessWidth : marginLeft - tabwidth;
  55. $taskContentInner.stop();
  56. $taskContentInner.animate({"margin-left": marginLeft + "px"}, 300, 'swing');
  57. });
  58. $(".admin-tab_prev").click(function () {
  59. var marginLeft = $taskContentInner.css("margin-left");
  60. marginLeft = parseInt(marginLeft.replace("px", ""));
  61. marginLeft = marginLeft + tabwidth > 0 ? 0 : marginLeft + tabwidth;
  62. // $taskContentInner.css("margin-left", marginLeft + "px");
  63. $taskContentInner.stop();
  64. $taskContentInner.animate({"margin-left": marginLeft + "px"}, 300, 'swing');
  65. });
  66. $('.admin-tab_inner>li:eq(1)').dblclick();
  67. // 空间计算
  68. $('.navbar-topnav li').each(function (index, item) {
  69. topMenuWidth[index] = $(this).width();
  70. });
  71. handleTopSpace();
  72. // 绑定事件
  73. $(window).resize(function () {
  74. handleTopSpace();
  75. });*/
  76. // 当前页面刷新
  77. $("#refresh-wrapper").click(function () {
  78. var $currentIframe = $("#content iframe:visible");
  79. $loading.show();
  80. //$currentIframe.attr("src",$currentIframe.attr("src"));
  81. $currentIframe[0].contentWindow.location.reload();
  82. return false;
  83. });
  84. // 首页隐藏左侧子菜单
  85. $('#sidebar').hide();
  86. // 初始切换到第一个一级目录
  87. /* switchMenu($('.navbar-topnav > li:eq(0)').attr('id'));*/
  88. //向左收缩事件
  89. // $('.navbar-toggle').click(function () {
  90. $('.sidebar_back').click(function () {
  91. if ($('#sidebar').hasClass('menu-min')) {
  92. $('.navbar-brand').animate({width: 200}, 0);
  93. $('#sidebar').animate({width: 200}, 0, function () {
  94. // $('#sidebar').removeClass('menu-min').find('.submenu .submenu').show();
  95. $('#sidebar').removeClass('menu-min');
  96. $('.sidebar_back').removeClass('menu-min');
  97. });
  98. } else {
  99. $('.navbar-brand').animate({width: 90}, 0);
  100. $('#sidebar').animate({width: 90}, 0, function () {
  101. // $('#sidebar').addClass('menu-min').find('.submenu .submenu').hide();
  102. $('#sidebar').addClass('menu-min');
  103. $('.sidebar_back').addClass('menu-min');
  104. });
  105. }
  106. });
  107. $('#sidebar').on('mouseenter', '.submenu li', function () {
  108. if ($(this).parents('.menu-min').length) {
  109. // $(this).find('.submenu').show();
  110. }
  111. });
  112. $('#sidebar').on('mouseleave', '.submenu li', function () {
  113. if ($(this).parents('.menu-min').length) {
  114. $(this).find('.submenu').hide();
  115. }
  116. });
  117. // 二级菜单点击事件
  118. $('.nav-list').on('click', '.outter>li', function () {
  119. if ($(this).attr('propagation') === 'stop') {
  120. $(this).removeAttr('propagation');
  121. return false;
  122. };
  123. $(this).find('ul').slideToggle(300, function () {
  124. $(this).toggleClass('open').find('>ul').removeAttr('style');
  125. }.bind(this));
  126. if (!$(this).hasClass('active')) {
  127. var $openLi = $(this).siblings('li.open:not(.active)');
  128. $openLi.find('ul').slideToggle(300, function () {
  129. $openLi.toggleClass('open').find('>ul').removeAttr('style');
  130. }.bind(this));
  131. }
  132. });
  133. // 位置栏切换事件
  134. $('.info_list').on('click', '.info_cnt', function () {
  135. var $id = $(this).attr('data-id');
  136. var $menu1st = $('li[data-menuid="' + $id + '"]');
  137. var $menu2nd = $('li[data-appid="' + $id + '"]');
  138. if ($(this).index() == 0) {
  139. $('[propagation="stop"]').removeAttr('propagation');
  140. $menu1st.find('>.submenu>li.active').attr('propagation', 'stop');
  141. switchMenu($id);
  142. } else if ($(this).index() == 1) {
  143. $('[propagation="stop"]').removeAttr('propagation');
  144. $menu2nd.attr('propagation', 'stop').find('.submenu>li:eq(0)>a').click();
  145. }
  146. });
  147. });
  148. function closeapp($this) {
  149. if (!$this.is(".noclose")) {
  150. if ($this.is('.active')) {
  151. $this.prev().click();
  152. }
  153. $this.remove();
  154. var appId = $this.attr("app-id");
  155. $("#appiframe-" + appId).remove();
  156. $('.nav-list li[data-appid="' + appId + '"]').removeClass('active');
  157. $(".admin-tab_prev").click();
  158. }
  159. }
  160. var task_item_tpl = '<li class="admin-tab_item">' +
  161. ' <a class="admin-tab_text">' +
  162. ' <i class="admin-tab_txt"></i>' +
  163. ' <i class="admin-tab_close fa fa-remove"></i>' +
  164. ' </a>' +
  165. '</li>';
  166. var appiframe_tpl = '<iframe style="width: 100%; height: 100%;" frameborder="0" class="appiframe"></iframe>';
  167. function openapp(url, appId, appname, refresh) {
  168. // 阻止冒泡
  169. var event = window.event || arguments.callee.caller.arguments[0];
  170. if (event) {
  171. event.stopPropagation();
  172. }
  173. // 调整 iframe 高度
  174. $content.height($(window).height() - headerHeight - openMenuHeight);
  175. // 通过 appId 寻找对应的三级菜单
  176. var $menu3rd = $('.nav-list').find('li[data-appid="' + appId + '"]');
  177. var $menu2nd = $menu3rd.parents('li:eq(0)');
  178. $('[propagation="stop"]').removeAttr('propagation');
  179. $menu2nd.attr('propagation', 'stop');
  180. if ($menu3rd.length === 0) {
  181. $menu3rd = $('.nav-list').find('.submenu .submenu .menu-text:contains(' + appname + ')').parent();
  182. $menu2nd = $menu3rd.parents('li:eq(1)');
  183. var menuid = $menu3rd.parents('li[data-menuid]').attr('data-menuid');
  184. switchMenu(menuid, false);
  185. $('[propagation="stop"]').removeAttr('propagation');
  186. $menu2nd.attr('propagation', 'stop');
  187. setTimeout(function () {
  188. $menu3rd.click();
  189. }, 0);
  190. }
  191. if (!$menu2nd.hasClass('active')) {
  192. $menu2nd.addClass('active open').siblings().removeClass('open');
  193. }
  194. //位置栏内容
  195. var menus = [];
  196. menus[0] = $('.navbar-topnav li.active .menu-text');
  197. menus[1] = $menu3rd.parents('li:eq(0)').find('> a > .menu-text');
  198. menus[2] = $menu3rd.find('> a > .menu-text', this);
  199. var remark = menus[2].attr('remark');
  200. $('.info_list').html('');
  201. $('.game-intro b').text(menus[2].text());
  202. $('.game-intro p').text(remark);
  203. for (var i = 0; i < menus.length; i++) {
  204. var parentNode = menus[i].parents('li:eq(0)');
  205. $('.info_list').append('<span class="info_cnt" data-id="' + (parentNode.attr('id') || parentNode.attr('data-appid')) + '">'+menus[i].text()+'</span>');
  206. }
  207. var $app = $(".admin-tab_inner li[app-id='" + appId + "']");
  208. $(".admin-tab_inner .active").removeClass("active");
  209. $('.nav-list .active').removeClass('active');
  210. $('.nav-list li[data-appid="' + appId + '"]').addClass('active').parents('li:eq(0)').addClass('active');
  211. $('#contextmenu').hide();
  212. if ($app.length == 0) {
  213. var task = $(task_item_tpl).attr({"app-id": appId, "app-url": url, "app-name": appname}).addClass("active");
  214. // var icon = $('[data-appid="' + appId + '"]').find('.fa').clone();
  215. // task.find('.admin-tab_text').prepend(icon);
  216. task.find(".admin-tab_txt").html(appname).attr("title", appname);
  217. $taskContentInner.append(task);
  218. $(".appiframe").hide();
  219. $loading.show();
  220. $appiframe = $(appiframe_tpl).attr("src", url).attr("id", "appiframe-" + appId);
  221. $appiframe.appendTo("#content");
  222. $appiframe.load(function () {
  223. var srcLoaded = $appiframe.get(0).contentWindow.location.href;
  224. if (srcLoaded.indexOf('admin/public/login') >= 0) {
  225. window.location.reload(true);
  226. }
  227. $loading.hide();
  228. });
  229. task.contextmenu(function (event) {
  230. event.preventDefault();
  231. var $contextmenu = $('#contextmenu');
  232. if ($contextmenu.length > 0) {
  233. $('#contextmenu').attr('curId', appId).css({'display': 'block', 'left': event.pageX, 'top': event.pageY});
  234. return false;
  235. }
  236. $('body').append('<div id="contextmenu" class="contextmenu"></div>');
  237. $('#contextmenu').attr('curId', appId).css({'left': event.pageX, 'top': event.pageY}).append('<a id="closeCurrent" href="javascript:;">关闭当前</a><a id="closeOther" href="javascript:;">关闭其他</a><a id="closeAll" href="javascript:;">关闭全部</a>');
  238. // 关闭当前
  239. $('#closeCurrent').click(function () {
  240. $('.admin-tab_inner li[app-id="' + $('#contextmenu').attr('curId') + '"]').dblclick();
  241. });
  242. // 关闭其他
  243. $('#closeOther').click(function () {
  244. $('.admin-tab_inner li').not(function (index) {
  245. return $(this).is('.noclose') || $(this).attr('app-id') === $('#contextmenu').attr('curId');
  246. }).dblclick();
  247. });
  248. // 关闭全部
  249. $('#closeAll').click(function () {
  250. $('.admin-tab_inner li:not(".noclose")').dblclick();
  251. });
  252. $(document).click(function () {
  253. $('#contextmenu').hide();
  254. });
  255. });
  256. } else {
  257. $app.addClass("active");
  258. $(".appiframe").hide();
  259. var $iframe = $("#appiframe-" + appId);
  260. var src = $iframe.get(0).contentWindow.location.href;
  261. src = src.substr(src.indexOf("://") + 3);
  262. if (refresh === true) {//刷新
  263. $loading.show();
  264. $iframe.attr("src", url);
  265. $iframe.load(function () {
  266. var srcLoaded = $iframe.get(0).contentWindow.location.href;
  267. if (srcLoaded.indexOf('admin/public/login') >= 0) {
  268. window.location.reload(true);
  269. }
  270. $loading.hide();
  271. });
  272. }
  273. $iframe.show();
  274. }
  275. var taskContentInner = $(".admin-tab_inner").width();
  276. var contentWidth = $(".admin-tab").width();
  277. if (taskContentInner <= contentWidth) { //如果没有开始滚动就不用进行下去了
  278. return;
  279. }
  280. var currentTabIndex = $(".admin-tab_inner li[app-id='" + appId + "']").index();
  281. var itemOffset = 0;
  282. var currentTabWidth = $(".admin-tab_inner li[app-id='" + appId + "']").width();
  283. $(".admin-tab_inner li:lt(" + currentTabIndex + ')').each(function () {
  284. itemOffset = itemOffset + $(this).width();
  285. });
  286. var cssMarginLeft = $taskContentInner.css("margin-left");
  287. cssMarginLeft = parseInt(cssMarginLeft.replace("px", ""));
  288. var marginLeft = currentTabWidth + itemOffset - contentWidth + cssMarginLeft;
  289. if (marginLeft > 0) {
  290. marginLeft = -(currentTabWidth + itemOffset - contentWidth);
  291. $taskContentInner.animate({"margin-left": marginLeft + "px"}, 300, 'swing');
  292. return;
  293. }
  294. if (itemOffset + cssMarginLeft < 0) {
  295. marginLeft = -itemOffset
  296. $taskContentInner.animate({"margin-left": marginLeft + "px"}, 300, 'swing');
  297. return;
  298. }
  299. }
  300. /**
  301. * 一级菜单切换
  302. */
  303. function switchMenu (id, subOpen) {
  304. subOpen = subOpen === undefined ? true : subOpen;
  305. // 一级菜单
  306. $('#'+id).addClass('active').siblings().removeClass('active');
  307. // 二级菜单
  308. var $subMenu = $('.nav-list li[data-menuid="' + id + '"]');
  309. $subMenu.show().siblings().hide().find('.open').removeClass('open');
  310. // $('.toggle-topnav li').removeClass('active');
  311. // $('#'+id+'-2').addClass('active');
  312. // 三级菜单
  313. if (subOpen) {
  314. $subMenu.find('>.submenu .submenu>li:eq(0)>a').click().parent().addClass('active');
  315. }
  316. /*if(!$('.nav-list li[data-menuid="' + id + '"]'+">.submenu .submenu").length){
  317. // $('.nav-list li[data-menuid="' + id + '"]'+">.submenu li:eq(0)>a").click();
  318. }*/
  319. // 左侧栏显示
  320. $('#sidebar').show();
  321. // 多页面标签 && 面包屑
  322. $('.admin-tab').show();
  323. }
  324. function openFrame (ppid, id, url) {
  325. var $parent = $('[id^="' + ppid + '"')
  326. $parent.find('> a').click()
  327. var _t = window.setInterval(function () {
  328. var $self = $('[data-appid^="' + id + '"')
  329. if ($self.length) {
  330. window.clearInterval(_t)
  331. $self.find('> a').click()
  332. }
  333. }, 60)
  334. }
  335. /**
  336. * 一级菜单空间控制
  337. */
  338. function handleTopSpace () {
  339. var topToggle = '<li class="topnav-toggle dropdown"><a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"><span class="icon-point"></span><span class="icon-point"></span><span class="icon-point"></span></a><ul class="toggle-topnav dropdown-menu pull-right"></ul></li>';
  340. if (!$('.topnav-toggle').length) {
  341. // 在一级菜单最后追加显示被隐藏菜单的入口
  342. $('.navbar-topnav').append(topToggle);
  343. }
  344. /*
  345. for (var i = 0, j = 0; i < topMenuWidth.length; i++) {
  346. j += topMenuWidth[i];
  347. var item = $('.navbar-topnav li').eq(i);
  348. if (winWidth - 500 > j) {
  349. if (item.is(':hidden')) {
  350. $('.toggle-topnav li[index="' + i + '"]').remove();
  351. item.show();
  352. }
  353. } else {
  354. if (item.is(':visible')) {
  355. $('.toggle-topnav').prepend(item.clone(true).show().attr({'index': i, 'id': item.attr('id') + '-2'}));
  356. item.hide();
  357. }
  358. }
  359. }
  360. */
  361. if (!$('.toggle-topnav li').length) {
  362. $('.topnav-toggle').remove();
  363. }
  364. }
  365. $('.tips').hover(function() {
  366. var offset = $(this).offset();
  367. $('.game-intro').show().css({
  368. left: offset.left + 20,
  369. top: offset.top
  370. });
  371. },function(){
  372. $('.game-intro').hide();
  373. });