controllers.js 16 KB

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