controllers.js 14 KB

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