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: '唯一账号密码:admin!!!', buttons: [ { text: '确定', type: 'button-calm', }, ] }); } } }]) //主页面控制器 starter.controller('homeCtrl',["$scope",'$http','$timeout','$ionicLoading','$state','$ionicPopup','config',function($scope,$http,$timeout,$ionicLoading,$state,$ionicPopup,config){ $http({ method:'get', url:config.server+'/list', }).success(function(newItem){ $scope.excals = newItem }) $scope.doRefresh = function(){ $ionicLoading.show({ template: '加载中...', }); $http({ method:'get', url:config.server+'/list', }).success(function(newItem){ $timeout(function(){ $ionicLoading.hide(); $scope.excals = newItem }); }).error(function(){ $timeout(function(){ $ionicLoading.hide(); var alertPopup = $ionicPopup.alert({ title: '连接超时', buttons: [ { text: '确定', type: 'button-calm', }, ] }); }) }) .finally(function() { $scope.$broadcast('scroll.refreshComplete'); }); } $scope.getName = function(name){ $state.go('show',{item:name}); } }]) //数据展示控制器 starter.controller('showCtrl',["$scope",'$ionicHistory','$state','$timeout','$stateParams','$http','$ionicLoading','$ionicPopup','config',function($scope,$ionicHistory,$state,$timeout,$stateParams,$http,$ionicLoading,$ionicPopup,config){ $scope.$on('$ionicView.beforeEnter', function () { $http({ method:'get', url:config.server+'/list', }).success(function(newItem){ $scope.excels = newItem }) name = $stateParams.item; $scope.name = name; $ionicLoading.show({ template: '加载中...', }); $http({ method:'get', url:config.server+'/data/'+name }).success(function(req){ $timeout(function() { $ionicLoading.hide(); //主页参数 $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); // var Stat = G2.Stat; // var vvvdata = []; // // for(var i = 0; i <= 20; i ++) { // // for(var j = 0; j <= 20; j ++) { // // var x = i*25.6; // // var y = j*19.2; // // var z = 700-(x+0.5*y)+Math.random()*(400); // // console.log(x); // // console.log(y); // // console.log(z); // // // // } // // } // var data1 = $scope.a; // var data2 = $scope.b; // var data3 = $scope.c; // for(var i=0;i<=212;i++){ // var x = data1[i]; // var y = data2[i]; // var z = data3[i]; // vvvdata.push({ // l:x, // g: y, // Altitude:z // }); // console.log(x+'x') // console.log(y+'y') // console.log(z+'z') // } // var chart = new G2.Chart({ // id: 'c1', // forceFit: true, // height: 1000 // }); // //为了将数据与图片上的位置完全吻合,我们需要将横轴和纵轴的范围设定为数据对应范围,并将范围优化处理关闭 // var defs = { // 'l': { // type: 'linear', // min: 2735, // max: 2900, // nice: false//优化处理关闭 // }, // 'g': { // type: 'linear', // min: 0, // max: 2, // nice: false // }, // 'Altitude': { // tickCount:5 // } // }; // chart.source(vvvdata,defs); // chart.contour().position(Stat.smooth.loess.triangular('l*g*Altitude',0.01)).color('Altitude','hue').size(3); // chart.render(); // document.getElementById('newchats').style.display='none'; }); }).error(function(){ $timeout(function(){ $ionicLoading.hide(); var alertPopup = $ionicPopup.alert({ title: '连接超时', buttons: [ { text: '确定', type: 'button-calm', }, ] }); }) }) }); $scope.change = function(selectedName){ $scope.name = selectedName; $ionicLoading.show({ template: '加载中...', }); $http({ method:'get', url:config.server+'/data/'+selectedName }).success(function(req){ $ionicLoading.hide(); $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]; }); }).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:'23%' }, //图例 legend: { data: $scope.legend1, textStyle:{ fontSize:22 } }, // 横轴坐标轴 xAxis: [ { type: 'category', // boundaryGap:false, axisLabel:{ textStyle:{ fontSize:20 }, formatter: '{value} rpm' }, data: $scope.item1 } ], // 纵轴坐标轴 yAxis: [ { type: 'value', // name: '扭\n矩\n(N*m)', min: 0, max: 4, position: 'left', offset:205, axisLine: { lineStyle: { color: colors[0], width:2 } }, axisLabel:{ margin:20, textStyle:{ fontSize:18 } } }, { type: 'value', // name: '电\n压\n(V)', min: 193, max: 202, position: 'left', offset: 150, axisLine: { lineStyle: { color: colors[1], width:2 } }, axisLabel:{ margin:15, textStyle:{ fontSize:18 } }, }, { type: 'value', // name: '输\n入\n功\n率\n(W)', min: 0, max: 1300, position: 'left', offset:90, axisLine: { lineStyle: { color: colors[2], width:2 } }, axisLabel:{ textStyle:{ fontSize:18 } }, }, { type: 'value', // name: '电\n流\n(A)', min: 1, max: 6, position: 'left', offset:45, axisLine: { lineStyle: { color: colors[3], width:2 } }, axisLabel:{ margin:20, textStyle:{ fontSize:18 } }, }, { type: 'value', // name: '效\n率\n(%)', min: 10, max: 80, position: 'left', offset:0, axisLine: { lineStyle: { color: colors[4], width:2 } }, axisLabel:{ margin:15, textStyle:{ fontSize:18 } }, } ], // 数据内容数组 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:'26%' }, //图例 legend: { data: $scope.legend2, textStyle:{ fontSize:22 } }, // toolbox: { // feature: { // dataView: {show: true, readOnly: false}, // restore: {show: true}, // saveAsImage: {show: true} // } // }, // 横轴坐标轴 xAxis: [ { type: 'category', // boundaryGap:false, axisLabel:{ textStyle:{ fontSize:20 }, formatter: '{value} N*m' }, data: $scope.item2 } ], // 纵轴坐标轴 yAxis: [ { type: 'value', // name: '功率因素', min: 0.27, max: 0.7, position: 'left', offset:225, axisLine: { lineStyle: { color: colors[0], width:2 } }, axisLabel:{ margin:20, textStyle:{ fontSize:18 } } }, { type: 'value', // name: '电\n压\n(V)', min: 130, max: 630, position: 'left', offset: 170, axisLine: { lineStyle: { color: colors[1], width:2 } }, axisLabel:{ margin:15, textStyle:{ fontSize:18 } }, }, { type: 'value', // name: '输\n入\n功\n率\n(W)', min: 64, max: 77, position: 'left', offset:125, axisLine: { lineStyle: { color: colors[2], width:2 } }, axisLabel:{ textStyle:{ fontSize:18 } }, }, { type: 'value', // name: '电\n流\n(A)', min: 2600, max: 2940, position: 'left', offset:50, axisLine: { lineStyle: { color: colors[3], width:2 } }, axisLabel:{ margin:20, textStyle:{ fontSize:18 } }, }, { type: 'value', // name: '效\n率\n(%)', min: 1.3, max: 2.3, position: 'left', offset:0, axisLine: { lineStyle: { color: colors[4], width:2 } }, axisLabel:{ margin:15, textStyle:{ fontSize:18 } }, } ], // 数据内容数组 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:'23%' }, //图例 legend: { data: $scope.legend3, textStyle:{ fontSize:22 } }, // 横轴坐标轴 xAxis: [ { type: 'category', // boundaryGap:false, axisLabel:{ textStyle:{ fontSize:20 }, formatter: '{value} rpm' }, data: $scope.item3 } ], // 纵轴坐标轴 yAxis: [ { type: 'value', // name: '扭\n矩\n(N*m)', min: 0, max: 4, position: 'left', offset:205, axisLine: { lineStyle: { color: colors[0], width:2 } }, axisLabel:{ margin:20, textStyle:{ fontSize:18 } } }, { type: 'value', // name: '电\n压\n(V)', min: 193, max: 202, position: 'left', offset: 150, axisLine: { lineStyle: { color: colors[1], width:2 } }, axisLabel:{ margin:15, textStyle:{ fontSize:18 } }, }, { type: 'value', // name: '输\n入\n功\n率\n(W)', min: 0, max: 1300, position: 'left', offset:90, axisLine: { lineStyle: { color: colors[2], width:2 } }, axisLabel:{ textStyle:{ fontSize:18 } }, }, { type: 'value', // name: '电\n流\n(A)', min: 1, max: 6, position: 'left', offset:45, axisLine: { lineStyle: { color: colors[3], width:2 } }, axisLabel:{ margin:20, textStyle:{ fontSize:18 } }, }, { type: 'value', // name: '效\n率\n(%)', min: 10, max: 80, position: 'left', offset:0, axisLine: { lineStyle: { color: colors[4], width:2 } }, axisLabel:{ margin:15, textStyle:{ fontSize:18 } }, } ], // 数据内容数组 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); } }; })