index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. var $, tab, skyconsWeather;
  2. layui.config({
  3. base: "js/"
  4. }).use(['bodyTab', 'form', 'element', 'layer', 'jquery'], function() {
  5. var form = layui.form,
  6. layer = layui.layer,
  7. element = layui.element;
  8. $ = layui.jquery;
  9. tab = layui.bodyTab();
  10. //用户昵称
  11. var userInfo = layui.sessionData(window.hywa.sessionTable.tableName);
  12. $('#userName').html(JSON.stringify(userInfo) != '{}' ? userInfo[window.hywa.sessionTable.userData].name :
  13. '游客用户');
  14. //退出
  15. $('#dropOut,#dropOut1').on("click", function() {
  16. layer.msg('注销中……', {
  17. icon: 6,
  18. time: 5000
  19. });
  20. $.ajax({
  21. type: "DELETE",
  22. url: 'loginOut?userId=' + userInfo[window.hywa.sessionTable.userData].userId,
  23. success: function(res) {
  24. if (!(res.code - 0)) {
  25. layui.sessionData(window.hywa.sessionTable.tableName, null);
  26. window.sessionStorage.removeItem("menu");
  27. let path = top.location.pathname.split('/');
  28. path.splice(-1,1,'');
  29. path = path.join('/');
  30. top.location.href = path + window.hywa.jumpPage.login;
  31. } else {
  32. }
  33. }
  34. });
  35. });
  36. $('#clickReturn').on('click', function() {
  37. location.href = "login/index.html"
  38. })
  39. //隐藏左侧导航
  40. $(".hideMenu").click(function() {
  41. $(".layui-layout-admin").toggleClass("showMenu");
  42. //渲染顶部窗口
  43. tab.tabMove();
  44. })
  45. //渲染左侧菜单
  46. tab.render();
  47. //锁屏
  48. function lockPage() {
  49. layer.open({
  50. title: false,
  51. type: 1,
  52. content: $("#lock-box"),
  53. closeBtn: 0,
  54. shade: 0.9
  55. })
  56. }
  57. //手机设备的简单适配
  58. var treeMobile = $('.site-tree-mobile'),
  59. shadeMobile = $('.site-mobile-shade')
  60. treeMobile.on('click', function() {
  61. $('body').addClass('site-mobile');
  62. });
  63. shadeMobile.on('click', function() {
  64. $('body').removeClass('site-mobile');
  65. });
  66. // 添加新窗口
  67. $(".layui-nav .layui-nav-item a").on("click", function() {
  68. addTab($(this));
  69. $(this).parent("li").siblings().removeClass("layui-nav-itemed");
  70. });
  71. //判断是否处于锁屏状态(如果关闭以后则未关闭浏览器之前不再显示)
  72. if (window.sessionStorage.getItem("lockcms") != "true" && window.sessionStorage.getItem("showNotice") !=
  73. "true") {
  74. if (typeof showNotice !== 'undefined') showNotice();
  75. }
  76. $(".showNotice").on("click", function() {
  77. showNotice();
  78. })
  79. //刷新当前
  80. $(".refresh").on("click", function() { //此处添加禁止连续点击刷新一是为了降低服务器压力,另外一个就是为了防止超快点击造成chrome本身的一些js文件的报错(不过貌似这个问题还是存在,不过概率小了很多)
  81. if ($(this).hasClass("refreshThis")) {
  82. $(this).removeClass("refreshThis");
  83. $(".clildFrame .layui-tab-item.layui-show").find("iframe")[0].contentWindow.location.reload(true);
  84. setTimeout(function() {
  85. $(".refresh").addClass("refreshThis");
  86. }, 2000)
  87. } else {
  88. layer.msg("您点击的速度超过了服务器的响应速度,还是等两秒再刷新吧!");
  89. }
  90. })
  91. //关闭其他
  92. $(".closePageOther").on("click", function() {
  93. if ($("#top_tabs li").length > 2 && $("#top_tabs li.layui-this cite").text() != "后台首页") {
  94. var menu = JSON.parse(window.sessionStorage.getItem("menu"));
  95. $("#top_tabs li").each(function() {
  96. if ($(this).attr("lay-id") != '' && !$(this).hasClass("layui-this")) {
  97. element.tabDelete("bodyTab", $(this).attr("lay-id")).init();
  98. //此处将当前窗口重新获取放入session,避免一个个删除来回循环造成的不必要工作量
  99. for (var i = 0; i < menu.length; i++) {
  100. if ($("#top_tabs li.layui-this cite").text() == menu[i].title) {
  101. menu.splice(0, menu.length, menu[i]);
  102. window.sessionStorage.setItem("menu", JSON.stringify(menu));
  103. }
  104. }
  105. }
  106. })
  107. } else if ($("#top_tabs li.layui-this cite").text() == "后台首页" && $("#top_tabs li").length > 1) {
  108. $("#top_tabs li").each(function() {
  109. if ($(this).attr("lay-id") != '' && !$(this).hasClass("layui-this")) {
  110. element.tabDelete("bodyTab", $(this).attr("lay-id")).init();
  111. window.sessionStorage.removeItem("menu");
  112. menu = [];
  113. window.sessionStorage.removeItem("curmenu");
  114. }
  115. })
  116. } else {
  117. layer.msg("没有可以关闭的窗口了@_@");
  118. }
  119. //渲染顶部窗口
  120. tab.tabMove();
  121. })
  122. //关闭全部
  123. $(".closePageAll").on("click", function() {
  124. if ($("#top_tabs li").length > 1) {
  125. $("#top_tabs li").each(function() {
  126. if ($(this).attr("lay-id") != '') {
  127. element.tabDelete("bodyTab", $(this).attr("lay-id")).init();
  128. window.sessionStorage.removeItem("menu");
  129. menu = [];
  130. window.sessionStorage.removeItem("curmenu");
  131. }
  132. })
  133. $('.layui-nav-tree').find('.layui-this').removeClass('layui-this')
  134. } else {
  135. layer.msg("没有可以关闭的窗口了@_@");
  136. }
  137. //渲染顶部窗口
  138. tab.tabMove();
  139. })
  140. })
  141. //打开新窗口
  142. function addTab(_this) {
  143. tab.tabAdd(_this);
  144. }