xadmin.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. $(function () {
  2. //加载弹出层
  3. layui.use(['form', 'element'],
  4. function () {
  5. layer = layui.layer;
  6. element = layui.element;
  7. });
  8. //触发事件
  9. var tab = {
  10. tabAdd: function (title, url, id) {
  11. //新增一个Tab项
  12. element.tabAdd('xbs_tab', {
  13. title: title,
  14. content: '<iframe tab-id="' + id + '" frameborder="0" src="' + url + '" scrolling="yes" class="x-iframe"></iframe>',
  15. id: id
  16. })
  17. },
  18. tabDelete: function (othis) {
  19. //删除指定Tab项
  20. element.tabDelete('xbs_tab', '44'); //删除:“商品管理”
  21. othis.addClass('layui-btn-disabled');
  22. },
  23. tabChange: function (id) {
  24. //切换到指定Tab项
  25. element.tabChange('xbs_tab', id); //切换到:用户管理
  26. }
  27. };
  28. tableCheck = {
  29. init: function () {
  30. $(".layui-form-checkbox").click(function (event) {
  31. if ($(this).hasClass('layui-form-checked')) {
  32. $(this).removeClass('layui-form-checked');
  33. if ($(this).hasClass('header')) {
  34. $(".layui-form-checkbox").removeClass('layui-form-checked');
  35. }
  36. } else {
  37. $(this).addClass('layui-form-checked');
  38. if ($(this).hasClass('header')) {
  39. $(".layui-form-checkbox").addClass('layui-form-checked');
  40. }
  41. }
  42. });
  43. },
  44. getData: function () {
  45. var obj = $(".layui-form-checked").not('.header');
  46. var arr = [];
  47. obj.each(function (index, el) {
  48. arr.push(obj.eq(index).attr('data-id'));
  49. });
  50. return arr;
  51. }
  52. }
  53. //开启表格多选
  54. tableCheck.init();
  55. $('.container .left_open i').click(function (event) {
  56. if ($('.left-nav').css('left') == '0px') {
  57. $('.left-nav').animate({
  58. left: '-221px'
  59. }, 100);
  60. $('.page-content').animate({
  61. left: '0px'
  62. }, 100);
  63. $('.page-content-bg').hide();
  64. } else {
  65. $('.left-nav').animate({
  66. left: '0px'
  67. }, 100);
  68. $('.page-content').animate({
  69. left: '221px'
  70. }, 100);
  71. if ($(window).width() < 768) {
  72. $('.page-content-bg').show();
  73. }
  74. }
  75. });
  76. $('.page-content-bg').click(function (event) {
  77. $('.left-nav').animate({
  78. left: '-221px'
  79. }, 100);
  80. $('.page-content').animate({
  81. left: '0px'
  82. }, 100);
  83. $(this).hide();
  84. });
  85. $('.layui-tab-close').click(function (event) {
  86. $('.layui-tab-title li').eq(0).find('i').remove();
  87. });
  88. $(".sub-menu li a").addClass("refreshThis");
  89. //左侧菜单效果
  90. // console.log($('.left-nav #nav li'))
  91. $('.left-nav #nav li').click(function (event) {
  92. if ($(this).children('.sub-menu').length) {
  93. if ($(this).hasClass('open')) {
  94. $(this).removeClass('open');
  95. $(this).find('.nav_right').html('&#xe697;');
  96. $(this).children('.sub-menu').stop().slideUp("fast");
  97. $(this).siblings().children('.sub-menu').slideUp("fast");
  98. } else {
  99. $(this).addClass('open');
  100. $(this).children('a').find('.nav_right').html('&#xe6a6;');
  101. $(this).children('.sub-menu').stop().slideDown("fast");
  102. $(this).siblings().children('.sub-menu').stop().slideUp("fast");
  103. $(this).siblings().find('.nav_right').html('&#xe697;');
  104. $(this).siblings().removeClass('open');
  105. }
  106. } else {
  107. var url = $(this).children('a').attr('_href');
  108. var title = $(this).find('cite').html();
  109. var index = $('.left-nav #nav li').index($(this));
  110. //当前选中样式
  111. $('li.J_for_active li').removeClass('active');
  112. $(this).addClass('active').siblings().removeClass("active");
  113. // 点击导航重加载功能
  114. if ($(this).children('a').hasClass("refreshThis")) {
  115. $(this).children('a').removeClass("refreshThis");
  116. for (var i = 0; i < $('.x-iframe').length; i++) {
  117. if ($('.x-iframe').eq(i).attr('tab-id') == index + 1) {
  118. $('.x-iframe').eq(i)[0].contentWindow.location = url;
  119. }
  120. };
  121. setTimeout(function () {
  122. $(".sub-menu li a").addClass("refreshThis");
  123. }, 300)
  124. } else {
  125. layer.msg("慢点!");
  126. }
  127. for (var i = 0; i < $('.x-iframe').length; i++) {
  128. if ($('.x-iframe').eq(i).attr('tab-id') == index + 1) {
  129. tab.tabChange(index + 1);
  130. event.stopPropagation();
  131. return;
  132. }
  133. };
  134. tab.tabAdd(title, url, index + 1);
  135. tab.tabChange(index + 1);
  136. // 判断是否过期,直接跳转到login页面
  137. $appiframe = $("[tab-id=" + (index + 1) + ']');
  138. $($appiframe).on('load', function () {
  139. var srcLoaded = $appiframe.get(0).contentWindow.location.href;
  140. if (srcLoaded.indexOf('/login/index') >= 0) {
  141. window.location.reload(true);
  142. }
  143. })
  144. }
  145. event.stopPropagation();
  146. })
  147. //针对子iframe,判断是否过期,直接跳转到login页面
  148. $("body").on("click", function () {
  149. // for (var i = 0; i < window.parent.document.getElementsByTagName("iframe").length; i++) {
  150. // if (window.parent.document.getElementsByTagName("iframe")[i].src.indexOf('/login/index') >= 0) {
  151. // window.location.reload(true);
  152. // }
  153. // }
  154. if (window != window.top && window.location.href.indexOf('/login/index') >= 0) {
  155. window.top.location.href = window.location.href;
  156. }
  157. })
  158. })
  159. /*弹出层*/
  160. /*
  161. 参数解释:
  162. title 标题
  163. url 请求的url
  164. id 需要操作的数据id
  165. w 弹出层宽度(缺省调默认值)
  166. h 弹出层高度(缺省调默认值)
  167. */
  168. function x_admin_show(title, url, w, h) {
  169. if (title == null || title == '') {
  170. title = false;
  171. };
  172. if (url == null || url == '') {
  173. url = "404.html";
  174. };
  175. if (w == null || w == '') {
  176. w = ($(window).width() * 0.9);
  177. };
  178. if (h == null || h == '') {
  179. h = ($(window).height() - 50);
  180. };
  181. layer.open({
  182. type: 2,
  183. area: [w + 'px', h + 'px'],
  184. fix: false, //不固定
  185. maxmin: true,
  186. shadeClose: true,
  187. shade: 0.4,
  188. title: title,
  189. content: url
  190. });
  191. }
  192. /*关闭弹出框口*/
  193. function x_admin_close() {
  194. var index = parent.layer.getFrameIndex(window.name);
  195. parent.layer.close(index);
  196. }