helmetHome.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. var _this, dataObj = [], baseTok = null;
  2. var map;
  3. var settIme;
  4. new Vue({
  5. el: '#app',
  6. data: function() {
  7. return {
  8. shipLi: [],
  9. nowTab: {},
  10. userForm: {},
  11. nowTime: "",
  12. cctvWarm: [{ "name": "离岗检测", "count": 0 },
  13. { "name": "手机检测", "count": 0 },
  14. { "name": "抽烟检测", "count": 0 },
  15. { "name": "物品检测", "count": 0 }],
  16. craneWarm: [{ "name": "钢丝绳检测", "count": 0 },
  17. { "name": "定滑轮检测", "count": 0 },
  18. { "name": "起重机检测", "count": 0 }],
  19. }
  20. },
  21. created() {
  22. _this = this;
  23. baseTok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
  24. _this.nowTime = parseTime(new Date(), `{y}/{m}/{d}`);
  25. _this.userForm = JSON.parse(getCookie("Admin-User"));
  26. // _this.initAjax(0);
  27. // settIme = setInterval(()=>{
  28. // _this.initAjax(1);
  29. // },30*1000);
  30. },
  31. mounted(){
  32. map = new AMap.Map("areaMap", {
  33. center: [113.5556, 22.9422],
  34. zoom: 14
  35. });
  36. map.addControl(new AMap.Scale({ visible: true }) );
  37. window.addEventListener('message',(data)=>{
  38. if(data.data != _this.nowTab.sn){
  39. _this.changTab(data.data);
  40. }
  41. })
  42. },
  43. methods: {
  44. initAjax(type){
  45. if(type == 0){
  46. var loading = this.$loading({ background: 'rgba(0, 0, 0, 0.4)' })
  47. } let _opts = {
  48. url: baseUrl + "/SelCctvListByUserId",
  49. type:"GET"
  50. };
  51. let _data = {
  52. "user_id": _this.userForm.userId
  53. };
  54. let _hea = {
  55. "Authorization": "Bearer " + baseTok
  56. }; getAxios(_opts,_data,_hea).then((res) => { if(res.code == 200&&res.data.length){
  57. let _xji = res.data;
  58. let _bji = _xji.map(item => item.mmsi);
  59. getCctvAis(_bji.toString(),function(_res){
  60. let _arr = [];
  61. _xji.forEach(item => {
  62. let sd = _res.filter(subitem => subitem[0] == item.mmsi)[0];
  63. let _newpo = GpsToGd(Number(sd[13]), Number(sd[12]));
  64. _arr.push({
  65. icon: staticUrl + "/img/ship.png",
  66. position: [_newpo.lon,_newpo.lat],
  67. lon: sd[12],
  68. lat: sd[13],
  69. prod: item.dev_name,
  70. sn: item.sn,
  71. mmsi: item.mmsi,
  72. en_name: item.en_name,
  73. speed: (item.mmsi == "413871376"&&sd[15]>1?0.1:sd[15]),
  74. time: sd[23]// sd[23]
  75. })
  76. })
  77. _this.shipLi = _arr;
  78. dataObj = _arr;
  79. let _sn = JSON.parse(localStorage.getItem("nowShip"));
  80. if(_sn !=null && _sn != "null"){
  81. let _ind = _this.shipLi.findIndex((i,ind) => {return i.sn == _sn.sn});
  82. if(_ind != -1){
  83. _sn = _this.shipLi[_ind];
  84. }else{
  85. _sn = _this.shipLi[0];
  86. }
  87. }else{
  88. _sn = _this.shipLi[0];
  89. }
  90. _this.nowTab = _sn;
  91. _this.setMap(_this.shipLi);
  92. }); }else{ _this.shipLi = [];
  93. _this.nowTab = null; }
  94. if(type == 0){loading.close();} }) },
  95. changTab(id){
  96. let ind = _this.shipLi.findIndex((it,ind) => {return id == it.sn});
  97. if(ind != -1){
  98. _this.nowTab = _this.shipLi[ind].sn;
  99. window.parent.postMessage({id: _this.nowTab},staticUrl+ "/");
  100. _this.openInfo(_this.nowTab);
  101. }
  102. },
  103. setMap(_obj){
  104. map.clearMap();
  105. _obj.forEach(function(_obj) {
  106. var marker = new AMap.Marker({
  107. map: map,
  108. icon: new AMap.Icon({
  109. size: new AMap.Size(50, 50),
  110. image: _obj.icon,
  111. imageSize: new AMap.Size(50, 50)
  112. }),
  113. position: _obj.position,
  114. offset: new AMap.Pixel(-13, -30),
  115. extData: _obj.sn
  116. });
  117. marker.setLabel({
  118. offset: new AMap.Pixel(0, 0),
  119. content: "<div style='color:#000;font-size:12px;'>" + _obj.prod + "</div>",
  120. direction: 'bottom'
  121. });
  122. marker.on('click', markerClick);
  123. });
  124. _this.openInfo(_this.nowTab.sn);
  125. function markerClick(e) {
  126. let _ind = e.target.getExtData();
  127. window.parent.postMessage({id: _ind}, staticUrl+ "/");
  128. _this.openInfo(_ind);
  129. }
  130. },
  131. openInfo(_sn){
  132. let _cmk = _this.shipLi;
  133. for (var i = 0; i < _cmk.length; i++) {
  134. if (_sn == _cmk[i].sn) {
  135. let _str = _cmk[i];
  136. _this.nowTab = _str;
  137. var info = [];
  138. getFormattedAddress(_str.position, function(_pos) {
  139. info.push(`<div class="nowShip">
  140. <div class="mapTitle">${_str.prod}</div>
  141. <div class="padding-sm mapInfo">
  142. <div><div>经度:</div><div>${duToGpsDM(_str.lon,'E')}</div></div>
  143. <div><div>纬度:</div><div>${duToGpsDM(_str.lat,'N')}</div></div>
  144. <div><div>航速:</div><div>${_str.speed} 节</div></div>
  145. <div><div>航速:</div><div>${ parseTime(_str.time, '{y}-{m}-{d} {h}:{d}:{s}')}</div></div>
  146. <div><div>地址:</div><div style="font-size: 12px;">${_pos}</div></div>
  147. </div>
  148. </div>`);
  149. infoWindow = new AMap.InfoWindow({
  150. offset: new AMap.Pixel(6, -30),
  151. content: info.join("")
  152. });
  153. infoWindow.open(map, _str.position);
  154. map.setCenter(_str.position);
  155. return;
  156. });
  157. }
  158. }
  159. }
  160. }
  161. })