mainnew.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. var _this, screenWidth, timeId;
  2. var map, geoCoder;
  3. var myChart1, myChart2, myChart3, myChart4, myChart5, myChart6;
  4. new Vue({
  5. el: '#app',
  6. data: function() {
  7. return {
  8. imgHei: 0,
  9. gutter: 5,
  10. fontS: 128,
  11. echTxt: 0,
  12. shipLi: [],
  13. tabDiv: 39,
  14. nowTab: {},
  15. addRess: "",
  16. vidWid: 80,
  17. tabInd: 0,
  18. selVis: false,
  19. shipCount: [{name: "船舶总数",count: 0,icon: "../img/shipnum.png"},
  20. {name: "在航船舶",count: 0,icon: "../img/online.png"},
  21. {name: "停航船舶",count: 0,icon: "../img/offline.png"}
  22. ],
  23. shipPeol: [{name: "在船人数",count: 297,col:"#51a3f4"},
  24. {name: "预警人数",count: 7,col:"#fbbd08"},
  25. {name: "超载人数",count: 10,col:"#fa0000"}],
  26. caremLi: [{
  27. alive: 1,
  28. cameraid: "001",
  29. name: "驾驶室",
  30. },{
  31. alive: 1,
  32. cameraid: "002",
  33. name: "机舱",
  34. },{
  35. alive: 0,
  36. cameraid: "003",
  37. name: "左舷",
  38. },{
  39. alive: 1,
  40. cameraid: "004",
  41. name: "右舷",
  42. }],
  43. carmAct: {},
  44. switLi: []
  45. }
  46. },
  47. created() {
  48. _this = this;
  49. _this.switLi = shipSwit;
  50. _this.carmAct = _this.caremLi[0];
  51. _this.init(0);
  52. timeId = setInterval(()=>{
  53. _this.init(1);
  54. },60*1000)
  55. },
  56. mounted() {
  57. map = new AMap.Map("areaMap", {
  58. center: [116.433322, 39.900256],
  59. layers: [new AMap.TileLayer.Satellite()],
  60. zoom: 14
  61. });
  62. map.addControl(new AMap.Scale({
  63. visible: true
  64. }));
  65. geoCoder = new AMap.Geocoder({
  66. radius: 1000
  67. });
  68. let screenWidth = 1920;
  69. // let screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body
  70. // .clientWidth;
  71. _this.gutter = Math.ceil(screenWidth / 320);
  72. _this.fontS = (screenWidth / 1440) * 16;
  73. _this.vidWid = _this.gutter*14;
  74. this.$nextTick(() => {
  75. myChart1 = echarts.init(document.getElementById("myChart1"));
  76. myChart2 = echarts.init(document.getElementById("myChart2"));
  77. myChart3 = echarts.init(document.getElementById("myChart3"));
  78. myChart4 = echarts.init(document.getElementById("myChart4"));
  79. myChart5 = echarts.init(document.getElementById("myChart5"));
  80. let el = document.getElementsByClassName("el-slider__runway");
  81. for(let i=0;i<el.length;i++){
  82. el[i].style.margin = (_this.gutter*0.53)+"px 0";
  83. el[i].style.height = (_this.gutter*1.7)+"px";
  84. }
  85. let els = document.getElementsByClassName("el-slider__bar");
  86. for(let i=0;i<els.length;i++){
  87. els[i].style.height = (_this.gutter*1.7)+"px";
  88. }
  89. // myChart2.resize({height:(_this.gutter*21.6)+"px"});
  90. // myChart3.resize({height:(_this.gutter*21.6)+"px"});
  91. _this.tabDiv = _this.$refs.titleDiv.offsetHeight;
  92. _this.echTxt = _this.$refs.chartxt.offsetHeight;
  93. // let _ech = _this.$refs.charts.offsetHeight;
  94. // myChart1.resize({height: _ech*0.71+"px"});
  95. })
  96. window.onresize = () => {
  97. _this.imgLoad();
  98. myChart1.resize();
  99. myChart2.resize();
  100. myChart3.resize();
  101. myChart4.resize();
  102. myChart5.resize();
  103. }
  104. },
  105. destroyed(){
  106. clearInterval(timeId);
  107. },
  108. methods: {
  109. init(num) {
  110. let loading = null;
  111. if(num == 0){
  112. loading = this.$loading({
  113. background: 'rgba(0, 0, 0, 0.4)'
  114. })
  115. }
  116. $.ajax({
  117. url: "http://121.37.6.200:8088/SelHswsSn?user_id=109",
  118. type: "GET",
  119. traditional: true,
  120. dataType: "json",
  121. async: false,
  122. data: {
  123. "euser_idnc": 109
  124. },
  125. headers:{
  126. "Authorization":"Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjVlNTcxMWNiLTI2YmEtNDAyYy1hZTAxLTU5YTAzMmIyNTU2MiJ9.dS_d4Z0XlIYSO0ji_Fu9DajYYCzf-Ja2XQNQlKFQX8_ket4HT4J3Ffzj1MlsjDtLdzFSw9KzED3rJZKqBHeo4g"
  127. },
  128. error: function() { },
  129. success: function(res) {
  130. if(res.code == 200){
  131. let _obj = res.data, _arr = [], _onl = 0;
  132. for(let i=0;i<_obj.length;i++){
  133. let item = _obj[i];
  134. if(item.dev_ver == 2){
  135. let _onli = item.online == undefined ?{lon:0,lat:0,speed:0,time:1639449590}:item.online;
  136. let _gps = wgsGcj(_onli.lat, _onli.lon);
  137. let _neol = _this.changeTime((_onli.time+"")>10?parseInt(_onli.time):parseInt(_onli.time)*1000);
  138. item.lat = _gps.lat;
  139. item.lon = _gps.lon;
  140. item.sog = _onli.speed.toFixed(1);
  141. item.position = [_gps.lon, _gps.lat];
  142. item.prod = item.dev_name;
  143. item.icon = "../img/ship.png",
  144. item.status = _neol == 1?'在航(主机推动)':'停航';
  145. item.mmsi = item.sn;
  146. item.hdg = 0.0;
  147. item.cog = 0.0;
  148. item.draught = 0.0;
  149. item.speed = _onli.speed.toFixed(2);
  150. if(_neol == 1){
  151. _onl += 1;
  152. }
  153. _arr.push(item);
  154. }
  155. }
  156. let _sn = _this.nowTab.mmsi;
  157. if (_sn != undefined) {
  158. let _ind = _arr.findIndex((i, ind) => {
  159. return i.mmsi == _sn
  160. });
  161. if (_ind != -1) {
  162. _sn = _arr[_ind];
  163. } else {
  164. _sn = _arr[0];
  165. }
  166. } else {
  167. _sn = _arr[0];
  168. }
  169. _this.shipLi = _arr;
  170. _this.nowTab = _sn;
  171. _this.shipCount[0].count = _this.shipLi.length;
  172. _this.shipCount[1].count = _this.shipLi.length;
  173. _this.setMap(_this.shipLi);
  174. }
  175. if(num == 0){loading.close();}
  176. }
  177. })
  178. },
  179. changeTime(time) {
  180. let date3 = new Date().getTime() - (parseInt(time));
  181. let str = 1;
  182. if (date3 > (5 * 60 * 1000)) {
  183. str = 0;
  184. }
  185. return str;
  186. },
  187. setEchart() {
  188. this.$nextTick(() => {
  189. myChart1.setOption(_this.setOption1([100, 140, 125, 160, 130, 145, 128],['2016', '2017', '2018', '2019', '2020', '2021', '2022']));
  190. myChart2.setOption(_this.setOption2([25, 28, 10, 17, 20],["在航", "故障", "维修", "靠泊", "锚泊"]));
  191. myChart3.setOption(_this.setOption2([25, 28, 10, 17, 20],[">20年", "15-20年", "10-15年", "5-10年", "<5年"]));
  192. myChart4.setOption(_this.setOption1([100, 140, 125, 160, 130, 145, 128],['2022-08-12', '2022-08-13', '2022-08-14', '2022-08-15', '2022-08-16', '2022-08-17', '2022-08-18']));
  193. myChart5.setOption(_this.setOption2([25, 28, 10, 17, 20],["疲惫", "分神", "离岗", "抽烟", "电话"],1));
  194. myChart1.resize();
  195. myChart2.resize();
  196. myChart3.resize();
  197. myChart4.resize();
  198. })
  199. },
  200. setMap(_obj) {
  201. this.$nextTick(() => {
  202. map.clearMap();
  203. _obj.forEach(function(_obj) {
  204. var marker = new AMap.Marker({
  205. map: map,
  206. icon: new AMap.Icon({
  207. size: new AMap.Size(_this.gutter * 12, _this.gutter * 12),
  208. image: _obj.icon,
  209. imageSize: new AMap.Size(_this.gutter * 12, _this.gutter * 12),
  210. rotation: Number(152) * (Math.PI / 180)
  211. }),
  212. position: _obj.position,
  213. offset: new AMap.Pixel(-13, -30),
  214. extData: _obj.mmsi
  215. });
  216. marker.setLabel({
  217. offset: new AMap.Pixel(0, 0),
  218. content: "<div style='color:#000;font-size:" + (_this.fontS*0.5) + "px'>" +
  219. _obj.prod + "</div>",
  220. direction: 'bottom'
  221. });
  222. marker.on('click', markerClick);
  223. });
  224. _this.openInfo(_this.nowTab.mmsi);
  225. function markerClick(e) {
  226. let _ind = e.target.getExtData();
  227. _this.openInfo(_ind);
  228. }
  229. })
  230. },
  231. openInfo(_sn) {
  232. let _cmk = _this.shipLi;
  233. for (var i = 0; i < _cmk.length; i++) {
  234. if (_sn == _cmk[i].mmsi) {
  235. var _str = _cmk[i];
  236. _str.lon = _str.position[0];
  237. _str.lat = _str.position[1];
  238. _this.nowTab = _str;
  239. var info = [];
  240. geoCoder.getAddress(_str.position, function(status, result) {
  241. if (status === 'complete' && result.regeocode) {
  242. var address = result.regeocode.formattedAddress;
  243. _this.addRess = address;
  244. } else {
  245. _this.addRess = '获取位置失败';
  246. }
  247. map.setCenter(_str.position);
  248. return;
  249. });
  250. _this.setEchart();
  251. }
  252. }
  253. },
  254. imgLoad() {
  255. var _Img = document.getElementById('headImg');
  256. this.$nextTick(() => {
  257. _this.imgHei = _Img.clientHeight
  258. })
  259. let screenWidth = 1920;
  260. // let screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body
  261. // .clientWidth;
  262. _this.gutter = Math.ceil(screenWidth / 320);
  263. _this.fontS = (screenWidth / 1440) * 16;
  264. },
  265. changeSn(key) {
  266. let _ind = _this.shipLi.findIndex((i, ind) => {
  267. return i.mmsi == key
  268. });
  269. if (_ind != -1) {
  270. _sn = _this.shipLi[_ind];
  271. } else {
  272. _sn = _this.shipLi[0];
  273. }
  274. _this.selVis = false;
  275. _this.nowTab = _sn;
  276. _this.setEchart();
  277. _this.openInfo(_this.nowTab.mmsi);
  278. },
  279. setOption1(_arr,_data) {
  280. option = {
  281. tooltip: {
  282. trigger: 'axis',
  283. axisPointer: {
  284. type: 'cross',
  285. label: {
  286. backgroundColor: '#6a7985'
  287. }
  288. }
  289. },
  290. grid: {
  291. top: '10%',
  292. left: '1%',
  293. right: '2%',
  294. bottom: '2%',
  295. containLabel: true
  296. },
  297. xAxis: {
  298. type: 'category',
  299. boundaryGap: true,
  300. splitLine: {
  301. show: true,
  302. lineStyle: {
  303. color: '#29437c'
  304. }
  305. },
  306. axisLabel: {
  307. textStyle: {
  308. color: '#fff',
  309. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  310. },
  311. showMaxLabel: true
  312. },
  313. data: _data
  314. },
  315. yAxis: {
  316. type: 'value',
  317. axisLabel: {
  318. textStyle: {
  319. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  320. },
  321. showMaxLabel: true
  322. },
  323. axisLine: {
  324. show: true,
  325. lineStyle: {
  326. color: ['#5f6ee1']
  327. }
  328. },
  329. splitLine: {
  330. show: true,
  331. lineStyle: {
  332. color: ['#29437c']
  333. }
  334. }
  335. },
  336. series: [{
  337. data: _arr,
  338. type: 'line',
  339. label: {
  340. show: true,
  341. position: 'top',
  342. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.6) : 10) + ''
  343. },
  344. itemStyle: {
  345. normal: {
  346. color: '#5f6ee1', //改变折线点的颜色
  347. lineStyle: {
  348. color: '#5f6ee1' //改变折线颜色
  349. }
  350. }
  351. }
  352. }]
  353. };
  354. return option;
  355. },
  356. setOption2(Num,Name,who) {
  357. let _serir = {
  358. name: '实时数据统计',
  359. type: 'pie',
  360. center: ['45%', '50%'],
  361. radius: ['50%', '60%'],
  362. avoidLabelOverlap: false,
  363. label: {
  364. show: false,
  365. position: 'center'
  366. },
  367. emphasis: {
  368. label: {
  369. show: true,
  370. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  371. fontWeight: 'bold'
  372. }
  373. },
  374. itemStyle: {
  375. normal: {
  376. borderRadius: 10,
  377. borderColor: '#323740',
  378. borderWidth: 2,
  379. label: {
  380. show: true,
  381. formatter: '{d}%',
  382. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  383. color: "#fff"
  384. },
  385. labelLine: {
  386. show: true
  387. }
  388. }
  389. },
  390. labelLine: {
  391. show: true
  392. },
  393. data: [{
  394. value: Num[0],
  395. name: Name[0]
  396. },{
  397. value: Num[1],
  398. name: Name[1]
  399. },{
  400. value: Num[2],
  401. name: Name[2]
  402. },{
  403. value: Num[3],
  404. name: Name[3]
  405. },{
  406. value: Num[4],
  407. name: Name[4]
  408. },{
  409. value: Num[5],
  410. name: Name[5]
  411. }]
  412. };
  413. if(who == 1) delete _serir["radius"];
  414. option = {
  415. tooltip: {
  416. trigger: 'item',
  417. formatter: '{a} <br/>{b}: {c} ({d}%)'
  418. },
  419. legend: {
  420. show: true,
  421. itemWidth: ((_this.fontS > 16) ? (_this.gutter * 0.9) : 10) ,
  422. itemHeight: ((_this.fontS > 16) ? (_this.gutter * 0.9) : 10),
  423. right: '3%',
  424. y: "center",
  425. itemGap: _this.gutter,
  426. orient: 'vertical',
  427. data:Name,
  428. textStyle: {
  429. color: "#fff",
  430. fontSize: ((_this.fontS > 16) ? (_this.fontS * 0.4) : 10) + '',
  431. }
  432. },
  433. color: ['#4f6dcd', '#fad972', '#f88582', '#3ae3bc', '#9299f3'],
  434. series: [_serir]
  435. };
  436. return option;
  437. },
  438. changeShow(){
  439. _this.vidWid = (_this.vidWid>0?0:_this.gutter*14);
  440. },
  441. changCarm(key){
  442. let _ind = _this.caremLi.findIndex((item,index)=>{
  443. return key == item.cameraid;
  444. });
  445. _this.carmAct = _this.caremLi[_ind];
  446. if(_this.carmAct.alive == 0){
  447. _this.$message({
  448. showClose: true,
  449. message: '设备离线中!!!',
  450. type: 'warning'
  451. });
  452. }
  453. }
  454. }
  455. })