index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. var tab;
  2. $(function () {
  3. // 左侧菜单切换
  4. $('.zhdj_open_close').click(function(){
  5. $(this).find('.left_icon').toggle(0,function(){
  6. if($(this).css('display') == 'none'){
  7. $('.zhdj_menu').animate({
  8. width:'90px'
  9. },500);
  10. $('.zhdj_menu ul li cite').css('display','none');
  11. $('.zhdj_content').animate({
  12. left:'90px'
  13. },500);
  14. }
  15. });
  16. $(this).find('.right_icon').toggle(0,function(){
  17. if($(this).css('display') == 'none'){
  18. $('.zhdj_menu').animate({
  19. width:'200px'
  20. },500);
  21. $('.zhdj_content').animate({
  22. left:'200px'
  23. },500,function(){
  24. $('.zhdj_menu ul li cite').css('display','inline');
  25. });
  26. }
  27. });
  28. });
  29. // header菜单的展开和收缩
  30. function dropdown(boxHeight){
  31. if($('.zhdi_drop_icon').find('.top_btn').css('display') == 'none'){
  32. $('.zhdj_second_menu').animate({
  33. height: '90px'
  34. })
  35. }else{
  36. $('.zhdj_second_menu').animate({
  37. height: boxHeight + 'px'
  38. })
  39. }
  40. }
  41. var boxHeight;
  42. $(window).resize(function(){
  43. boxHeight = $('.zhdj_second_menu ul').height();
  44. if(boxHeight > 90){
  45. dropdown(boxHeight);
  46. }
  47. });
  48. $('.zhdi_drop_icon').click(function(){
  49. boxHeight = $('.zhdj_second_menu ul').height();
  50. $(this).find('.top_btn').toggle();
  51. $(this).find('.bottom_btn').toggle();
  52. if(boxHeight > 90){
  53. dropdown(boxHeight);
  54. }
  55. });
  56. $(document.body).on('click', '.layui-col-md1:not(:first)', function () {
  57. $('.zhdi_drop_icon').find('.top_btn').hide();
  58. $('.zhdi_drop_icon').find('.bottom_btn').show();
  59. $('.zhdj_second_menu').animate({
  60. height: '90px'
  61. });
  62. });
  63. layui.use(['element', 'form', 'layer', 'laytpl'], function () {
  64. var $ = layui.jquery, element = layui.element, form = layui.form, layer = layui.layer, laytpl = layui.laytpl;
  65. var index = 0;
  66. $(document.body).on('click', ".layui-nav-tree li", function (event) {
  67. var url = $(this).children('a').attr('_href');
  68. var title = $(this).find('cite').html();
  69. // var list = $('.x-iframe').get();
  70. // var index = list.length;
  71. // for (var i = 0; i < list.length; i++) {
  72. // var n = list[i];
  73. // let _title = $(n).attr('_title');
  74. // if (_title === title) {
  75. // index = i;
  76. // }
  77. // }
  78. //遍历打开的窗口,如果当前点击的选项已经打开,则跳转到对应窗口去,不再执行for外面的两条语句,创建新窗口
  79. for (var i = 0; i < $('.x-iframe').length; i++) {
  80. console.log($('.x-iframe').eq(i).attr('tab-id'),title);
  81. if ($('.x-iframe').eq(i).attr('tab-id') == title) {
  82. // debugger
  83. tab.tabChange(title);
  84. event.stopPropagation();
  85. return;
  86. }
  87. }
  88. tab.tabAdd(title, url, title);
  89. tab.tabChange(title);
  90. });
  91. //点击新增子页面
  92. tab = {
  93. tabAdd: function (title, url, id) {
  94. element.tabAdd('mainTab', {
  95. title: title,//用于演示
  96. content: '<iframe tab-id="' + id + '" frameborder="0" _title="' + title + '" src="' + url + '" scrolling="no" class="x-iframe"></iframe>',
  97. id: id //实际使用一般是规定好的id,这里以时间戳模拟下
  98. })
  99. },
  100. tabDelete: function (id) {
  101. element.tabDelete('mainTab', id);
  102. othis.addClass('layui-btn-disabled');
  103. },
  104. tabChange: function (id) {
  105. //切换到指定Tab项
  106. element.tabChange('mainTab', id); //切换到:用户管理
  107. var tab = $('.layui-tab-title').children().filter(function () {
  108. return $(this).attr('lay-id') == id
  109. }).get(0)
  110. tab.parentElement.scrollLeft = tab.offsetLeft - (window.document.body.clientWidth /2)
  111. }
  112. };
  113. });
  114. $(document.body).on('click', '.zhdj_second_menu ul li', function () {
  115. $(this).addClass('current').siblings().removeClass('current');
  116. $(this).parent('ul').siblings().find('li').removeClass('current');
  117. });
  118. $(document.body).on('click', '.zhdj_menu ul li', function () {
  119. $(this).addClass('layui-this').siblings().removeClass('layui-this');
  120. $(this).parent('ul').siblings().find('li').removeClass('layui-this');
  121. });
  122. // 默认隐藏左侧菜单
  123. $('.left_icon').hide()
  124. $('.right_icon').show()
  125. $('.zhdj_menu').animate({
  126. width:'90px'
  127. },500);
  128. $('.zhdj_menu ul li cite').css('display','none');
  129. $('.zhdj_content').animate({
  130. left:'90px'
  131. },500);
  132. });
  133. $(function () {
  134. $('#left_button').click(function () {
  135. var tabp = $('.layui-tab-title').get(0);
  136. var left = tabp.scrollLeft - (window.document.body.clientWidth / 3);
  137. if(left<0) left = 0;
  138. tabp.scrollLeft = left;
  139. });
  140. $('#right_button').click(function () {
  141. var tabp = $('.layui-tab-title').get(0);
  142. var left = tabp.scrollLeft + (window.document.body.clientWidth / 3);
  143. // if(left>window.document.body.clientWidth) left = window.document.body.clientWidth;
  144. tabp.scrollLeft = left;
  145. });
  146. });