HKModal.jsx 9.44 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2 3
import React, { useEffect, useState } from 'react';
import { Form, Modal, Row, Col, Input, Select, notification } from 'antd';
import { addInsertVideoConfig, editInsertVideoConfig } from '@/services/videoManger/videoManger';
皮倩雯's avatar
皮倩雯 committed
4
import CryptoJS from 'crypto-js';
皮倩雯's avatar
皮倩雯 committed
5 6 7 8 9 10 11 12 13 14 15

const AddHKModal = props => {
  const { callBackSubmit = () => {}, visible, onCancel, type, kind, obj } = props;

  const [form] = Form.useForm();
  const { Item } = Form;
  const { TextArea } = Input;

  const [selectChange, setSelectChange] = useState('轻应用');
  const [selectChange1, setSelectChange1] = useState('否');
  const [selectChange2, setSelectChange2] = useState('主码流');
16
  const [load, setLoad] = useState(false); // 提交加载
皮倩雯's avatar
皮倩雯 committed
17

皮倩雯's avatar
皮倩雯 committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  const key = CryptoJS.enc.Utf8.parse('1p2a3n4d5a6o7m8s9a10n1e2t3c4o5re'); // 十六位十六进制数作为密钥
  const iv = CryptoJS.enc.Utf8.parse('1234567890000000');

  // 解密
  const Decrypt = word => {
    let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
    let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
    let decrypt = CryptoJS.AES.decrypt(srcs, key, {
      iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7,
    });
    let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
    return decryptedStr.toString();
  };

  // 加密
  const Encrypt = word => {
    let srcs = CryptoJS.enc.Utf8.parse(word);
    let encrypted = CryptoJS.AES.encrypt(srcs, key, {
      iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7,
    });
    return encrypted.ciphertext.toString().toUpperCase();
  };

皮倩雯's avatar
皮倩雯 committed
45 46 47 48 49 50 51 52 53 54 55 56 57
  const onChange = value => {
    setSelectChange(value);
  };

  const onChange1 = value => {
    setSelectChange1(value);
  };

  const onChange2 = value => {
    setSelectChange2(value);
  };

  useEffect(() => {
皮倩雯's avatar
皮倩雯 committed
58
    console.log(obj.LoginPwd);
59
    setLoad(false);
皮倩雯's avatar
皮倩雯 committed
60 61 62
    if (kind === 'add') {
      form.resetFields();
    } else {
皮倩雯's avatar
皮倩雯 committed
63
      form.setFieldsValue({ ...obj, LoginPwd: obj.LoginPwd ? Decrypt(obj.LoginPwd) : '' });
皮倩雯's avatar
皮倩雯 committed
64 65 66 67 68
    }
  }, [visible]);
  const onSubmit = () => {
    form.validateFields().then(validate => {
      if (validate) {
69
        setLoad(true);
皮倩雯's avatar
皮倩雯 committed
70 71 72 73 74 75 76 77 78 79 80 81 82
        let getValue = form.getFieldsValue();
        console.log(getValue);
        if (getValue.PlayModel === undefined) {
          getValue.PlayModel = '轻应用';
        }
        if (getValue.PlayZeroChannel === undefined) {
          getValue.PlayZeroChannel = '否';
        }
        if (getValue.StreamType === undefined) {
          getValue.StreamType = '主码流';
        }
        getValue.VideoManufacturer = type;
        if (kind === 'add') {
皮倩雯's avatar
皮倩雯 committed
83
          addInsertVideoConfig({ ...getValue, LoginPwd: Encrypt(getValue.LoginPwd) }).then(res => {
皮倩雯's avatar
皮倩雯 committed
84
            if (res.msg === 'Ok') {
85 86
              onCancel();
              setLoad(false);
皮倩雯's avatar
皮倩雯 committed
87 88 89 90 91 92 93 94
              form.resetFields();
              callBackSubmit();
              notification.success({
                message: '提示',
                duration: 3,
                description: '新增成功',
              });
            } else {
95
              setLoad(false);
皮倩雯's avatar
皮倩雯 committed
96 97 98 99 100 101 102 103 104 105 106 107
              notification.error({
                message: '提示',
                duration: 3,
                description: res.msg,
              });
            }
          });
        }
        if (kind === 'edit') {
          editInsertVideoConfig({
            ...getValue,
            Id: obj.Id,
皮倩雯's avatar
皮倩雯 committed
108
            LoginPwd: Encrypt(getValue.LoginPwd),
皮倩雯's avatar
皮倩雯 committed
109 110
          }).then(res => {
            if (res.msg === 'Ok') {
111 112
              onCancel();
              setLoad(false);
皮倩雯's avatar
皮倩雯 committed
113 114 115 116 117 118 119 120
              form.resetFields();
              callBackSubmit();
              notification.success({
                message: '提示',
                duration: 3,
                description: '编辑成功',
              });
            } else {
121
              setLoad(false);
皮倩雯's avatar
皮倩雯 committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
              notification.error({
                message: '提示',
                duration: 3,
                description: res.msg,
              });
            }
          });
        }
      }
    });
  };

  return (
    <Modal
      visible={visible}
      title={
        kind === 'add' ? (
          <span style={{ fontSize: '18px' }}>新增配置</span>
        ) : (
          <span style={{ fontSize: '18px' }}>编辑配置</span>
        )
      }
      width="1000px"
      destroyOnClose
      maskClosable={false}
147
      confirmLoading={load}
皮倩雯's avatar
皮倩雯 committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
      onCancel={onCancel}
      onOk={onSubmit}
    >
      <p style={{ fontSize: '16px', marginLeft: '16px' }}>基本信息</p>
      <Form
        form={form}
        labelCol={{ span: 7 }}
        style={{ height: '25rem', overflowY: 'scroll' }}
        autocomplete="off"
      >
        <Row>
          <Col span={11}>
            <Item
              label="名称"
              name="Name"
              rules={[
                {
                  required: true,
                  message: '请输入名称',
                },
              ]}
            >
              <Input placeholder="请输入名称" maxlength="20px" />
            </Item>
          </Col>
          <Col span={12}>
            <span
              style={{
                position: 'absolute',
                left: '12%',
                top: '9%',
                color: 'red',
                fontSize: '16px',
              }}
            >
              *
            </span>
            <Item label="视频厂商" name="VideoManufacturer">
              <Input placeholder="海康ISC" disabled />
            </Item>
          </Col>

          <Col span={11}>
            <Item
              label="登录名"
              name="LoginName"
              rules={[
                {
                  required: true,
                  message: '请输入登录名',
                },
              ]}
            >
              <Input placeholder="账户登录名" maxlength="100px" />
            </Item>
          </Col>
          <Col span={12}>
            <Item
              label="登录密码"
              name="LoginPwd"
              rules={[
                {
                  required: true,
                  message: '请输入登录密码',
                },
              ]}
            >
              <Input.Password placeholder="请输入登录密码" />
            </Item>
          </Col>

          <Col span={11}>
            <Item
              label="设备编码"
              name="EquipmentCode"
              rules={[
                {
                  required: true,
                  message: '请输入设备编码',
                },
              ]}
            >
              <Input placeholder="设备台账对应设备编码字段" />
            </Item>
          </Col>
          <Col span={12}>
            <Item
              label="通道ID"
              name="PassageId"
              rules={[
                {
                  required: true,
                  message: '请输入通道ID',
                },
              ]}
            >
              <TextArea placeholder="视频监控点ID,请用英文逗好分隔" />
            </Item>
          </Col>
          <Col span={24}>
            <p style={{ fontSize: '16px', marginLeft: '16px' }}>{type}</p>
          </Col>
          <Col span={11}>
            <Item
              label="登录IP"
              name="LoginIp"
              rules={[
                {
                  required: true,
                  message: '请输入登录ID',
                },
              ]}
            >
              <Input placeholder="登录ID" />
            </Item>
          </Col>
          <Col span={12}>
            <Item
              label="视频端口"
              name="VideoPort"
              rules={[
                {
                  required: true,
                  message: '请输入视频端口',
                },
              ]}
            >
              <Input placeholder="视频端口" />
            </Item>
          </Col>
          <Col span={11}>
            <Item
              label="视频名称"
              name="VideoName"
              rules={[
                {
                  required: true,
                  message: '请输入视频名称',
                },
              ]}
            >
              <Input placeholder="视频监控点名称" />
            </Item>
          </Col>
          <Col span={12}>
            <span
              style={{
                position: 'absolute',
                left: '12%',
                top: '9%',
                color: 'red',
                fontSize: '16px',
              }}
            >
              *
            </span>
            <Item
              label="码流类型"
              name="StreamType"
              rules={[
                {
                  validator: (_rule, value) => {
                    if (form.getFieldsValue().StreamType == '') {
                      return Promise.reject('请选择码流类型');
                    }
                    return Promise.resolve();
                  },
                },
              ]}
            >
              <Select defaultValue="主码流" value={selectChange2} onChange={onChange2}>
                <Option value="主码流">主码流</Option>
                <Option value="子码流">子码流</Option>
              </Select>
            </Item>
          </Col>
          <Col span={11}>
            <Item label="默认通道ID" name="DefaultPassageId">
              <TextArea placeholder="默认视频监控点ID,请用英文逗好分隔" />
            </Item>
          </Col>
        </Row>
      </Form>
    </Modal>
  );
};
export default AddHKModal;