var starter = angular.module('starter.controllers', []) //登录页面控制器 starter.controller('loginCtrl',["$scope",'$state','$ionicLoading','$timeout','$ionicPopup',function($scope,$state,$ionicLoading,$timeout,$ionicPopup){ $scope.vm = { mobile:'', password:'' }; $scope.login = function(){ if($scope.vm.username == 'admin' && $scope.vm.password == 'admin'){ $ionicLoading.show({ template: '加载中...' }); $timeout(function(){ $ionicLoading.hide(); $state.go('home'); },1500); }else{ var alertPopup = $ionicPopup.alert({ title: '错误!', template: '账号或密码输入错误!', buttons: [ { text: '确定', type: 'button-calm', }, ] }); } } }]) //主页面控制器 starter.controller('homeCtrl',["$scope",'$http','$timeout','$ionicLoading','$state','$ionicPopup','config',function($scope,$http,$timeout,$ionicLoading,$state,$ionicPopup,config){ $scope.doRefresh = function(sec){ if($scope.isChecked.checked){ mytimer = $timeout(function() { $scope.doRefresh(sec); }, sec*1000); localStorage.refreshtime=sec; }else{ $timeout.cancel(mytimer); localStorage.refreshtime=0; } console.log(mytimer); $scope.refresh(); } $scope.refresh = function(){ $ionicLoading.show({ template: '加载中...', }); $http({ method:'get', url:config.server+'/list', }).success(function(newItems){ $timeout(function(){ $scope.excals = newItems $ionicLoading.hide(); }); }).error(function(){ $timeout(function(){ $ionicLoading.hide(); var alertPopup = $ionicPopup.alert({ title: '连接超时', buttons: [ { text: '确定', type: 'button-calm', }, ] }); }) }) .finally(function() { $scope.$broadcast('scroll.refreshComplete'); }); } var mytimer; $scope.$on('$ionicView.beforeEnter', function () { $scope.refreshtime = 5; $scope.isChecked = { checked: localStorage.refreshtime!=0?true:false }; if(localStorage.refreshtime!=0){ $scope.refreshtime = localStorage.refreshtime; $timeout.cancel(mytimer); $scope.doRefresh(localStorage.refreshtime); }else{ $scope.refresh(); } }); $scope.$on('$ionicView.beforeLeave', function () { console.log(mytimer); $timeout.cancel(mytimer); }); $scope.getName = function(name){ $state.go('show',{item:name}); } $scope.blur = function(sec){ if($scope.isChecked.checked){ localStorage.refreshtime=sec; }else{ localStorage.refreshtime=0; } } }]) //数据展示控制器 starter.controller('showCtrl',["$scope",'$ionicHistory','$state','$timeout','$stateParams','$http','$ionicLoading','$ionicPopup','config',function($scope,$ionicHistory,$state,$timeout,$stateParams,$http,$ionicLoading,$ionicPopup,config){ var newtimer; $scope.$on('$ionicView.beforeEnter', function () { name = $stateParams.item; $scope.name = name; $scope.doSelected(name); }); $scope.$on('$ionicView.beforeLeave', function () { $timeout.cancel(newtimer); }); $scope.change = function(name){ $timeout.cancel(mytimer); $scope.name = name; $scope.doSelected(name); } $scope.doSelected = function(name){ if(localStorage.refreshtime!=0){ newtimer = $timeout(function() { $http({ method:'get', url:config.server+'/list', }).success(function(newItems){ if(newItems.length>0&&name) $scope.doSelected(newItems[newItems.length-1]); }) }, localStorage.refreshtime*1000); }else{ $scope.selectedName(name); $timeout.cancel(mytimer); } $scope.selectedName(name); } $scope.selectedName = function(name){ $scope.name = name; $ionicLoading.show({ template: '加载中...', }); $http({ method:'get', url:config.server+'/data/'+name }).success(function(req){ // $timeout(function() { //主页参数 $scope.table1 = req.t.t1; $scope.table2 = req.t.t2; $scope.table3 = req.t.t3; $scope.table4 = req.t.t4; //tn曲线图参数 $scope.item1= req.speed; $scope.data2 = [req.torque,req.v,req.p,req.a,req.efficiency]; //五轴图参数 $scope.item2 = req.nj; $scope.data3 = [req.glys,req.ssgl,req.xl,req.zs,req.dl]; //效率云图 $scope.item3= req.n_speed; $scope.data4 = [req.n_torque,req.n_v,req.n_p,req.n_a,req.n_efficiency]; // console.log(req.n_speed); // console.log($scope.data4); // }); $ionicLoading.hide(); }).error(function(){ // $timeout(function(){ $ionicLoading.hide(); var alertPopup = $ionicPopup.alert({ title: '连接超时', buttons: [ { text: '确定', type: 'button-calm', }, ] }); // }) }); } $scope.tabs = [ {"title":"主页","url":"line.html"}, {"title":"TN曲线","url":"tn.html"}, {"title":"自动测试","url":"zhou.html"}, {"title":"耐久测试","url":"strom.html"}]; $scope.currentTab = 'line.html'; $scope.go = function(result){ $state.go(result) }; $scope.isActiveTab = function(tabUrl){ return tabUrl == $scope.currentTab; }; $scope.onClickTab = function(tab){ // if(tab.url=="strom.html"){ // document.getElementById('newchats').style.display='block'; // }else{ // document.getElementById('newchats').style.display='none'; // } $scope.currentTab = tab.url; }; //TN曲线图 $scope.legend1 = ["扭矩", "电压",'输入功率','电流','效率']; $scope.legend2 = ["功率因素", "输入功率",'效率','转速','电流']; $scope.legend3 = ["扭矩", "电压",'输入功率','电流','效率']; $scope.num = [0,1,2,3,4]; }]) starter.filter('filet', function () { return function (filepath) { if(filepath){ var pos = filepath.replace(".xlsx", ""); return pos; } }; }) starter.directive('main', function() { return { scope: { id: "@", legend1: "=", item1: "=", num:"=", data2: "=" }, restrict: 'E', template: '
', replace: true, link: function($scope, element, attrs, controller) { var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a']; var option = { color:colors, // 提示框,鼠标悬浮交互时的信息提示 tooltip: { show: true, trigger: 'axis' }, grid:{ left:'43%', right:'1%' }, //图例 legend: { top:15, data: $scope.legend1, textStyle:{ fontSize:12 } }, // 横轴坐标轴 xAxis: [ { type: 'category', // boundaryGap:false, axisLabel:{ textStyle:{ fontSize:12 }, formatter: '{value} rpm' }, data: $scope.item1 } ], // 纵轴坐标轴 yAxis: [ { type: 'value', // name: '扭\n矩\n(N*m)', min: 0, max: 4, position: 'left', offset:135, axisLine: { lineStyle: { color: colors[0], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } } }, { type: 'value', // name: '电\n压\n(V)', min: 193, max: 202, position: 'left', offset: 100, axisLine: { lineStyle: { color: colors[1], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, }, { type: 'value', // name: '输\n入\n功\n率\n(W)', min: 0, max: 1300, position: 'left', offset:57, axisLine: { lineStyle: { color: colors[2], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, }, { type: 'value', // name: '电\n流\n(A)', min: 1, max: 6, position: 'left', offset:35, axisLine: { lineStyle: { color: colors[3], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, }, { type: 'value', // name: '效\n率\n(%)', min: 10, max: 80, position: 'left', offset:0, axisLine: { lineStyle: { color: colors[4], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, } ], // 数据内容数组 series: function(){ var serie=[]; for(var i=0;i<$scope.legend1.length;i++){ var item1 = { name : $scope.legend1[i], type: 'line', yAxisIndex:$scope.num[i], data: $scope.data2[i] }; serie.push(item1); } return serie; }() }; var myChart = echarts.init(document.getElementById($scope.id),'macarons'); myChart.setOption(option); } }; }) starter.directive('line', function() { return { scope: { id: "@", legend2: "=", item2: "=", num:"=", data3: "=" }, restrict: 'E', template: '', replace: true, link: function($scope, element, attrs, controller) { var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a']; var option = { color:colors, // 提示框,鼠标悬浮交互时的信息提示 tooltip: { show: true, trigger: 'axis' }, grid:{ left:'50%', right:'1%' }, //图例 legend: { top:15, data: $scope.legend2, textStyle:{ fontSize:12 } }, // toolbox: { // feature: { // dataView: {show: true, readOnly: false}, // restore: {show: true}, // saveAsImage: {show: true} // } // }, // 横轴坐标轴 xAxis: [ { type: 'category', // boundaryGap:false, axisLabel:{ textStyle:{ fontSize:12 }, formatter: '{value} N*m' }, data: $scope.item2 } ], // 纵轴坐标轴 yAxis: [ { type: 'value', // name: '功率因素', min: 0.27, max: 0.7, position: 'left', offset:150, axisLine: { lineStyle: { color: colors[0], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } } }, { type: 'value', // name: '电\n压\n(V)', min: 130, max: 630, position: 'left', offset: 110, axisLine: { lineStyle: { color: colors[1], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, }, { type: 'value', // name: '输\n入\n功\n率\n(W)', min: 64, max: 77, position: 'left', offset:80, axisLine: { lineStyle: { color: colors[2], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, }, { type: 'value', // name: '电\n流\n(A)', min: 2600, max: 2940, position: 'left', offset:30, axisLine: { lineStyle: { color: colors[3], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, }, { type: 'value', // name: '效\n率\n(%)', min: 1.3, max: 2.3, position: 'left', offset:0, axisLine: { lineStyle: { color: colors[4], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, } ], // 数据内容数组 series: function(){ var serie=[]; for(var i=0;i<$scope.legend2.length;i++){ var item2 = { name : $scope.legend2[i], type: 'line', yAxisIndex:$scope.num[i], data: $scope.data3[i] }; serie.push(item2); } return serie; }() }; var myChart = echarts.init(document.getElementById($scope.id),'macarons'); myChart.setOption(option); } }; }) starter.directive('strom', function() { return { scope: { id: "@", legend3: "=", item3: "=", num:"=", data4: "=" }, restrict: 'E', template: '', replace: true, link: function($scope, element, attrs, controller) { var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a']; var option = { color:colors, // 提示框,鼠标悬浮交互时的信息提示 tooltip: { show: true, trigger: 'axis' }, grid:{ left:'43%', right:'1%' }, //图例 legend: { top:15, data: $scope.legend3, textStyle:{ fontSize:12 } }, // 横轴坐标轴 xAxis: [ { type: 'category', // boundaryGap:false, axisLabel:{ textStyle:{ fontSize:12 }, formatter: '{value} rpm' }, data: $scope.item3 } ], // 纵轴坐标轴 yAxis: [ { type: 'value', // name: '扭\n矩\n(N*m)', position: 'left', offset:125, axisLine: { lineStyle: { color: colors[0], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } } }, { type: 'value', // name: '电\n压\n(V)', position: 'left', offset: 90, axisLine: { lineStyle: { color: colors[1], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, }, { type: 'value', // name: '输\n入\n功\n率\n(W)', position: 'left', offset:50, axisLine: { lineStyle: { color: colors[2], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, }, { type: 'value', // name: '电\n流\n(A)', position: 'left', offset:30, axisLine: { lineStyle: { color: colors[3], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, }, { type: 'value', // name: '效\n率\n(%)', position: 'left', offset:0, axisLine: { lineStyle: { color: colors[4], width:2 } }, axisLabel:{ textStyle:{ fontSize:12 } }, } ], // 数据内容数组 series: function(){ var serie=[]; for(var i=0;i<$scope.legend3.length;i++){ var item3 = { name : $scope.legend3[i], type: 'line', yAxisIndex:$scope.num[i], data: $scope.data4[i] }; serie.push(item3); } return serie; }() }; var myChart = echarts.init(document.getElementById($scope.id),'macarons'); myChart.setOption(option); } }; })