menu.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. 菜单 处理
  3. **/
  4. (function (vc) {
  5. var vm = new Vue({
  6. el: '#menu-nav',
  7. data: {
  8. menus: [],
  9. logo: '',
  10. },
  11. mounted: function () {
  12. this._initSysInfo();
  13. this.getMenus();
  14. },
  15. methods: {
  16. _initSysInfo: function () {
  17. var sysInfo = vc.getData("_sysInfo");
  18. if (sysInfo == null) {
  19. this.logo = "HC";
  20. return;
  21. }
  22. this.logo = sysInfo.logo;
  23. },
  24. _gotoIndex:function(){
  25. vc.jumpToPage("/")
  26. },
  27. getMenus: function () {
  28. var _tmpMenus = vc.getMenus();
  29. //浏览器缓存中能获取到
  30. if (_tmpMenus != null && _tmpMenus != undefined) {
  31. this.miniMenu();
  32. this.menus = _tmpMenus;
  33. return;
  34. }
  35. var param = {
  36. params: {
  37. msg: this.message
  38. }
  39. }
  40. //发送get请求
  41. vc.http.get('menu',
  42. 'getMenus',
  43. param,
  44. function (json, res) {
  45. var _menus = JSON.parse(json);
  46. if (_menus == null || _menus.length == 0) {
  47. return;
  48. }
  49. _menus.sort(function (a, b) {
  50. return a.seq - b.seq
  51. });
  52. var _currentMenusId = vc.getCurrentMenu() == null ? _menus[0].id : vc.getCurrentMenu();
  53. vm.menus = vm.refreshMenuActive(_menus, _currentMenusId);
  54. vc.setMenus(vm.menus);
  55. vm.miniMenu();
  56. }, function (errInfo, error) {
  57. console.log('请求失败处理');
  58. }
  59. );
  60. },
  61. refreshMenuActive: function (jsonArray, _id) {
  62. for (var menuIndex = 0; menuIndex < jsonArray.length; menuIndex++) {
  63. if (jsonArray[menuIndex].hasOwnProperty('childs')) {
  64. var _childs = jsonArray[menuIndex].childs;
  65. _childs.sort(function (_child, _newChild) {
  66. return _child.seq - _newChild.seq
  67. });
  68. jsonArray[menuIndex].childs = _childs;
  69. }
  70. if (_id === jsonArray[menuIndex].id) {
  71. if (jsonArray[menuIndex].active === true) {
  72. //如果当前本身是打开状态,说明 需要关闭
  73. jsonArray[menuIndex].active = false;
  74. continue;
  75. }
  76. jsonArray[menuIndex].active = true;
  77. continue;
  78. }
  79. jsonArray[menuIndex].active = false;
  80. }
  81. return jsonArray;
  82. },
  83. switchMenu: function (_id) {
  84. //设置菜单ID
  85. vc.setCurrentMenu(_id);
  86. vm.menus = vm.refreshMenuActive(vm.menus, _id);
  87. vc.setMenus(vm.menus);
  88. },
  89. miniMenu: function () {
  90. vc.setMenuState('ON');
  91. if (vc.notNull(vc.getMenuState()) && vc.getMenuState() == 'ON') {
  92. return;
  93. }
  94. $("body").toggleClass("mini-navbar");
  95. vc.setMenuState('OFF');
  96. }
  97. },
  98. });
  99. })(window.vc)