index.vue 6.5 KB

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