| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <template>
- <div>
- <div class="camera-main">
- <div class="camera-tree" v-show="cameraTreeVisible">
- <CameraTreeCom
- :loading="presetListStore.loading"
- :camera-tree="cameraTree || []"
- :total="codeShowList.length"
- :no-integration-num="noIntegrationNum"
- :no-networking-num="noNetworkingNum"
- />
- </div>
- <div v-if="cameraTreeVisible" class="arrow-icon" @click="cameraTreeVisible = false"
- ><el-icon><DArrowLeft /></el-icon
- ></div>
- <div v-else class="arrow-icon" @click="cameraTreeVisible = true"
- ><el-icon><DArrowRight /></el-icon
- ></div>
- <div class="camera-placeholder" v-if="!cameraDetailStore.cameraId">请选择左侧相机</div>
- <div v-else class="camera-setting-wrapper">
- <NvrCameraView ref="nvrCameraViewRef" :camera-id="cameraDetailStore.cameraId" />
- </div>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import { ElIcon } from 'element-plus';
- import { DArrowLeft, DArrowRight } from '@element-plus/icons-vue';
- import NvrCameraView from './components/NvrCameraView.vue';
- import CameraTreeCom from '@/views/cameras/preview/components/CameraTree/CameraTreeOldVersion.vue';
- import { onUnmounted, onBeforeUnmount, ref, watch } from 'vue';
- import useCameraDetail from '@/views/cameras/preview/store/useCameraDetailStore';
- import usePresetListStore from '@/views/cameras/preview/store/usePresetListStore';
- import useFenceStore from '@/views/cameras/preview/store/useFenceStore';
- import useCameraAlgoStore from '@/views/cameras/preview/store/useCameraAlgoStore';
- import { onMounted } from 'vue';
- // import { IsPtz } from '@/types/camera/constant';
- import { CameraDetailServer } from '@/types/camera/type';
- import { CameraTree, getFullCameraTree } from '@/api/camera/camera-preview';
- import useCameraStatus from '@/views/cameras/preview/store/useCameraStatus';
- const cameraStatus = useCameraStatus();
- const { noNetworkingNum, openInterval, closeInterval } = cameraStatus;
- const cameraDetailStore = useCameraDetail();
- const fenceStore = useFenceStore();
- const presetListStore = usePresetListStore();
- const cameraAlgoStore = useCameraAlgoStore();
- const cameraTree = ref<CameraTree[]>([]);
- const codeShowList = ref<string[]>([]);
- const noIntegrationNum = ref<number>(0);
- const nvrCameraViewRef = ref();
- const cameraTreeVisible = ref(true);
- // const { allAlgoList } = storeToRefs(cameraAlgoStore);
- function updateNetworkingState(data, targetData) {
- let integrationCount = 0;
- for (let i = 0; i < data.length; i++) {
- const node = data[i];
- const matchedNode = targetData.find((item) => item.cameraCode === node.code);
- if (matchedNode) {
- node.networkingState = matchedNode.networkingState;
- node.integrationState = matchedNode.integrationState;
- }
- if (node.integrationState === 1) {
- integrationCount++;
- }
- if (node.children && node.children.length > 0) {
- const childIntegrationCount = updateNetworkingState(node.children, targetData);
- integrationCount += childIntegrationCount;
- }
- }
- noIntegrationNum.value = integrationCount;
- return integrationCount;
- }
- function getCameraList(data) {
- let cameraList = [] as string[];
- for (let i = 0; i < data.length; i++) {
- const node = data[i];
- if (node.nodeType === 'camera') {
- cameraList.push(node.code);
- }
- if (node.children && node.children.length > 0) {
- const childCameraList = getCameraList(node.children);
- cameraList.push(...childCameraList);
- }
- }
- return cameraList;
- }
- watch(
- () => cameraDetailStore.cameraId,
- async (cameraId) => {
- fenceStore.clear();
- if (cameraId) {
- if (cameraTree.value.length === 0) {
- /** 如果当前树为空,那么切换相机的时候,要重新请求树结构 */
- const tree = await getFullCameraTree();
- cameraTree.value = tree as unknown as CameraTree[];
- codeShowList.value = getCameraList(tree);
- closeInterval();
- openInterval(codeShowList.value, (targetData) => {
- updateNetworkingState(cameraTree.value, targetData);
- });
- }
- const detail: CameraDetailServer = getCameraDetail(
- cameraTree.value,
- cameraDetailStore.cameraId,
- ) as unknown as CameraDetailServer;
- if (detail) {
- cameraDetailStore.setDetail(detail);
- }
- // cameraAlgoStore.getCameraAlgoList(cameraId);
- // cameraAlgoStore.selectedAlgoId = null;
- cameraAlgoStore.selectedAlgoList = [];
- cameraAlgoStore.getCameraAlgoList(cameraId).then();
- nvrCameraViewRef.value.clearNvrUrl();
- } else {
- /** 没有相机的时候也要请求相机树 */
- const tree = await getFullCameraTree();
- cameraTree.value = tree as unknown as CameraTree[];
- }
- },
- {
- immediate: true,
- },
- );
- onMounted(() => {
- // getCameraTreeOldVersion().then((res) => {
- // cameraTree.value = res;
- // codeShowList.value = getCameraList(res);
- // openInterval(codeShowList.value, (targetData) => {
- // updateNetworkingState(cameraTree.value, targetData);
- // });
- // });
- });
- onBeforeUnmount(() => {
- if (nvrCameraViewRef.value) {
- nvrCameraViewRef.value.clearNvrUrl();
- }
- });
- onUnmounted(() => {
- /** 离开页面要清理掉所有的store */
- cameraDetailStore.clear();
- cameraAlgoStore.clear();
- fenceStore.clear();
- presetListStore.clear();
- closeInterval();
- });
- function getCameraDetail(tree: CameraTree[], cameraId: number): CameraTree | null {
- let detail: CameraTree | null = null;
- function getDetail(t: CameraTree[]) {
- t.forEach((x) => {
- if (x.nodeType === 'camera' && x.id === cameraId) {
- detail = x;
- } else if (x.children && x.children.length > 0) {
- getDetail(x.children);
- }
- });
- }
- getDetail(tree);
- return detail;
- }
- </script>
- <style lang="scss" scoped>
- .camera-main {
- display: flex;
- background: #fff;
- .camera-tree {
- // width: 250px;
- flex-shrink: 0;
- border: 1px solid #f0f2f5;
- margin: 5px;
- }
- .camera-placeholder {
- color: #333;
- text-align: center;
- margin-top: 100px;
- margin-left: 100px;
- }
- .camera-setting-wrapper {
- width: 960px;
- }
- }
- .arrow-icon {
- width: 16px;
- height: 48px;
- margin: 320px 0;
- border-radius: 15px;
- display: flex;
- justify-content: center;
- align-items: center;
- cursor: pointer;
- background-color: #bee2ff;
- }
- .arrow-icon:hover {
- color: #fff;
- background-color: #0052d9;
- }
- </style>
|