import React, { useState, useRef, useEffect, useImperativeHandle } from "react"; import { connect } from "react-redux"; import { Form, Row, Col } from "@douyinfe/semi-ui"; import "./cameraModal.less"; function ipcCamera ({ aRef, CameraKind, CameraAbility, venderList, cameraData, ashTrue, ashFalse }) { const { TextArea } = Form; const form = useRef(); const [cloud, setcloud] = useState(""); //云台支持 const [voice, setvoice] = useState(""); //语音支持 const [memoryList, setMemoryList] = useState([ { 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", }, ]); //内存卡列表 useEffect(() => { setcloud(cameraData.cloudControl || ""); setvoice(cameraData.voice || ""); }, []); function handleLocation () { //高德经纬度 window.open("https://lbs.amap.com/tools/picker", "_blank"); } function positionForm (val) { //安装位置校验 let zz = /^(-?\d+)(\.\d+)?$/; if (!val) { return "请输入或拾取高德经纬度坐标"; } else if (val.split(",").length != 2) { return "请输入格式为116.354169,39.835452的经纬度坐标"; } else if (!zz.test(val.split(",")[0])) { return "只能填写数字"; } else if (!zz.test(val.split(",")[1])) { return "只能填写数字"; } else { return ""; } } useImperativeHandle(aRef, () => ({ //传给父组件方法 //子组件暴露给父组件的方法 ipcCameraForm: form.current.validate, resetIpcCamera: form.current.reset, toempty: empty, })); function empty () { setcloud(null); setvoice(null); } return ( <>
{ let setting = ["abilityId", "cloudControl", "kindId", "name", "position", "serialNo"] // let setting = ["abilityId", "cloudControl", "kindId", "name", "position", "rtmp", "serialNo"] let b = {} setting.map((item) => { if (values.hasOwnProperty(item)) { return b.true = values.hasOwnProperty(item) } else { return b.false = values.hasOwnProperty(item) } }) Object.keys(b).length == 1 ? ashTrue() : ashFalse() }} initValues={{ name: cameraData.name || "", venderId: cameraData.venderId || "", memoryCard: cameraData.memoryCard || "", position: cameraData.longitude ? `${cameraData.longitude},${cameraData.latitude}` : "", kindId: cameraData.kindId || "", abilityId: cameraData.cameraAbilities ? cameraData.cameraAbilities.map((item) => item.id) : "", cloudControl: cameraData.cloudControl || "", voice: cameraData.voice || "", serialNo: cameraData.serialNo || "", rtmp: "此处无效 自动生成", // rtmp: cameraData.rtmp || "", }} getFormApi={(formApi) => (form.current = formApi)} > {venderList.map((item, index) => ( {item.name} ))} {memoryList.map((item, index) => ( {item.value} ))}
{CameraKind.map((item, index) => ( {item.kind} ))} { if (checked.target.value == true) { setcloud(true); } else { setcloud(false); } }} >
支持
{cloud == true ? (
1
) : ( "" )}
不支持
{cloud == false && cloud !== "" ? (
1
) : ( "" )}
{ if (checked.target.value == true) { setvoice(true); } else { setvoice(false); } }} >
支持
{voice == true ? (
1
) : ( "" )}
不支持
{voice == false && voice !== "" ? (
1
) : ( "" )}
{CameraAbility.map((item, index) => ( {item.ability} ))} {/*