sub_menu.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. $(setting.miniMenuList).show();
  48. miniHint.popover('hide');
  49. if (setting.hintKey) {
  50. setLocalCache(setting.hintKey, '1');
  51. }
  52. });
  53. miniMenu.mouseleave(function () {
  54. $(setting.miniMenuList).hide();
  55. });
  56. }
  57. })(jQuery);