controllers.js 20 KB

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