controllers.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. $state.go('home');
  11. // $ionicLoading.show({
  12. // template: '<div class="loader"><svg class="circular"><circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"/></svg></div>'
  13. // });
  14. // $timeout(function(){
  15. // $ionicLoading.hide();
  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. // $timeout(function() {
  29. // ionicMaterialInk.displayEffect();
  30. // }, 0);
  31. }
  32. }
  33. }])
  34. //主页面控制器
  35. starter.controller('homeCtrl',["$scope",'$http','$timeout','$ionicLoading','$state',function($scope,$http,$timeout,$ionicLoading,$state){
  36. $http({
  37. method:'get',
  38. url:'http://172.31.40.29/list',
  39. }).success(function(newItem){
  40. $scope.excals = newItem
  41. })
  42. $scope.doRefresh = function(){
  43. $ionicLoading.show({
  44. template: '加载中...',
  45. animation: 'fade-in',
  46. showBackdrop: true,
  47. maxWidth: 200,
  48. showDelay: 0
  49. });
  50. $http({
  51. method:'get',
  52. url:'http://172.31.40.29/list',
  53. }).success(function(newItem){
  54. $timeout(function(){
  55. $ionicLoading.hide();
  56. $scope.excals = newItem
  57. });
  58. })
  59. .finally(function() {
  60. $scope.$broadcast('scroll.refreshComplete');
  61. });
  62. }
  63. $scope.getName = function(name){
  64. // name = this.$$watchers[0].last;
  65. $state.go('show',{item:name});
  66. }
  67. }])
  68. //数据展示控制器
  69. starter.controller('showCtrl',["$scope",'$ionicHistory','$state','$timeout','$stateParams','$http',function($scope,$ionicHistory,$state,$timeout,$stateParams,$http){
  70. $scope.$on('$ionicView.beforeEnter', function () {
  71. name = $stateParams.item;
  72. $scope.name = name;
  73. $ionicLoading.show({
  74. template: '加载中...',
  75. animation: 'fade-in',
  76. showBackdrop: true,
  77. maxWidth: 200,
  78. showDelay: 0
  79. });
  80. $http({
  81. method:'get',
  82. url:'http://172.31.40.29/data/'+name
  83. }).success(function(req){
  84. $timeout(function() {
  85. $ionicLoading.hide();
  86. $scope.item= req.speed;
  87. $scope.data = [req.torque,req.v,req.p,req.a,req.efficiency];
  88. $scope.item1 = req.torque;
  89. $scope.data1 = [req.speed,req.v,req.p,req.a,req.efficiency];
  90. });
  91. })
  92. });
  93. $scope.tabs = [
  94. {"title":"主页","url":"line.html"},
  95. {"title":"TN曲线","url":"tn.html"},
  96. {"title":"五轴图","url":"zhou.html"},
  97. {"title":"效率云图","url":"strom.html"}];
  98. $scope.currentTab = 'line.html';
  99. $scope.go = function(result){
  100. $state.go(result)
  101. };
  102. $scope.isActiveTab = function(tabUrl){
  103. return tabUrl == $scope.currentTab;
  104. };
  105. $scope.onClickTab = function(tab){
  106. $scope.currentTab = tab.url;
  107. // $http({
  108. // method:'get',
  109. // url:'http://172.31.40.29/data/'+name
  110. // }).success(function(req){
  111. // $scope.item= req.speed;
  112. // $scope.data = [req.torque,req.v,req.p,req.a,req.efficiency];
  113. // $scope.item1 = req.torque;
  114. // $scope.data1 = [req.speed,req.v,req.p,req.a,req.efficiency];
  115. // })
  116. };
  117. //TN曲线图
  118. $scope.legend = ["扭矩", "电压",'输入功率','电流','效率'];
  119. $scope.legend1 = ["转速", "电压",'输入功率','电流','效率'];
  120. $scope.item = ['200rpm','400rpm','600rpm','800rpm','1000rpm','1200rpm','1400rpm','1600rpm','1800rpm','2000rpm','2200rpm','2400rpm'];
  121. $scope.item1 = [0,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5,5.5];
  122. $scope.num = [0,1,2,3,4];
  123. $scope.data = [
  124. [1,1,1,1,1,1,1,1,1,1,1,1], //扭矩
  125. [196,196,196,196,196,196,196,196,196,196,196,196,], //电压
  126. [500,500,500,500,500,500,500,500,500,500,500,500,], //输入功率
  127. [4,4,4,4,4,4,4,4,4,4,4,4], //电流
  128. [68,68,68,68,68,68,68,68,68,68,68,68,]//效率
  129. ];
  130. $scope.data1 = [
  131. [800,800,800,800,800,800,800,800,800,800,800,800], //转速
  132. [196,196,196,196,196,196,196,196,196,196,196,196,], //电压
  133. [500,500,500,500,500,500,500,500,500,500,500,500,], //输入功率
  134. [4,4,4,4,4,4,4,4,4,4,4,4], //电流
  135. [68,68,68,68,68,68,68,68,68,68,68,68,]//效率
  136. ];
  137. }])
  138. starter.directive('main', function() {
  139. return {
  140. scope: {
  141. id: "@",
  142. legend: "=",
  143. item: "=",
  144. num:"=",
  145. data: "="
  146. },
  147. restrict: 'E',
  148. template: '<div style="height:700px;"></div>',
  149. replace: true,
  150. link: function($scope, element, attrs, controller) {
  151. var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a'];
  152. var option = {
  153. color:colors,
  154. // 提示框,鼠标悬浮交互时的信息提示
  155. tooltip: {
  156. show: true,
  157. trigger: 'axis'
  158. },
  159. grid:{
  160. left:'23%'
  161. },
  162. //图例
  163. legend: {
  164. data: $scope.legend ,
  165. textStyle:{
  166. fontSize:22
  167. }
  168. },
  169. // toolbox: {
  170. // feature: {
  171. // dataView: {show: true, readOnly: false},
  172. // restore: {show: true},
  173. // saveAsImage: {show: true}
  174. // }
  175. // },
  176. // 横轴坐标轴
  177. xAxis: [
  178. {
  179. type: 'category',
  180. // boundaryGap:false,
  181. axisLabel:{
  182. textStyle:{
  183. fontSize:20
  184. },
  185. formatter: '{value} rpm'
  186. },
  187. data: $scope.item
  188. }
  189. ],
  190. // 纵轴坐标轴
  191. yAxis: [
  192. {
  193. type: 'value',
  194. // name: '扭\n矩\n(N*m)',
  195. min: 0,
  196. max: 4,
  197. position: 'left',
  198. offset:205,
  199. axisLine: {
  200. lineStyle: {
  201. color: colors[0],
  202. width:2
  203. }
  204. },
  205. axisLabel:{
  206. margin:20,
  207. textStyle:{
  208. fontSize:18
  209. }
  210. }
  211. },
  212. {
  213. type: 'value',
  214. // name: '电\n压\n(V)',
  215. min: 193,
  216. max: 202,
  217. position: 'left',
  218. offset: 150,
  219. axisLine: {
  220. lineStyle: {
  221. color: colors[1],
  222. width:2
  223. }
  224. },
  225. axisLabel:{
  226. margin:15,
  227. textStyle:{
  228. fontSize:18
  229. }
  230. },
  231. },
  232. {
  233. type: 'value',
  234. // name: '输\n入\n功\n率\n(W)',
  235. min: 0,
  236. max: 1300,
  237. position: 'left',
  238. offset:90,
  239. axisLine: {
  240. lineStyle: {
  241. color: colors[2],
  242. width:2
  243. }
  244. },
  245. axisLabel:{
  246. textStyle:{
  247. fontSize:18
  248. }
  249. },
  250. },
  251. {
  252. type: 'value',
  253. // name: '电\n流\n(A)',
  254. min: 1,
  255. max: 6,
  256. position: 'left',
  257. offset:45,
  258. axisLine: {
  259. lineStyle: {
  260. color: colors[3],
  261. width:2
  262. }
  263. },
  264. axisLabel:{
  265. margin:20,
  266. textStyle:{
  267. fontSize:18
  268. }
  269. },
  270. },
  271. {
  272. type: 'value',
  273. // name: '效\n率\n(%)',
  274. min: 10,
  275. max: 80,
  276. position: 'left',
  277. offset:0,
  278. axisLine: {
  279. lineStyle: {
  280. color: colors[4],
  281. width:2
  282. }
  283. },
  284. axisLabel:{
  285. margin:15,
  286. textStyle:{
  287. fontSize:18
  288. }
  289. },
  290. }
  291. ],
  292. // 数据内容数组
  293. series: function(){
  294. var serie=[];
  295. for(var i=0;i<$scope.legend.length;i++){
  296. var item = {
  297. name : $scope.legend[i],
  298. type: 'line',
  299. yAxisIndex:$scope.num[i],
  300. data: $scope.data[i]
  301. };
  302. serie.push(item);
  303. }
  304. return serie;
  305. }()
  306. };
  307. var myChart = echarts.init(document.getElementById($scope.id),'macarons');
  308. myChart.setOption(option);
  309. }
  310. };
  311. })
  312. starter.directive('line', function() {
  313. return {
  314. scope: {
  315. id: "@",
  316. legend1: "=",
  317. item1: "=",
  318. num:"=",
  319. data1: "="
  320. },
  321. restrict: 'E',
  322. template: '<div style="height:700px;"></div>',
  323. replace: true,
  324. link: function($scope, element, attrs, controller) {
  325. var colors = ['#a62ca6', '#8e0515', '#45baf3','#ff2420','#1a9a1a'];
  326. var option = {
  327. color:colors,
  328. // 提示框,鼠标悬浮交互时的信息提示
  329. tooltip: {
  330. show: true,
  331. trigger: 'axis'
  332. },
  333. grid:{
  334. left:'26%'
  335. },
  336. //图例
  337. legend: {
  338. data: $scope.legend1 ,
  339. textStyle:{
  340. fontSize:22
  341. }
  342. },
  343. // toolbox: {
  344. // feature: {
  345. // dataView: {show: true, readOnly: false},
  346. // restore: {show: true},
  347. // saveAsImage: {show: true}
  348. // }
  349. // },
  350. // 横轴坐标轴
  351. xAxis: [
  352. {
  353. type: 'category',
  354. // boundaryGap:false,
  355. axisLabel:{
  356. textStyle:{
  357. fontSize:20
  358. },
  359. formatter: '{value} N*m'
  360. },
  361. data: $scope.item1
  362. }
  363. ],
  364. // 纵轴坐标轴
  365. yAxis: [
  366. {
  367. type: 'value',
  368. // name: '转速',
  369. min: 600,
  370. max: 2000,
  371. position: 'left',
  372. offset:205,
  373. axisLine: {
  374. lineStyle: {
  375. color: colors[0],
  376. width:2
  377. }
  378. },
  379. axisLabel:{
  380. margin:20,
  381. textStyle:{
  382. fontSize:18
  383. }
  384. }
  385. },
  386. {
  387. type: 'value',
  388. // name: '电\n压\n(V)',
  389. min: 193,
  390. max: 202,
  391. position: 'left',
  392. offset: 150,
  393. axisLine: {
  394. lineStyle: {
  395. color: colors[1],
  396. width:2
  397. }
  398. },
  399. axisLabel:{
  400. margin:15,
  401. textStyle:{
  402. fontSize:18
  403. }
  404. },
  405. },
  406. {
  407. type: 'value',
  408. // name: '输\n入\n功\n率\n(W)',
  409. min: 0,
  410. max: 1300,
  411. position: 'left',
  412. offset:90,
  413. axisLine: {
  414. lineStyle: {
  415. color: colors[2],
  416. width:2
  417. }
  418. },
  419. axisLabel:{
  420. textStyle:{
  421. fontSize:18
  422. }
  423. },
  424. },
  425. {
  426. type: 'value',
  427. // name: '电\n流\n(A)',
  428. min: 1,
  429. max: 6,
  430. position: 'left',
  431. offset:45,
  432. axisLine: {
  433. lineStyle: {
  434. color: colors[3],
  435. width:2
  436. }
  437. },
  438. axisLabel:{
  439. margin:20,
  440. textStyle:{
  441. fontSize:18
  442. }
  443. },
  444. },
  445. {
  446. type: 'value',
  447. // name: '效\n率\n(%)',
  448. min: 10,
  449. max: 80,
  450. position: 'left',
  451. offset:0,
  452. axisLine: {
  453. lineStyle: {
  454. color: colors[4],
  455. width:2
  456. }
  457. },
  458. axisLabel:{
  459. margin:15,
  460. textStyle:{
  461. fontSize:18
  462. }
  463. },
  464. }
  465. ],
  466. // 数据内容数组
  467. series: function(){
  468. var serie=[];
  469. for(var i=0;i<$scope.legend1.length;i++){
  470. var item1 = {
  471. name : $scope.legend1[i],
  472. type: 'line',
  473. yAxisIndex:$scope.num[i],
  474. data: $scope.data1[i]
  475. };
  476. serie.push(item1);
  477. }
  478. return serie;
  479. }()
  480. };
  481. var myChart = echarts.init(document.getElementById($scope.id),'macarons');
  482. myChart.setOption(option);
  483. }
  484. };
  485. })