index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div class="container">
  3. <Left ref="inspRef"></Left>
  4. <Right @refreshLeftList="refreshLeftList" :inspectionOptions="inspectionOptions"></Right>
  5. </div>
  6. </template>
  7. <script>
  8. import Left from './left.vue'
  9. import Right from './right.vue'
  10. import * as mars3d from 'mars3d'
  11. import Vue from 'vue'
  12. let graphicsLayer = null
  13. Vue.prototype.mars3d = mars3d
  14. Vue.prototype.Cesium = mars3d.Cesium
  15. export default {
  16. components: {
  17. Left,
  18. Right
  19. },
  20. data() {
  21. return {
  22. inspectionOptions: [
  23. {
  24. latitude: '28.189249',
  25. longitude: '113.065505',
  26. devName: '浏阳市中和丁字村无线机房_1"',
  27. deviceCode: '43010000831327000018',
  28. channelCode: '430100430000000021130000033'
  29. },
  30. {
  31. latitude: '28.194911',
  32. longitude: '113.066789',
  33. devName: '长沙芙蓉区隆平路与望龙路交叉口-东瑞社区',
  34. deviceCode: '43010000831327000019',
  35. channelCode: '430100430000000021130000037'
  36. }
  37. ]
  38. }
  39. },
  40. mounted() {
  41. this.getData()
  42. },
  43. methods: {
  44. getData() {
  45. window
  46. .requestSDK(
  47. '/ttdevice/ttview/device/queryDeviceInfoPage',
  48. {
  49. pageNum: 1,
  50. pageSize: 10,
  51. platFlag: '1',
  52. operType: '0'
  53. },
  54. {},
  55. 'post'
  56. )
  57. .then(async (res) => {
  58. this.formatData(res.rows)
  59. })
  60. },
  61. formatData(data) {
  62. this.inspectionOptions = data.map((item) => {
  63. const result = {
  64. latitude: item.latitude,
  65. longitude: item.longitude,
  66. devName: item.devName,
  67. deviceCode: item.deviceCode,
  68. channelCode: item.children && item.children.length > 0 ? item.children[0].channelCode : null
  69. }
  70. if (!item.children || item.children.length === 0) {
  71. result.disabled = true
  72. }
  73. return result
  74. })
  75. this.addInitialPoints()
  76. },
  77. refreshLeftList() {
  78. this.$refs.inspRef.getSecurityPatrolList()
  79. },
  80. // 添加初始点
  81. addInitialPoints() {
  82. this.inspectionOptions.forEach((point) => {
  83. if(!point.disabled){
  84. this.addPointToMap(point)
  85. }
  86. })
  87. },
  88. // 添加点到地图
  89. addPointToMap(point) {
  90. // if (graphicsLayer) {
  91. // window.map.removeLayer(graphicsLayer)
  92. // }
  93. graphicsLayer = new this.mars3d.layer.GraphicLayer()
  94. window.map.addLayer(graphicsLayer)
  95. const graphic = new mars3d.graphic.PointEntity({
  96. position: [point.longitude, point.latitude],
  97. billboard: {
  98. image: require('./image/camera.png'),
  99. scale: 1,
  100. horizontalOrigin: this.Cesium.HorizontalOrigin.CENTER,
  101. verticalOrigin: this.Cesium.VerticalOrigin.BOTTOM
  102. },
  103. attr: {
  104. ...point
  105. },
  106. label: {
  107. text: point.devName,
  108. font_size: 32,
  109. color: '#red',
  110. outline: true,
  111. outlineColor: '#000000',
  112. outlineWidth: 2,
  113. horizontalOrigin: this.Cesium.HorizontalOrigin.LEFT,
  114. verticalOrigin: this.Cesium.VerticalOrigin.BOTTOM,
  115. pixelOffset: new this.Cesium.Cartesian2(15, 0)
  116. }
  117. })
  118. graphicsLayer.addGraphic(graphic)
  119. let that = this
  120. graphic.on(this.mars3d.EventType.click, function () {
  121. const pointData = graphic.attr
  122. that.fetchUrl(pointData).then((res) => {
  123. if(res.code == 4001){
  124. that.$message.warning('设备离线')
  125. }else{
  126. const url = res.data.streamUrl
  127. that.$set(pointData, 'url', url)
  128. that.$globalEventBus.$emit('clickVideoPlay', {point: pointData, visible: true ,type:'click'})
  129. }
  130. })
  131. })
  132. },
  133. fetchUrl(item) {
  134. return new Promise((resolve, reject) => {
  135. window
  136. .requestSDK(
  137. '/ttvideo/video/player/getVideoRealtimeUrl',
  138. {
  139. deviceCode: item.deviceCode,
  140. channelCode: item.channelCode,
  141. netType: '1',
  142. protocolType: 5,
  143. streamType: 1
  144. },
  145. {},
  146. 'post'
  147. )
  148. .then(async (res) => {
  149. resolve(res)
  150. })
  151. })
  152. },
  153. }
  154. }
  155. </script>
  156. <style></style>