xadmin.js 8.3 KB

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