index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <pannel class="fence-location-container">
  3. <template v-slot:icon>
  4. <svg-icon icon-class="bd_real_time"/>
  5. </template>
  6. <template v-slot:title>
  7. 实时坐标
  8. </template>
  9. <template v-slot:action>
  10. </template>
  11. <template v-slot:content>
  12. <div class="location-list">
  13. <template v-for="device in deviceList">
  14. <div :key="`evt_${device.id}`" class="list-item">
  15. <span class="over-flow-hidden" style="width: 40%">
  16. {{ device.desc }}
  17. </span>
  18. <span class="over-flow-hidden" style="width: 40%">
  19. {{ device.uwbKey }}
  20. </span>
  21. <span class="over-flow-hidden" style="width: 20%">
  22. <svg-icon :icon-class="`${selectedFlag[device.deviceId]?'bd_signal':'bd_signal_off'}`"
  23. title="查看设备定位"
  24. @click="()=>showLocation(device)"
  25. />
  26. <!-- <i-->
  27. <!-- class="el-icon-circle-close"-->
  28. <!-- title="查看设备定位"-->
  29. <!-- @click="()=>play(device)"-->
  30. <!-- />-->
  31. </span>
  32. </div>
  33. </template>
  34. <socket-message
  35. v-for="item in selectedDevice"
  36. :key="`device_${item.id}`" :onMessage="onMessage"
  37. :ws="`/ws/point/${item.deviceId}`"></socket-message>
  38. </div>
  39. </template>
  40. </pannel>
  41. </template>
  42. <script>
  43. import {pushDevcLocation} from '@/api/bd/fenceInfo';
  44. import SocketMessage from '@/components/WebsocketMessage/index.vue';
  45. import item from '@/layout/components/Sidebar/Item.vue';
  46. import Pannel from '@/views/bd/pannel/index.vue';
  47. import dayjs from 'dayjs';
  48. import position from './icon/position.png';
  49. export default {
  50. name: 'realtime-location',
  51. computed: {
  52. item() {
  53. return item;
  54. },
  55. },
  56. components: {
  57. SocketMessage,
  58. Pannel,
  59. },
  60. data() {
  61. return {
  62. deviceList: [
  63. {
  64. id: 1,
  65. desc: 'uwb001',
  66. deviceId: 'uwb001',
  67. },
  68. ],
  69. fp: null,
  70. ws: null,
  71. markLayer: null,
  72. locationMarkers: {},
  73. selectedDevice: [],
  74. playInterval: null,
  75. selectedFlag: {},
  76. };
  77. },
  78. // 组件卸载前清空图层信息
  79. beforeDestroy() {
  80. this.markLayer && window.map.removeLayersById('markerLayer');
  81. this.playInterval && clearInterval(this.playInterval);
  82. },
  83. created() {
  84. this.markLayer = new BDLayers.Lib.Layer.CBVectorLayer('markerLayer', true);
  85. window.map.addCustomLayers(this.markLayer, 5);
  86. },
  87. mounted() {
  88. this.getFenceVioEvtList();
  89. },
  90. methods: {
  91. dayjs,
  92. async getFenceVioEvtList() {
  93. // const { rows } = await listFenceVioEvt({
  94. // pageNum: 1,
  95. // pageSize: 10,
  96. // });
  97. // this.deviceList = rows;
  98. },
  99. addMarker(data) {
  100. const {
  101. latitude,
  102. longitude,
  103. deviceId,
  104. } = data;
  105. const marker = new BDLayers.Lib.Overlays.MarkerImg(
  106. `marker${deviceId}`,
  107. [longitude, latitude],
  108. {
  109. imgurl: position,
  110. iconSize: [50, 60],
  111. symbol: {
  112. 'textName': 'm4',
  113. 'textSize': 14,
  114. 'markerFile': position,
  115. 'markerHorizontalAlignment': 'middle', // left, middle(默认), right
  116. 'markerVerticalAlignment': 'middle', // top, middle, bottom(默认)
  117. },
  118. },
  119. );
  120. this.markLayer.addMarker(marker);
  121. return marker;
  122. },
  123. showLocation(device) {
  124. const exist = this.selectedDevice.find(item => item.deviceId === device.deviceId);
  125. if (exist) {
  126. this.selectedDevice = this.selectedDevice.filter(item => item.deviceId !== device.deviceId);
  127. this.selectedFlag = {
  128. ...this.selectedFlag,
  129. [device.deviceId]: false,
  130. };
  131. return;
  132. }
  133. this.selectedDevice.push(device);
  134. this.selectedFlag = {
  135. ...this.selectedFlag,
  136. [device.deviceId]: true,
  137. };
  138. this.selectedDevice = [...this.selectedDevice];
  139. this.play();
  140. },
  141. onMessage(a) {
  142. const data = JSON.parse(a.data);
  143. const {
  144. latitude,
  145. longitude,
  146. deviceId,
  147. } = data;
  148. console.log('>>>>>>>>>>>>>>>>>>>>>>>>', data);
  149. if (!this.locationMarkers[deviceId]) {
  150. this.locationMarkers[deviceId] = this.addMarker(data);
  151. return;
  152. }
  153. this.locationMarkers[deviceId].moveMarker([longitude, latitude], 2000, false);
  154. },
  155. play() {
  156. this.playInterval && clearInterval(this.playInterval);
  157. const gps =
  158. [
  159. [118.868446580271, 32.0123378608057],
  160. [118.868406952344, 32.0123370689339],
  161. [118.868366815026, 32.0123546053505],
  162. [118.868358676065, 32.0123880632266],
  163. [118.868350452205, 32.0124245758027],
  164. [118.86834900893, 32.0124765058939],
  165. [118.868344642304, 32.012503926295],
  166. [118.868332136717, 32.0125648044994],
  167. [118.868320565014, 32.0125920808978],
  168. [118.86830547567, 32.0126162305943],
  169. [118.868297336709, 32.0126496883748],
  170. [118.868296572622, 32.0126771807122],
  171. [118.868295214246, 32.0127260559583],
  172. [118.868293601174, 32.0127840952791],
  173. [118.868289064751, 32.0128176249864],
  174. [118.868281265384, 32.012838863901],
  175. [118.868280671094, 32.0128602467866],
  176. [118.868290375029, 32.0129001738105],
  177. [118.86833686844, 32.0129133284373],
  178. [118.868358313875, 32.0129198697561],
  179. [118.868408240027, 32.0129392057582],
  180. [118.868415360206, 32.0129424044289],
  181. [118.868425828228, 32.012954839171],
  182. [118.86843277861, 32.0129641472296],
  183. [118.868435786859, 32.0129856020738],
  184. [118.868442737241, 32.0129949101293],
  185. [118.868445915288, 32.0130102555814],
  186. [118.868445066302, 32.0130408025022],
  187. [118.868447395363, 32.013086694852],
  188. [118.868446716175, 32.0131111323691],
  189. [118.868446036987, 32.0131355698797],
  190. [118.868444933306, 32.0131752808204],
  191. [118.868447517062, 32.0132120090459],
  192. [118.868446668077, 32.0132425558994],
  193. [118.868445479497, 32.0132853214773],
  194. [118.868463492191, 32.0132856814153],
  195. [118.868506722657, 32.0132865452666]
  196. ];
  197. let i = 0;
  198. this.playInterval = setInterval(() => {
  199. if (i === gps.length - 1) {
  200. return;
  201. }
  202. pushDevcLocation({
  203. devcKey: 'uwb001',
  204. lat: gps[i][1],
  205. lng: gps[i][0],
  206. });
  207. i++;
  208. }, 2000);
  209. },
  210. },
  211. };
  212. </script>
  213. <style lang="scss" src="./index.scss"/>