controllers.js 14 KB

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