Chinaunix首页 | 论坛 | 博客
  • 博客访问: 96262
  • 博文数量: 20
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 202
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-07 01:56
个人简介

数据库技术爱好者

文章分类

全部博文(20)

文章存档

2016年(11)

2015年(9)

我的朋友

分类: JavaScript

2016-10-09 22:55:29


点击(此处)折叠或打开

  1. //定义模块
  2. var myAppModule = angular.module('myApp',[]);
  3. myAppModule.controller('historyController',function($scope,$http){
  4.     var url = '/MaWeb/data/data.txt';
  5.     $http.get(url).success(function(data,status,headers,config){
  6.         var dataArr = data.split('\n');
  7.         $scope.histroyList = [];
  8.         for(var i = 0;i<dataArr.length;i++){
  9.             var ball = dataArr[i].split(',');
  10.             var item = {};
  11.             item['firstBall']=ball[0];
  12.             item['sencondBall']=ball[1];
  13.             item['thirdBall']=ball[2];
  14.             item['fifthBall']=ball[3];
  15.             item['fifthBall']=ball[4];
  16.             item['sixBall']=ball[5];
  17.             item['blueBall']=ball[6];
  18.             $scope.histroyList[i]=item;
  19.         }        
  20.     });
  21.     
  22.    $scope.redList = [];
  23.    for(var i = 0;i<33;i++){
  24.      $scope.redList[i] = i+1;
  25.    };
  26.    $scope.blueList = [];
  27.    for(var i = 0;i<16;i++){
  28.      $scope.blueList[i] = i+1;
  29.    };
  30.    $scope.isSelected =function(num,item,type){
  31.      for(v in item){
  32.          if(type==='redBall'){
  33.              if(num == item[v]&&v!='blueBall'){
  34.                  return true;
  35.              }
  36.          }else if(type==='blueBall'){
  37.              if(num == item[v]&&v=='blueBall'){
  38.                  return true;
  39.              }
  40.          }
  41.         
  42.      }
  43.    };
  44.    
  45. });
  46. myAppModule.controller('chooseController',function($scope,$interval){
  47.      $scope.balls = {};
  48.      $scope.next = 1;
  49.      $scope.whichBall = '';
  50.      $scope.isStart = false;
  51.      $scope.start =function(){
  52.          $scope.balls = {};
  53.          $scope.isStart = true ;
  54.          $scope.next =1;
  55.          $scope.whichBall = 'redBall'+ $scope.next;
  56.          $scope.next++;
  57.      };
  58.      function in_obj(value,obj){
  59.          for(v in obj){
  60.              if(obj[v]==value){
  61.                  return true;
  62.              }
  63.          }
  64.          return false;
  65.      }
  66.      var calcBall = function(ball,maxValue,time){
  67.          $scope.balls[ball] = 0;
  68.          $scope.isReady = 0;
  69.          var updateball = function(){
  70.              var num = Math.floor(Math.random(0,1)*maxValue)+1;
  71.              if($scope.next<8&&!in_obj(num,$scope.balls)){
  72.                  $scope.balls[ball] = num;
  73.              }else if($scope.next==8){
  74.                  $scope.balls[ball] = num;
  75.              }
  76.              if($scope.isReady>=time){
  77.                  $interval.cancel($scope.intval);
  78.              }
  79.          }
  80.          //使用promise模式
  81.          $scope.intval = $interval(function(){
  82.              updateball();
  83.           },100);
  84.          $scope.intval.then(
  85.              function(){
  86.           console.log('HI CHANGXIN');
  87.      },
  88.      function(){
  89.      console.log('error!');
  90.      $scope.whichBall = 'redBall'+$scope.next;
  91.                   if($scope.next==8){
  92.                       $scope.isStart = false;
  93.                   }
  94.                   $scope.next++;
  95.      },
  96.      function(){
  97.      console.log('HI LVTU');
  98.      $scope.isReady =$scope.isReady+100;
  99.      }
  100.            );
  101.          updateball();
  102.      }
  103.     
  104.      function watchFn(newValue,oldValue,scope){
  105.          if(newValue!=''){
  106.              if(newValue.substring(7)<7){
  107.                  calcBall(newValue,33,2000);
  108.              }else if (newValue.substring(7)==7){
  109.                  calcBall(newValue,16,2000);
  110.              }
  111.             
  112.          }
  113.      }
  114.      //deepWatch
  115.      $scope.$watch('whichBall',watchFn);
  116. });

阅读(1128) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~