main.min.js 5.1 KB

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