controllers.js 15 KB

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