admin.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. ,
  15. content: '<iframe tab-id="' + id + '" frameborder="0" src="' + url + '" scrolling="yes" class="x-iframe"></iframe>'
  16. ,
  17. id: id
  18. })
  19. }
  20. , tabDelete: function (othis) {
  21. //删除指定Tab项
  22. element.tabDelete('xbs_tab', '44'); //删除:“商品管理”
  23. othis.addClass('layui-btn-disabled');
  24. }
  25. , tabChange: function (id) {
  26. //切换到指定Tab项
  27. element.tabChange('xbs_tab', id); //切换到:用户管理
  28. }
  29. };
  30. tableCheck = {
  31. init: function () {
  32. $(".layui-form-checkbox").click(function (event) {
  33. if ($(this).hasClass('layui-form-checked')) {
  34. $(this).removeClass('layui-form-checked');
  35. if ($(this).hasClass('header')) {
  36. $(".layui-form-checkbox").removeClass('layui-form-checked');
  37. }
  38. } else {
  39. $(this).addClass('layui-form-checked');
  40. if ($(this).hasClass('header')) {
  41. $(".layui-form-checkbox").addClass('layui-form-checked');
  42. }
  43. }
  44. });
  45. },
  46. getData: function () {
  47. var obj = $(".layui-form-checked").not('.header');
  48. var arr = [];
  49. obj.each(function (index, el) {
  50. arr.push(obj.eq(index).attr('data-id'));
  51. });
  52. return arr;
  53. }
  54. }
  55. //开启表格多选
  56. tableCheck.init();
  57. $('.container .left_open i').click(function (event) {
  58. if ($('.left-nav').css('left') == '0px') {
  59. $('.left-nav').animate({left: '-221px'}, 100);
  60. $('.page-content').animate({left: '0px'}, 100);
  61. $('.page-content-bg').hide();
  62. } else {
  63. $('.left-nav').animate({left: '0px'}, 100);
  64. $('.page-content').animate({left: '221px'}, 100);
  65. if ($(window).width() < 768) {
  66. $('.page-content-bg').show();
  67. }
  68. }
  69. });
  70. $('.page-content-bg').click(function (event) {
  71. $('.left-nav').animate({left: '-221px'}, 100);
  72. $('.page-content').animate({left: '0px'}, 100);
  73. $(this).hide();
  74. });
  75. $('.layui-tab-close').click(function (event) {
  76. $('.layui-tab-title li').eq(0).find('i').remove();
  77. });
  78. $("tbody.x-cate tr[fid!='0']").hide();
  79. // 栏目多级显示效果
  80. $('.x-show').click(function () {
  81. if ($(this).attr('status') == 'true') {
  82. $(this).html('&#xe625;');
  83. $(this).attr('status', 'false');
  84. cateId = $(this).parents('tr').attr('cate-id');
  85. $("tbody tr[fid=" + cateId + "]").show();
  86. } else {
  87. cateIds = [];
  88. $(this).html('&#xe623;');
  89. $(this).attr('status', 'true');
  90. cateId = $(this).parents('tr').attr('cate-id');
  91. getCateId(cateId);
  92. for (var i in cateIds) {
  93. $("tbody tr[cate-id=" + cateIds[i] + "]").hide().find('.x-show').html('&#xe623;').attr('status', 'true');
  94. }
  95. }
  96. })
  97. //左侧菜单效果
  98. // $('#content').bind("click",function(event){
  99. $('.left-nav #nav li').click(function (event) {
  100. if ($(this).children('.sub-menu').length) {
  101. if ($(this).hasClass('open')) {
  102. $(this).removeClass('open');
  103. $(this).find('.nav_right').html('&#xe697;');
  104. $(this).children('.sub-menu').stop().slideUp();
  105. $(this).siblings().children('.sub-menu').slideUp();
  106. } else {
  107. $(this).addClass('open');
  108. $(this).children('a').find('.nav_right').html('&#xe6a6;');
  109. $(this).children('.sub-menu').stop().slideDown();
  110. $(this).siblings().children('.sub-menu').stop().slideUp();
  111. $(this).siblings().find('.nav_right').html('&#xe697;');
  112. $(this).siblings().removeClass('open');
  113. }
  114. } else {
  115. var url = $(this).children('a').attr('_href');
  116. var title = $(this).find('cite').html();
  117. var index = $('.left-nav #nav li').index($(this));
  118. for (var i = 0; i < $('.x-iframe').length; i++) {
  119. if ($('.x-iframe').eq(i).attr('tab-id') == index + 1) {
  120. tab.tabChange(index + 1);
  121. event.stopPropagation();
  122. return;
  123. }
  124. }
  125. ;
  126. tab.tabAdd(title, url, index + 1);
  127. tab.tabChange(index + 1);
  128. }
  129. event.stopPropagation();
  130. })
  131. })
  132. var cateIds = [];
  133. function getCateId(cateId) {
  134. $("tbody tr[fid=" + cateId + "]").each(function (index, el) {
  135. id = $(el).attr('cate-id');
  136. cateIds.push(id);
  137. getCateId(id);
  138. });
  139. }
  140. /*弹出层*/
  141. /*
  142. 参数解释:
  143. title 标题
  144. url 请求的url
  145. id 需要操作的数据id
  146. w 弹出层宽度(缺省调默认值)
  147. h 弹出层高度(缺省调默认值)
  148. */
  149. function x_admin_show(title, url, w, h) {
  150. if (title == null || title == '') {
  151. title = false;
  152. }
  153. ;
  154. if (url == null || url == '') {
  155. url = "404.html";
  156. }
  157. ;
  158. if (w == null || w == '') {
  159. w = ($(window).width() * 0.9);
  160. }
  161. ;
  162. if (h == null || h == '') {
  163. h = ($(window).height() - 50);
  164. }
  165. ;
  166. layer.open({
  167. type: 2,
  168. area: [w + 'px', h + 'px'],
  169. fix: false, //不固定
  170. maxmin: true,
  171. shadeClose: true,
  172. shade: 0.4,
  173. title: title,
  174. content: url
  175. });
  176. }
  177. /*关闭弹出框口*/
  178. function x_admin_close() {
  179. var index = parent.layer.getFrameIndex(window.name);
  180. parent.layer.close(index);
  181. }
  182. function formatDate(date) {
  183. var date = new Date(date);
  184. var YY = date.getFullYear() + '-';
  185. var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  186. var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
  187. var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  188. var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  189. var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  190. return YY + MM + DD + " " + hh + mm + ss;
  191. };