ajax.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. function getOneYsy(devs, cb, who) {
  2. let _opts = {
  3. url: ys7Url + "/api/lapp/device/info",
  4. type: "POST"
  5. };
  6. let _data = {
  7. deviceSerial: devs,
  8. accessToken: getCookie("ylToken")
  9. };
  10. let _hea = {
  11. "Content-Type": "application/x-www-form-urlencoded"
  12. };
  13. postAxios(_opts, _data, _hea).then((res) => {
  14. let _acb = res.data;
  15. if (who != undefined) {
  16. cb(_acb);
  17. } else {
  18. let ysysData = {
  19. icon: "../imgs/ship.png",
  20. position: [113.207453, 21.976270],
  21. prod: _acb.deviceName,
  22. sn: _acb.deviceSerial,
  23. sog: 0,
  24. time: getTime(new Date())[0] + getTime(new Date())[1],
  25. online: _acb.status,
  26. devVer: 4,
  27. };
  28. cb(ysysData);
  29. }
  30. })
  31. }
  32. function getCctvYsy(devs, cb) {
  33. let _opts = {
  34. url: ys7Url + "/api/lapp/device/info",
  35. type: "POST"
  36. };
  37. let _data = {
  38. accessToken: getCookie("ylToken"),
  39. pageStart: 0,
  40. pageSize: 50
  41. };
  42. let _hea = {
  43. "Content-Type": "application/x-www-form-urlencoded"
  44. };
  45. postAxios(_opts, _data, _hea).then((res) => {
  46. let _acb = result.data,
  47. _arr = [];
  48. devs.forEach(item => {
  49. let sd = _acb.filter(subitem => subitem.deviceSerial == item.sn)[0]
  50. _arr.push({
  51. prod: sd.deviceName,
  52. sn: sd.deviceSerial,
  53. time: getTime(new Date())[0] + getTime(new Date())[1],
  54. online: sd.status,
  55. mmsi: item.mmsi,
  56. devVer: 4
  57. })
  58. })
  59. cb(_arr);
  60. });
  61. }
  62. function getCctvAis(_ais, cb) {
  63. $.ajax({
  64. url: "https://www.enstation.com:8083/ruico-ais/open/ais/getAisInfo",
  65. type: "POST",
  66. traditional: true,
  67. async: false,
  68. data: {
  69. key: "7b581bc63821b05b2870456fbb6f47df",
  70. mmsi: _ais
  71. },
  72. error: function(XMLHttpRequest) {},
  73. success: function(data) {
  74. let _data = ""
  75. if (data.data != undefined) {
  76. _data = data.data;
  77. localStorage.setItem("Histroy-List", _data);
  78. } else {
  79. if (localStorage.getItem("Histroy-List") != undefined && localStorage.getItem(
  80. "Histroy-List") != null) {
  81. _data = localStorage.getItem("Histroy-List");
  82. } else {
  83. _data = "";
  84. }
  85. }
  86. if (_data != "") {
  87. let _obj = deCoded(_data);
  88. cb(_obj);
  89. }
  90. }
  91. })
  92. }
  93. function getHisMap(query, cb) {
  94. $.ajax({
  95. url: "https://www.enstation.com:8083/ruico-ais/open/getAisTrack",
  96. type: "POST",
  97. traditional: true,
  98. async: false,
  99. data: query,
  100. error: function(XMLHttpRequest) {},
  101. success: function(data) {
  102. if (data.result) {
  103. let _obj = deCoded(data.data);
  104. cb(_obj);
  105. } else {
  106. let mmsi = query.mmsi;
  107. let _obj = {};
  108. _obj[mmsi] = []
  109. cb(_obj);
  110. }
  111. }
  112. })
  113. }
  114. function deCoded(key) {
  115. let decodedData = atob(key);
  116. let charData = decodedData.split('').map(x => x.charCodeAt(0));
  117. let binData = new Uint8Array(charData);
  118. let data = pako.inflate(binData);
  119. let _dhj = Utf8ArrayToStr(data);
  120. return _dhj
  121. }
  122. function Utf8ArrayToStr(array) {
  123. var out, i, len, c;
  124. var char2, char3;
  125. out = "";
  126. len = array.length;
  127. i = 0;
  128. while (i < len) {
  129. c = array[i++];
  130. switch (c >> 4) {
  131. case 0:
  132. case 1:
  133. case 2:
  134. case 3:
  135. case 4:
  136. case 5:
  137. case 6:
  138. case 7:
  139. out += String.fromCharCode(c);
  140. break;
  141. case 12:
  142. case 13:
  143. char2 = array[i++];
  144. out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
  145. break;
  146. case 14:
  147. char2 = array[i++];
  148. char3 = array[i++];
  149. out += String.fromCharCode(((c & 0x0F) << 12) |
  150. ((char2 & 0x3F) << 6) |
  151. ((char3 & 0x3F) << 0));
  152. break;
  153. }
  154. }
  155. return JSON.parse(out)
  156. };
  157. function duToGpsDM(duStr, duDir) {
  158. // console.log(duStr, duDir);
  159. duStr = (duStr + '').toLowerCase();
  160. duStr = duStr.replace(/\s+/g, "");
  161. duDir = duDir.toUpperCase();
  162. var strLength = duStr.length;
  163. var tempString = "";
  164. var tempStrArray = new Array();
  165. var tempCount = 0;
  166. var tempPointFlag = 0;
  167. var gpsDM;
  168. for (var i = 0; i <= strLength; i++) {
  169. if (duStr[i] >= '0' && duStr[i] <= '9') {
  170. tempString += duStr[i];
  171. continue;
  172. } else if (duStr[i] == '.') {
  173. tempStrArray[tempCount] = tempString;
  174. tempString = "";
  175. tempCount++;
  176. tempStrArray[tempCount] = '.';
  177. tempPointFlag = 1;
  178. tempCount++;
  179. } else if (tempString.length > 0) {
  180. tempStrArray[tempCount] = tempString;
  181. tempString = "";
  182. tempCount++;
  183. }
  184. }
  185. if (tempPointFlag == 1) {
  186. var num1 = tempStrArray[0];
  187. var num2 = parseFloat('0' + tempStrArray[1] + tempStrArray[2], 10) * 60;
  188. gpsDM = num1 + "°" + num2.toFixed(4) + " " + duDir;
  189. //gpsDM=+num1+"°"+num2+"′"+" "+duDir;
  190. // console.log(gpsDM);
  191. }
  192. return gpsDM;
  193. }
  194. function getFormattedAddress(_obj, _calbcl) {
  195. $.ajax({
  196. url: "https://restapi.amap.com/v3/geocode/regeo",
  197. type: "POST",
  198. dataType: "json",
  199. data: {
  200. output: "json",
  201. location: _obj.toString(),
  202. key: "b7123477fa51cba7b47769d2e7b4b9d7",
  203. radius: 1000,
  204. extensions: "base"
  205. },
  206. error: function(XMLHttpRequest, textStatus, errorThrown) {
  207. },
  208. success: function(dart) {
  209. if (dart.status == 1 && dart.regeocode.formatted_address.length) {
  210. _calbcl(dart.regeocode.formatted_address);
  211. } else {
  212. _calbcl("获取位置失败");
  213. }
  214. }
  215. });
  216. }