$(function() { var vmm = new Vue({ el: '#dz_content', data: { baseUrl: '', //请求地址 secondLevel: {}, //二级菜单 threeLevel: {}, //二级菜单 fristName: '', secondName: '', menuList: [], //菜单 levelDepth: 1, //当前层级 isCollapse: true, isMoveout: false, times: null, }, mounted:function() { this.initMenuList(); }, methods: { headleShowPcMenu:function() { this.isMoveout = false; $(".dz_content").removeClass("displayNone"); }, headleHoidePcMenu:function() { var that=this; this.isMoveout = true; that.times = setTimeout(function(){ if (that.isMoveout) { $(".dz_content").addClass("displayNone"); clearTimeout(that.times); } }, 500) }, setNavMenu: function(name) { console.log(name) var that = this; var menuList=this.menuList; for(var m in menuList){ if (menuList[m].name == name) { // 如果一级下面有二级 var isHas=false; if(menuList[m].children.length){ for(var n in menuList[m].children){ if(menuList[m].children[n].children.length){ isHas=true } } } if(isHas){ this.fristName = menuList[m].name; this.secondName = menuList[m].children[0].name; this.secondLevel = menuList[m]; this.threeLevel = menuList[m].children[0]; this.levelDepth = 2; } else { this.fristName = menuList[m].name; this.secondLevel = {}; this.threeLevel = menuList[m]; this.levelDepth = 3; } } } }, // 一级菜单选择 changeLevelFrist: function(data) { var that = this; var menuList=this.menuList; for(var m in menuList){ if (menuList[m].name == data.name) { // 如果一级下面有二级 var isHas=false; if(menuList[m].children.length){ for(var n in menuList[m].children){ if(menuList[m].children[n].children.length){ isHas=true } } } if(isHas){ this.fristName = menuList[m].name; this.secondName = menuList[m].children[0].name; this.secondLevel = menuList[m]; this.threeLevel = menuList[m].children[0]; this.levelDepth = 2; } else { this.fristName = menuList[m].name; this.secondName = menuList[m].name; this.secondLevel = {}; this.threeLevel = menuList[m]; this.levelDepth = 3; } } } }, // 二级菜单选择 changeLevelSecond: function(data) { var that = this; var menuList=this.secondLevel.children; for(var m in menuList){ if (menuList[m].name == data.name) { this.threeLevel = menuList[m]; this.secondName = menuList[m].name; this.levelDepth = 3; } } }, // 三级点击 changeLevelThree: function(data) {}, //返回上一层 headleBack: function() { if (this.levelDepth >= 2) { if(!this.secondLevel.name){ this.levelDepth=1; }else{ this.levelDepth-- } } }, // 关闭 headleClose: function() { this.levelDepth = 1; }, /** * 加载并初始化数据 */ initMenuList:function() { var that = this; $.ajax({ type: "GET", url: 'https://hbyd.pro.tokeys.com/ydMenu/getTree', success: function(res) { if (res.length) { for(var m in res){ res[m].children = res[m].children || [] for(var n in res[m].children){ res[m].children[n].children = res[m].children[n].children || [] } } console.log(JSON.stringify(res)) that.menuList = res; that.secondLevel = that.menuList[0]; that.threeLevel = that.menuList[0].children[0]; that.fristName = that.menuList[0].name; that.secondName = that.menuList[0].children[0].name; } }, error: function(err) { } }) }, } }); //移动端展开nav $('#navToggle').on('click', function() { $(".dz_content").removeClass("displayNone"); vmm.setNavMenu() }) $(document).on('mouseenter', '.pc_navs_menu .levelFristNav', function(e) { $(".dz_content").removeClass("displayNone"); vmm.setNavMenu((e.target.innerText).trim()) }).on('mouseout', '.pc_navs_menu .levelFristNav', function(e) { $(".dz_content").addClass("displayNone"); }) });