controllers.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. var starter = angular.module('starter.controllers', [])
  2. //登录页面控制器
  3. starter.controller('loginCtrl',["$scope",'$state','$ionicLoading','$timeout','$ionicPopup',function($scope,$state,$ionicLoading,$timeout,$ionicPopup){
  4. $scope.vm = {
  5. mobile:'',
  6. password:''
  7. };
  8. $scope.login = function(){
  9. if($scope.vm.username == 'admin' && $scope.vm.password == 'admin'){
  10. $ionicLoading.show({
  11. template: '加载中...'
  12. });
  13. $timeout(function(){
  14. $ionicLoading.hide();
  15. $state.go('home');
  16. },1500);
  17. }else{
  18. var alertPopup = $ionicPopup.alert({
  19. title: '错误!',
  20. template: '账号或密码输入错误!',
  21. buttons: [
  22. {
  23. text: '<b>确定</b>',
  24. type: 'button-calm',
  25. },
  26. ]
  27. });
  28. }
  29. }
  30. }])
  31. //主页面控制器
  32. starter.controller('homeCtrl',["$scope",'$http','$timeout','$ionicLoading','$state','$ionicPopup','config',function($scope,$http,$timeout,$ionicLoading,$state,$ionicPopup,config){
  33. $scope.doRefresh = function(sec){
  34. if($scope.isChecked.checked){
  35. mytimer = $timeout(function() {
  36. $scope.doRefresh(sec);
  37. }, sec*1000);
  38. localStorage.refreshtime=sec;
  39. }else{
  40. $timeout.cancel(mytimer);
  41. localStorage.refreshtime=0;
  42. }
  43. console.log(mytimer);
  44. $scope.refresh();
  45. }
  46. $scope.refresh = function(){
  47. $ionicLoading.show({
  48. template: '加载中...',
  49. });
  50. $http({
  51. method:'get',
  52. url:config.server+'/list',
  53. }).success(function(newItem){
  54. $timeout(function(){
  55. $scope.excals = newItem
  56. $ionicLoading.hide();
  57. });
  58. }).error(function(){
  59. $timeout(function(){
  60. $ionicLoading.hide();
  61. var alertPopup = $ionicPopup.alert({
  62. title: '连接超时',
  63. buttons: [
  64. {
  65. text: '<b>确定</b>',
  66. type: 'button-calm',
  67. },
  68. ]
  69. });
  70. })
  71. })
  72. .finally(function() {
  73. $scope.$broadcast('scroll.refreshComplete');
  74. });
  75. }
  76. var mytimer;
  77. $scope.$on('$ionicView.beforeEnter', function () {
  78. $scope.refreshtime = 5;
  79. $scope.isChecked = { checked: localStorage.refreshtime!=0?true:false };
  80. if(localStorage.refreshtime!=0){
  81. $scope.refreshtime = localStorage.refreshtime;
  82. $timeout.cancel(mytimer);
  83. $scope.doRefresh(localStorage.refreshtime);
  84. }else{
  85. $scope.refresh();
  86. }
  87. });
  88. $scope.$on('$ionicView.beforeLeave', function () {
  89. console.log(mytimer);
  90. $timeout.cancel(mytimer);
  91. });
  92. $scope.getName = function(name){
  93. $state.go('show',{item:name});
  94. }
  95. $scope.blur = function(sec){
  96. if($scope.isChecked.checked){
  97. localStorage.refreshtime=sec;
  98. }else{
  99. localStorage.refreshtime=0;
  100. }
  101. }
  102. }])
  103. //数据展示控制器
  104. starter.controller('showCtrl',["$scope",'$ionicHistory','$state','$timeout','$stateParams','$http','$ionicLoading','$ionicPopup','config',function($scope,$ionicHistory,$state,$timeout,$stateParams,$http,$ionicLoading,$ionicPopup,config){
  105. var newtimer;
  106. $scope.$on('$ionicView.beforeEnter', function () {
  107. name = $stateParams.item;
  108. $scope.name = name;
  109. $scope.doSelected(name);
  110. });
  111. $scope.$on('$ionicView.beforeLeave', function () {
  112. $timeout.cancel(newtimer);
  113. });
  114. $scope.change = function(name){
  115. $timeout.cancel(mytimer);
  116. $scope.name = name;
  117. $scope.doSelected(name);
  118. }
  119. $scope.doSelected = function(name){
  120. if(localStorage.refreshtime!=0){
  121. newtimer = $timeout(function() {
  122. $scope.doSelected(name);
  123. }, localStorage.refreshtime*1000);
  124. }else{
  125. $timeout.cancel(mytimer);
  126. }
  127. $scope.selectedName(name);
  128. }
  129. $scope.selectedName = function(name){
  130. $ionicLoading.show({
  131. template: '加载中...',
  132. });
  133. $http({
  134. method:'get',
  135. url:config.server+'/data/'+name
  136. }).success(function(req){
  137. // $timeout(function() {
  138. //主页参数
  139. $scope.table1 = req.t.t1;
  140. $scope.table2 = req.t.t2;
  141. $scope.table3 = req.t.t3;
  142. $scope.table4 = req.t.t4;
  143. //tn曲线图参数
  144. $scope.item1= req.speed;
  145. $scope.data2 = [req.torque,req.v,req.p,req.a,req.efficiency];
  146. //五轴图参数
  147. $scope.item2 = req.nj;
  148. $scope.data3 = [req.glys,req.ssgl,req.xl,req.zs,req.dl];
  149. //效率云图
  150. $scope.item3= req.n_speed;
  151. $scope.data4 = [req.n_torque,req.n_v,req.n_p,req.n_a,req.n_efficiency];
  152. // console.log(req.n_speed);
  153. // console.log($scope.data4);
  154. // });
  155. $ionicLoading.hide();
  156. }).error(function(){
  157. // $timeout(function(){
  158. $ionicLoading.hide();
  159. var alertPopup = $ionicPopup.alert({
  160. title: '连接超时',
  161. buttons: [
  162. {
  163. text: '<b>确定</b>',
  164. type: 'button-calm',
  165. },
  166. ]
  167. });
  168. // })
  169. });
  170. }
  171. $scope.tabs = [
  172. {"title":"主页","url":"line.html"},
  173. {"title":"TN曲线","url":"tn.html"},
  174. {"title":"自动测试","url":"zhou.html"},
  175. {"title":"耐久测试","url":"strom.html"}];
  176. $scope.currentTab = 'line.html';
  177. $scope.go = function(result){
  178. $state.go(result)
  179. };
  180. $scope.isActiveTab = function(tabUrl){
  181. return tabUrl == $scope.currentTab;
  182. };
  183. $scope.onClickTab = function(tab){
  184. // if(tab.url=="strom.html"){
  185. // document.getElementById('newchats').style.display='block';
  186. // }else{
  187. // document.getElementById('newchats').style.display='none';
  188. // }
  189. $scope.currentTab = tab.url;
  190. };
  191. //TN曲线图
  192. $scope.legend1 = ["扭矩", "电压",'输入功率','电流','效率'];
  193. $scope.legend2 = ["功率因素", "输入功率",'效率','转速','电流'];
  194. $scope.legend3 = ["扭矩", "电压",'输入功率','电流','效率'];
  195. $scope.num = [0,1,2,3,4];
  196. }])
  197. starter.filter('filet', function () {
  198. return function (filepath) {
  199. if(filepath){
  200. var pos = filepath.replace(".xlsx", "");
  201. return pos;
  202. }
  203. };
  204. })
  205. starter.directive('main', function() {
  206. return {
  207. scope: {
  208. id: "@",
  209. legend1: "=",
  210. item1: "=",
  211. num:"=",
  212. data2: "="
  213. },
  214. restrict: 'E',
  215. template: '<div style="height:300px;"></div>',
  216. replace: true,
  217. link: function($scope, element, attrs, controller) {
  218. var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a'];
  219. var option = {
  220. color:colors,
  221. // 提示框,鼠标悬浮交互时的信息提示
  222. tooltip: {
  223. show: true,
  224. trigger: 'axis'
  225. },
  226. grid:{
  227. left:'43%',
  228. right:'1%'
  229. },
  230. //图例
  231. legend: {
  232. top:15,
  233. data: $scope.legend1,
  234. textStyle:{
  235. fontSize:12
  236. }
  237. },
  238. // 横轴坐标轴
  239. xAxis: [
  240. {
  241. type: 'category',
  242. // boundaryGap:false,
  243. axisLabel:{
  244. textStyle:{
  245. fontSize:12
  246. },
  247. formatter: '{value} rpm'
  248. },
  249. data: $scope.item1
  250. }
  251. ],
  252. // 纵轴坐标轴
  253. yAxis: [
  254. {
  255. type: 'value',
  256. // name: '扭\n矩\n(N*m)',
  257. min: 0,
  258. max: 4,
  259. position: 'left',
  260. offset:135,
  261. axisLine: {
  262. lineStyle: {
  263. color: colors[0],
  264. width:2
  265. }
  266. },
  267. axisLabel:{
  268. textStyle:{
  269. fontSize:12
  270. }
  271. }
  272. },
  273. {
  274. type: 'value',
  275. // name: '电\n压\n(V)',
  276. min: 193,
  277. max: 202,
  278. position: 'left',
  279. offset: 100,
  280. axisLine: {
  281. lineStyle: {
  282. color: colors[1],
  283. width:2
  284. }
  285. },
  286. axisLabel:{
  287. textStyle:{
  288. fontSize:12
  289. }
  290. },
  291. },
  292. {
  293. type: 'value',
  294. // name: '输\n入\n功\n率\n(W)',
  295. min: 0,
  296. max: 1300,
  297. position: 'left',
  298. offset:57,
  299. axisLine: {
  300. lineStyle: {
  301. color: colors[2],
  302. width:2
  303. }
  304. },
  305. axisLabel:{
  306. textStyle:{
  307. fontSize:12
  308. }
  309. },
  310. },
  311. {
  312. type: 'value',
  313. // name: '电\n流\n(A)',
  314. min: 1,
  315. max: 6,
  316. position: 'left',
  317. offset:35,
  318. axisLine: {
  319. lineStyle: {
  320. color: colors[3],
  321. width:2
  322. }
  323. },
  324. axisLabel:{
  325. textStyle:{
  326. fontSize:12
  327. }
  328. },
  329. },
  330. {
  331. type: 'value',
  332. // name: '效\n率\n(%)',
  333. min: 10,
  334. max: 80,
  335. position: 'left',
  336. offset:0,
  337. axisLine: {
  338. lineStyle: {
  339. color: colors[4],
  340. width:2
  341. }
  342. },
  343. axisLabel:{
  344. textStyle:{
  345. fontSize:12
  346. }
  347. },
  348. }
  349. ],
  350. // 数据内容数组
  351. series: function(){
  352. var serie=[];
  353. for(var i=0;i<$scope.legend1.length;i++){
  354. var item1 = {
  355. name : $scope.legend1[i],
  356. type: 'line',
  357. yAxisIndex:$scope.num[i],
  358. data: $scope.data2[i]
  359. };
  360. serie.push(item1);
  361. }
  362. return serie;
  363. }()
  364. };
  365. var myChart = echarts.init(document.getElementById($scope.id),'macarons');
  366. myChart.setOption(option);
  367. }
  368. };
  369. })
  370. starter.directive('line', function() {
  371. return {
  372. scope: {
  373. id: "@",
  374. legend2: "=",
  375. item2: "=",
  376. num:"=",
  377. data3: "="
  378. },
  379. restrict: 'E',
  380. template: '<div style="height:300px;"></div>',
  381. replace: true,
  382. link: function($scope, element, attrs, controller) {
  383. var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a'];
  384. var option = {
  385. color:colors,
  386. // 提示框,鼠标悬浮交互时的信息提示
  387. tooltip: {
  388. show: true,
  389. trigger: 'axis'
  390. },
  391. grid:{
  392. left:'50%',
  393. right:'1%'
  394. },
  395. //图例
  396. legend: {
  397. top:15,
  398. data: $scope.legend2,
  399. textStyle:{
  400. fontSize:12
  401. }
  402. },
  403. // toolbox: {
  404. // feature: {
  405. // dataView: {show: true, readOnly: false},
  406. // restore: {show: true},
  407. // saveAsImage: {show: true}
  408. // }
  409. // },
  410. // 横轴坐标轴
  411. xAxis: [
  412. {
  413. type: 'category',
  414. // boundaryGap:false,
  415. axisLabel:{
  416. textStyle:{
  417. fontSize:12
  418. },
  419. formatter: '{value} N*m'
  420. },
  421. data: $scope.item2
  422. }
  423. ],
  424. // 纵轴坐标轴
  425. yAxis: [
  426. {
  427. type: 'value',
  428. // name: '功率因素',
  429. min: 0.27,
  430. max: 0.7,
  431. position: 'left',
  432. offset:150,
  433. axisLine: {
  434. lineStyle: {
  435. color: colors[0],
  436. width:2
  437. }
  438. },
  439. axisLabel:{
  440. textStyle:{
  441. fontSize:12
  442. }
  443. }
  444. },
  445. {
  446. type: 'value',
  447. // name: '电\n压\n(V)',
  448. min: 130,
  449. max: 630,
  450. position: 'left',
  451. offset: 110,
  452. axisLine: {
  453. lineStyle: {
  454. color: colors[1],
  455. width:2
  456. }
  457. },
  458. axisLabel:{
  459. textStyle:{
  460. fontSize:12
  461. }
  462. },
  463. },
  464. {
  465. type: 'value',
  466. // name: '输\n入\n功\n率\n(W)',
  467. min: 64,
  468. max: 77,
  469. position: 'left',
  470. offset:80,
  471. axisLine: {
  472. lineStyle: {
  473. color: colors[2],
  474. width:2
  475. }
  476. },
  477. axisLabel:{
  478. textStyle:{
  479. fontSize:12
  480. }
  481. },
  482. },
  483. {
  484. type: 'value',
  485. // name: '电\n流\n(A)',
  486. min: 2600,
  487. max: 2940,
  488. position: 'left',
  489. offset:30,
  490. axisLine: {
  491. lineStyle: {
  492. color: colors[3],
  493. width:2
  494. }
  495. },
  496. axisLabel:{
  497. textStyle:{
  498. fontSize:12
  499. }
  500. },
  501. },
  502. {
  503. type: 'value',
  504. // name: '效\n率\n(%)',
  505. min: 1.3,
  506. max: 2.3,
  507. position: 'left',
  508. offset:0,
  509. axisLine: {
  510. lineStyle: {
  511. color: colors[4],
  512. width:2
  513. }
  514. },
  515. axisLabel:{
  516. textStyle:{
  517. fontSize:12
  518. }
  519. },
  520. }
  521. ],
  522. // 数据内容数组
  523. series: function(){
  524. var serie=[];
  525. for(var i=0;i<$scope.legend2.length;i++){
  526. var item2 = {
  527. name : $scope.legend2[i],
  528. type: 'line',
  529. yAxisIndex:$scope.num[i],
  530. data: $scope.data3[i]
  531. };
  532. serie.push(item2);
  533. }
  534. return serie;
  535. }()
  536. };
  537. var myChart = echarts.init(document.getElementById($scope.id),'macarons');
  538. myChart.setOption(option);
  539. }
  540. };
  541. })
  542. starter.directive('strom', function() {
  543. return {
  544. scope: {
  545. id: "@",
  546. legend3: "=",
  547. item3: "=",
  548. num:"=",
  549. data4: "="
  550. },
  551. restrict: 'E',
  552. template: '<div style="height:300px;"></div>',
  553. replace: true,
  554. link: function($scope, element, attrs, controller) {
  555. var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a'];
  556. var option = {
  557. color:colors,
  558. // 提示框,鼠标悬浮交互时的信息提示
  559. tooltip: {
  560. show: true,
  561. trigger: 'axis'
  562. },
  563. grid:{
  564. left:'43%',
  565. right:'1%'
  566. },
  567. //图例
  568. legend: {
  569. top:15,
  570. data: $scope.legend3,
  571. textStyle:{
  572. fontSize:12
  573. }
  574. },
  575. // 横轴坐标轴
  576. xAxis: [
  577. {
  578. type: 'category',
  579. // boundaryGap:false,
  580. axisLabel:{
  581. textStyle:{
  582. fontSize:12
  583. },
  584. formatter: '{value} rpm'
  585. },
  586. data: $scope.item3
  587. }
  588. ],
  589. // 纵轴坐标轴
  590. yAxis: [
  591. {
  592. type: 'value',
  593. // name: '扭\n矩\n(N*m)',
  594. position: 'left',
  595. offset:125,
  596. axisLine: {
  597. lineStyle: {
  598. color: colors[0],
  599. width:2
  600. }
  601. },
  602. axisLabel:{
  603. textStyle:{
  604. fontSize:12
  605. }
  606. }
  607. },
  608. {
  609. type: 'value',
  610. // name: '电\n压\n(V)',
  611. position: 'left',
  612. offset: 90,
  613. axisLine: {
  614. lineStyle: {
  615. color: colors[1],
  616. width:2
  617. }
  618. },
  619. axisLabel:{
  620. textStyle:{
  621. fontSize:12
  622. }
  623. },
  624. },
  625. {
  626. type: 'value',
  627. // name: '输\n入\n功\n率\n(W)',
  628. position: 'left',
  629. offset:50,
  630. axisLine: {
  631. lineStyle: {
  632. color: colors[2],
  633. width:2
  634. }
  635. },
  636. axisLabel:{
  637. textStyle:{
  638. fontSize:12
  639. }
  640. },
  641. },
  642. {
  643. type: 'value',
  644. // name: '电\n流\n(A)',
  645. position: 'left',
  646. offset:30,
  647. axisLine: {
  648. lineStyle: {
  649. color: colors[3],
  650. width:2
  651. }
  652. },
  653. axisLabel:{
  654. textStyle:{
  655. fontSize:12
  656. }
  657. },
  658. },
  659. {
  660. type: 'value',
  661. // name: '效\n率\n(%)',
  662. position: 'left',
  663. offset:0,
  664. axisLine: {
  665. lineStyle: {
  666. color: colors[4],
  667. width:2
  668. }
  669. },
  670. axisLabel:{
  671. textStyle:{
  672. fontSize:12
  673. }
  674. },
  675. }
  676. ],
  677. // 数据内容数组
  678. series: function(){
  679. var serie=[];
  680. for(var i=0;i<$scope.legend3.length;i++){
  681. var item3 = {
  682. name : $scope.legend3[i],
  683. type: 'line',
  684. yAxisIndex:$scope.num[i],
  685. data: $scope.data4[i]
  686. };
  687. serie.push(item3);
  688. }
  689. return serie;
  690. }()
  691. };
  692. var myChart = echarts.init(document.getElementById($scope.id),'macarons');
  693. myChart.setOption(option);
  694. }
  695. };
  696. })