controllers.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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: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. $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. if(filepath){
  232. var pos = filepath.replace(".xlsx", "");
  233. return pos;
  234. }
  235. };
  236. })
  237. starter.directive('main', function() {
  238. return {
  239. scope: {
  240. id: "@",
  241. legend1: "=",
  242. item1: "=",
  243. num:"=",
  244. data2: "="
  245. },
  246. restrict: 'E',
  247. template: '<div style="height:700px;"></div>',
  248. replace: true,
  249. link: function($scope, element, attrs, controller) {
  250. var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a'];
  251. var option = {
  252. color:colors,
  253. // 提示框,鼠标悬浮交互时的信息提示
  254. tooltip: {
  255. show: true,
  256. trigger: 'axis'
  257. },
  258. grid:{
  259. left:'23%'
  260. },
  261. //图例
  262. legend: {
  263. data: $scope.legend1,
  264. textStyle:{
  265. fontSize:22
  266. }
  267. },
  268. // 横轴坐标轴
  269. xAxis: [
  270. {
  271. type: 'category',
  272. // boundaryGap:false,
  273. axisLabel:{
  274. textStyle:{
  275. fontSize:20
  276. },
  277. formatter: '{value} rpm'
  278. },
  279. data: $scope.item1
  280. }
  281. ],
  282. // 纵轴坐标轴
  283. yAxis: [
  284. {
  285. type: 'value',
  286. // name: '扭\n矩\n(N*m)',
  287. min: 0,
  288. max: 4,
  289. position: 'left',
  290. offset:205,
  291. axisLine: {
  292. lineStyle: {
  293. color: colors[0],
  294. width:2
  295. }
  296. },
  297. axisLabel:{
  298. margin:20,
  299. textStyle:{
  300. fontSize:18
  301. }
  302. }
  303. },
  304. {
  305. type: 'value',
  306. // name: '电\n压\n(V)',
  307. min: 193,
  308. max: 202,
  309. position: 'left',
  310. offset: 150,
  311. axisLine: {
  312. lineStyle: {
  313. color: colors[1],
  314. width:2
  315. }
  316. },
  317. axisLabel:{
  318. margin:15,
  319. textStyle:{
  320. fontSize:18
  321. }
  322. },
  323. },
  324. {
  325. type: 'value',
  326. // name: '输\n入\n功\n率\n(W)',
  327. min: 0,
  328. max: 1300,
  329. position: 'left',
  330. offset:90,
  331. axisLine: {
  332. lineStyle: {
  333. color: colors[2],
  334. width:2
  335. }
  336. },
  337. axisLabel:{
  338. textStyle:{
  339. fontSize:18
  340. }
  341. },
  342. },
  343. {
  344. type: 'value',
  345. // name: '电\n流\n(A)',
  346. min: 1,
  347. max: 6,
  348. position: 'left',
  349. offset:45,
  350. axisLine: {
  351. lineStyle: {
  352. color: colors[3],
  353. width:2
  354. }
  355. },
  356. axisLabel:{
  357. margin:20,
  358. textStyle:{
  359. fontSize:18
  360. }
  361. },
  362. },
  363. {
  364. type: 'value',
  365. // name: '效\n率\n(%)',
  366. min: 10,
  367. max: 80,
  368. position: 'left',
  369. offset:0,
  370. axisLine: {
  371. lineStyle: {
  372. color: colors[4],
  373. width:2
  374. }
  375. },
  376. axisLabel:{
  377. margin:15,
  378. textStyle:{
  379. fontSize:18
  380. }
  381. },
  382. }
  383. ],
  384. // 数据内容数组
  385. series: function(){
  386. var serie=[];
  387. for(var i=0;i<$scope.legend1.length;i++){
  388. var item1 = {
  389. name : $scope.legend1[i],
  390. type: 'line',
  391. yAxisIndex:$scope.num[i],
  392. data: $scope.data2[i]
  393. };
  394. serie.push(item1);
  395. }
  396. return serie;
  397. }()
  398. };
  399. var myChart = echarts.init(document.getElementById($scope.id),'macarons');
  400. myChart.setOption(option);
  401. }
  402. };
  403. })
  404. starter.directive('line', function() {
  405. return {
  406. scope: {
  407. id: "@",
  408. legend2: "=",
  409. item2: "=",
  410. num:"=",
  411. data3: "="
  412. },
  413. restrict: 'E',
  414. template: '<div style="height:700px;"></div>',
  415. replace: true,
  416. link: function($scope, element, attrs, controller) {
  417. var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a'];
  418. var option = {
  419. color:colors,
  420. // 提示框,鼠标悬浮交互时的信息提示
  421. tooltip: {
  422. show: true,
  423. trigger: 'axis'
  424. },
  425. grid:{
  426. left:'26%'
  427. },
  428. //图例
  429. legend: {
  430. data: $scope.legend2,
  431. textStyle:{
  432. fontSize:22
  433. }
  434. },
  435. // toolbox: {
  436. // feature: {
  437. // dataView: {show: true, readOnly: false},
  438. // restore: {show: true},
  439. // saveAsImage: {show: true}
  440. // }
  441. // },
  442. // 横轴坐标轴
  443. xAxis: [
  444. {
  445. type: 'category',
  446. // boundaryGap:false,
  447. axisLabel:{
  448. textStyle:{
  449. fontSize:20
  450. },
  451. formatter: '{value} N*m'
  452. },
  453. data: $scope.item2
  454. }
  455. ],
  456. // 纵轴坐标轴
  457. yAxis: [
  458. {
  459. type: 'value',
  460. // name: '功率因素',
  461. min: 0.27,
  462. max: 0.7,
  463. position: 'left',
  464. offset:225,
  465. axisLine: {
  466. lineStyle: {
  467. color: colors[0],
  468. width:2
  469. }
  470. },
  471. axisLabel:{
  472. margin:20,
  473. textStyle:{
  474. fontSize:18
  475. }
  476. }
  477. },
  478. {
  479. type: 'value',
  480. // name: '电\n压\n(V)',
  481. min: 130,
  482. max: 630,
  483. position: 'left',
  484. offset: 170,
  485. axisLine: {
  486. lineStyle: {
  487. color: colors[1],
  488. width:2
  489. }
  490. },
  491. axisLabel:{
  492. margin:15,
  493. textStyle:{
  494. fontSize:18
  495. }
  496. },
  497. },
  498. {
  499. type: 'value',
  500. // name: '输\n入\n功\n率\n(W)',
  501. min: 64,
  502. max: 77,
  503. position: 'left',
  504. offset:125,
  505. axisLine: {
  506. lineStyle: {
  507. color: colors[2],
  508. width:2
  509. }
  510. },
  511. axisLabel:{
  512. textStyle:{
  513. fontSize:18
  514. }
  515. },
  516. },
  517. {
  518. type: 'value',
  519. // name: '电\n流\n(A)',
  520. min: 2600,
  521. max: 2940,
  522. position: 'left',
  523. offset:50,
  524. axisLine: {
  525. lineStyle: {
  526. color: colors[3],
  527. width:2
  528. }
  529. },
  530. axisLabel:{
  531. margin:20,
  532. textStyle:{
  533. fontSize:18
  534. }
  535. },
  536. },
  537. {
  538. type: 'value',
  539. // name: '效\n率\n(%)',
  540. min: 1.3,
  541. max: 2.3,
  542. position: 'left',
  543. offset:0,
  544. axisLine: {
  545. lineStyle: {
  546. color: colors[4],
  547. width:2
  548. }
  549. },
  550. axisLabel:{
  551. margin:15,
  552. textStyle:{
  553. fontSize:18
  554. }
  555. },
  556. }
  557. ],
  558. // 数据内容数组
  559. series: function(){
  560. var serie=[];
  561. for(var i=0;i<$scope.legend2.length;i++){
  562. var item2 = {
  563. name : $scope.legend2[i],
  564. type: 'line',
  565. yAxisIndex:$scope.num[i],
  566. data: $scope.data3[i]
  567. };
  568. serie.push(item2);
  569. }
  570. return serie;
  571. }()
  572. };
  573. var myChart = echarts.init(document.getElementById($scope.id),'macarons');
  574. myChart.setOption(option);
  575. }
  576. };
  577. })