xadmin.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. $('.left-nav #nav li').click(function (event) {
  98. if($(this).children('.sub-menu').length){
  99. if($(this).hasClass('open')){
  100. $(this).removeClass('open');
  101. $(this).find('.nav_right').html('&#xe697;');
  102. $(this).children('.sub-menu').stop().slideUp();
  103. $(this).siblings().children('.sub-menu').slideUp();
  104. }else{
  105. $(this).addClass('open');
  106. $(this).children('a').find('.nav_right').html('&#xe6a6;');
  107. $(this).children('.sub-menu').stop().slideDown();
  108. $(this).siblings().children('.sub-menu').stop().slideUp();
  109. $(this).siblings().find('.nav_right').html('&#xe697;');
  110. $(this).siblings().removeClass('open');
  111. }
  112. }else{
  113. var url = $(this).children('a').attr('_href');
  114. var title = $(this).find('cite').html();
  115. var index = $('.left-nav #nav li').index($(this));
  116. for (var i = 0; i <$('.x-iframe').length; i++) {
  117. if($('.x-iframe').eq(i).attr('tab-id')==index+1){
  118. tab.tabChange(index+1);
  119. event.stopPropagation();
  120. return;
  121. }
  122. };
  123. tab.tabAdd(title,url,index+1);
  124. tab.tabChange(index+1);
  125. }
  126. event.stopPropagation();
  127. })
  128. })
  129. var cateIds = [];
  130. function getCateId(cateId) {
  131. $("tbody tr[fid="+cateId+"]").each(function(index, el) {
  132. id = $(el).attr('cate-id');
  133. cateIds.push(id);
  134. getCateId(id);
  135. });
  136. }
  137. /*弹出层*/
  138. /*
  139. 参数解释:
  140. title 标题
  141. url 请求的url
  142. id 需要操作的数据id
  143. w 弹出层宽度(缺省调默认值)
  144. h 弹出层高度(缺省调默认值)
  145. */
  146. function x_admin_show(title,url,w,h){
  147. if (title == null || title == '') {
  148. title=false;
  149. };
  150. if (url == null || url == '') {
  151. url="404.html";
  152. };
  153. if (w == null || w == '') {
  154. w=($(window).width()*0.9);
  155. };
  156. if (h == null || h == '') {
  157. h=($(window).height() - 50);
  158. };
  159. layer.open({
  160. type: 2,
  161. area: [w+'px', h +'px'],
  162. fix: false, //不固定
  163. maxmin: true,
  164. shadeClose: true,
  165. shade:0.4,
  166. title: title,
  167. content: url
  168. });
  169. }
  170. /*关闭弹出框口*/
  171. function x_admin_close(){
  172. var index = parent.layer.getFrameIndex(window.name);
  173. parent.layer.close(index);
  174. }