app.js 9.87 KB
Newer Older
manxiaoqiang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
(function(){
	angular.module("app")
	.controller("indexCtrl",["$rootScope","$scope","HttpService","ToolService","UtilService","$state","$location","DateService","$timeout",indexCtrl]);


	function indexCtrl($rootScope,$scope,HttpService,ToolService,UtilService,$state,$location,DateService,$timeout){

        $rootScope.unfoldFlag = $rootScope.unfoldFlag==undefined?false:$rootScope.unfoldFlag;
        $scope.queryLimit = function(appid){
            if(angular.isDefined(appid)){
                limitPM = HttpService.getInfo("login/limit/"+appid);
            }
            else{
                limitPM = HttpService.getInfo("login/limit");
            }

            limitPM.then(function(data){
                $rootScope.limitInfo = data;
                UtilService.setItem("limitInfo",JSON.stringify($rootScope.limitInfo));
            });
        }

        $rootScope.demoU = ToolService.isDemoUser();
        $scope.goLogin = function(){
            window.location.href = "/login.html";
        }

				//msgflag=1,新建app刷list
        $scope.queryApp = function(msgflag){
					var appPM = HttpService.getInfo("app/findall");
					appPM.then(function(data){
						$scope.appAlllistInfo = data;
						$scope.applistInfo = data.filter(function(item){
								return item.isDebug!=true;
						});

						if(msgflag==1){return false;}

						var lastId = UtilService.getCookie("ryioLastApp");
            var demoapk = UtilService.getCookie("ryioDemoapk");
            UtilService.setCookie("ryioDemoapk","");
						if($scope.applistInfo.length > 0){
							if(UtilService.isNullStr(lastId)){
								lastId = "-1";
							}
							lastId = Number(lastId);
							var apps = $scope.applistInfo.filter(function(item){
                    if(!UtilService.isNullStr(demoapk)){
                        return item.appkey == demoapk;
                    }
                    else{
                        return item.id == lastId;
                    }
									});
									if(apps.length == 0){
										lastId = $scope.applistInfo[0].id;
									}
                else{
                    lastId = apps[0].id;
                }
                if($scope.appidInit == lastId){
                    $scope.appfresh = ++rmd;
                }else{
                    $scope.appidInit = lastId;
                }
                for(i=0; i < $scope.applistInfo.length; i++){
                    if($scope.applistInfo[i].id == $scope.appidInit){
                        $scope.appkey = $scope.applistInfo[i].appkey;
                    }
                }
					}
					else{
						if($rootScope.isSuper || $rootScope.isManage || $rootScope.isAppManage){
							$state.go("collect.app");
						}
	          else{
	              $scope.goLogin();
	          }
					}
			});
		};

		$scope.$on('f5Applist',function(e,msg){
			$scope.queryApp(msg);
		});

    $rootScope.webHideMenus = [];
		$scope.$on("appid",function(e,msg){
        $rootScope.appInstance = msg.info;
        $scope.platform = msg.info.platform;
        $rootScope.isandroid = $scope.platform == 'Android';
        $rootScope.isios = $scope.platform == 'iOS';
        $rootScope.isweb = $scope.platform == 'H5';

				var path = $location.$$path,idx = path.indexOf("Detail");
				if(path.indexOf('appDetail')>-1){return false;}

				if(idx>-1){
					$scope.appid = undefined;
					$location.path(path.substring(0,idx));
				}
        else if($rootScope.isweb && $rootScope.webHideMenus.indexOf($rootScope.pagePath)>-1){
            $scope.appid = undefined;
            $location.path($rootScope.firstMeau);
        }

				if($rootScope.pagePath == '' || $rootScope.pagePath == 'collect'
                    || (!$rootScope.isSuper && $rootScope.curRoleAuth && !$scope.hasTheMenu($rootScope.pagePath)))
				{
					$scope.appid = undefined;
					$location.path($rootScope.firstMeau);
				}

        $rootScope.appid = $scope.appid = msg.info.id;
				UtilService.setCookie("ryioLastApp",$scope.appid,7);
		});

    $scope.goToCustom = function(id,name){
        $location.path("/collect/custommenu/"+id);
        $rootScope.custID = id;
    }
    $scope.gotoCustonMenu = function(menuId){
        var url = $state.href('collect.custommenu');
        window.open(url+'/'+menuId,'_blank');
    }
		var rmd = new Date().getTime();
		$scope.$on("mngappTo",function(e,msg){
			if($scope.appid == msg){return false;}
			if($scope.appidInit == msg){
				$scope.appfresh = ++rmd;
			}else{
				$scope.appidInit = msg;
			}
		});

yangfangfang committed
136 137 138 139
		var uuser = ToolService.getUser();
    $scope.loginuserName = uuser.email;
		$scope.currentAccountId = uuser.id;
    $scope.userPastDate = uuser.pastDate;
manxiaoqiang committed
140 141 142 143 144

			$scope.errorBack = function(msg){
				ToolService.showTips(msg);
			};

yangfangfang committed
145
				var rmdId = UtilService.randRangeId(),auid = ToolService.getUser().id;
manxiaoqiang committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

				$scope.goPage = function(ui){
						$rootScope.channeluniqueName = 'normal';
			      if(ui == 'home'){
							ui = $rootScope.firstMeau;
							ui = ui.substring(1).replace("/",".");
						}

			      if(ui == 'collect.custommenu'){
			          $rootScope.custID = "";
			      }
						var mmenu = ui.substring(ui.indexOf('.')+1);
			      if(mmenu == 'channel'){
			          $rootScope.channeluniqueName = "normal";
			      }
			      if($state.current && $state.current.name == ui){
			          $state.reload(ui,{pageid:null});
			      }else{
			          $state.go(ui,{pageid:null});
			      }
				}
yangfangfang committed
167

yangfangfang committed
168
				$rootScope.noLeftMenus = ["userinfo","nopower","auth","app","product"];
manxiaoqiang committed
169 170
        $scope.resizeStyle = function(){
            var mleft = '0px';
yangfangfang committed
171 172 173
            if($rootScope.noLeftMenus.indexOf($rootScope.pagePath) == -1){
			        mleft = $rootScope.unfoldFlag ? '40px' : '186px';
			      }
manxiaoqiang committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
            $(".conditionAlpha").css('left',mleft);
            $rootScope.panelw = $(window).width()-mleft.slice(0,-2)-84;
            return {'margin-left':mleft};
        }
        $scope.toggleMenu = function(){
            $rootScope.unfoldFlag = !$rootScope.unfoldFlag;
            UtilService.setCookie("unfoldFlag",$rootScope.unfoldFlag);

            $scope.$broadcast("conentresize",true);
        }

        $rootScope.showSubMenus = function(mainMenu){
            if($scope.channelAlert){
                return false;
            }
            if(mainMenu!='management' && $scope.applistInfo && $scope.applistInfo.length == 0){
                if($scope.appAlllistInfo.length > 0){
                    ToolService.showTips("请先完成"+$scope.appAlllistInfo[0].name+"的数据调试");
                }
                else{
                    ToolService.showTips("请先创建应用");
                }
                return false;
            }
            $rootScope.mainMenu = mainMenu;
            var first = "";
            if(mainMenu=='behavior'){
								first = "/collect/"+$rootScope.mainMenus.behavior[0];
						}else if(mainMenu=='export'){
								first = "/collect/"+$rootScope.mainMenus.dataexport[$rootScope.isweb?1:0];
						}else{
								first = "/manage/"+$rootScope.mainMenus.manage[0];
						}
						$location.path(first);
        }
        $rootScope.showMenu = function(name,flag){
            if(name == null){
                name = $scope.pagePath;
            }
            if($scope.isweb && $scope.webHideMenus.indexOf(name)>-1){
                return false;
            }
            if($rootScope.isSuper || $rootScope.isManage || $rootScope.isAppManage){
                return true;
            }
        }
        $rootScope.hasEditPower = function(){
            return $rootScope.showMenu(null,2);
        }

        $scope.formTipMsg = "信息没填全或数据格式有误,请检查";

        $rootScope.$watch("pagePath+isweb",function(n){
          n = $scope.pagePath;
        	if(angular.isDefined(n) && n!='' && n!= "product"){
              var tipPM = HttpService.getInfo("tip/"+n, {});
	        		tipPM.then(function(data){
	        			$rootScope.currentPageTips = data;
	        		},function(data){
	        			$rootScope.currentPageTips = {};
	        		});
        	}
        	else{
        		$rootScope.currentPageTips = {};
        	}
        });

        $scope.userLogout = function(){
        	var lgPM = HttpService.getInfo("login/logout", {});
	    		lgPM.then(function(data){
	    			HttpService.logOutCookie();
	    		});
				}


        $scope.initpage = function(){
            $scope.queryLimit();
            $scope.queryApp();
        }

        var lpath = $location.path();
        if(lpath!='/active/product'){
            $scope.initpage();
        }
        //判断是否需要向后台发送请求检测名称重复
        $scope.judgeNameChange = function(oldname,newname){
            if(!UtilService.isNullStr(newname)  && (oldname !='' && newname !=''  && angular.lowercase(oldname) != angular.lowercase(newname) || (oldname=='' && newname!=''))){
                return true;
            }
            else{
                return false;
            }
        }

yangfangfang committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
				//提示框
        $scope.closeFlow = function(type){
            if($rootScope.pastLong < 0){
                $scope.userLogout();
            }
            else if($scope.behaviorAuth  && $rootScope.ioPercentRel <= -0.05 && !$rootScope.flowRestrict){
                $scope.userLogout();
            }

            $scope.flowKnow = true;
						UtilService.setCookie("ryioRedCircle",true,7);

            if(type == 'ioAlert'){
                $scope.ioAlert = false;
            }
            else if(type == 'ioDateAlert'){
                $scope.ioDateAlert = false;
            }
        }

yangfangfang committed
288 289 290 291 292 293 294 295 296 297 298
				$rootScope.menuSubmitData = function(submenu){
            ToolService.getMenuSubmitData(submenu);
        }
        $rootScope.operSubmitData = function(opername){
            ToolService.getOperSubmitData(opername);
        }
        $rootScope.$watch("thirdtab",function(n){
            if(angular.isDefined(n)){
                ToolService.getMenuSubmitData(n);
            }
        });
yangfangfang committed
299

manxiaoqiang committed
300 301 302
        $scope.pwdPlacehold = "仅支持数字,大小写字母,且至少包含其中2种,长度限制为6-18位";
	}
})();