location.html 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>location</title>
  6. <script src="js/axios.min.js"></script>
  7. </head>
  8. <body>
  9. <h1 id="msg"></h1>
  10. <script>
  11. Date.prototype.format = function (fmt) {
  12. var o = {
  13. "M+": this.getMonth() + 1, //月份
  14. "d+": this.getDate(), //日
  15. "h+": this.getHours(), //小时
  16. "m+": this.getMinutes(), //分
  17. "s+": this.getSeconds(), //秒
  18. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  19. "S": this.getMilliseconds() //毫秒
  20. };
  21. if (/(y+)/.test(fmt)) {
  22. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  23. }
  24. for (var k in o) {
  25. if (new RegExp("(" + k + ")").test(fmt)) {
  26. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  27. }
  28. }
  29. return fmt;
  30. }
  31. navigator.geolocation.getCurrentPosition(function (position) {
  32. let longitude = position.coords.longitude;
  33. let latitude = position.coords.latitude;
  34. axios.post("https://api.tianyunperfect.cn/web_history/location_history", {
  35. "location_str": "",
  36. "location_xy": longitude + "-" + latitude,
  37. "msg": "",
  38. "create_time": new Date().format('yyyy-MM-dd hh:mm:ss'),
  39. "update_time": new Date().format('yyyy-MM-dd hh:mm:ss')
  40. }).then(res => {
  41. if (res.data.code === 1) {
  42. window.close();
  43. document.querySelector("#msg").innerHTML = "OK";
  44. }
  45. });
  46. }, function (error) {
  47. alert(error.message);
  48. }, {
  49. timeout: 90000
  50. });
  51. </script>
  52. </body>
  53. </html>