location_list.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. <style>
  11. .container {
  12. width: 500px;
  13. height: 50px;
  14. margin: 100px auto;
  15. }
  16. .parent {
  17. width: 100%;
  18. height: 42px;
  19. top: 4px;
  20. position: relative;
  21. }
  22. .parent > input:first-of-type {
  23. /*输入框高度设置为40px, border占据2px,总高度为42px*/
  24. width: 380px;
  25. height: 40px;
  26. border: 1px solid #ccc;
  27. font-size: 16px;
  28. outline: none;
  29. }
  30. .parent > input:first-of-type:focus {
  31. border: 1px solid #317ef3;
  32. padding-left: 10px;
  33. }
  34. .parent > input:last-of-type {
  35. /*button按钮border并不占据外围大小,设置高度42px*/
  36. width: 100px;
  37. height: 44px;
  38. position: absolute;
  39. background: #317ef3;
  40. border: 1px solid #317ef3;
  41. color: #fff;
  42. font-size: 16px;
  43. outline: none;
  44. }
  45. </style>
  46. </head>
  47. <body>
  48. <div id="tby">
  49. <div class="container">
  50. <form action="" class="parent">
  51. <input type="text" v-model="msg">
  52. <input type="button" value="搜索" @click="search">
  53. </form>
  54. </div>
  55. <table>
  56. <thead>
  57. <tr>
  58. <td>id</td>
  59. <td>事件</td>
  60. <td>地点</td>
  61. <td>信息</td>
  62. <td>操作</td>
  63. </tr>
  64. </thead>
  65. <tbody>
  66. <tr v-for="(item,index) in list">
  67. <td>{{item.id}}</td>
  68. <td>{{new Date(item.create_time).format("yyyy-MM-dd hh:mm:ss")}}</td>
  69. <td>
  70. <a :href="'https://api.map.baidu.com/marker?location='+ item.location_xy + '&title=' + item.msg + '&content=&output=html&src=webapp.baidu.openAPIdemo'"
  71. target="_blank">{{item.location_xy}}</a>
  72. </td>
  73. <td>{{item.msg}}</td>
  74. <td>
  75. <span @click="to_update(item)">跳转更新</span>
  76. <span> | | | | </span>
  77. <span @click="delete_by_id(item.id)">删除</span>
  78. </td>
  79. </tr>
  80. </tbody>
  81. </table>
  82. <!-- 分页按钮 -->
  83. <div class="page-icon">
  84. <button class="firstPage" @click="first_click">第一页</button>
  85. <button class="beforePage" @click="prev_click">上一页</button>
  86. <button>第<input v-model="page" @change="choose_page" type="text" value="1"/>页</button>
  87. <button class="nextPage" @click="next_click">下一页</button>
  88. </div>
  89. <hr>
  90. <p>根据 id 更新</p>
  91. <input v-model="update_id" placeholder="id" id="update_id">
  92. <input v-model="update_msg" placeholder="信息">
  93. <button @click="update">更新</button>
  94. </div>
  95. <script>
  96. Date.prototype.format = function (fmt) {
  97. var o = {
  98. "M+": this.getMonth() + 1, //月份
  99. "d+": this.getDate(), //日
  100. "h+": this.getHours(), //小时
  101. "m+": this.getMinutes(), //分
  102. "s+": this.getSeconds(), //秒
  103. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  104. "S": this.getMilliseconds() //毫秒
  105. };
  106. if (/(y+)/.test(fmt)) {
  107. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  108. }
  109. for (var k in o) {
  110. if (new RegExp("(" + k + ")").test(fmt)) {
  111. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  112. }
  113. }
  114. return fmt;
  115. }
  116. const scrollElement = (el)=>{
  117. document.querySelector(el).scrollIntoView({behavior: 'smooth'});
  118. }
  119. let _this = new Vue({
  120. el: '#tby',
  121. data: {
  122. update_id: '',
  123. update_msg: '',
  124. page: 1,
  125. size: 1000,
  126. msg: "",
  127. user_id: "",
  128. list: []
  129. },
  130. mounted: function () {
  131. this.user_id = getQueryString("user_id");
  132. this.search();
  133. },
  134. methods: {
  135. delete_by_id: function (id) {
  136. if (confirm("确定要删除吗?不可恢复!!!")) {
  137. axios.get("https://api.tianyunperfect.cn/web_history/location_delete", {
  138. params: {
  139. "id": id,
  140. "user_id": _this.user_id,
  141. }
  142. }).then(res => {
  143. if (res.data.code === 1) {
  144. _this.search();
  145. _this.update_id = '';
  146. _this.update_msg = '';
  147. }
  148. });
  149. }
  150. },
  151. to_update: function (item) {
  152. this.update_id = item.id;
  153. if (item.msg && item.msg.length > 1) {
  154. this.update_msg = item.msg;
  155. }
  156. scrollElement("#update_id");
  157. },
  158. update: function () {
  159. axios.get("https://api.tianyunperfect.cn/web_history/location_update", {
  160. params: {
  161. "id": _this.update_id,
  162. "user_id": _this.user_id,
  163. "msg": _this.update_msg
  164. }
  165. }).then(res => {
  166. if (res.data.code === 1) {
  167. _this.search();
  168. _this.update_id = '';
  169. _this.update_msg = '';
  170. }
  171. });
  172. },
  173. first_click: function () {
  174. this.page = 1;
  175. this.search();
  176. },
  177. prev_click: function () {
  178. this.page -= 1;
  179. this.search();
  180. },
  181. choose_page: function () {
  182. this.search();
  183. },
  184. next_click: function () {
  185. this.page += 1;
  186. this.search();
  187. },
  188. getParam: function () {
  189. let obj = {};
  190. obj['user_id'] = this.user_id;
  191. obj['limit1'] = (this.page - 1) * this.size;
  192. obj['limit2'] = this.page * this.size;
  193. if (this.msg.length > 0) {
  194. obj["msg"] = this.msg;
  195. }
  196. return obj;
  197. },
  198. search: function () {
  199. axios.get("https://api.tianyunperfect.cn/web_history/location_history", {params: this.getParam()}).then(res => {
  200. if (res.data.code === 1) {
  201. _this.list = res.data.data;
  202. }
  203. });
  204. }
  205. }
  206. });
  207. </script>
  208. </body>
  209. </html>