MonitorCameras.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div class="monitor-cameras-container">
  3. <div class="main-camera">
  4. <div class="has-main-camera" v-if="curPlayingCamera && getCameraUrl(curPlayingCamera)">
  5. <LiveVideo
  6. :url="getCameraUrl(curPlayingCamera)"
  7. :poster="getCameraImg(curPlayingCamera)"
  8. :id="`monitor-livevideo`"
  9. class="main-video"
  10. />
  11. <img
  12. src="@/assets/images/disaster-overview/full-screen.png"
  13. alt=""
  14. class="full-screen"
  15. @click="isFullScreen ? exitFullscreen() : fullScreen(`monitor-livevideo`, 'overview-monitor')"
  16. />
  17. </div>
  18. <div class="no-main-camera" v-if="!curPlayingCamera || !getCameraUrl(curPlayingCamera)">
  19. <img class="cameraEmptyImg" src="@/assets/icons/nine-square-grid/cameraEmpty.png" />
  20. <span>暂无监控相机画面</span>
  21. </div>
  22. </div>
  23. <div class="all-cameras">
  24. <div class="camera-edit">
  25. <div>
  26. <img src="@/assets/images/disaster-overview/camera.png" alt="" />
  27. <span class="title">监控相机</span>
  28. </div>
  29. <div class="add-area" @click="updateMonitorVisible = true">
  30. <span class="add-icon">+</span>
  31. <span>编辑监控相机</span>
  32. </div>
  33. </div>
  34. <div class="camera-list">
  35. <div v-if="selectedCamerasOfCommandCenter.length === 0" class="no-camera-list">
  36. <img class="empty-img" src="@/assets/images/empty.png" alt="" />
  37. <span>暂无监控相机</span>
  38. </div>
  39. <div
  40. v-for="(item, index) in selectedCamerasOfCommandCenter"
  41. :key="index"
  42. class="monitor-item"
  43. :class="{ 'cur-playing': curPlayingCamera?.id === item.id }"
  44. @click="curPlayingCamera = item"
  45. >
  46. <img
  47. v-if="!getCameraUrl(item)"
  48. src="@/assets/images/disaster-overview/no-camera-url.png"
  49. alt=""
  50. class="monitor-no-url"
  51. />
  52. <LiveVideo
  53. :url="getCameraUrl(item)"
  54. :poster="getCameraImg(item)"
  55. :id="`monitor-livevideo-${index}`"
  56. class="live-video"
  57. />
  58. <div>{{ item.name }}</div>
  59. </div>
  60. </div>
  61. </div>
  62. <UpdateMonitorArea v-if="updateMonitorVisible" @confirm="handleConfirmAddMonitor" @close="handleCloseAddMonitor" />
  63. </div>
  64. </template>
  65. <script setup lang="ts">
  66. import { onMounted, onUnmounted, ref, watch } from 'vue';
  67. import { useRoute } from 'vue-router';
  68. import { storeToRefs } from 'pinia';
  69. import screenfull from 'screenfull';
  70. import urlJoin from 'url-join';
  71. import { ElMessage } from 'element-plus';
  72. import LiveVideo from '@/components/live/LiveVideo.vue';
  73. import UpdateMonitorArea from '@/components/monitor-camera-edit/UpdateMonitorArea.vue';
  74. import { useMonitorCameraEdit } from '@/store/modules/useMonitorCameraEdit';
  75. import { userSplitScreenFullScreen } from '@/store/modules/userSplitScreenFullScreen';
  76. import { CameraInfo, CameraInTree, updateCameraToOverviewGroup } from '@/api/disaster-overview';
  77. const monitorCameraEdit = useMonitorCameraEdit();
  78. const { idOfEmergencyEvent, idOfCommandCenter, selectedCamerasOfCommandCenter } = storeToRefs(monitorCameraEdit);
  79. const { getSelectedCameraIdsOfCommandCenter } = monitorCameraEdit;
  80. const { isFullScreen, curFullScreenType } = storeToRefs(userSplitScreenFullScreen());
  81. const { fullScreen, exitFullscreen } = userSplitScreenFullScreen();
  82. const route = useRoute();
  83. const emergencyEventId = Number(route.params.id);
  84. const curPlayingCamera = ref<CameraInfo>();
  85. const updateMonitorVisible = ref(false);
  86. const isHttps = () => {
  87. return window.location.protocol.startsWith('https');
  88. };
  89. const getCameraUrl = (val: CameraInfo | undefined) => {
  90. if (val?.pushStreamDTO && val?.pushStreamDTO.videoUrls) {
  91. const videoUrl = val?.pushStreamDTO.videoUrls.pushstreamIp;
  92. const protocol = isHttps() ? 'wss' : 'ws';
  93. // 如果是绝对地址
  94. if (videoUrl.startsWith('http')) {
  95. // 如果是https的话,websocket要用wss
  96. return videoUrl.replace('http', protocol);
  97. }
  98. const u = urlJoin(
  99. `${protocol}://`,
  100. window.location.host,
  101. window.location.pathname === '/' ? '' : window.location.pathname,
  102. videoUrl,
  103. );
  104. return u;
  105. }
  106. return '';
  107. };
  108. const getCameraImg = (val: CameraInfo | undefined) => {
  109. if (val?.pushStreamDTO && val?.pushStreamDTO.imageUrl) {
  110. return val?.pushStreamDTO.imageUrl;
  111. }
  112. return '';
  113. };
  114. const handleConfirmAddMonitor = (data: CameraInTree[]) => {
  115. updateMonitorVisible.value = false;
  116. const cameraAddIds: number[] = data.map((item) => item.id);
  117. updateCameraToOverviewGroup({ groupId: idOfCommandCenter.value, cameraIdList: cameraAddIds }).then(() => {
  118. getSelectedCameraIdsOfCommandCenter();
  119. ElMessage({
  120. message: '监测区域编辑成功',
  121. type: 'success',
  122. });
  123. });
  124. };
  125. const handleCloseAddMonitor = () => {
  126. updateMonitorVisible.value = false;
  127. };
  128. watch(
  129. () => emergencyEventId,
  130. (newVal) => {
  131. idOfEmergencyEvent.value = newVal;
  132. },
  133. );
  134. watch(
  135. () => selectedCamerasOfCommandCenter.value,
  136. (newVal) => {
  137. curPlayingCamera.value = newVal[0];
  138. },
  139. );
  140. onMounted(() => {
  141. idOfEmergencyEvent.value = emergencyEventId;
  142. getSelectedCameraIdsOfCommandCenter();
  143. });
  144. window.onresize = () => {
  145. if (!screenfull.isFullscreen) {
  146. isFullScreen.value = false; //判断退出全屏,进行赋值
  147. curFullScreenType.value = 'single';
  148. }
  149. };
  150. onUnmounted(() => {
  151. window.onresize = null;
  152. });
  153. </script>
  154. <style scoped lang="scss">
  155. .monitor-cameras-container {
  156. padding: 10px;
  157. .main-camera {
  158. width: 100%;
  159. height: calc(100% - 220px);
  160. }
  161. .has-main-camera {
  162. width: 100%;
  163. height: 100%;
  164. position: relative;
  165. .main-video {
  166. height: 100%;
  167. }
  168. .full-screen {
  169. position: absolute;
  170. bottom: 0px;
  171. right: 0px;
  172. cursor: pointer;
  173. padding: 12px;
  174. background: rgba(0, 0, 0, 0.6);
  175. border-radius: 8px 0px 0px 8px;
  176. }
  177. }
  178. .no-main-camera {
  179. height: 100%;
  180. display: flex;
  181. flex-direction: column;
  182. align-items: center;
  183. justify-content: center;
  184. gap: 20px;
  185. color: #999;
  186. }
  187. .all-cameras {
  188. width: 100%;
  189. height: 200px;
  190. margin-top: 20px;
  191. }
  192. }
  193. .camera-edit {
  194. display: flex;
  195. justify-content: space-between;
  196. align-items: center;
  197. .title {
  198. font-weight: 500;
  199. font-size: 16px;
  200. color: #000000;
  201. margin-left: 5px;
  202. }
  203. .add-area {
  204. padding: 0 16px;
  205. display: flex;
  206. align-items: center;
  207. font-size: 14px;
  208. color: #333333;
  209. cursor: pointer;
  210. .add-icon {
  211. width: 24px;
  212. height: 24px;
  213. border: 1px dashed #1777ff;
  214. color: #1777ff;
  215. font-size: 20px;
  216. line-height: 24px;
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. margin-right: 12px;
  221. }
  222. }
  223. .add-area:hover {
  224. color: #1777ff;
  225. }
  226. }
  227. .camera-list {
  228. width: 100%;
  229. height: calc(100% - 40px);
  230. margin-top: 10px;
  231. overflow: auto;
  232. display: flex;
  233. flex-wrap: wrap;
  234. gap: 20px;
  235. .monitor-item {
  236. width: 235px;
  237. height: 100%;
  238. cursor: pointer;
  239. }
  240. .cur-playing .live-video {
  241. border: 2px solid #1777ff;
  242. }
  243. .monitor-no-url {
  244. width: 100%;
  245. height: calc(100% - 26px);
  246. object-fit: contain;
  247. }
  248. .live-video {
  249. width: 100%;
  250. height: calc(100% - 26px);
  251. border: 1px solid #ddd;
  252. }
  253. }
  254. .no-camera-list {
  255. width: 100%;
  256. height: 100%;
  257. display: flex;
  258. flex-direction: column;
  259. justify-content: center;
  260. align-items: center;
  261. color: #999;
  262. .empty-img {
  263. height: 80%;
  264. object-fit: contain;
  265. }
  266. }
  267. </style>