controllers.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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: '唯一账号密码:admin!!!',
  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.a = req.n_zs;
  106. $scope.b = req.n_nj;
  107. $scope.c = req.n_xl;
  108. var Stat = G2.Stat;
  109. var vvvdata = [];
  110. // for(var i = 0; i <= 20; i ++) {
  111. // for(var j = 0; j <= 20; j ++) {
  112. // var x = i*25.6;
  113. // var y = j*19.2;
  114. // var z = 700-(x+0.5*y)+Math.random()*(400);
  115. // console.log(x);
  116. // console.log(y);
  117. // console.log(z);
  118. //
  119. // }
  120. // }
  121. var data1 = $scope.a;
  122. var data2 = $scope.b;
  123. var data3 = $scope.c;
  124. for(var i=0;i<=212;i++){
  125. var x = data1[i];
  126. var y = data2[i];
  127. var z = data3[i];
  128. vvvdata.push({
  129. l:x,
  130. g: y,
  131. Altitude:z
  132. });
  133. console.log(x+'x')
  134. console.log(y+'y')
  135. console.log(z+'z')
  136. }
  137. var chart = new G2.Chart({
  138. id: 'c1',
  139. forceFit: true,
  140. height: 1000
  141. });
  142. //为了将数据与图片上的位置完全吻合,我们需要将横轴和纵轴的范围设定为数据对应范围,并将范围优化处理关闭
  143. var defs = {
  144. 'l': {
  145. type: 'linear',
  146. min: 2735,
  147. max: 2900,
  148. nice: false//优化处理关闭
  149. },
  150. 'g': {
  151. type: 'linear',
  152. min: 0,
  153. max: 2,
  154. nice: false
  155. },
  156. 'Altitude': {
  157. tickCount:5
  158. }
  159. };
  160. chart.source(vvvdata,defs);
  161. chart.contour().position(Stat.smooth.loess.triangular('l*g*Altitude',0.01)).color('Altitude','hue').size(3);
  162. chart.render();
  163. document.getElementById('newchats').style.display='none';
  164. });
  165. }).error(function(){
  166. $timeout(function(){
  167. $ionicLoading.hide();
  168. var alertPopup = $ionicPopup.alert({
  169. title: '连接超时',
  170. buttons: [
  171. {
  172. text: '<b>确定</b>',
  173. type: 'button-calm',
  174. },
  175. ]
  176. });
  177. })
  178. })
  179. });
  180. $scope.change = function(selectedName){
  181. $scope.name = selectedName;
  182. $ionicLoading.show({
  183. template: '加载中...',
  184. });
  185. $http({
  186. method:'get',
  187. url:config.server+'/data/'+selectedName
  188. }).success(function(req){
  189. $ionicLoading.hide();
  190. $timeout(function() {
  191. //主页参数
  192. $scope.table1 = req.t.t1;
  193. $scope.table2 = req.t.t2;
  194. $scope.table3 = req.t.t3;
  195. $scope.table4 = req.t.t4;
  196. //tn曲线图参数
  197. $scope.item1= req.speed;
  198. $scope.data2 = [req.torque,req.v,req.p,req.a,req.efficiency];
  199. //五轴图参数
  200. $scope.item2 = req.nj;
  201. $scope.data3 = [req.glys,req.ssgl,req.xl,req.zs,req.dl];
  202. });
  203. }).error(function(){
  204. $timeout(function(){
  205. $ionicLoading.hide();
  206. var alertPopup = $ionicPopup.alert({
  207. title: '连接超时',
  208. buttons: [
  209. {
  210. text: '<b>确定</b>',
  211. type: 'button-calm',
  212. },
  213. ]
  214. });
  215. })
  216. })
  217. }
  218. $scope.tabs = [
  219. {"title":"主页","url":"line.html"},
  220. {"title":"TN曲线","url":"tn.html"},
  221. {"title":"五轴图","url":"zhou.html"},
  222. {"title":"效率云图","url":"strom.html"}];
  223. $scope.currentTab = 'line.html';
  224. $scope.go = function(result){
  225. $state.go(result)
  226. };
  227. $scope.isActiveTab = function(tabUrl){
  228. return tabUrl == $scope.currentTab;
  229. };
  230. $scope.onClickTab = function(tab){
  231. if(tab.url=="strom.html"){
  232. document.getElementById('newchats').style.display='block';
  233. }else{
  234. document.getElementById('newchats').style.display='none';
  235. }
  236. $scope.currentTab = tab.url;
  237. };
  238. //TN曲线图
  239. $scope.legend1 = ["扭矩", "电压",'输入功率','电流','效率'];
  240. $scope.legend2 = ["功率因素", "输入功率",'效率','转速','电流'];
  241. $scope.num = [0,1,2,3,4];
  242. }])
  243. starter.filter('filet', function () {
  244. return function (filepath) {
  245. if(filepath){
  246. var pos = filepath.replace(".xlsx", "");
  247. return pos;
  248. }
  249. };
  250. })
  251. starter.directive('main', function() {
  252. return {
  253. scope: {
  254. id: "@",
  255. legend1: "=",
  256. item1: "=",
  257. num:"=",
  258. data2: "="
  259. },
  260. restrict: 'E',
  261. template: '<div style="height:700px;"></div>',
  262. replace: true,
  263. link: function($scope, element, attrs, controller) {
  264. var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a'];
  265. var option = {
  266. color:colors,
  267. // 提示框,鼠标悬浮交互时的信息提示
  268. tooltip: {
  269. show: true,
  270. trigger: 'axis'
  271. },
  272. grid:{
  273. left:'23%'
  274. },
  275. //图例
  276. legend: {
  277. data: $scope.legend1,
  278. textStyle:{
  279. fontSize:22
  280. }
  281. },
  282. // 横轴坐标轴
  283. xAxis: [
  284. {
  285. type: 'category',
  286. // boundaryGap:false,
  287. axisLabel:{
  288. textStyle:{
  289. fontSize:20
  290. },
  291. formatter: '{value} rpm'
  292. },
  293. data: $scope.item1
  294. }
  295. ],
  296. // 纵轴坐标轴
  297. yAxis: [
  298. {
  299. type: 'value',
  300. // name: '扭\n矩\n(N*m)',
  301. min: 0,
  302. max: 4,
  303. position: 'left',
  304. offset:205,
  305. axisLine: {
  306. lineStyle: {
  307. color: colors[0],
  308. width:2
  309. }
  310. },
  311. axisLabel:{
  312. margin:20,
  313. textStyle:{
  314. fontSize:18
  315. }
  316. }
  317. },
  318. {
  319. type: 'value',
  320. // name: '电\n压\n(V)',
  321. min: 193,
  322. max: 202,
  323. position: 'left',
  324. offset: 150,
  325. axisLine: {
  326. lineStyle: {
  327. color: colors[1],
  328. width:2
  329. }
  330. },
  331. axisLabel:{
  332. margin:15,
  333. textStyle:{
  334. fontSize:18
  335. }
  336. },
  337. },
  338. {
  339. type: 'value',
  340. // name: '输\n入\n功\n率\n(W)',
  341. min: 0,
  342. max: 1300,
  343. position: 'left',
  344. offset:90,
  345. axisLine: {
  346. lineStyle: {
  347. color: colors[2],
  348. width:2
  349. }
  350. },
  351. axisLabel:{
  352. textStyle:{
  353. fontSize:18
  354. }
  355. },
  356. },
  357. {
  358. type: 'value',
  359. // name: '电\n流\n(A)',
  360. min: 1,
  361. max: 6,
  362. position: 'left',
  363. offset:45,
  364. axisLine: {
  365. lineStyle: {
  366. color: colors[3],
  367. width:2
  368. }
  369. },
  370. axisLabel:{
  371. margin:20,
  372. textStyle:{
  373. fontSize:18
  374. }
  375. },
  376. },
  377. {
  378. type: 'value',
  379. // name: '效\n率\n(%)',
  380. min: 10,
  381. max: 80,
  382. position: 'left',
  383. offset:0,
  384. axisLine: {
  385. lineStyle: {
  386. color: colors[4],
  387. width:2
  388. }
  389. },
  390. axisLabel:{
  391. margin:15,
  392. textStyle:{
  393. fontSize:18
  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:700px;"></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:'26%'
  441. },
  442. //图例
  443. legend: {
  444. data: $scope.legend2,
  445. textStyle:{
  446. fontSize:22
  447. }
  448. },
  449. // toolbox: {
  450. // feature: {
  451. // dataView: {show: true, readOnly: false},
  452. // restore: {show: true},
  453. // saveAsImage: {show: true}
  454. // }
  455. // },
  456. // 横轴坐标轴
  457. xAxis: [
  458. {
  459. type: 'category',
  460. // boundaryGap:false,
  461. axisLabel:{
  462. textStyle:{
  463. fontSize:20
  464. },
  465. formatter: '{value} N*m'
  466. },
  467. data: $scope.item2
  468. }
  469. ],
  470. // 纵轴坐标轴
  471. yAxis: [
  472. {
  473. type: 'value',
  474. // name: '功率因素',
  475. min: 0.27,
  476. max: 0.7,
  477. position: 'left',
  478. offset:225,
  479. axisLine: {
  480. lineStyle: {
  481. color: colors[0],
  482. width:2
  483. }
  484. },
  485. axisLabel:{
  486. margin:20,
  487. textStyle:{
  488. fontSize:18
  489. }
  490. }
  491. },
  492. {
  493. type: 'value',
  494. // name: '电\n压\n(V)',
  495. min: 130,
  496. max: 630,
  497. position: 'left',
  498. offset: 170,
  499. axisLine: {
  500. lineStyle: {
  501. color: colors[1],
  502. width:2
  503. }
  504. },
  505. axisLabel:{
  506. margin:15,
  507. textStyle:{
  508. fontSize:18
  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:125,
  519. axisLine: {
  520. lineStyle: {
  521. color: colors[2],
  522. width:2
  523. }
  524. },
  525. axisLabel:{
  526. textStyle:{
  527. fontSize:18
  528. }
  529. },
  530. },
  531. {
  532. type: 'value',
  533. // name: '电\n流\n(A)',
  534. min: 2600,
  535. max: 2940,
  536. position: 'left',
  537. offset:50,
  538. axisLine: {
  539. lineStyle: {
  540. color: colors[3],
  541. width:2
  542. }
  543. },
  544. axisLabel:{
  545. margin:20,
  546. textStyle:{
  547. fontSize:18
  548. }
  549. },
  550. },
  551. {
  552. type: 'value',
  553. // name: '效\n率\n(%)',
  554. min: 1.3,
  555. max: 2.3,
  556. position: 'left',
  557. offset:0,
  558. axisLine: {
  559. lineStyle: {
  560. color: colors[4],
  561. width:2
  562. }
  563. },
  564. axisLabel:{
  565. margin:15,
  566. textStyle:{
  567. fontSize:18
  568. }
  569. },
  570. }
  571. ],
  572. // 数据内容数组
  573. series: function(){
  574. var serie=[];
  575. for(var i=0;i<$scope.legend2.length;i++){
  576. var item2 = {
  577. name : $scope.legend2[i],
  578. type: 'line',
  579. yAxisIndex:$scope.num[i],
  580. data: $scope.data3[i]
  581. };
  582. serie.push(item2);
  583. }
  584. return serie;
  585. }()
  586. };
  587. var myChart = echarts.init(document.getElementById($scope.id),'macarons');
  588. myChart.setOption(option);
  589. }
  590. };
  591. })