main.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. myChart00 = echarts.init(document.getElementById("myChart00"));
  69. myChart01 = echarts.init(document.getElementById("myChart01"));
  70. let el = document.getElementsByClassName("el-slider__runway");
  71. for(let i=0;i<el.length;i++){
  72. el[i].style.margin = (_this.gutter*0.53)+"px 0";
  73. el[i].style.height = (_this.gutter*1.7)+"px";
  74. }
  75. let els = document.getElementsByClassName("el-slider__bar");
  76. for(let i=0;i<els.length;i++){
  77. els[i].style.height = (_this.gutter*1.7)+"px";
  78. }
  79. myChart2.resize({height:(_this.gutter*30)+"px"});
  80. myChart3.resize({height:(_this.gutter*30)+"px"});
  81. _this.tabDiv = _this.$refs.titleDiv.offsetHeight;
  82. _this.tabBh = _this.$refs.tabbar.offsetHeight;
  83. _this.echTxt = _this.$refs.chartxt.offsetHeight;
  84. let _ech = _this.$refs.charts.offsetHeight;
  85. myChart1.resize({height: _ech*0.84+"px"});
  86. })
  87. window.onresize = () => {
  88. _this.imgLoad();
  89. }
  90. },
  91. destroyed(){
  92. clearInterval(timeId);
  93. },
  94. methods: {
  95. init(num) {
  96. let loading = null;
  97. if(num == 0){
  98. loading = this.$loading({
  99. background: 'rgba(0, 0, 0, 0.4)'
  100. })
  101. }
  102. getList(function acb(_obj, _online){
  103. let _sn = _this.nowTab.mmsi;
  104. if (_sn != undefined) {
  105. let _ind = _obj.findIndex((i, ind) => {
  106. return i.mmsi == _sn
  107. });
  108. if (_ind != -1) {
  109. _sn = _obj[_ind];
  110. } else {
  111. _sn = _obj[0];
  112. }
  113. } else {
  114. _sn = _obj[0];
  115. }
  116. _this.shipLi = _obj;
  117. _this.nowTab = _sn;
  118. _this.shipCount[0].count = _this.shipLi.length;
  119. _this.shipCount[1].count = _online;
  120. _this.shipCount[2].count = parseInt(_this.shipLi.length) - _online;
  121. _this.setMap(_this.shipLi);
  122. if(num == 0){loading.close();}
  123. })
  124. },
  125. changeTime(time) {
  126. let date3 = new Date().getTime() - (parseInt(time));
  127. let str = 1;
  128. if (date3 > (5 * 60 * 1000)) {
  129. str = 0;
  130. }
  131. return str;
  132. },
  133. setEchart() {
  134. this.$nextTick(() => {
  135. myChart1.setOption(_this.setOption1([100, 140, 125, 160, 130, 145, 128]));
  136. myChart2.setOption(_this.setOption2([25, 28, 10, 17, 20],["在航", "故障", "维修", "靠泊", "锚泊"]));
  137. myChart3.setOption(_this.setOption2([25, 28, 10, 17, 20],[">20年", "15-20年", "10-15年", "5-10年", "<5年"]));
  138. myChart4.setOption(_this.setOption3(_this.nowTab.speed, 20));
  139. myChart5.setOption(_this.setOption4(0.0));
  140. myChart6.setOption(_this.setOption4(0.0));
  141. myChart70.setOption(_this.setOption3(10, 3000));
  142. myChart80.setOption(_this.setOption3(10, 1500));
  143. myChart71.setOption(_this.setOption3(10, 3000));
  144. myChart81.setOption(_this.setOption3(10, 1500));
  145. myChart90.setOption(_this.setOption3(10, 3000));
  146. myChart00.setOption(_this.setOption3(10, 1500));
  147. myChart01.setOption(_this.setOption3(10, 3000));
  148. myChart91.setOption(_this.setOption3(10, 1500));
  149. // myChart02.setOption(_this.setOption3(10, 3000));
  150. // myChart92.setOption(_this.setOption3(10, 1500));
  151. // myChart92.setOption(_this.setOption3(10, 3000));
  152. // myChart02.setOption(_this.setOption3(10, 1500));
  153. myChart1.resize();
  154. myChart2.resize();
  155. myChart3.resize();
  156. myChart4.resize();
  157. myChart5.resize();
  158. myChart6.resize();
  159. myChart70.resize();
  160. myChart80.resize();
  161. myChart81.resize();
  162. myChart71.resize();
  163. myChart90.resize();
  164. myChart91.resize();
  165. // myChart92.resize();
  166. myChart00.resize();
  167. myChart01.resize();
  168. // myChart02.resize();
  169. })
  170. },
  171. setMap(_obj) {
  172. this.$nextTick(() => {
  173. map.clearMap();
  174. _obj.forEach(function(_obj) {
  175. var marker = new AMap.Marker({
  176. map: map,
  177. icon: new AMap.Icon({
  178. size: new AMap.Size(_this.gutter * 12, _this.gutter * 12),
  179. image: _obj.icon,
  180. imageSize: new AMap.Size(_this.gutter * 12, _this.gutter * 12),
  181. rotation: Number(152) * (Math.PI / 180)
  182. }),
  183. position: _obj.position,
  184. offset: new AMap.Pixel(-13, -30),
  185. extData: _obj.mmsi
  186. });
  187. marker.setLabel({
  188. offset: new AMap.Pixel(0, 0),
  189. content: "<div style='color:#000;font-size:" + (_this.fontS*0.5) + "px'>" +
  190. _obj.prod + "</div>",
  191. direction: 'bottom'
  192. });
  193. marker.on('click', markerClick);
  194. });
  195. _this.openInfo(_this.nowTab.mmsi);
  196. function markerClick(e) {
  197. let _ind = e.target.getExtData();
  198. _this.openInfo(_ind);
  199. }
  200. })
  201. },
  202. openInfo(_sn) {
  203. let _cmk = _this.shipLi;
  204. for (var i = 0; i < _cmk.length; i++) {
  205. if (_sn == _cmk[i].mmsi) {
  206. var _str = _cmk[i];
  207. _this.nowTab = _str;
  208. var info = [];
  209. geoCoder.getAddress(_str.position, function(status, result) {
  210. if (status === 'complete' && result.regeocode) {
  211. var address = result.regeocode.formattedAddress;
  212. _this.addRess = address;
  213. } else {
  214. _this.addRess = '获取位置失败';
  215. }
  216. map.setCenter(_str.position);
  217. return;
  218. });
  219. _this.setEchart();
  220. }
  221. }
  222. },
  223. imgLoad() {
  224. var _Img = document.getElementById('headImg');
  225. this.$nextTick(() => {
  226. _this.imgHei = _Img.clientHeight
  227. })
  228. //let screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  229. let screenWidth = 1920;
  230. _this.gutter = Math.ceil(screenWidth / 320);
  231. _this.fontS = (screenWidth / 1440) * 16;
  232. },
  233. changeTab(ind) {
  234. _this.tabBar = ind;
  235. _this.setEchart();
  236. },
  237. changeSn(key) {
  238. let _ind = _this.shipLi.findIndex((i, ind) => {
  239. return i.mmsi == key
  240. });
  241. if (_ind != -1) {
  242. _sn = _this.shipLi[_ind];
  243. } else {
  244. _sn = _this.shipLi[0];
  245. }
  246. _this.selVis = false;
  247. _this.nowTab = _sn;
  248. _this.setEchart();
  249. _this.openInfo(_this.nowTab.mmsi);
  250. },
  251. setOption1(_arr) {
  252. option = {
  253. tooltip: {
  254. trigger: 'axis',
  255. axisPointer: {
  256. type: 'cross',
  257. label: {
  258. backgroundColor: '#6a7985'
  259. }
  260. }
  261. },
  262. grid: {
  263. top: '10%',
  264. left: '1%',
  265. right: '2%',
  266. bottom: '2%',
  267. containLabel: true
  268. },
  269. xAxis: {
  270. type: 'category',
  271. boundaryGap: true,
  272. splitLine: {
  273. show: true,
  274. lineStyle: {
  275. color: '#29437c'
  276. }
  277. },
  278. axisLabel: {
  279. textStyle: {
  280. color: '#fff',
  281. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  282. },
  283. showMaxLabel: true
  284. },
  285. data: ['2016', '2017', '2018', '2019', '2020', '2021', '2022']
  286. },
  287. yAxis: {
  288. type: 'value',
  289. axisLabel: {
  290. textStyle: {
  291. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  292. },
  293. showMaxLabel: true
  294. },
  295. axisLine: {
  296. show: true,
  297. lineStyle: {
  298. color: ['#5f6ee1']
  299. }
  300. },
  301. splitLine: {
  302. show: true,
  303. lineStyle: {
  304. color: ['#29437c']
  305. }
  306. }
  307. },
  308. series: [{
  309. data: _arr,
  310. type: 'line',
  311. label: {
  312. show: true,
  313. position: 'top',
  314. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  315. },
  316. itemStyle: {
  317. normal: {
  318. color: '#5f6ee1', //改变折线点的颜色
  319. lineStyle: {
  320. color: '#5f6ee1' //改变折线颜色
  321. }
  322. }
  323. }
  324. }]
  325. };
  326. return option;
  327. },
  328. setOption2(Num,Name) {
  329. option = {
  330. tooltip: {
  331. trigger: 'item',
  332. formatter: '{a} <br/>{b}: {c} ({d}%)'
  333. },
  334. legend: {
  335. show: true,
  336. itemWidth: ((_this.fontS > 16) ? (_this.gutter * 0.8) : 10) ,
  337. itemHeight: ((_this.fontS > 16) ? (_this.gutter * 0.8) : 10),
  338. right: '3%',
  339. y: "center",
  340. itemGap: _this.gutter,
  341. orient: 'vertical',
  342. data:Name,
  343. textStyle: {
  344. color: "#fff",
  345. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  346. }
  347. },
  348. color: ['#4f6dcd', '#fad972', '#f88582', '#3ae3bc', '#9299f3'],
  349. series: [{
  350. name: '实时数据统计',
  351. type: 'pie',
  352. center: ['45%', '50%'],
  353. radius: ['50%', '60%'],
  354. avoidLabelOverlap: false,
  355. label: {
  356. show: false,
  357. position: 'center'
  358. },
  359. emphasis: {
  360. label: {
  361. show: true,
  362. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  363. fontWeight: 'bold'
  364. }
  365. },
  366. itemStyle: {
  367. normal: {
  368. borderRadius: 10,
  369. borderColor: '#323740',
  370. borderWidth: 2,
  371. label: {
  372. show: true,
  373. formatter: '{d}%',
  374. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  375. color: "#fff"
  376. },
  377. labelLine: {
  378. show: true
  379. }
  380. }
  381. },
  382. labelLine: {
  383. show: true
  384. },
  385. data: [{
  386. value: Num[0],
  387. name: Name[0]
  388. },
  389. {
  390. value: Num[1],
  391. name: Name[1]
  392. },
  393. {
  394. value: Num[2],
  395. name: Name[2]
  396. },
  397. {
  398. value: Num[3],
  399. name: Name[3]
  400. },
  401. {
  402. value: Num[4],
  403. name: Name[4]
  404. },
  405. {
  406. value: Num[5],
  407. name: Name[5]
  408. }
  409. ]
  410. }]
  411. };
  412. return option;
  413. },
  414. setOption3(num, max) {
  415. option = {
  416. series: [{
  417. name: '实时数据',
  418. min: 0,
  419. max: max,
  420. splitNumber: 10,
  421. type: 'gauge',
  422. center: ['50%', '50%'],
  423. radius: '80%',
  424. detail: {
  425. show: false,
  426. },
  427. data: [{
  428. value: num
  429. }],
  430. axisLine: {
  431. lineStyle: {
  432. color: [
  433. [0.09, 'lime'],
  434. [0.82, '#1e90ff'],
  435. [1, '#ff4500']
  436. ],
  437. width: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5) + ''
  438. }
  439. },
  440. axisTick: {
  441. distance: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5),
  442. length: _this.gutter * 0.8,
  443. },
  444. pointer: {
  445. width: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5),
  446. length: "60%",
  447. },
  448. splitLine: {
  449. distance: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5),
  450. length: ((_this.fontS > 16) ? _this.gutter : 6),
  451. lineStyle: {
  452. width: ((_this.fontS > 16) ? (_this.gutter * 0.2) : 2),
  453. color: '#fff',
  454. }
  455. },
  456. axisLabel: {
  457. textStyle: {
  458. color: '#fff',
  459. fontSize: ((_this.fontS > 16) ? (max == 20?_this.fontS * 0.6:_this.fontS * 0.2) : 10) + '',
  460. },
  461. distance: _this.gutter*0.5
  462. },
  463. title: {
  464. textStyle: {
  465. color: '#fff',
  466. }
  467. },
  468. }]
  469. };
  470. return option;
  471. },
  472. setOption4(num) {
  473. option = {
  474. series: [{
  475. name: '实时数据',
  476. min: 0,
  477. max: 360,
  478. splitNumber: 12,
  479. type: 'gauge',
  480. fontSize: 0,
  481. center: ['50%', '50%'],
  482. radius: '80%',
  483. startAngle: 90,
  484. endAngle: -269.999999,
  485. detail: {
  486. show: false
  487. },
  488. axisTick: {
  489. distance: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5),
  490. length: _this.gutter * 0.8,
  491. },
  492. data: [{
  493. value: num
  494. }],
  495. axisLine: {
  496. lineStyle: {
  497. color: [
  498. [1, '#1e90ff']
  499. ],
  500. width: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5) + ''
  501. },
  502. },
  503. axisLabel: {
  504. textStyle: {
  505. color: '#fff',
  506. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.5) : 10) + '',
  507. },
  508. distance: _this.gutter,
  509. formatter: function(e) {
  510. switch (e + "") {
  511. case "0":
  512. return "0";
  513. case "30":
  514. return "30";
  515. case "60":
  516. return "60";
  517. case "90":
  518. return "90";
  519. case "120":
  520. return "120";
  521. case "150":
  522. return "150";
  523. case "180":
  524. return "180";
  525. case "210":
  526. return "210";
  527. case "240":
  528. return "240";
  529. case "270":
  530. return "270";
  531. case "300":
  532. return "300";
  533. case "330":
  534. return "330";
  535. default:
  536. return "";
  537. }
  538. }
  539. },
  540. pointer: {
  541. width: ((_this.fontS > 16) ? (_this.gutter * 0.7) : 5),
  542. length: "60%",
  543. },
  544. splitLine: {
  545. distance: ((_this.fontS > 16) ? (_this.gutter * 0.5) : 5),
  546. length: ((_this.fontS > 16) ? _this.gutter : 6),
  547. lineStyle: {
  548. width: ((_this.fontS > 16) ? (_this.gutter * 0.2) : 2),
  549. color: '#fff',
  550. }
  551. },
  552. title: {
  553. textStyle: {
  554. color: '#fff',
  555. }
  556. },
  557. }]
  558. };
  559. return option;
  560. }
  561. }
  562. })