common.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. $(document).ready(function() {
  2. /*根据分辨率调整菜单*/
  3. if ($(window).width() < 769) {
  4. $('body').addClass('body-small')
  5. } else {
  6. $('body').removeClass('body-small')
  7. }
  8. if ($(window).width() < 1200 && !$('body').hasClass('body-small')) {
  9. $('body').addClass('mini-navbar')
  10. } else {
  11. $('body').removeClass('mini-navbar')
  12. }
  13. /*左侧菜单*/
  14. $('.navbar-minimalize').click(function () {
  15. var body = $('body');
  16. body.toggleClass("mini-navbar");
  17. SmoothlyMenu();
  18. });
  19. $('.nav-second-level').each(function(){
  20. $(this).find('li.active').parent().addClass('in');
  21. $(this).find('li.active').parent().parent().addClass('active');
  22. });
  23. /*全选*/
  24. $(document).on('click', '#check-all', function() {
  25. var op = $(this).is(':checked');
  26. if(op==true){
  27. $('[type=checkbox]').prop('checked', true);
  28. } else {
  29. $('[type=checkbox]').prop('checked', false);
  30. }
  31. });
  32. /*table项目点击*/
  33. $(document).on('click', '.table tbody tr', function() {
  34. $('.table tbody tr').removeAttr('id');
  35. $(this).attr('id','clicked');
  36. });
  37. });
  38. $(window).bind("resize", function () {
  39. if ($(this).width() < 769) {
  40. $('body').addClass('body-small')
  41. } else {
  42. $('body').removeClass('body-small')
  43. }
  44. if ($(window).width() < 1200 && !$('body').hasClass('body-small')) {
  45. $('body').addClass('mini-navbar')
  46. } else {
  47. $('body').removeClass('mini-navbar')
  48. }
  49. });
  50. /*单页显示条目*/
  51. var page_size = function(){
  52. var u = window.location.href,
  53. sz = $('#sz').val(),
  54. url = '';
  55. if(u.indexOf('sz=') > 0 ) {
  56. url = u.replace(/sz=\d+/g, 'sz='+sz);
  57. } else {
  58. if(u.indexOf('=') > 0 ) {
  59. url = u + '&sz=' + sz;
  60. } else {
  61. url = u + '?sz=' + sz;
  62. }
  63. }
  64. //console.log(url);
  65. window.location.href = url;
  66. }
  67. /*删除和批量删除*/
  68. var del_all=function(id,url){
  69. var ids = [];
  70. if(id>0){
  71. ids[0] = id;
  72. }else{
  73. var arr = $('input[name="id[]"]:checked');
  74. for (var i=0;i<arr.length;i++){
  75. ids[i] = arr[i].value;
  76. }
  77. }
  78. if(ids.length==0){
  79. bootbox.alert('请选择需要删除的条目');
  80. return false;
  81. }
  82. bootbox.confirm(
  83. '是否要删除选中的条目?',
  84. function(result){
  85. if (result) {
  86. window.location.href = url+ '?ids='+ ids;
  87. // $("#myModal").modal({
  88. // remote : url+ '?ids='+ ids
  89. // });
  90. }
  91. }
  92. );
  93. };
  94. function SmoothlyMenu() {
  95. if (!$('body').hasClass('mini-navbar') || $('body').hasClass('body-small')) {
  96. $('#side-menu').hide();
  97. setTimeout(
  98. function () {
  99. $('#side-menu').fadeIn(400);
  100. }, 200);
  101. } else if ($('body').hasClass('fixed-sidebar')) {
  102. $('#side-menu').hide();
  103. setTimeout(
  104. function () {
  105. $('#side-menu').fadeIn(400);
  106. }, 100);
  107. } else {
  108. $('#side-menu').removeAttr('style');
  109. }
  110. }