sub_menu.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. (function($){
  10. $.subMenu = function (setting) {
  11. const menu = $(setting.menu), miniMenu = $(setting.miniMenu);
  12. const toMenu = $(setting.toMenu), toMiniMenu = $(setting.toMiniMenu);
  13. const miniHint = $(setting.miniHint);
  14. const showMenu = function () {
  15. menu.show();
  16. miniMenu.removeClass('d-flex').hide();
  17. setting.callback({mini: false});
  18. };
  19. const showMiniMenu = function () {
  20. menu.hide();
  21. miniMenu.addClass('d-flex').show();
  22. setting.callback({mini: true});
  23. };
  24. const menuType = setting.key ? getLocalCache(setting.key) : null;
  25. if (menuType && menuType === 'miniMenu') {
  26. showMiniMenu();
  27. } else {
  28. showMenu();
  29. }
  30. toMenu.click(function () {
  31. showMenu();
  32. if (setting.key) {
  33. setLocalCache(setting.key, 'menu');
  34. }
  35. });
  36. toMiniMenu.click(function () {
  37. showMiniMenu();
  38. if (setting.key) {
  39. setLocalCache(setting.key, 'miniMenu');
  40. }
  41. const hint = setting.hintKey ? getLocalCache(setting.hintKey) : '';
  42. if (hint !== '1') {
  43. miniHint.popover('show');
  44. }
  45. });
  46. miniMenu.mouseenter(function () {
  47. toMenu.show();
  48. toMenu.siblings('i').hide();
  49. // miniMenu.find('.side-switch i').addClass('fa-indent text-primary').removeClass('fa-bars');
  50. $(setting.miniMenuList).show();
  51. miniHint.popover('hide');
  52. if (setting.hintKey) {
  53. setLocalCache(setting.hintKey, '1');
  54. }
  55. });
  56. miniMenu.mouseleave(function () {
  57. toMenu.hide();
  58. toMenu.siblings('i').show();
  59. // miniMenu.find('.side-switch i').addClass('fa-bars').removeClass('fa-indent text-primary');
  60. $(setting.miniMenuList).hide();
  61. });
  62. let timeMake = false;
  63. $(setting.menu).find('.side-show').mouseenter(function () {
  64. $(setting.menu).find('.side-fold').show();
  65. timeMake = false;
  66. });
  67. $(setting.menu).find('.side-show').mouseleave(function () {
  68. timeMake = true;
  69. setTimeout(function () {
  70. if (timeMake) {
  71. $(setting.menu).find('.side-fold').hide();
  72. }
  73. }, 500);
  74. });
  75. $(setting.menu).find('.side-fold').mouseenter(function () {
  76. timeMake = false;
  77. $(this).css('width', '15px');
  78. });
  79. $(setting.menu).find('.side-fold').mouseleave(function () {
  80. timeMake = true;
  81. setTimeout(function () {
  82. if (timeMake) {
  83. $(setting.menu).find('.side-fold').hide();
  84. }
  85. }, 500);
  86. $(this).css('width', '6px');
  87. })
  88. }
  89. })(jQuery);