index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. [118.868474555524, 32.013913750075],
  159. [118.868459917135, 32.0138560330253],
  160. [118.868460650064, 32.0137600494265],
  161. [118.868469791963, 32.0135491295906],
  162. [118.868450597046, 32.0135969285238],
  163. [118.868451821878, 32.0134372342673],
  164. [118.868369085172, 32.0134271059761],
  165. [118.868229813542, 32.0134261784667],
  166. [118.868037844538, 32.0134249000077],
  167. [118.867988911263, 32.013424574126],
  168. [118.867990212059, 32.0132809893746],
  169. [118.867986825628, 32.0132395072755],
  170. [118.867987028075, 32.0132171885197],
  171. [118.867987432888, 32.0131725599655],
  172. [118.867984539806, 32.0130769425047],
  173. [118.867977454441, 32.0130291167663],
  174. [118.86797791828, 32.0129781711549],
  175. [118.867978150146, 32.0129527041872],
  176. [118.867974855578, 32.0129017568948],
  177. [118.868046176274, 32.0129117791912],
  178. [118.868121507934, 32.0128931867922],
  179. [118.868117943319, 32.0128708893801],
  180. [118.868126616248, 32.012737367597],
  181. [118.868127634971, 32.0126197858525],
  182. [118.868127662494, 32.0126166091195],
  183. [118.868165320753, 32.0126041528561],
  184. [118.868173101262, 32.0125724412675],
  185. [118.868240681514, 32.0125728913369],
  186. [118.868308235972, 32.0125765173023],
  187. [118.868334874981, 32.0125322352762],
  188. [118.868324305199, 32.012446455205],
  189. [118.868361835438, 32.0124467051483],
  190. [118.868364679658, 32.0125610134717],
  191. [118.868492254263, 32.0125713907483],
  192. [118.868541014618, 32.0125780675563],
  193. [118.868732580782, 32.012566639437],
  194. [118.868841456955, 32.0125673645282],
  195. [118.868976574771, 32.0125746162152],
  196. [118.869070453844, 32.0125720654824],
  197. [118.869096734551, 32.0125722405062],
  198. [118.869156822422, 32.0125694647922],
  199. [118.869179313588, 32.0125759664106],
  200. [118.869201684821, 32.0126047016424],
  201. [118.869186178487, 32.0126935647542],
  202. [118.869193065594, 32.0128080658432],
  203. [118.869192510216, 32.0129098661745],
  204. [118.86919198924, 32.0130053604978],
  205. [118.869179854563, 32.0131613771548],
  206. [118.869190250492, 32.0133240705021],
  207. [118.869185964264, 32.0134197772962],
  208. [118.86917071489, 32.0134547924615],
  209. [118.869159014503, 32.0135281642937],
  210. [118.869166174307, 32.0135953030259],
  211. [118.869165521059, 32.0137135723353],
  212. [118.869187426642, 32.0138416759025],
  213. [118.869153188005, 32.0138990608231],
  214. [118.868990969654, 32.0139203908971],
  215. [118.868768561862, 32.0139189097324],
  216. [118.868572541435, 32.0139176042992],
  217. [118.868557462941, 32.0139175038812],
  218. [118.868474555524, 32.013913750075],
  219. ];
  220. let i = 0;
  221. this.playInterval = setInterval(() => {
  222. pushDevcLocation({
  223. devcKey: 'uwb001',
  224. lat: gps[i][1],
  225. lng: gps[i][0],
  226. });
  227. if (i === gps.length - 1) {
  228. i = 0;
  229. return;
  230. }
  231. i++;
  232. }, 2000);
  233. },
  234. },
  235. };
  236. </script>
  237. <style lang="scss" src="./index.scss" />