DHModal.jsx 8.29 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2 3 4
/* eslint-disable default-case */
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
5
import CryptoJS from 'crypto-js';
皮倩雯's avatar
皮倩雯 committed
6 7 8 9 10 11 12 13 14 15 16

const AddDHModal = 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('主码流');
17
  const [load, setLoad] = useState(false); // 提交加载
皮倩雯's avatar
皮倩雯 committed
18

皮倩雯's avatar
皮倩雯 committed
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 45
  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
46 47 48 49 50 51 52 53 54 55 56 57 58
  const onChange = value => {
    setSelectChange(value);
  };

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

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

  useEffect(() => {
皮倩雯's avatar
皮倩雯 committed
59
    console.log(obj.LoginPwd);
60
    setLoad(false);
皮倩雯's avatar
皮倩雯 committed
61 62 63
    if (kind === 'add') {
      form.resetFields();
    } else {
皮倩雯's avatar
皮倩雯 committed
64
      form.setFieldsValue({ ...obj, LoginPwd: obj.LoginPwd ? Decrypt(obj.LoginPwd) : '' });
皮倩雯's avatar
皮倩雯 committed
65 66 67 68 69
    }
  }, [visible]);
  const onSubmit = () => {
    form.validateFields().then(validate => {
      if (validate) {
70
        setLoad(true);
皮倩雯's avatar
皮倩雯 committed
71 72 73 74 75 76 77 78 79 80 81 82 83
        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
84
          addInsertVideoConfig({ ...getValue, LoginPwd: Encrypt(getValue.LoginPwd) }).then(res => {
皮倩雯's avatar
皮倩雯 committed
85
            if (res.msg === 'Ok') {
86 87
              onCancel();
              setLoad(false);
皮倩雯's avatar
皮倩雯 committed
88 89 90 91 92 93 94 95
              form.resetFields();
              callBackSubmit();
              notification.success({
                message: '提示',
                duration: 3,
                description: '新增成功',
              });
            } else {
96
              setLoad(false);
皮倩雯's avatar
皮倩雯 committed
97 98 99 100 101 102 103 104 105 106 107 108
              notification.error({
                message: '提示',
                duration: 3,
                description: res.msg,
              });
            }
          });
        }
        if (kind === 'edit') {
          editInsertVideoConfig({
            ...getValue,
            Id: obj.Id,
皮倩雯's avatar
皮倩雯 committed
109
            LoginPwd: Encrypt(getValue.LoginPwd),
皮倩雯's avatar
皮倩雯 committed
110 111
          }).then(res => {
            if (res.msg === 'Ok') {
112 113
              onCancel();
              setLoad(false);
皮倩雯's avatar
皮倩雯 committed
114 115 116 117 118 119 120 121
              form.resetFields();
              callBackSubmit();
              notification.success({
                message: '提示',
                duration: 3,
                description: '编辑成功',
              });
            } else {
122
              setLoad(false);
皮倩雯's avatar
皮倩雯 committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
              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}
148
      confirmLoading={load}
皮倩雯's avatar
皮倩雯 committed
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
      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="大华" disabled />
            </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="EquipmentPort"
              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}>
            <Item
              label="默认通道ID"
              name="DefaultPassageId"
              rules={[
                {
                  required: true,
                  message: '请输入默认通道ID',
                },
              ]}
            >
              <TextArea placeholder="默认视频监控点ID,请用英文逗好分隔" />
            </Item>
          </Col>
          <Col span={11}>
            <Item
              label="视频服务地址"
              name="VideoPath"
              rules={[
                {
                  required: true,
                  message: '请输入视频名称',
                },
              ]}
            >
              <Input placeholder="视频服务地址" />
            </Item>
          </Col>
        </Row>
      </Form>
    </Modal>
  );
};
export default AddDHModal;