wuxw
2019-05-08 035539b4e23f36b10dfba16fec01f26d3c629e29
WebService/src/main/resources/components/nav/nav.js
@@ -7,8 +7,15 @@
        data:{
            nav:{},
            userName:"",
            navCommunityInfo:{
                _currentCommunity:{
                },
                communityInfos:[]
            }
        },
        mounted:function(){
            this.getNavCommunity();
            this.getNavData();
            this.getUserInfo();
        },
@@ -70,6 +77,48 @@
                                console.log('请求失败处理');
                             }
                           );
            },
            getNavCommunity:function(){
                var _tmpCurrentCommunity = vc.getCurrentCommunity();
                //浏览器缓存中能获取到
                if(_tmpCurrentCommunity != null && _tmpCurrentCommunity != undefined){
                    this.navCommunityInfo._currentCommunity = _tmpCurrentCommunity;
                    this.navCommunityInfo.communityInfos = vc.getCommunitys();
                    return ;
                }
                //说明缓存中没有数据
                //发送get请求
                /**
                    [{community:"123123",name:"测试1小区"},{community:"223123",name:"测试2小区"}]
                **/
               vc.http.get('nav',
                            'getCommunitys',
                             '',
                             function(json,res){
                                if(res.status == 200){
                                    vm.navCommunityInfo.communityInfos = JSON.parse(json);
                                    if(vm.navCommunityInfo.communityInfos == null || vm.navCommunityInfo.communityInfos.length == 0){
                                          vm.navCommunityInfo._currentCommunity ={
                                                name:"还没有入驻小区"
                                          };
                                          return;
                                    }
                                    vm.navCommunityInfo._currentCommunity = vm.navCommunityInfo.communityInfos[0];
                                    vc.setCurrentCommunity(vm.navCommunityInfo._currentCommunity);
                                    vc.setCommunitys(vm.navCommunityInfo.communityInfos);
                               }
                             },function(){
                                console.log('请求失败处理');
                             }
                           );
            },
            changeCommunity:function(_community){
                 vc.setCurrentCommunity(_community);
            }
        }