import React, { useState, useRef, useEffect, useImperativeHandle } from "react"; import { connect } from "react-redux"; import { Form, Row, Col, Checkbox, Radio, CheckboxGroup, } from "@douyinfe/semi-ui"; import { IconEdit, IconPlayCircle, } from "@douyinfe/semi-icons"; import "./cameraModal.less"; import PerfectScrollbar from "perfect-scrollbar"; let equipmentScrollbar; function cascadeCamera ({ dRef, dispatch, actions, cameraData, parentCamera, testComplete }) { const form = useRef(); const { equipmentWarehouse } = actions; const [sip, setSip] = useState([]); const [NVRcameraList, setNVRcameraList] = useState([]); //nvr视频流列表 const [nvrCheckList, setNvrCheckList] = useState([]); //nvr视频流多选 const [isAllChoose, setIsAllChoose] = useState(false); //全选 const cameraDataNvr = cameraData.nvr || ""; useEffect(() => { dispatch(equipmentWarehouse.getCascadeSIP()).then((res) => { setSip(res.payload.data); }); const videoStreaming = document.getElementById("video_streaming"); if (videoStreaming && equipmentScrollbar) { equipmentScrollbar.update(); } }, []); useEffect(() => { NVRcameraList ? (equipmentScrollbar = new PerfectScrollbar("#video_streaming", { suppressScrollX: true, })) : ""; }, [NVRcameraList]); useEffect(() => { //测试成功后获取级联视频流 console.log(testComplete) if (testComplete) { dispatch(equipmentWarehouse.getCascadeStream({ sip: "111" })).then((res) => { console.log(res.payload.data); let chooseList = []; let data = res.payload.data.map((item, index) => { item.change = false; return item; }) setNVRcameraList(data) for (let index = 0; index < data.length; index++) { chooseList.push(data[index].id); } setNvrCheckList(chooseList); setIsAllChoose(true); }); } }, [testComplete]) //内存卡列表 const memoryList = [ { id: 1, value: "8g", }, { id: 2, value: "16g", }, { id: 3, value: "32g", }, { id: 4, value: "64g", }, { id: 5, value: "128g", }, { id: 6, value: "256g", }, { id: 7, value: ">256g", }, ]; function NvrChangeName (e, index, name) { //级联摄像头视频流获取修改名称 let NvrchangeList = JSON.parse(JSON.stringify(NVRcameraList)); if (cameraData.name == name) { NvrchangeList[index].change = true; setNVRcameraList(NvrchangeList); } e.stopPropagation(); } function nvronBlur (index) { //nvr摄像头名称修改失去焦点 let NvrchangeList = JSON.parse(JSON.stringify(NVRcameraList)); NvrchangeList[index].change = false; setNVRcameraList(NvrchangeList); } function inputchange (e, index) { //nvr摄像头名称修改 let NvrchangeList = JSON.parse(JSON.stringify(NVRcameraList)); NvrchangeList[index].name = e; setNVRcameraList(NvrchangeList); } function allChoose (e) { //全选/全不选 let chooseList = []; if (NVRcameraList.length == nvrCheckList.length) { setNvrCheckList([]); setIsAllChoose(false); } else { for (let index = 0; index < NVRcameraList.length; index++) { chooseList.push(NVRcameraList[index].id); } setNvrCheckList(chooseList); setIsAllChoose(true); } } function playVideo (e) { //nvr播放视频 console.log("22222222222222222"); e.stopPropagation(); } function onDisabled (name) { if ((cameraDataNvr && cameraData.name == name) || !cameraDataNvr) { return false; } else { return true; } } useImperativeHandle(dRef, () => ({ //传给父组件方法 //子组件暴露给父组件的方法 cascadeCameraForm: form.current.validate, resetCascadeCamera: form.current.reset, })); return ( <>
> ); } function mapStateToProps (state) { const { auth, global, members } = state; return { loading: members.isRequesting, user: auth.user, actions: global.actions, members: members.data, }; } export default connect(mapStateToProps)(cascadeCamera);