article.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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({left: '-221px'}, 100);
  58. $('.page-content').animate({left: '0px'}, 100);
  59. $('.page-content-bg').hide();
  60. }else{
  61. $('.left-nav').animate({left: '0px'}, 100);
  62. $('.page-content').animate({left: '221px'}, 100);
  63. if($(window).width()<768){
  64. $('.page-content-bg').show();
  65. }
  66. }
  67. });
  68. $('.page-content-bg').click(function(event) {
  69. $('.left-nav').animate({left: '-221px'}, 100);
  70. $('.page-content').animate({left: '0px'}, 100);
  71. $(this).hide();
  72. });
  73. $('.layui-tab-close').click(function(event) {
  74. $('.layui-tab-title li').eq(0).find('i').remove();
  75. });
  76. $("tbody.x-cate tr[fid!='0']").hide();
  77. // 栏目多级显示效果
  78. $('.x-show').click(function () {
  79. if($(this).attr('status')=='true'){
  80. $(this).html('&#xe625;');
  81. $(this).attr('status','false');
  82. cateId = $(this).parents('tr').attr('cate-id');
  83. $("tbody tr[fid="+cateId+"]").show();
  84. }else{
  85. cateIds = [];
  86. $(this).html('&#xe623;');
  87. $(this).attr('status','true');
  88. cateId = $(this).parents('tr').attr('cate-id');
  89. getCateId(cateId);
  90. for (var i in cateIds) {
  91. $("tbody tr[cate-id="+cateIds[i]+"]").hide().find('.x-show').html('&#xe623;').attr('status','true');
  92. }
  93. }
  94. })
  95. //左侧菜单效果
  96. // $('#content').bind("click",function(event){
  97. //点击菜单显示效果
  98. $(document).ready(function() {
  99. $('.left-nav #nav li .sub-menu li ').click(function(){
  100. $(this).addClass('menu-current').siblings().removeClass('menu-current');
  101. })
  102. });
  103. $('.left-nav #nav li').click(function (event) {
  104. if($(this).children('.sub-menu').length){
  105. if($(this).hasClass('open')){
  106. $(this).removeClass('open');
  107. $(this).find('.nav_right').html('&#xe6a7;');
  108. $(this).children('.sub-menu').stop().slideUp();
  109. $(this).siblings().children('.sub-menu').slideUp();
  110. }else{
  111. $(this).addClass('open');
  112. $(this).children('a').find('.nav_right').html('&#xe6a6;');
  113. $(this).children('.sub-menu').stop().slideDown();
  114. $(this).siblings().children('.sub-menu').stop().slideUp();
  115. $(this).siblings().find('.nav_right').html('&#xe6a7;');
  116. $(this).siblings().removeClass('open');
  117. }
  118. }else{
  119. var url = $(this).children('a').attr('_href');
  120. var title = $(this).find('cite').html();
  121. var index = $('.left-nav #nav li').index($(this));
  122. for (var i = 0; i <$('.x-iframe').length; i++) {
  123. if($('.x-iframe').eq(i).attr('tab-id')==index+1){
  124. tab.tabChange(index+1);
  125. event.stopPropagation();
  126. return;
  127. }
  128. };
  129. tab.tabAdd(title,url,index+1);
  130. tab.tabChange(index+1);
  131. }
  132. event.stopPropagation();
  133. })
  134. })
  135. var cateIds = [];
  136. function getCateId(cateId) {
  137. $("tbody tr[fid="+cateId+"]").each(function(index, el) {
  138. id = $(el).attr('cate-id');
  139. cateIds.push(id);
  140. getCateId(id);
  141. });
  142. }
  143. /*弹出层*/
  144. /*
  145. 参数解释:
  146. title 标题
  147. url 请求的url
  148. id 需要操作的数据id
  149. w 弹出层宽度(缺省调默认值)
  150. h 弹出层高度(缺省调默认值)
  151. */
  152. function x_admin_show(title,url,w,h){
  153. if (title == null || title == '') {
  154. title=false;
  155. };
  156. if (url == null || url == '') {
  157. url="404.html";
  158. };
  159. if (w == null || w == '') {
  160. w=($(window).width()*0.9);
  161. };
  162. if (h == null || h == '') {
  163. h=($(window).height() - 50);
  164. };
  165. layer.open({
  166. type: 2,
  167. area: [w+'px', h +'px'],
  168. fix: false, //不固定
  169. maxmin: true,
  170. shadeClose: true,
  171. shade:0.4,
  172. title: title,
  173. content: url,
  174. end: function () {
  175. location.reload();
  176. }
  177. });
  178. }
  179. /*关闭弹出框口*/
  180. function x_admin_close(){
  181. var index = parent.layer.getFrameIndex(window.name);
  182. parent.layer.close(index);
  183. }