main.min.js 5.8 KB

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