main.min.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. ;
  2. jQuery( function() {
  3. // 滚动条
  4. const ps = new PerfectScrollbar('.lyear-layout-sidebar-scroll', {
  5. swipeEasing: false,
  6. suppressScrollX: true
  7. });
  8. // 侧边栏
  9. $(".lyear-aside-toggler").bind('click', function(){
  10. $('.lyear-layout-sidebar').toggleClass('lyear-aside-open');
  11. $("body").toggleClass('lyear-layout-sidebar-close');
  12. if ($('.lyear-mask-modal').length == 0) {
  13. $('<div class="lyear-mask-modal"></div>').prependTo('body');
  14. } else {
  15. $( '.lyear-mask-modal' ).remove();
  16. }
  17. $('.lyear-mask-modal').on( 'click', function() {
  18. $( this ).remove();
  19. $('.lyear-layout-sidebar').toggleClass('lyear-aside-open');
  20. $('body').toggleClass('lyear-layout-sidebar-close');
  21. });
  22. });
  23. // 侧边栏导航
  24. $( '.nav-item-has-subnav > a' ).on( 'click', function() {
  25. $subnavToggle = jQuery( this );
  26. $navHasSubnav = $subnavToggle.parent();
  27. $topHasSubNav = $subnavToggle.parents('.nav-item-has-subnav').last();
  28. $subnav = $navHasSubnav.find('.nav-subnav').first();
  29. $viSubHeight = $navHasSubnav.siblings().find('.nav-subnav:visible').outerHeight();
  30. $scrollBox = $('.lyear-layout-sidebar-scroll');
  31. $navHasSubnav.siblings().find('.nav-subnav:visible').slideUp(500).parent().removeClass('open');
  32. $subnav.slideToggle( 300, function() {
  33. $navHasSubnav.toggleClass( 'open' );
  34. // 新增滚动条处理
  35. var scrollHeight = 0;
  36. pervTotal = $topHasSubNav.prevAll().length,
  37. boxHeight = $scrollBox.outerHeight(),
  38. innerHeight = $('.sidebar-main').outerHeight(),
  39. thisScroll = $scrollBox.scrollTop(),
  40. thisSubHeight = $(this).outerHeight(),
  41. footHeight = 121;
  42. if (footHeight + innerHeight - boxHeight >= (pervTotal * 48)) {
  43. scrollHeight = pervTotal * 48;
  44. }
  45. if ($subnavToggle.parents('.nav-item-has-subnav').length == 1) {
  46. $scrollBox.animate({scrollTop: scrollHeight}, 300);
  47. } else {
  48. // 子菜单操作
  49. if (typeof($viSubHeight) != 'undefined' && $viSubHeight != null) {
  50. scrollHeight = thisScroll + thisSubHeight - $viSubHeight;
  51. $scrollBox.animate({scrollTop: scrollHeight}, 300);
  52. } else {
  53. if ((thisScroll + boxHeight - $scrollBox[0].scrollHeight) == 0) {
  54. scrollHeight = thisScroll - thisSubHeight;
  55. $scrollBox.animate({scrollTop: scrollHeight}, 300);
  56. }
  57. }
  58. }
  59. });
  60. });
  61. // 提示
  62. if($('[data-toggle="tooltip"]')[0]) {
  63. $('[data-toggle="tooltip"]').tooltip({
  64. "container" : 'body',
  65. });
  66. }
  67. // 弹出框
  68. if($('[data-toggle="popover"]')[0]) {
  69. $('[data-toggle="popover"]').popover();
  70. }
  71. // 标签
  72. if($('.js-tags-input')[0]) {
  73. $('.js-tags-input').tagsInput({
  74. height: '36px',
  75. width: '100%',
  76. defaultText: '添加标签',
  77. removeWithBackspace: true,
  78. delimiter: [',']
  79. });
  80. }
  81. // 时间选择
  82. jQuery('.js-datetimepicker').each(function() {
  83. var $input = jQuery(this);
  84. $input.datetimepicker({
  85. format: $input.data('format') ? $input.data('format') : false,
  86. useCurrent: $input.data('use-current') ? $input.data('use-current') : false,
  87. locale: moment.locale('' + ($input.data('locale') ? $input.data('locale') : '') + ''),
  88. showTodayButton: $input.data('show-today-button') ? $input.data('show-today-button') : false,
  89. showClear: $input.data('show-clear') ? $input.data('show-clear') : false,
  90. showClose: $input.data('show-close') ? $input.data('show-close') : false,
  91. sideBySide: $input.data('side-by-side') ? $input.data('side-by-side') : false,
  92. inline: $input.data('inline') ? $input.data('inline') : false,
  93. });
  94. });
  95. // 日期选择
  96. jQuery('.js-datepicker').each(function() {
  97. var $input = jQuery(this);
  98. $input.datepicker({
  99. weekStart: 1,
  100. autoclose: true,
  101. todayHighlight: true,
  102. language: 'zh-CN',
  103. });
  104. });
  105. // 颜色选取
  106. jQuery('.js-colorpicker').each(function() {
  107. var $colorpicker = jQuery(this);
  108. var $colorpickerMode = $colorpicker.data('colorpicker-mode') ? $colorpicker.data('colorpicker-mode') : 'hex';
  109. var $colorpickerinline = $colorpicker.data('colorpicker-inline') ? true: false;
  110. $colorpicker.colorpicker({
  111. 'format': $colorpickerMode,
  112. 'inline': $colorpickerinline
  113. });
  114. });
  115. // 复选框全选
  116. $("#check-all").change(function () {
  117. $("input[type='checkbox']").prop('checked', $(this).prop("checked"));
  118. });
  119. });