shipWarmManage.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. fenceWarm: [{ "name": "甲板警戒区", "count": 0 },
  17. { "name": "浮吊警戒区", "count": 0 }],
  18. craneWarm: [{ "name": "钢丝绳检测", "count": 0 },
  19. { "name": "起重机检测", "count": 0 }],
  20. genWarmDetail: [{ "name": "生理疲劳", "count": 0 },
  21. { "name": "分神驾驶", "count": 0 },
  22. { "name": "遮挡摄像头", "count": 0 },
  23. { "name": "超时驾驶", "count": 0 }]
  24. // { "name": "定滑轮检测", "count": 0 },
  25. }
  26. },
  27. created() {
  28. _this = this;
  29. baseTok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
  30. _this.nowTime = parseTime(new Date(), `{y}/{m}/{d}`);
  31. _this.userForm = JSON.parse(getCookie("Admin-User"));
  32. _this.initAjax(0);
  33. settIme = setInterval(()=>{
  34. _this.initAjax(1);
  35. },30*1000);
  36. },
  37. mounted(){
  38. map = new AMap.Map("areaMap", {
  39. center: [113.5556, 22.9422],
  40. zoom: 14
  41. });
  42. map.addControl(new AMap.Scale({ visible: true }) );
  43. window.addEventListener('message',(data)=>{
  44. if(data.data != _this.nowTab.sn){
  45. _this.changTab(data.data);
  46. }
  47. })
  48. },
  49. methods: {
  50. initAjax(type){
  51. if(type == 0){
  52. var loading = this.$loading({ background: 'rgba(0, 0, 0, 0.4)' })
  53. } let _opts = {
  54. url: baseUrl + "/SelCctvListByUserId",
  55. type:"GET"
  56. };
  57. let _data = {
  58. "user_id": _this.userForm.userId
  59. };
  60. let _hea = {
  61. "Authorization": "Bearer " + baseTok
  62. }; getAxios(_opts,_data,_hea).then((res) => { if(res.code == 200&&res.data.length){
  63. let _xji = res.data;
  64. let _bji = _xji.map(item => item.mmsi);
  65. getCctvAis(_bji.toString(),function(_res){
  66. let _arr = [];
  67. _xji.forEach(item => {
  68. let sd = _res.filter(subitem => subitem[0] == item.mmsi)[0];
  69. let _newpo = GpsToGd(Number(sd[13]), Number(sd[12]));
  70. _arr.push({
  71. icon: staticUrl + "/img/ship.png",
  72. position: [_newpo.lon,_newpo.lat],
  73. lon: sd[12],
  74. lat: sd[13],
  75. prod: item.dev_name,
  76. sn: item.sn,
  77. mmsi: item.mmsi,
  78. en_name: item.en_name,
  79. speed: (item.mmsi == "413871376"&&sd[15]>1?0.1:sd[15]),
  80. time: sd[23]// sd[23]
  81. })
  82. })
  83. _this.shipLi = _arr;
  84. dataObj = _arr;
  85. let _sn = JSON.parse(localStorage.getItem("nowShip"));
  86. if(_sn !=null && _sn != "null"){
  87. let _ind = _this.shipLi.findIndex((i,ind) => {return i.sn == _sn.sn});
  88. if(_ind != -1){
  89. _sn = _this.shipLi[_ind];
  90. }else{
  91. _sn = _this.shipLi[0];
  92. }
  93. }else{
  94. _sn = _this.shipLi[0];
  95. }
  96. _this.nowTab = _sn;
  97. _this.setMap(_this.shipLi);
  98. }); // let _obj = res.data;
  99. // let _arr = [];
  100. // _obj.forEach((item,ind) => {
  101. // let _nlon = wgsGcj(item.lat, item.lon);
  102. // _arr.push({
  103. // icon: staticUrl + "/img/ship.png",
  104. // position: [_nlon.lon, _nlon.lat],
  105. // prod: item.prod,
  106. // sn: item.sn,
  107. // speed: item.speed,
  108. // devicelist: item.devicelist
  109. // })
  110. // })
  111. }else{ _this.shipLi = [];
  112. _this.nowTab = null; }
  113. // _this.getWire();
  114. // _this.getCctv();
  115. // _this.getLedar();
  116. _this.getGenAlarm(); if(type == 0){loading.close();} }) },
  117. changTab(id){
  118. let ind = _this.shipLi.findIndex((it,ind) => {return id == it.sn});
  119. if(ind != -1){
  120. _this.nowTab = _this.shipLi[ind].sn;
  121. window.parent.postMessage({id: _this.nowTab},staticUrl+ "/");
  122. _this.openInfo(_this.nowTab);
  123. }
  124. },
  125. setMap(_obj){
  126. map.clearMap();
  127. _obj.forEach(function(_obj) {
  128. var marker = new AMap.Marker({
  129. map: map,
  130. icon: new AMap.Icon({
  131. size: new AMap.Size(50, 50),
  132. image: _obj.icon,
  133. imageSize: new AMap.Size(50, 50)
  134. }),
  135. position: _obj.position,
  136. offset: new AMap.Pixel(-13, -30),
  137. extData: _obj.sn
  138. });
  139. marker.setLabel({
  140. offset: new AMap.Pixel(0, 0),
  141. content: "<div style='color:#000;font-size:12px;'>" + _obj.prod + "</div>",
  142. direction: 'bottom'
  143. });
  144. marker.on('click', markerClick);
  145. });
  146. _this.openInfo(_this.nowTab.sn);
  147. function markerClick(e) {
  148. let _ind = e.target.getExtData();
  149. window.parent.postMessage({id: _ind}, staticUrl+ "/");
  150. _this.openInfo(_ind);
  151. }
  152. },
  153. openInfo(_sn){
  154. let _cmk = _this.shipLi;
  155. for (var i = 0; i < _cmk.length; i++) {
  156. if (_sn == _cmk[i].sn) {
  157. let _str = _cmk[i];
  158. _this.nowTab = _str;
  159. var info = [];
  160. getFormattedAddress(_str.position, function(_pos) {
  161. info.push(`<div class="nowShip">
  162. <div class="mapTitle">${_str.prod}</div>
  163. <div class="padding-sm mapInfo">
  164. <div><div>经度:</div><div>${duToGpsDM(_str.lon,'E')}</div></div>
  165. <div><div>纬度:</div><div>${duToGpsDM(_str.lat,'N')}</div></div>
  166. <div><div>航速:</div><div>${_str.speed} 节</div></div>
  167. <div><div>时间:</div><div>${ parseTime(_str.time, '{y}-{m}-{d} {h}:{d}:{s}')}</div></div>
  168. </div>
  169. </div>`);
  170. infoWindow = new AMap.InfoWindow({
  171. offset: new AMap.Pixel(6, -30),
  172. content: info.join("")
  173. });
  174. infoWindow.open(map, _str.position);
  175. map.setCenter(_str.position);
  176. return;
  177. });
  178. }
  179. }
  180. },
  181. getWire(){
  182. let dj = parseTime(new Date(), `{y}-{m}-{d}`);
  183. var imieList = ["ZJ216801593395575038","ZJ217008114043323047"];
  184. var total = 0;
  185. imieList.forEach((item,index)=>{
  186. getWireWarmHistory({
  187. imei: item,
  188. gt: (new Date(dj+" 00:00:00").getTime())/1000,
  189. lt: (new Date(dj+" 23:59:59").getTime())/1000,
  190. orderSql: "time desc",
  191. page: 1,
  192. rows: 1,
  193. accessToken: getCookie("wireToken")
  194. },function(res){
  195. total += parseFloat(res.total);
  196. if((index+1) == imieList.length){
  197. let _obj = _this.craneWarm;
  198. _obj[0].count = total;
  199. _this.craneWarm = _obj;
  200. }
  201. });
  202. });
  203. },
  204. getCctv(){
  205. let _obj = _this.shipLi;
  206. var _warnli = [];
  207. for(let i=0;i<_obj.length;i++){
  208. let _item = _obj[i];
  209. if(_item.en_name != ""&&_item.en_name != null){
  210. let _opts = {
  211. url: vipUrl + "/receive",
  212. type:"GET"
  213. };
  214. let _data = {
  215. user: _item.en_name,
  216. msgType: "",
  217. enddate: _this.nowTime,
  218. startdate: _this.nowTime,
  219. pageNum: 0,
  220. pageSize: 500
  221. };
  222. let _hea = {
  223. "Authorization": "ZDhlNjhjOTAwM2EyJWd6eXolaWUldXNlciV6aF9DTg==",
  224. "Content-Type": "application/json;charset=UTF-8"
  225. };
  226. getAxios(_opts, _data, _hea).then((res) => {
  227. if(res.success&&res.data.length){
  228. _warnli = [..._warnli, ...res.data];
  229. }
  230. if((i+1) == _obj.length){
  231. _this.getCctvCount(_warnli);
  232. }
  233. })
  234. }
  235. }
  236. },
  237. getCctvCount(_obj){
  238. if(_obj.length){
  239. let al = 0, bl = 0, cl = 0, dl = 0, el = 0;
  240. _obj.forEach((item,index) => {
  241. if(item.msgType === "lgjc"){
  242. al += 1;
  243. }else if(item.msgType === "ddhjc"||item.msgType === "wsjjc"){
  244. bl += 1;
  245. }else if(item.msgType === "cyjc"){
  246. cl += 1;
  247. }else if(item.msgType === "aqmjc"||item.msgType === "gzfjc"||item.msgType === "kzjc"||item.msgType === "yhsb"){
  248. dl += 1;
  249. }else if(item.msgType === "qycr"){
  250. el += 1;
  251. }
  252. });
  253. _this.cctvWarm = [{ "name": "离岗检测", "count": al },
  254. { "name": "手机检测", "count": bl },
  255. { "name": "抽烟检测", "count": cl },
  256. { "name": "物品检测", "count": dl }];
  257. let afsafbj = _this.fenceWarm;
  258. afsafbj[0].count = el;
  259. _this.fenceWarm = afsafbj;
  260. }else{
  261. _this.cctvWarm = [{ "name": "离岗检测", "count": 0 },
  262. { "name": "手机检测", "count": 0 },
  263. { "name": "抽烟检测", "count": 0 },
  264. { "name": "物品检测", "count": 0 }];
  265. }
  266. },
  267. getLedar(){
  268. let _obj = _this.shipLi;
  269. var _warnli = 0;
  270. for(let i=0;i<_obj.length;i++){
  271. let _item = _obj[i];
  272. if(_item.en_name != ""&&_item.en_name != null){
  273. let _data = {
  274. sn: _item.en_name,
  275. endTime: _this.nowTime.replace(/\//g,"-"),
  276. beginTime: _this.nowTime.replace(/\//g,"-"),
  277. pageNum: 1,
  278. pageSize: 2
  279. };
  280. getLedarData(_data, function(_res){
  281. _warnli += _res.total;
  282. if((i+1) == _obj.length){
  283. let _obj = _this.craneWarm;
  284. _obj[0].count = _warnli;
  285. _this.craneWarm = _obj;
  286. }
  287. })
  288. }
  289. }
  290. },
  291. getGenAlarm(){
  292. getAllAlarm(_this.nowTime).then(res => {
  293. let g1 = 0, g2 = 0, g3 = 0, g4 = 0;
  294. if(JSON.stringify(res.result) != "{}"){
  295. let _obj = res.result;
  296. for(let key in _obj){
  297. let _subObj = _obj[key];
  298. for(let val in _subObj){
  299. console.log(_subObj[val])
  300. if(val == "am"){
  301. g2 += parseFloat(_subObj[val]);
  302. }else if(val == "td"){
  303. g4 += parseFloat(_subObj[val]);
  304. }else if(val == "t3d"){
  305. g3 += parseFloat(_subObj[val]);
  306. }else if(val == "fd" || val == "ya" || val == "cey"){
  307. g1 += parseFloat(_subObj[val]);
  308. }
  309. }
  310. }
  311. }
  312. _this.genWarmDetail = [{ "name": "生理疲劳", "count": g1 },
  313. { "name": "分神驾驶", "count": g2 },
  314. { "name": "遮挡摄像头", "count": g3 },
  315. { "name": "超时驾驶", "count": g4 }];
  316. })
  317. }
  318. }
  319. })