location_list.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
  6. <script src="https://web.tianyunperfect.cn/util.js"></script>
  7. <title>location_list</title>
  8. <script src="js/axios.min.js"></script>
  9. <script src="js/vue.min.js"></script>
  10. <script src="https://api.map.baidu.com/api?v=2.0&ak=WMYeXwq7z0VcaiUXTuYTGPZsm8Selmfd"></script>
  11. <style>
  12. .container {
  13. width: 500px;
  14. height: 50px;
  15. margin: 20px auto;
  16. }
  17. .parent {
  18. width: 100%;
  19. height: 42px;
  20. top: 4px;
  21. position: relative;
  22. }
  23. .parent > input:first-of-type {
  24. /*输入框高度设置为40px, border占据2px,总高度为42px*/
  25. width: 380px;
  26. height: 40px;
  27. border: 1px solid #ccc;
  28. font-size: 16px;
  29. outline: none;
  30. }
  31. .parent > input:first-of-type:focus {
  32. border: 1px solid #317ef3;
  33. padding-left: 10px;
  34. }
  35. .parent > input:last-of-type {
  36. /*button按钮border并不占据外围大小,设置高度42px*/
  37. width: 100px;
  38. height: 44px;
  39. position: absolute;
  40. background: #317ef3;
  41. border: 1px solid #317ef3;
  42. color: #fff;
  43. font-size: 16px;
  44. outline: none;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <div id="tby">
  50. <div class="container">
  51. <form action="" class="parent">
  52. <input type="text" v-model="msg">
  53. <input type="button" value="搜索" @click="search">
  54. </form>
  55. </div>
  56. <table>
  57. <thead>
  58. <tr>
  59. <td>id</td>
  60. <td>时间</td>
  61. <td>经纬度</td>
  62. <td>附加信息</td>
  63. <td>猜测位置</td>
  64. <td>与我大概距离</td>
  65. <td>操作</td>
  66. </tr>
  67. </thead>
  68. <tbody>
  69. <tr v-for="(item,index) in list">
  70. <td>{{item.id}}</td>
  71. <td>{{new Date(item.create_time).format("yyyy-MM-dd hh:mm:ss")}}</td>
  72. <td>
  73. <a :href="'https://api.map.baidu.com/marker?location='+ item.location_xy + '&title=' + item.msg + '&content=&output=html&src=webapp.baidu.openAPIdemo'"
  74. target="_blank">{{item.location_xy}}</a>
  75. </td>
  76. <td>{{item.msg}}</td>
  77. <td>{{item.location_str}}</td>
  78. <td>{{item['distance']}}</td>
  79. <td>
  80. <span @click="to_update(item)">跳转更新</span>
  81. <span> | | | | </span>
  82. <span @click="delete_by_id(item.id)">删除</span>
  83. </td>
  84. </tr>
  85. </tbody>
  86. </table>
  87. <!-- 分页按钮 -->
  88. <div class="page-icon">
  89. <button class="firstPage" @click="first_click">第一页</button>
  90. <button class="beforePage" @click="prev_click">上一页</button>
  91. <button>第<input v-model="page" @change="choose_page" type="text" value="1"/>页</button>
  92. <button class="nextPage" @click="next_click">下一页</button>
  93. </div>
  94. <hr>
  95. <p>根据 id 更新</p>
  96. <input v-model="update_id" placeholder="id" id="update_id">
  97. <input v-model="update_msg" placeholder="信息">
  98. <button @click="update">更新</button>
  99. </div>
  100. <script>
  101. Date.prototype.format = function (fmt) {
  102. var o = {
  103. "M+": this.getMonth() + 1, //月份
  104. "d+": this.getDate(), //日
  105. "h+": this.getHours(), //小时
  106. "m+": this.getMinutes(), //分
  107. "s+": this.getSeconds(), //秒
  108. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  109. "S": this.getMilliseconds() //毫秒
  110. };
  111. if (/(y+)/.test(fmt)) {
  112. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  113. }
  114. for (var k in o) {
  115. if (new RegExp("(" + k + ")").test(fmt)) {
  116. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  117. }
  118. }
  119. return fmt;
  120. }
  121. const scrollElement = (el) => {
  122. document.querySelector(el).scrollIntoView({behavior: 'smooth'});
  123. }
  124. let longitude = '';
  125. let latitude;
  126. // 获取经纬度
  127. function getLocation() {
  128. // 创建百度地理位置实例,代替 navigator.geolocation
  129. var geolocation = new BMap.Geolocation();
  130. geolocation.getCurrentPosition(function (e) {
  131. if (this.getStatus() == BMAP_STATUS_SUCCESS) {
  132. // 百度 geolocation 的经纬度属性不同,此处是 point.lat 而不是 coords.latitude
  133. latitude = e.point.lat;
  134. longitude = e.point.lng;
  135. _this.updateLocationStr();
  136. } else {
  137. }
  138. });
  139. }
  140. getLocation();
  141. let _this = new Vue({
  142. el: '#tby',
  143. data: {
  144. update_id: '',
  145. update_msg: '',
  146. page: 1,
  147. size: 1000,
  148. msg: "",
  149. user_id: "",
  150. list: []
  151. },
  152. mounted: function () {
  153. this.user_id = getQueryString("user_id");
  154. this.search();
  155. },
  156. methods: {
  157. updateLocationStr() {
  158. for (const item of _this.list) {
  159. if (item.location_xy.indexOf("un") < 0 && longitude.toString().length > 2) {
  160. let split = item.location_xy.split(",");
  161. item['distance'] = _this.getDistance(split[1], split[0], longitude, latitude);
  162. }
  163. }
  164. _this.$forceUpdate();
  165. },
  166. getDistance(lon1, lat1, lon2, lat2) {
  167. const map = new BMap.Map("allmap");
  168. const pointA = new BMap.Point(lon1, lat1); // 创建点坐标A
  169. const pointB = new BMap.Point(lon2, lat2); // 创建点坐标B
  170. const range = map.getDistance(pointA, pointB).toFixed(2); //获取两点距离,保留小数点后两位
  171. return range;
  172. },
  173. delete_by_id: function (id) {
  174. if (confirm("确定要删除吗?不可恢复!!!")) {
  175. axios.get("https://api.tianyunperfect.cn/web_history/location_delete", {
  176. params: {
  177. "id": id,
  178. "user_id": _this.user_id,
  179. }
  180. }).then(res => {
  181. if (res.data.code === 1) {
  182. _this.search();
  183. _this.update_id = '';
  184. _this.update_msg = '';
  185. }
  186. });
  187. }
  188. },
  189. to_update: function (item) {
  190. this.update_id = item.id;
  191. if (item.msg && item.msg.length > 1) {
  192. this.update_msg = item.msg;
  193. }
  194. scrollElement("#update_id");
  195. },
  196. update: function () {
  197. axios.get("https://api.tianyunperfect.cn/web_history/location_update", {
  198. params: {
  199. "id": _this.update_id,
  200. "user_id": _this.user_id,
  201. "msg": _this.update_msg
  202. }
  203. }).then(res => {
  204. if (res.data.code === 1) {
  205. _this.search();
  206. _this.update_id = '';
  207. _this.update_msg = '';
  208. }
  209. });
  210. },
  211. first_click: function () {
  212. this.page = 1;
  213. this.search();
  214. },
  215. prev_click: function () {
  216. this.page -= 1;
  217. this.search();
  218. },
  219. choose_page: function () {
  220. this.search();
  221. },
  222. next_click: function () {
  223. this.page += 1;
  224. this.search();
  225. },
  226. getParam: function () {
  227. let obj = {};
  228. obj['user_id'] = this.user_id;
  229. obj['limit1'] = (this.page - 1) * this.size;
  230. obj['limit2'] = this.page * this.size;
  231. if (this.msg.length > 0) {
  232. obj["msg"] = this.msg;
  233. }
  234. return obj;
  235. },
  236. search: function () {
  237. axios.get("https://api.tianyunperfect.cn/web_history/location_history", {params: this.getParam()}).then(res => {
  238. if (res.data.code === 1) {
  239. _this.list = res.data.data;
  240. }
  241. });
  242. }
  243. }
  244. });
  245. </script>
  246. </body>
  247. </html>