123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718 |
- 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: '<b>确定</b>',
- 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: '<b>确定</b>',
- 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: '<b>确定</b>',
- 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: '<div style="height:300px;"></div>',
- 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: '<div style="height:300px;"></div>',
- 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: '<div style="height:300px;"></div>',
- 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);
- }
- };
- })
|