main1.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. var _this, screenWidth, timeId;
  2. var map, geoCoder;
  3. var myChart1, myChart2, myChart3, myChart4, myChart5, myChart6, myChart70, myChart71, myChart80, myChart81,
  4. myChart90, myChart91, myChart92, myChart00, myChart01, myChart02;
  5. new Vue({
  6. el: '#app',
  7. data: function() {
  8. return {
  9. imgHei: 0,
  10. gutter: 5,
  11. fontS: 16,
  12. tabBar: 0,
  13. tabBh: 0,
  14. echTxt: 0,
  15. shipLi: [],
  16. tabDiv: 39,
  17. nowTab: {},
  18. addRess: "",
  19. tabInd: 0,
  20. selVis: false,
  21. shipCount: [{name: "船舶总数",count: 0,icon: "../img/shipnum.png"},
  22. {name: "在航船舶",count: 0,icon: "../img/online.png"},
  23. {name: "停航船舶",count: 0,icon: "../img/offline.png"}
  24. ],
  25. shipPeol: [{name: "在船人数",count: 297,col:"#51a3f4"},
  26. {name: "预警人数",count: 7,col:"#fbbd08"},
  27. {name: "超载人数",count: 10,col:"#fa0000"}],
  28. switLi: []
  29. }
  30. },
  31. created() {
  32. _this = this;
  33. _this.switLi = shipSwit;
  34. _this.init(0);
  35. timeId = setInterval(()=>{
  36. _this.init(1);
  37. },60*1000)
  38. },
  39. mounted() {
  40. map = new AMap.Map("areaMap", {
  41. center: [116.433322, 39.900256],
  42. layers: [new AMap.TileLayer.Satellite()],
  43. zoom: 14
  44. });
  45. map.addControl(new AMap.Scale({
  46. visible: true
  47. }));
  48. geoCoder = new AMap.Geocoder({
  49. radius: 1000
  50. });
  51. //let screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  52. let screenWidth = 1920;
  53. _this.gutter = Math.ceil(screenWidth / 320);
  54. _this.fontS = (screenWidth / 1440) * 16;
  55. this.$nextTick(() => {
  56. myChart1 = echarts.init(document.getElementById("myChart1"));
  57. myChart2 = echarts.init(document.getElementById("myChart2"));
  58. myChart3 = echarts.init(document.getElementById("myChart3"));
  59. myChart4 = echarts.init(document.getElementById("myChart4"));
  60. myChart5 = echarts.init(document.getElementById("myChart5"));
  61. myChart6 = echarts.init(document.getElementById("myChart6"));
  62. myChart70 = echarts.init(document.getElementById("myChart70"));
  63. myChart80 = echarts.init(document.getElementById("myChart80"));
  64. myChart71 = echarts.init(document.getElementById("myChart71"));
  65. myChart81 = echarts.init(document.getElementById("myChart81"));
  66. myChart90 = echarts.init(document.getElementById("myChart90"));
  67. myChart91 = echarts.init(document.getElementById("myChart91"));
  68. // myChart92 = echarts.init(document.getElementById("myChart92"));
  69. myChart00 = echarts.init(document.getElementById("myChart00"));
  70. myChart01 = echarts.init(document.getElementById("myChart01"));
  71. // myChart02 = echarts.init(document.getElementById("myChart02"));
  72. let el = document.getElementsByClassName("el-slider__runway");
  73. for(let i=0;i<el.length;i++){
  74. el[i].style.margin = (_this.gutter*0.53)+"px 0";
  75. el[i].style.height = (_this.gutter*1.7)+"px";
  76. }
  77. let els = document.getElementsByClassName("el-slider__bar");
  78. for(let i=0;i<els.length;i++){
  79. els[i].style.height = (_this.gutter*1.7)+"px";
  80. }
  81. myChart2.resize({height:(_this.gutter*21.6)+"px"});
  82. myChart3.resize({height:(_this.gutter*21.6)+"px"});
  83. myChart4.resize({height:(_this.gutter*30)+"px"});
  84. myChart5.resize({height:(_this.gutter*30)+"px"});
  85. myChart6.resize({height:(_this.gutter*30)+"px"});
  86. _this.tabDiv = _this.$refs.titleDiv.offsetHeight;
  87. _this.tabBh = _this.$refs.tabbar.offsetHeight;
  88. _this.echTxt = _this.$refs.chartxt.offsetHeight;
  89. let _ech = _this.$refs.charts.offsetHeight;
  90. myChart1.resize({height: _ech*0.71+"px"});
  91. })
  92. window.onresize = () => {
  93. _this.imgLoad();
  94. }
  95. },
  96. destroyed(){
  97. clearInterval(timeId);
  98. },
  99. methods: {
  100. init(num) {
  101. let loading = null;
  102. if(num == 0){
  103. loading = this.$loading({
  104. background: 'rgba(0, 0, 0, 0.4)'
  105. })
  106. }
  107. $.ajax({
  108. // url: "http://api.shipxy.com/apicall/GetManyShip",
  109. url: "http://121.37.6.200/zhgHy/js/zhgJson.json",
  110. type: "GET",
  111. traditional: true,
  112. dataType: "json",
  113. async: false,
  114. data: {
  115. "k": "e9df7104d99b4659931150ed94d01436",
  116. "enc": 1,
  117. "id": shipMmsi.toString(),
  118. },
  119. error: function() { },
  120. success: function(res) {
  121. if(res.status == 0){
  122. let _obj = res.data, _arr = [], _onl = 0, _kb = 0, _gps = {};
  123. _obj.forEach(item => {
  124. _gps = {};
  125. item.prod = shipData[item.mmsi];
  126. item.icon = "../img/ship.png",
  127. _gps = wgsGcj(item.lat / 1000000, item.lon / 1000000);
  128. item.lat = _gps.lat;
  129. item.lon = _gps.lon;
  130. item.sog = (item.sog/514).toFixed(1);
  131. item.position = [_gps.lon, _gps.lat];
  132. item.status = _this.checkSta(item.navistatus);
  133. if(item.navistatus == 0){
  134. _onl += 1;
  135. }else if(item.navistatus == 5){
  136. _kb += 1;
  137. }
  138. })
  139. let _sn = _this.nowTab.mmsi;
  140. if (_sn != undefined) {
  141. let _ind = _obj.findIndex((i, ind) => {
  142. return i.mmsi == _sn
  143. });
  144. if (_ind != -1) {
  145. _sn = _obj[_ind];
  146. } else {
  147. _sn = _obj[0];
  148. }
  149. } else {
  150. _sn = _obj[0];
  151. }
  152. _this.shipLi = _obj;
  153. _this.nowTab = _sn;
  154. _this.shipCount[0].count = _this.shipLi.length;
  155. _this.shipCount[1].count = _onl;
  156. _this.shipCount[2].count = _kb;
  157. _this.setMap(_this.shipLi);
  158. }
  159. if(num == 0){loading.close();}
  160. }
  161. })
  162. },
  163. checkSta(key){
  164. let _str = "";
  165. switch(parseInt(key)){
  166. case 0: _str = "在航(主机推动)";break;
  167. case 1: _str = "锚泊";break;
  168. case 2: _str = "失控";break;
  169. case 3: _str = "操纵受限";break;
  170. case 4: _str = "吃水受限";break;
  171. case 5: _str = "靠泊";break;
  172. case 6: _str = "搁浅";break;
  173. case 7: _str = "捕捞作业";break;
  174. case 8: _str = "靠帆船提供动力";break;
  175. default: _str = "其他";break;
  176. }
  177. return _str;
  178. },
  179. setEchart() {
  180. this.$nextTick(() => {
  181. myChart1.setOption(_this.setOption1([100, 140, 125, 160, 130, 145, 128]));
  182. myChart2.setOption(_this.setOption2([25, 28, 10, 17, 20],["在航", "故障", "维修", "靠泊", "锚泊"]));
  183. myChart3.setOption(_this.setOption2([25, 28, 10, 17, 20],[">20年", "15-20年", "10-15年", "5-10年", "<5年"]));
  184. myChart4.setOption(_this.setOption3(_this.nowTab.sog, 20));
  185. myChart5.setOption(_this.setOption4(_this.nowTab.hdg == 51100?'0.0':(_this.nowTab.hdg/100)));
  186. myChart6.setOption(_this.setOption4(_this.nowTab.cog/100));
  187. myChart70.setOption(_this.setOption3(10, 3000));
  188. myChart80.setOption(_this.setOption3(10, 1500));
  189. myChart71.setOption(_this.setOption3(10, 3000));
  190. myChart81.setOption(_this.setOption3(10, 1500));
  191. myChart90.setOption(_this.setOption3(10, 3000));
  192. myChart00.setOption(_this.setOption3(10, 1500));
  193. myChart91.setOption(_this.setOption3(10, 3000));
  194. myChart01.setOption(_this.setOption3(10, 1500));
  195. // myChart92.setOption(_this.setOption3(10, 3000));
  196. // myChart02.setOption(_this.setOption3(10, 1500));
  197. myChart1.resize();
  198. myChart2.resize();
  199. myChart3.resize();
  200. myChart4.resize();
  201. myChart5.resize();
  202. myChart6.resize();
  203. myChart70.resize();
  204. myChart80.resize();
  205. myChart81.resize();
  206. myChart71.resize();
  207. myChart90.resize();
  208. myChart91.resize();
  209. // myChart92.resize();
  210. myChart00.resize();
  211. myChart01.resize();
  212. // myChart02.resize();
  213. })
  214. },
  215. setMap(_obj) {
  216. this.$nextTick(() => {
  217. map.clearMap();
  218. _obj.forEach(function(_obj) {
  219. var marker = new AMap.Marker({
  220. map: map,
  221. icon: new AMap.Icon({
  222. size: new AMap.Size(_this.gutter * 12, _this.gutter * 12),
  223. image: _obj.icon,
  224. imageSize: new AMap.Size(_this.gutter * 12, _this.gutter * 12),
  225. rotation: Number(152) * (Math.PI / 180)
  226. }),
  227. position: _obj.position,
  228. offset: new AMap.Pixel(-13, -30),
  229. extData: _obj.mmsi
  230. });
  231. marker.setLabel({
  232. offset: new AMap.Pixel(0, 0),
  233. content: "<div style='color:#000;font-size:" + (_this.fontS*0.5) + "px'>" +
  234. _obj.prod + "</div>",
  235. direction: 'bottom'
  236. });
  237. marker.on('click', markerClick);
  238. });
  239. _this.openInfo(_this.nowTab.mmsi);
  240. function markerClick(e) {
  241. let _ind = e.target.getExtData();
  242. _this.openInfo(_ind);
  243. }
  244. })
  245. },
  246. openInfo(_sn) {
  247. let _cmk = _this.shipLi;
  248. for (var i = 0; i < _cmk.length; i++) {
  249. if (_sn == _cmk[i].mmsi) {
  250. var _str = _cmk[i];
  251. _str.lon = _str.position[0];
  252. _str.lat = _str.position[1];
  253. _this.nowTab = _str;
  254. var info = [];
  255. geoCoder.getAddress(_str.position, function(status, result) {
  256. if (status === 'complete' && result.regeocode) {
  257. var address = result.regeocode.formattedAddress;
  258. _this.addRess = address;
  259. } else {
  260. _this.addRess = '获取位置失败';
  261. }
  262. map.setCenter(_str.position);
  263. return;
  264. });
  265. _this.setEchart();
  266. }
  267. }
  268. },
  269. imgLoad() {
  270. var _Img = document.getElementById('headImg');
  271. this.$nextTick(() => {
  272. _this.imgHei = _Img.clientHeight
  273. })
  274. //let screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  275. let screenWidth = 1920;
  276. _this.gutter = Math.ceil(screenWidth / 320);
  277. _this.fontS = (screenWidth / 1440) * 16;
  278. },
  279. changeTab(ind) {
  280. _this.tabBar = ind;
  281. _this.setEchart();
  282. },
  283. changeSn(key) {
  284. let _ind = _this.shipLi.findIndex((i, ind) => {
  285. return i.mmsi == key
  286. });
  287. if (_ind != -1) {
  288. _sn = _this.shipLi[_ind];
  289. } else {
  290. _sn = _this.shipLi[0];
  291. }
  292. _this.selVis = false;
  293. _this.nowTab = _sn;
  294. _this.setEchart();
  295. _this.openInfo(_this.nowTab.mmsi);
  296. },
  297. setOption1(_arr) {
  298. option = {
  299. tooltip: {
  300. trigger: 'axis',
  301. axisPointer: {
  302. type: 'cross',
  303. label: {
  304. backgroundColor: '#6a7985'
  305. }
  306. }
  307. },
  308. grid: {
  309. top: '10%',
  310. left: '1%',
  311. right: '2%',
  312. bottom: '2%',
  313. containLabel: true
  314. },
  315. xAxis: {
  316. type: 'category',
  317. boundaryGap: true,
  318. splitLine: {
  319. show: true,
  320. lineStyle: {
  321. color: '#29437c'
  322. }
  323. },
  324. axisLabel: {
  325. textStyle: {
  326. color: '#fff',
  327. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  328. },
  329. showMaxLabel: true
  330. },
  331. data: ['2016', '2017', '2018', '2019', '2020', '2021', '2022']
  332. },
  333. yAxis: {
  334. type: 'value',
  335. axisLabel: {
  336. textStyle: {
  337. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  338. },
  339. showMaxLabel: true
  340. },
  341. axisLine: {
  342. show: true,
  343. lineStyle: {
  344. color: ['#5f6ee1']
  345. }
  346. },
  347. splitLine: {
  348. show: true,
  349. lineStyle: {
  350. color: ['#29437c']
  351. }
  352. }
  353. },
  354. series: [{
  355. data: _arr,
  356. type: 'line',
  357. label: {
  358. show: true,
  359. position: 'top',
  360. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  361. },
  362. itemStyle: {
  363. normal: {
  364. color: '#5f6ee1', //改变折线点的颜色
  365. lineStyle: {
  366. color: '#5f6ee1' //改变折线颜色
  367. }
  368. }
  369. }
  370. }]
  371. };
  372. return option;
  373. },
  374. setOption2(Num,Name) {
  375. option = {
  376. tooltip: {
  377. trigger: 'item',
  378. formatter: '{a} <br/>{b}: {c} ({d}%)'
  379. },
  380. legend: {
  381. show: true,
  382. itemWidth: ((_this.fontS > 16) ? (_this.gutter * 0.8) : 10) ,
  383. itemHeight: ((_this.fontS > 16) ? (_this.gutter * 0.8) : 10),
  384. right: '3%',
  385. y: "center",
  386. itemGap: _this.gutter,
  387. orient: 'vertical',
  388. data:Name,
  389. textStyle: {
  390. color: "#fff",
  391. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  392. }
  393. },
  394. color: ['#4f6dcd', '#fad972', '#f88582', '#3ae3bc', '#9299f3'],
  395. series: [{
  396. name: '实时数据统计',
  397. type: 'pie',
  398. center: ['45%', '50%'],
  399. radius: ['50%', '60%'],
  400. avoidLabelOverlap: false,
  401. label: {
  402. show: false,
  403. position: 'center'
  404. },
  405. emphasis: {
  406. label: {
  407. show: true,
  408. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  409. fontWeight: 'bold'
  410. }
  411. },
  412. itemStyle: {
  413. normal: {
  414. borderRadius: 10,
  415. borderColor: '#323740',
  416. borderWidth: 2,
  417. label: {
  418. show: true,
  419. formatter: '{d}%',
  420. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  421. color: "#fff"
  422. },
  423. labelLine: {
  424. show: true
  425. }
  426. }
  427. },
  428. labelLine: {
  429. show: true
  430. },
  431. data: [{
  432. value: Num[0],
  433. name: Name[0]
  434. },
  435. {
  436. value: Num[1],
  437. name: Name[1]
  438. },
  439. {
  440. value: Num[2],
  441. name: Name[2]
  442. },
  443. {
  444. value: Num[3],
  445. name: Name[3]
  446. },
  447. {
  448. value: Num[4],
  449. name: Name[4]
  450. },
  451. {
  452. value: Num[5],
  453. name: Name[5]
  454. }
  455. ]
  456. }]
  457. };
  458. return option;
  459. },
  460. setOption3(num, max) {
  461. option = {
  462. series: [{
  463. name: '实时数据',
  464. min: 0,
  465. max: max,
  466. splitNumber: 10,
  467. type: 'gauge',
  468. center: ['50%', '55%'],
  469. radius: '90%',
  470. detail: {
  471. show: false,
  472. },
  473. data: [{
  474. value: num
  475. }],
  476. axisLine: {
  477. lineStyle: {
  478. color: [
  479. [0.09, 'lime'],
  480. [0.82, '#1e90ff'],
  481. [1, '#ff4500']
  482. ],
  483. width: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5) + ''
  484. }
  485. },
  486. axisTick: {
  487. distance: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5),
  488. length: _this.gutter * 0.8,
  489. },
  490. pointer: {
  491. width: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5),
  492. length: "60%",
  493. },
  494. splitLine: {
  495. distance: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5),
  496. length: ((_this.fontS > 16) ? _this.gutter : 6),
  497. lineStyle: {
  498. width: ((_this.fontS > 16) ? (_this.gutter * 0.2) : 2),
  499. color: '#fff',
  500. }
  501. },
  502. axisLabel: {
  503. textStyle: {
  504. color: '#fff',
  505. fontSize: ((_this.fontS > 16) ? (max == 20?_this.fontS * 0.6:_this.fontS * 0.2) : 10) + '',
  506. },
  507. distance: _this.gutter*0.5
  508. },
  509. title: {
  510. textStyle: {
  511. color: '#fff',
  512. }
  513. },
  514. }]
  515. };
  516. return option;
  517. },
  518. setOption4(num) {
  519. option = {
  520. series: [{
  521. name: '实时数据',
  522. min: 0,
  523. max: 360,
  524. splitNumber: 12,
  525. type: 'gauge',
  526. fontSize: 0,
  527. center: ['50%', '55%'],
  528. radius: '90%',
  529. startAngle: 90,
  530. endAngle: -269.999999,
  531. detail: {
  532. show: false
  533. },
  534. axisTick: {
  535. distance: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5),
  536. length: _this.gutter * 0.8,
  537. },
  538. data: [{
  539. value: num
  540. }],
  541. axisLine: {
  542. lineStyle: {
  543. color: [
  544. [1, '#1e90ff']
  545. ],
  546. width: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5) + ''
  547. },
  548. },
  549. axisLabel: {
  550. textStyle: {
  551. color: '#fff',
  552. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.5) : 10) + '',
  553. },
  554. distance: _this.gutter,
  555. formatter: function(e) {
  556. switch (e + "") {
  557. case "0":
  558. return "0";
  559. case "30":
  560. return "30";
  561. case "60":
  562. return "60";
  563. case "90":
  564. return "90";
  565. case "120":
  566. return "120";
  567. case "150":
  568. return "150";
  569. case "180":
  570. return "180";
  571. case "210":
  572. return "210";
  573. case "240":
  574. return "240";
  575. case "270":
  576. return "270";
  577. case "300":
  578. return "300";
  579. case "330":
  580. return "330";
  581. default:
  582. return "";
  583. }
  584. }
  585. },
  586. pointer: {
  587. width: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5),
  588. length: "60%",
  589. },
  590. splitLine: {
  591. distance: ((_this.fontS > 16) ? (_this.gutter * 0.5) : 5),
  592. length: ((_this.fontS > 16) ? _this.gutter : 6),
  593. lineStyle: {
  594. width: ((_this.fontS > 16) ? (_this.gutter * 0.2) : 2),
  595. color: '#fff',
  596. }
  597. },
  598. title: {
  599. textStyle: {
  600. color: '#fff',
  601. }
  602. },
  603. }]
  604. };
  605. return option;
  606. }
  607. }
  608. })