index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. $(function () {
  2. // 左侧菜单切换
  3. $('.zhdj_open_close').click(function () {
  4. $(this).find('.left_icon').toggle(0, function () {
  5. if ($(this).css('display') == 'none') {
  6. $('.zhdj_menu').animate({
  7. width: '90px'
  8. }, 500);
  9. $('.zhdj_menu ul li cite').css('display', 'none');
  10. $('.zhdj_content').animate({
  11. left: '90px'
  12. }, 500);
  13. }
  14. });
  15. $(this).find('.right_icon').toggle(0, function () {
  16. if ($(this).css('display') == 'none') {
  17. $('.zhdj_menu').animate({
  18. width: '200px'
  19. }, 500);
  20. $('.zhdj_content').animate({
  21. left: '200px'
  22. }, 500, function () {
  23. $('.zhdj_menu ul li cite').css('display', 'inline');
  24. });
  25. }
  26. });
  27. });
  28. // header菜单的展开和收缩
  29. function dropdown(boxHeight) {
  30. if ($('.zhdi_drop_icon').find('.top_btn').css('display') == 'none') {
  31. $('.zhdj_second_menu').animate({
  32. height: '90px'
  33. })
  34. } else {
  35. $('.zhdj_second_menu').animate({
  36. height: boxHeight + 'px'
  37. })
  38. }
  39. }
  40. var boxHeight;
  41. $(window).resize(function () {
  42. boxHeight = $('.zhdj_second_menu ul').height();
  43. if (boxHeight > 90) {
  44. dropdown(boxHeight);
  45. }
  46. });
  47. $('.zhdi_drop_icon').click(function () {
  48. boxHeight = $('.zhdj_second_menu ul').height();
  49. $(this).find('.top_btn').toggle();
  50. $(this).find('.bottom_btn').toggle();
  51. if (boxHeight > 90) {
  52. dropdown(boxHeight);
  53. }
  54. });
  55. $(document.body).on('click', '.layui-col-md1:not(:first)', function () {
  56. $('.zhdi_drop_icon').find('.top_btn').hide();
  57. $('.zhdi_drop_icon').find('.bottom_btn').show();
  58. $('.zhdj_second_menu').animate({
  59. height: '90px'
  60. });
  61. });
  62. layui.use(['element', 'form', 'layer', 'laytpl'], function () {
  63. var $ = layui.jquery, element = layui.element, form = layui.form, layer = layui.layer, laytpl = layui.laytpl;
  64. var index = 0;
  65. $(document.body).on('click', ".layui-nav-tree li", function (event) {
  66. var url = $(this).children('a').attr('_href');
  67. var title = $(this).find('cite').html();
  68. // var list = $('.x-iframe').get();
  69. // index =list.length;
  70. // for (var i = 0; i < list.length; i++) {
  71. // var n = list[i];
  72. // let _title = $(n).attr('_title');
  73. // if (_title === title) {
  74. // index = i;
  75. // }
  76. // }
  77. if (title == '统计分析') {
  78. $('iframe[tab-id="' + title + '"]').attr('src', url);
  79. }
  80. // var index = $('.layui-nav-tree li').index($(this));
  81. //遍历打开的窗口,如果当前点击的选项已经打开,则跳转到对应窗口去,不再执行for外面的两条语句,创建新窗口
  82. for (var i = 0; i < $('.x-iframe').length; i++) {
  83. console.log($('.x-iframe').eq(i).attr('tab-id'), title);
  84. if ($('.x-iframe').eq(i).attr('tab-id') == title) {
  85. // debugger
  86. tab.tabChange(title);
  87. event.stopPropagation();
  88. return;
  89. }
  90. }
  91. tab.tabAdd(title, url, title);
  92. tab.tabChange(title);
  93. });
  94. //点击新增子页面
  95. var tab = {
  96. tabAdd: function (title, url, id) {
  97. element.tabAdd('mainTab', {
  98. title: title,//用于演示
  99. content: '<iframe tab-id="' + id + '" id="' + id + '" frameborder="0" src="' + url + '" scrolling="no" class="x-iframe"></iframe>',
  100. id: id //实际使用一般是规定好的id,这里以时间戳模拟下
  101. })
  102. },
  103. tabDelete: function (othis) {
  104. element.tabDelete('mainTab', id);
  105. othis.addClass('layui-btn-disabled');
  106. },
  107. tabChange: function (id) {
  108. //切换到指定Tab项
  109. element.tabChange('mainTab', id); //切换到:用户管理
  110. var tab = $('.layui-tab-title').children().filter(function () {
  111. return $(this).attr('lay-id') == id
  112. }).get(0)
  113. tab.parentElement.scrollLeft = tab.offsetLeft - (window.document.body.clientWidth / 2)
  114. }
  115. };
  116. });
  117. /**
  118. * 设置请求头
  119. * @returns
  120. */
  121. function setHeader() {
  122. // $.cookie('the_cookie'); // 读取 cookie
  123. // $.cookie('the_cookie', 'the_value'); // 存储 cookie
  124. // $.cookie('the_cookie', 'the_value', { expires: 7 }); // 存储一个带7天期限的 cookie
  125. // $.cookie('the_cookie', '', { expires: -1 }); // 删除 cookie
  126. var token = window.localStorage.getItem('tCookie');
  127. // var token = $.cookie("4b3c17fc6d869272dec20686acce38f1");
  128. return {"token": token, "isClient": "web"};
  129. }
  130. var username = window.localStorage.getItem('userName');
  131. $.ajax({
  132. url: "http://39.104.21.7:20312/fpmsUser/getMyAllInfo.do?username=" + username, //请求地址
  133. type: "POST",
  134. // async:false,//请求类型
  135. //data:{"userName" :username,"pwd":userPWD}, //请求数据
  136. timeout: 200000, //请求超时时间(毫秒)
  137. headers: setHeader(),
  138. success: function (res) {
  139. var data = res.resultData.fpmsPower[0];
  140. diGui(data);
  141. // var d = res.resultData.fpmsPower[0].children;
  142. console.error(ddd)
  143. localStorage.setItem('power', JSON.stringify(ddd))
  144. }
  145. });
  146. $(document.body).on('click', '.zhdj_second_menu ul li', function () {
  147. $(this).addClass('current').siblings().removeClass('current');
  148. $(this).parent('ul').siblings().find('li').removeClass('current');
  149. });
  150. $(document.body).on('click', '.zhdj_menu ul li', function () {
  151. $(this).addClass('layui-this').siblings().removeClass('layui-this');
  152. $(this).parent('ul').siblings().find('li').removeClass('layui-this');
  153. })
  154. });
  155. var ddd = [];
  156. function diGui(data) {
  157. var dd = data.children;
  158. if (!data.hasOwnProperty('length')) {
  159. if (data && !data.hasOwnProperty('children'))
  160. ddd.push(data)
  161. }
  162. if (dd) {
  163. for (d in dd) {
  164. var data2 = diGui(dd[d]);
  165. if (data2 && !data2.hasOwnProperty('children'))
  166. ddd.push(data2);
  167. }
  168. }
  169. }
  170. $(function () {
  171. $('#left_button').click(function () {
  172. var tabp = $('.layui-tab-title').get(0);
  173. var left = tabp.scrollLeft - (window.document.body.clientWidth / 3);
  174. if (left < 0) left = 0;
  175. tabp.scrollLeft = left;
  176. });
  177. $('#right_button').click(function () {
  178. var tabp = $('.layui-tab-title').get(0);
  179. var left = tabp.scrollLeft + (window.document.body.clientWidth / 3);
  180. // if(left>window.document.body.clientWidth) left = window.document.body.clientWidth;
  181. tabp.scrollLeft = left;
  182. });
  183. });