controllers.js 21 KB

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