1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>location</title>
- <script src="js/axios.min.js"></script>
- </head>
- <body>
- <textarea id="msg" style="width: 100%;" rows="10"></textarea>
- <h1 id="tip">2秒内发送</h1>
- <script>
- Date.prototype.format = function (fmt) {
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- }
- for (var k in o) {
- if (new RegExp("(" + k + ")").test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- }
- }
- return fmt;
- }
- </script>
- <script>
- let longitude;
- let latitude;
- let status = false;
- navigator.geolocation.getCurrentPosition(function (position) {
- longitude = position.coords.longitude;
- latitude = position.coords.latitude;
- }, function (error) {
- alert(error.message);
- }, {
- timeout: 90000
- });
- setTimeout(() => {
- if (status === false) {
- sendMsg();
- }
- }, 2000)
- function setTip(str) {
- document.querySelector('#tip').innerHTML = str;
- }
- document.querySelector("#msg").onfocus = function () {
- status = true;
- setTip('点击发送');
- document.querySelector("#tip").onclick = function () {
- sendMsg();
- };
- };
- function sendMsg() {
- axios.post("https://api.tianyunperfect.cn/web_history/location_history", {
- "location_str": "",
- "location_xy": longitude + "-" + latitude,
- "msg": document.querySelector("#msg").innerHTML,
- "create_time": new Date().format('yyyy-MM-dd hh:mm:ss'),
- "update_time": new Date().format('yyyy-MM-dd hh:mm:ss')
- }).then(res => {
- if (res.data.code === 1) {
- // window.close();
- if (longitude === undefined) {
- setTip("发送成功,但是没有经纬度");
- } else {
- setTip("发送成功!!!!!!");
- }
- }
- });
- }
- </script>
- </body>
- </html>
|