Playback.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div>
  3. <div class="camera-main">
  4. <div class="camera-tree" v-show="cameraTreeVisible">
  5. <CameraTreeCom
  6. :loading="presetListStore.loading"
  7. :camera-tree="cameraTree || []"
  8. :total="codeShowList.length"
  9. :no-integration-num="noIntegrationNum"
  10. :no-networking-num="noNetworkingNum"
  11. />
  12. </div>
  13. <div v-if="cameraTreeVisible" class="arrow-icon" @click="cameraTreeVisible = false"
  14. ><el-icon><DArrowLeft /></el-icon
  15. ></div>
  16. <div v-else class="arrow-icon" @click="cameraTreeVisible = true"
  17. ><el-icon><DArrowRight /></el-icon
  18. ></div>
  19. <div class="camera-placeholder" v-if="!cameraDetailStore.cameraId">请选择左侧相机</div>
  20. <div v-else class="camera-setting-wrapper">
  21. <NvrCameraView ref="nvrCameraViewRef" :camera-id="cameraDetailStore.cameraId" />
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script setup lang="ts">
  27. import { ElIcon } from 'element-plus';
  28. import { DArrowLeft, DArrowRight } from '@element-plus/icons-vue';
  29. import NvrCameraView from './components/NvrCameraView.vue';
  30. import CameraTreeCom from '@/views/cameras/preview/components/CameraTree/CameraTreeOldVersion.vue';
  31. import { onUnmounted, onBeforeUnmount, ref, watch } from 'vue';
  32. import useCameraDetail from '@/views/cameras/preview/store/useCameraDetailStore';
  33. import usePresetListStore from '@/views/cameras/preview/store/usePresetListStore';
  34. import useFenceStore from '@/views/cameras/preview/store/useFenceStore';
  35. import useCameraAlgoStore from '@/views/cameras/preview/store/useCameraAlgoStore';
  36. import { onMounted } from 'vue';
  37. // import { IsPtz } from '@/types/camera/constant';
  38. import { CameraDetailServer } from '@/types/camera/type';
  39. import { CameraTree, getFullCameraTree } from '@/api/camera/camera-preview';
  40. import useCameraStatus from '@/views/cameras/preview/store/useCameraStatus';
  41. const cameraStatus = useCameraStatus();
  42. const { noNetworkingNum, openInterval, closeInterval } = cameraStatus;
  43. const cameraDetailStore = useCameraDetail();
  44. const fenceStore = useFenceStore();
  45. const presetListStore = usePresetListStore();
  46. const cameraAlgoStore = useCameraAlgoStore();
  47. const cameraTree = ref<CameraTree[]>([]);
  48. const codeShowList = ref<string[]>([]);
  49. const noIntegrationNum = ref<number>(0);
  50. const nvrCameraViewRef = ref();
  51. const cameraTreeVisible = ref(true);
  52. // const { allAlgoList } = storeToRefs(cameraAlgoStore);
  53. function updateNetworkingState(data, targetData) {
  54. let integrationCount = 0;
  55. for (let i = 0; i < data.length; i++) {
  56. const node = data[i];
  57. const matchedNode = targetData.find((item) => item.cameraCode === node.code);
  58. if (matchedNode) {
  59. node.networkingState = matchedNode.networkingState;
  60. node.integrationState = matchedNode.integrationState;
  61. }
  62. if (node.integrationState === 1) {
  63. integrationCount++;
  64. }
  65. if (node.children && node.children.length > 0) {
  66. const childIntegrationCount = updateNetworkingState(node.children, targetData);
  67. integrationCount += childIntegrationCount;
  68. }
  69. }
  70. noIntegrationNum.value = integrationCount;
  71. return integrationCount;
  72. }
  73. function getCameraList(data) {
  74. let cameraList = [] as string[];
  75. for (let i = 0; i < data.length; i++) {
  76. const node = data[i];
  77. if (node.nodeType === 'camera') {
  78. cameraList.push(node.code);
  79. }
  80. if (node.children && node.children.length > 0) {
  81. const childCameraList = getCameraList(node.children);
  82. cameraList.push(...childCameraList);
  83. }
  84. }
  85. return cameraList;
  86. }
  87. watch(
  88. () => cameraDetailStore.cameraId,
  89. async (cameraId) => {
  90. fenceStore.clear();
  91. if (cameraId) {
  92. if (cameraTree.value.length === 0) {
  93. /** 如果当前树为空,那么切换相机的时候,要重新请求树结构 */
  94. const tree = await getFullCameraTree();
  95. cameraTree.value = tree as unknown as CameraTree[];
  96. codeShowList.value = getCameraList(tree);
  97. closeInterval();
  98. openInterval(codeShowList.value, (targetData) => {
  99. updateNetworkingState(cameraTree.value, targetData);
  100. });
  101. }
  102. const detail: CameraDetailServer = getCameraDetail(
  103. cameraTree.value,
  104. cameraDetailStore.cameraId,
  105. ) as unknown as CameraDetailServer;
  106. if (detail) {
  107. cameraDetailStore.setDetail(detail);
  108. }
  109. // cameraAlgoStore.getCameraAlgoList(cameraId);
  110. // cameraAlgoStore.selectedAlgoId = null;
  111. cameraAlgoStore.selectedAlgoList = [];
  112. cameraAlgoStore.getCameraAlgoList(cameraId).then();
  113. nvrCameraViewRef.value.clearNvrUrl();
  114. } else {
  115. /** 没有相机的时候也要请求相机树 */
  116. const tree = await getFullCameraTree();
  117. cameraTree.value = tree as unknown as CameraTree[];
  118. }
  119. },
  120. {
  121. immediate: true,
  122. },
  123. );
  124. onMounted(() => {
  125. // getCameraTreeOldVersion().then((res) => {
  126. // cameraTree.value = res;
  127. // codeShowList.value = getCameraList(res);
  128. // openInterval(codeShowList.value, (targetData) => {
  129. // updateNetworkingState(cameraTree.value, targetData);
  130. // });
  131. // });
  132. });
  133. onBeforeUnmount(() => {
  134. if (nvrCameraViewRef.value) {
  135. nvrCameraViewRef.value.clearNvrUrl();
  136. }
  137. });
  138. onUnmounted(() => {
  139. /** 离开页面要清理掉所有的store */
  140. cameraDetailStore.clear();
  141. cameraAlgoStore.clear();
  142. fenceStore.clear();
  143. presetListStore.clear();
  144. closeInterval();
  145. });
  146. function getCameraDetail(tree: CameraTree[], cameraId: number): CameraTree | null {
  147. let detail: CameraTree | null = null;
  148. function getDetail(t: CameraTree[]) {
  149. t.forEach((x) => {
  150. if (x.nodeType === 'camera' && x.id === cameraId) {
  151. detail = x;
  152. } else if (x.children && x.children.length > 0) {
  153. getDetail(x.children);
  154. }
  155. });
  156. }
  157. getDetail(tree);
  158. return detail;
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. .camera-main {
  163. display: flex;
  164. background: #fff;
  165. .camera-tree {
  166. // width: 250px;
  167. flex-shrink: 0;
  168. border: 1px solid #f0f2f5;
  169. margin: 5px;
  170. }
  171. .camera-placeholder {
  172. color: #333;
  173. text-align: center;
  174. margin-top: 100px;
  175. margin-left: 100px;
  176. }
  177. .camera-setting-wrapper {
  178. width: 960px;
  179. }
  180. }
  181. .arrow-icon {
  182. width: 16px;
  183. height: 48px;
  184. margin: 320px 0;
  185. border-radius: 15px;
  186. display: flex;
  187. justify-content: center;
  188. align-items: center;
  189. cursor: pointer;
  190. background-color: #bee2ff;
  191. }
  192. .arrow-icon:hover {
  193. color: #fff;
  194. background-color: #0052d9;
  195. }
  196. </style>