DatabaseInitialization.jsx 59.8 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2
/* eslint-disable guard-for-in */
/* eslint-disable no-restricted-syntax */
3
/* eslint-disable no-lonely-if */
4
/* eslint-disable prefer-promise-reject-errors */
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* eslint-disable no-else-return */
/* eslint-disable spaced-comment */
/* eslint-disable eqeqeq */
import React, { useEffect, useRef, useState } from 'react';
import {
  Card,
  Form,
  Input,
  Button,
  Space,
  notification,
  Modal,
  Spin,
  Divider,
  Checkbox,
  Popconfirm,
  Timeline,
22
  Tooltip,
皮倩雯's avatar
皮倩雯 committed
23
  Table,
24
  message,
25
  Select,
26 27 28 29 30 31 32 33 34 35 36
} from 'antd';
import PageContainer from '@/components/BasePageContainer';
import { connect } from 'react-redux';
import {
  getInitDBLogNew,
  deleteInitDBLogNew,
  GetProductList, // 获取产品列表
  GetDbProduct, // 获取产品方案配置
  SetAdminMenuToRole,
  CheckDatabaseIsExist,
  NewInitAddDataBase,
皮倩雯's avatar
皮倩雯 committed
37
  InitEditDataBase,
皮倩雯's avatar
皮倩雯 committed
38
  getDataBaseConfigNew,
39
  UpgradeDataBase,
40
} from '@/services/database/api';
41 42 43 44 45 46 47 48
import {
  CloseCircleOutlined,
  CheckCircleOutlined,
  ZoomInOutlined,
  ExclamationCircleOutlined,
  BarcodeOutlined,
  UserOutlined,
  CalendarOutlined,
皮倩雯's avatar
皮倩雯 committed
49 50 51 52
  CheckOutlined,
  MinusSquareOutlined,
  PlusOutlined,
  EyeOutlined,
53
} from '@ant-design/icons';
皮倩雯's avatar
皮倩雯 committed
54
import CryptoJS from 'crypto-js';
55 56
import styles from './DatabaseInitialization.less';
import styles1 from '../InitDataBase/InitDataBase.less';
皮倩雯's avatar
皮倩雯 committed
57
import AppendModal from './AppendModal';
58 59 60 61 62 63 64 65 66 67

const CheckboxGroup = Checkbox.Group;
const formLables = {
  ip: '服务器地址',
  userName: '用户名称',
  password: '用户密码',
  dbName: '数据库名称',
};
let time = null;
const DatabaseInitialization = props => {
68
  const { callBackSubmit = () => {}, visible } = props;
69 70 71 72 73 74 75
  const [form] = Form.useForm();
  const [modalVisible, setModalVisible] = useState({
    describeVisible: false, // 描述弹窗
    versionVisible: false, // 检查版本弹窗
    initVisible: false, // 初始化选择产品弹窗
  }); // 修改弹窗
  const [initVisible, setInitVisible] = useState(false); // 数据库初始化弹窗
76
  const [initVisibledetail, setinitVisibledetail] = useState(false); // 数据库初始化详细信息弹窗
77
  const [initContent, setInitContent] = useState(''); // 数据库初始化内容
78
  const [initContentdetail, setInitContentdetail] = useState(''); // 数据库初始化详细内容
79 80 81 82 83
  const [cardLoading, setCardLoading] = useState(false); // 初始化card Loading
  const [finish, setFinish] = useState(false);
  const [initLoading, setInitLoading] = useState(false);
  const [keepDb, setKeepDb] = useState([]);
  const [keepProduct, setKeepProduct] = useState([]);
皮倩雯's avatar
皮倩雯 committed
84
  const [keepStatus, setKeepStatus] = useState([]);
85 86 87 88 89 90 91 92 93
  const scroll = useRef(null);

  const [data, setData] = useState([]);
  const [title, setTitle] = useState([]);
  const [keepCode, setKeepCode] = useState([]);
  const [keepData, setKeepData] = useState([]);
  const [keepValue, setKeepValue] = useState([]);
  const [value, setValue] = useState([]);
  const [product, setProduct] = useState([]);
94
  const [msg, setMsg] = useState('null');
95 96 97 98 99
  const [keepNumber, setkeepNumber] = useState('');
  const [keepNa, setkeepNa] = useState('');
  const [keepCo, setkeepCo] = useState('');
  const [keepMsg, setkeepMsg] = useState('');
  const [allLength, setAllLength] = useState('');
100
  const [beforeColor, setbeforeColor] = useState('gray');
101 102 103 104
  const [firstColor, setfirstColor] = useState('gray');
  const [secordColor, setsecordColor] = useState('gray');
  const [lastColor, setLastColor] = useState('gray');
  const [totalProduct, setTotalProduct] = useState('');
皮倩雯's avatar
皮倩雯 committed
105
  const [simpleProduct, setSimpleProduct] = useState('');
106
  const [show, setShow] = useState('hidden');
107 108
  const [keepInline, setKeepInline] = useState([]);
  const [ifInline, setIfInline] = useState('hidden');
109
  const [result, setResult] = useState('');
110 111 112
  const [dataResult, setDataResult] = useState('');
  const [productResult, setProductResult] = useState('');
  const [keepInitContent, setKeepInitContent] = useState('');
皮倩雯's avatar
皮倩雯 committed
113
  const [keepInitContentDetail, setKeepInitContentDetail] = useState('');
114 115
  const [keepinitVisible, setKeepInitVisible] = useState(false);
  const [password, setPassword] = useState(false);
116 117
  const [isAuthorize, setIsAuthorize] = useState(false);
  const [showDetali, setShowDetali] = useState(false);
118
  const [keepLast, setKeepLast] = useState('');
皮倩雯's avatar
皮倩雯 committed
119 120 121
  const [appendVisible, setAppendVisible] = useState(false);
  const [append, setAppend] = useState('不需要追加');
  const [dataValue, setDataValue] = useState();
皮倩雯's avatar
皮倩雯 committed
122 123 124
  const [keepHistroy, setKeepHistroy] = useState([]);
  const [historyVisible, setHistoryVisible] = useState(false);
  const [keepInitDetailVisible, setKeepInitDetailVisible] = useState(false);
125
  const [appendType, setAppendType] = useState('no');
126

皮倩雯's avatar
皮倩雯 committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  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();
  };

154 155 156 157
  // 获取数据库配置信息
  useEffect(() => {
    setCardLoading(true);
    getProductList();
158
  }, [visible]);
159

160 161 162 163
  const getProductList = () => {
    GetProductList().then(res => {
      setCardLoading(false);
      if (res.code === 0) {
164
        GetDb(res.data);
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
        setKeepData(res.data);
        let arr = formateArrDataA(res.data, 'productName');
        let aa = Object.keys(arr);
        aa.map(i => {
          let list = [];
          arr[i].map(j => {
            list.push(j.name);
          });
          arr[i] = list;
        });
        setAllLength(res.data.length);
        setTitle(aa);
        setData(arr);
      }
    });
  };

  const formateArrDataA = (initialArr, name) => {
    // 判定传参是否符合规则
    if (!(initialArr instanceof Array)) {
      return '请传入正确格式的数组';
    }
    if (!name) {
      return '请传入对象属性';
    }
    // 先获取一下这个数组中有多少个"name"
    let nameArr = [];
    for (let i in initialArr) {
      if (nameArr.indexOf(initialArr[i][`${name}`]) === -1) {
        nameArr.push(initialArr[i][`${name}`]);
      }
    }
    // 新建一个包含多个list的结果对象
    let tempObj = {};
    // 根据不同的"name"生成多个数组
    for (let k in nameArr) {
      for (let j in initialArr) {
        if (initialArr[j][`${name}`] == nameArr[k]) {
          // 每次外循环时新建一个对应"name"的数组, 内循环时当前数组不变
          tempObj[nameArr[k]] = tempObj[nameArr[k]] || [];
          tempObj[nameArr[k]].push(initialArr[j]);
        }
      }
    }
    for (let keys in tempObj) {
      let arr = [];
      tempObj[keys].map((item, index) => {
        tempObj[keys] = arr;
        item.key = index;
        arr.push(item);
      });
    }
    return tempObj;
  };
  // 弹出模态框
  const handleShowModal = (key, value) => {
    setModalVisible({ ...modalVisible, [key]: value });
  };

  // 获取日志
  const doInitLog = () => {
    setInitLoading(true);
    getInitDBLogNew()
      .then(res => {
        if (res.code === 0) {
          if (res.data.content) {
            let arr = [];
            arr.push(
              res.data.content.split(/(\r\n)|(\n)/).map((item, index) => (
                // eslint-disable-next-line react/no-danger
                <p key={index} dangerouslySetInnerHTML={{ __html: item }} />
              )),
            );
            console.log(arr);
            setInitContent(arr);
240
            setKeepInitContent(arr);
241 242
            scroll.current.scrollTop = scroll.current.scrollHeight;
          }
243

244 245 246 247 248 249
          if (!res.data.finish) {
            time = setTimeout(() => {
              doInitLog();
            }, 600);
          } else {
            setInitLoading(false);
250
            setShow('visible');
251 252 253 254 255 256 257 258
            if (time) {
              clearTimeout(time);
              time = null;
            }
          }
        }
      })
      .catch(err => {
259 260 261 262 263
        if (time) {
          clearTimeout(time);
          time = null;
        }
        message.error(err);
264 265 266 267
        setFinish(true);
      });
  };

268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
  // 获取详细日志
  const doInitLogdetali = () => {
    getInitDBLogNew({ isAllInitDBLog: true })
      .then(res => {
        if (res.code === 0) {
          if (res.data.content) {
            let arr = [];
            arr.push(
              res.data.content.split(/(\r\n)|(\n)/).map((item, index) => (
                // eslint-disable-next-line react/no-danger
                <p key={index} dangerouslySetInnerHTML={{ __html: item }} />
              )),
            );
            console.log(arr);
            setInitContentdetail(arr);
皮倩雯's avatar
皮倩雯 committed
283
            setKeepInitContentDetail(arr);
284
            setShowDetali(true);
285 286 287 288 289 290 291 292 293
            scroll.current.scrollTop = scroll.current.scrollHeight;
          }
        }
      })
      .catch(err => {
        console.log(err);
      });
  };

294 295 296 297
  const onValuesChange = (value, b) => {
    form.setFieldsValue(value);
  };

298
  const handlelook = () => {
皮倩雯's avatar
皮倩雯 committed
299 300
    setInitVisible(false);
    setinitVisibledetail(true);
301 302 303 304 305 306
    doInitLogdetali();
  };

  // 关闭弹窗
  const handleClickdetail = () => {
    setinitVisibledetail(false);
皮倩雯's avatar
皮倩雯 committed
307
    setInitContent('');
308 309
    setInitContentdetail('');
    setFinish(false);
皮倩雯's avatar
皮倩雯 committed
310
    // deleteInitDBLogNew();
皮倩雯's avatar
皮倩雯 committed
311
    setShowDetali(false);
312 313
  };

314 315 316
  // 关闭弹窗
  const handleClick = () => {
    setInitVisible(false);
皮倩雯's avatar
皮倩雯 committed
317 318
    // setInitContent('');
    // setInitContentdetail('');
319
    setFinish(false);
皮倩雯's avatar
皮倩雯 committed
320
    // deleteInitDBLogNew();
321
    setShowDetali(false);
322 323
  };

324
  const GetDb = kk => {
皮倩雯's avatar
皮倩雯 committed
325 326 327 328 329
    getDataBaseConfigNew().then(resdata => {
      GetDbProduct({
        ip: resdata.data.ip,
        dbName: resdata.data.dbName,
        userName: resdata.data.userName,
邓超's avatar
邓超 committed
330
        password: resdata.data.password,
皮倩雯's avatar
皮倩雯 committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
      }).then(res => {
        if (res.code === 0) {
          if (res.data.DbInfo.ip == '127.0.0.1' || !res.data.DbInfo.ip) {
            setIfInline('hidden');
          } else {
            setIfInline('visible');
          }
          setKeepInline(res.data.DbInfo);
          if (res.data.Project && res.data.Project.length > 0) {
            setKeepHistroy(res.data.Project);
            setkeepNumber(res.data.Project[res.data.Project.length - 1].license);
            setkeepMsg(res.data.Project[res.data.Project.length - 1].projectName);
            setkeepNa(res.data.Project[res.data.Project.length - 1].applicantName);
            setkeepCo(res.data.Project[res.data.Project.length - 1].jobNumber);
          } else {
            setKeepHistroy([]);
            // setKeepProductData('');
            setkeepNumber('');
            setkeepMsg('');
            setkeepNa('');
            setkeepCo('');
          }
皮倩雯's avatar
皮倩雯 committed
353

皮倩雯's avatar
皮倩雯 committed
354 355 356 357 358
          // form.setFieldsValue(res.data.DbInfo);
          form.setFieldsValue({
            ip: resdata.data.ip,
            dbName: resdata.data.dbName,
            userName: resdata.data.userName,
359
            password: resdata.data.password,
360
            providerType: resdata.data.providerType,
361
          });
皮倩雯's avatar
皮倩雯 committed
362 363 364
          GetDbChangeFirst(kk);
          // 有License的情况下首次进入展示数据
          // if (res.data.IsAuthorize) {
365 366
          console.log(res.data.Product);
          if (res.data.Product.length > 0) {
皮倩雯's avatar
皮倩雯 committed
367 368 369
            let aa = [];
            let gg = [];
            res.data.Product.map(i => {
370 371 372 373 374
              if (i.name !== null) {
                if (i.status == 1) {
                  gg.push(i.name);
                }
                aa.push(i.name);
皮倩雯's avatar
皮倩雯 committed
375
              }
376
            });
皮倩雯's avatar
皮倩雯 committed
377 378 379 380 381 382 383 384
            if (aa.length > 0) {
              let dd = [];
              aa.map(i => {
                kk.map(j => {
                  if (j.name === i) {
                    dd.push(j);
                  }
                });
385
              });
皮倩雯's avatar
皮倩雯 committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
              let Arr = Array.from(new Set(dd));
              let arr = formateArrDataA(Arr, 'productName');
              let a = Object.keys(arr);
              a.map(i => {
                let list = [];
                arr[i].map(j => {
                  list.push(j.name);
                });
                arr[i] = list;
              });
              setProduct(arr);
              setKeepValue(arr);
            }
            let newArr = Array.from(new Set(aa));
            setKeepStatus(gg);
401 402 403 404 405 406 407 408 409 410
            console.log(newArr);
            if (newArr.length > 0) {
              setKeepProduct(newArr);
              setKeepCode(newArr);
              setValue(newArr);
            } else {
              setKeepProduct([]);
              setKeepCode([]);
              setValue([]);
            }
411
          }
皮倩雯's avatar
皮倩雯 committed
412 413 414 415
          setKeepDb(res.data);
          setIsAuthorize(res.data.IsAuthorize);
          if (res.data.IsAuthorize) {
            setMsg('');
皮倩雯's avatar
皮倩雯 committed
416
          } else {
皮倩雯's avatar
皮倩雯 committed
417 418 419
            if (
              res.data.Project &&
              res.data.Project[0] &&
420
              res.data.Project[res.data.Project.length - 1].license == '已使用'
皮倩雯's avatar
皮倩雯 committed
421 422
            ) {
              setbeforeColor('red');
423 424
              setResult('未检测到可用License');
              setMsg('未检测到可用License');
皮倩雯's avatar
皮倩雯 committed
425 426 427 428 429
            } else {
              setbeforeColor('red');
              setResult('未检测到License');
              setMsg('未检测到License');
            }
皮倩雯's avatar
皮倩雯 committed
430
          }
皮倩雯's avatar
皮倩雯 committed
431 432 433 434 435 436
        } else {
          notification.error({
            message: '提示',
            duration: 3,
            description: res.msg,
          });
皮倩雯's avatar
皮倩雯 committed
437
        }
皮倩雯's avatar
皮倩雯 committed
438
      });
皮倩雯's avatar
皮倩雯 committed
439 440 441
    });
  };

皮倩雯's avatar
皮倩雯 committed
442 443 444 445
  const isAlphanumeric = str => {
    return /^[A-Za-z0-9]+$/.test(str);
  };

皮倩雯's avatar
皮倩雯 committed
446 447
  const GetDbChangeFirst = kk => {
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
448 449 450 451
    let pwd = obj.password;
    if (obj.password.length < 32 || !isAlphanumeric(obj.password)) {
      pwd = Encrypt(obj.password);
    }
452
    GetDbProduct({ ...obj, password: pwd }).then(res => {
皮倩雯's avatar
皮倩雯 committed
453 454 455 456
      setCardLoading(false);
      if (res.code === 0) {
        if (res.data.IsAuthorize) {
          if (kk) {
皮倩雯's avatar
皮倩雯 committed
457
            findCheck1(res.data.IsAppend);
皮倩雯's avatar
皮倩雯 committed
458 459 460
          } else {
            onCheckLaster(res.data.IsAppend);
          }
461
        } else {
皮倩雯's avatar
皮倩雯 committed
462 463 464
          if (
            res.data.Project &&
            res.data.Project[0] &&
465
            res.data.Project[res.data.Project.length - 1].license == '已使用'
皮倩雯's avatar
皮倩雯 committed
466
          ) {
467
            setbeforeColor('red');
468 469
            setResult('未检测到可用License');
            setMsg('未检测到可用License');
470
          } else {
471 472 473
            setbeforeColor('red');
            setResult('未检测到License');
            setMsg('未检测到License');
474 475
          }
        }
皮倩雯's avatar
皮倩雯 committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489
        if (res.data.Project && res.data.Project.length > 0) {
          setKeepHistroy(res.data.Project);
          setkeepNumber(res.data.Project[res.data.Project.length - 1].license);
          setkeepMsg(res.data.Project[res.data.Project.length - 1].projectName);
          setkeepNa(res.data.Project[res.data.Project.length - 1].applicantName);
          setkeepCo(res.data.Project[res.data.Project.length - 1].jobNumber);
        } else {
          // setKeepProductData('');
          setKeepHistroy([]);
          setkeepNumber('');
          setkeepMsg('');
          setkeepNa('');
          setkeepCo('');
        }
490
      } else {
491
        notification.error({
492
          message: '提示',
493
          duration: 3,
494 495 496 497 498 499
          description: res.msg,
        });
      }
    });
  };

500
  const GetDbChange = e => {
501
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
502 503 504 505
    let pwd = obj.password;
    if (obj.password.length < 32 || !isAlphanumeric(obj.password)) {
      pwd = Encrypt(obj.password);
    }
506
    GetDbProduct({ ...obj, password: pwd }).then(res => {
507
      setCardLoading(false);
508
      if (res.code === 0) {
509
        if (res.data.IsAuthorize) {
510 511
          // setMsg('');
          if (e) {
皮倩雯's avatar
皮倩雯 committed
512
            findCheck(res.data.IsAppend);
513
          } else {
皮倩雯's avatar
皮倩雯 committed
514
            onCheckLaster(res.data.IsAppend);
515
          }
516
        } else {
皮倩雯's avatar
皮倩雯 committed
517
          let obj1 = form.getFieldsValue();
518
          CheckDatabaseIsExist({ ...obj1, password: pwd }).then(res1 => {
皮倩雯's avatar
皮倩雯 committed
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
            setCardLoading(false);
            if (res1.code === 0) {
              if (
                res1.data.Project &&
                res1.data.Project[0] &&
                res1.data.Project[res1.data.Project.length - 1].license == '已使用'
              ) {
                setbeforeColor('red');
                setResult('未检测到可用License');
                setMsg('未检测到可用License');
              } else {
                setbeforeColor('red');
                setResult('未检测到License');
                setMsg('未检测到License');
              }
            } else {
              setbeforeColor('red');
              setResult(`${res1.msg}`);
              setMsg(res1.msg);
            }
          });
540
        }
541
        if (res.data.Project && res.data.Project.length > 0) {
皮倩雯's avatar
皮倩雯 committed
542 543 544 545 546
          setKeepHistroy(res.data.Project);
          setkeepNumber(res.data.Project[res.data.Project.length - 1].license);
          setkeepMsg(res.data.Project[res.data.Project.length - 1].projectName);
          setkeepNa(res.data.Project[res.data.Project.length - 1].applicantName);
          setkeepCo(res.data.Project[res.data.Project.length - 1].jobNumber);
547
        } else {
皮倩雯's avatar
皮倩雯 committed
548 549
          // setKeepProductData('');
          setKeepHistroy([]);
550 551 552 553 554
          setkeepNumber('');
          setkeepMsg('');
          setkeepNa('');
          setkeepCo('');
        }
555
        if (res.data.Product.length > 0) {
556
          let aa = [];
皮倩雯's avatar
皮倩雯 committed
557
          let gg = [];
558
          res.data.Product.map(i => {
559 560 561 562 563
            if (i.name !== null) {
              if (i.status == 1) {
                gg.push(i.name);
              }
              aa.push(i.name);
皮倩雯's avatar
皮倩雯 committed
564
            }
565 566 567 568 569 570 571 572 573
          });
          if (aa.length > 0) {
            let dd = [];
            aa.map(i => {
              keepData.map(j => {
                if (j.name === i) {
                  dd.push(j);
                }
              });
574
            });
575 576 577 578 579 580 581 582 583
            let Arr = Array.from(new Set(dd));
            let arr = formateArrDataA(Arr, 'productName');
            let a = Object.keys(arr);
            a.map(i => {
              let list = [];
              arr[i].map(j => {
                list.push(j.name);
              });
              arr[i] = list;
584
            });
585
            setProduct(arr);
586
            console.log(arr);
587
            setKeepValue(arr);
588
          }
589
          let newArr = Array.from(new Set(aa));
590
          // 当前数据库已存在和上一个已存在数据库值重新赋值
皮倩雯's avatar
皮倩雯 committed
591
          if (newArr.length > 0) {
592
            console.log(newArr);
皮倩雯's avatar
皮倩雯 committed
593
            setKeepProduct(newArr);
皮倩雯's avatar
皮倩雯 committed
594
            setKeepStatus(gg);
皮倩雯's avatar
皮倩雯 committed
595 596 597 598
            setKeepCode(newArr);
            setValue(newArr);
          } else {
            setKeepProduct([]);
皮倩雯's avatar
皮倩雯 committed
599
            setKeepStatus([]);
皮倩雯's avatar
皮倩雯 committed
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
            setKeepCode([]);
            setValue([]);
          }
          if (res.data.Product.length == 0) {
            setKeepValue([]);
          }
        }
        setKeepDb(res.data);
        setIsAuthorize(res.data.IsAuthorize);
      } else {
        notification.error({
          message: '提示',
          duration: 3,
          description: res.msg,
        });
      }
    });
  };

  const GetDbChangeAppend = () => {
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
621 622 623 624
    let pwd = obj.password;
    if (obj.password.length < 32 || !isAlphanumeric(obj.password)) {
      pwd = Encrypt(obj.password);
    }
625
    GetDbProduct({ ...obj, password: pwd }).then(res => {
皮倩雯's avatar
皮倩雯 committed
626 627
      setCardLoading(false);
      if (res.code === 0) {
628
        if (res.data.Product.length > 0) {
皮倩雯's avatar
皮倩雯 committed
629
          let aa = [];
皮倩雯's avatar
皮倩雯 committed
630
          let gg = [];
皮倩雯's avatar
皮倩雯 committed
631
          res.data.Product.map(i => {
632 633 634 635 636
            if (i.name !== null) {
              if (i.status == 1) {
                gg.push(i.name);
              }
              aa.push(i.name);
皮倩雯's avatar
皮倩雯 committed
637
            }
皮倩雯's avatar
皮倩雯 committed
638
          });
639
          // 后端返回出局的分组名可能发生改变,前端处理数据展示新分组名
皮倩雯's avatar
皮倩雯 committed
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
          if (aa.length > 0) {
            let dd = [];
            aa.map(i => {
              keepData.map(j => {
                if (j.name === i) {
                  dd.push(j);
                }
              });
            });
            let Arr = Array.from(new Set(dd));
            let arr = formateArrDataA(Arr, 'productName');
            let a = Object.keys(arr);
            a.map(i => {
              let list = [];
              arr[i].map(j => {
                list.push(j.name);
              });
              arr[i] = list;
            });
            setProduct(arr);
            setKeepValue(arr);
          }
          let newArr = Array.from(new Set(aa));
          // 当前数据库已存在和上一个已存在数据库值重新赋值
          if (newArr.length > 0) {
665
            console.log(newArr);
666
            setKeepProduct(newArr);
皮倩雯's avatar
皮倩雯 committed
667
            setKeepStatus(gg);
668 669
            setKeepCode(newArr);
            setValue(newArr);
皮倩雯's avatar
皮倩雯 committed
670 671
          } else {
            setKeepProduct([]);
皮倩雯's avatar
皮倩雯 committed
672
            setKeepStatus([]);
皮倩雯's avatar
皮倩雯 committed
673 674
            setKeepCode([]);
            setValue([]);
675
          }
676 677 678
          if (res.data.Product.length == 0) {
            setKeepValue([]);
          }
679
        }
皮倩雯's avatar
皮倩雯 committed
680 681 682 683 684
        if (res.data.Project && res.data.Project.length > 0) {
          setKeepHistroy(res.data.Project);
        } else {
          setKeepHistroy([]);
        }
685
        setKeepDb(res.data);
686
        setIsAuthorize(res.data.IsAuthorize);
687
      } else {
688
        notification.error({
689
          message: '提示',
690
          duration: 3,
691 692 693 694 695 696
          description: res.msg,
        });
      }
    });
  };

697 698
  const onOK = arr => {
    initDatabasePro(arr);
699 700 701
  };

  // 数据库初始化
702
  const initDatabasePro = e => {
703 704 705 706 707 708
    let productSetting = e;
    let obj = form.getFieldsValue();
    // 数据库存在调用编辑接口否则调用新增接口
    handleShowModal('initVisible', false);
    setInitVisible(true);
    doInitLog();
皮倩雯's avatar
皮倩雯 committed
709 710 711 712
    let pwd = obj.password;
    if (obj.password.length < 32 || !isAlphanumeric(obj.password)) {
      pwd = Encrypt(obj.password);
    }
713
    NewInitAddDataBase({ ...obj, productSetting, password: pwd }).then(res => {
714
      if (res.code === 0) {
715
        GetDbChangeAppend(); // 刷星已初始化的产品勾选
716
        setMsg('未检测到可用License');
717
        setfirstColor('green');
718 719

        setDataResult('成功');
720 721
        notification.success({
          message: '提示',
722
          duration: 3,
723 724
          description: '数据库初始化成功',
        });
725 726 727
        if (keepNumber != '') {
          setkeepNumber('已使用');
        }
皮倩雯's avatar
皮倩雯 committed
728 729 730 731 732 733 734 735
        if (res.data.productPackageCount == 0) {
          setProductResult('产品授权不包含已初始化的产品');
          setsecordColor('#eda625');
        } else {
          setsecordColor('green');
        }
        setTotalProduct(res.data.productPackageSumCount);
        setSimpleProduct(res.data.productPackageCount);
736
        // 给平台管理员赋值所有菜单权限
皮倩雯's avatar
皮倩雯 committed
737 738 739 740 741 742 743 744 745
        SetAdminMenuToRole().then(resdata => {
          if (resdata.code === 0) {
            setLastColor('green');
            setKeepLast('');
          } else {
            setLastColor('red');
            setKeepLast(res.data.msg);
          }
        });
746 747 748
        if (visible) {
          callBackSubmit({ ...obj, productSetting, password: pwd });
        }
皮倩雯's avatar
皮倩雯 committed
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
      } else {
        setDataResult(res.msg);
        setFinish(true);
        setfirstColor('red');
        setsecordColor('gray');
        setLastColor('gray');
        notification.error({
          message: '提示',
          duration: 3,
          description: res.msg,
        });
      }
    });
  };

  // 数据库初始化追加
  const initDatabaseProAppend = () => {
    // 数据库存在调用编辑接口否则调用新增接口
    handleShowModal('initVisible', false);
    setInitVisible(true);
    doInitLog();
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
771 772 773 774
    let pwd = obj.password;
    if (obj.password.length < 32 || !isAlphanumeric(obj.password)) {
      pwd = Encrypt(obj.password);
    }
775 776
    InitEditDataBase({
      ...obj,
777
      password: pwd,
778 779
      isOldDbToNewDb: appendType === 'yes' ? true : false,
    }).then(res => {
皮倩雯's avatar
皮倩雯 committed
780
      if (res.code === 0) {
皮倩雯's avatar
皮倩雯 committed
781
        GetDbChangeAppend();
782
        setMsg('未检测到可用License');
皮倩雯's avatar
皮倩雯 committed
783 784 785 786 787 788 789 790 791 792
        setfirstColor('green');
        setDataResult('成功');
        notification.success({
          message: '提示',
          duration: 3,
          description: '数据库初始化追加成功',
        });
        if (keepNumber != '') {
          setkeepNumber('已使用');
        }
793 794 795 796 797 798
        if (res.data.productPackageCount == 0) {
          setProductResult('产品授权不包含已初始化的产品');
          setsecordColor('#eda625');
        } else {
          setsecordColor('green');
        }
皮倩雯's avatar
皮倩雯 committed
799 800
        setTotalProduct(res.data.productPackageSumCount);
        setSimpleProduct(res.data.productPackageCount);
801 802
        setLastColor('green');
        setKeepLast('');
803 804 805 806 807 808
        if (visible) {
          callBackSubmit({
            ...obj,
            password: pwd,
          });
        }
809
      } else {
810
        setDataResult(res.msg);
811 812 813 814 815 816
        setFinish(true);
        setfirstColor('red');
        setsecordColor('gray');
        setLastColor('gray');
        notification.error({
          message: '提示',
817
          duration: 3,
818 819 820 821 822 823 824
          description: res.msg,
        });
      }
    });
  };

  const flagChange = () => {
825 826 827 828
    setbeforeColor('gray');
    setfirstColor('gray');
    setsecordColor('gray');
    setLastColor('gray');
皮倩雯's avatar
皮倩雯 committed
829 830
    setSimpleProduct('');
    setTotalProduct('');
831 832 833 834 835
    onCheck();
  };

  const onCheck = () => {
    let obj = form.getFieldsValue();
836
    if (obj.ip && obj.userName && obj.password && obj.dbName && obj.providerType) {
837 838
      // setKeepValue([]);
      setProduct([]);
839
      setCardLoading(true);
皮倩雯's avatar
皮倩雯 committed
840 841 842 843
      let pwd = obj.password;
      if (obj.password.length < 32 || !isAlphanumeric(obj.password)) {
        pwd = Encrypt(obj.password);
      }
844
      GetProductList({ ...obj, password: pwd }).then(res => {
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865
        if (res.code === 0) {
          console.log(res.data);
          GetDbChange();
          setKeepData(res.data);
          let arr = formateArrDataA(res.data, 'productName');
          let aa = Object.keys(arr);
          aa.map(i => {
            let list = [];
            arr[i].map(j => {
              list.push(j.name);
            });
            arr[i] = list;
          });
          setAllLength(res.data.length);
          setTitle(aa);
          setData(arr);
        } else {
          setCardLoading(false);
        }
      });

皮倩雯's avatar
皮倩雯 committed
866
      // deleteInitDBLogNew();
867 868 869 870 871 872
    } else {
      setbeforeColor('red');
      setResult('请输入完整数据库信息');
      setMsg('请输入完整数据库信息');
    }
  };
皮倩雯's avatar
皮倩雯 committed
873

皮倩雯's avatar
皮倩雯 committed
874 875
  const onCheckLaster = aa => {
    // 此时有授权码才能进入
876
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
877 878 879 880
    let pwd = obj.password;
    if (obj.password.length < 32 || !isAlphanumeric(obj.password)) {
      pwd = Encrypt(obj.password);
    }
881
    CheckDatabaseIsExist({ ...obj, password: pwd }).then(res => {
882
      setCardLoading(false);
皮倩雯's avatar
皮倩雯 committed
883
      if (res.code == 0) {
皮倩雯's avatar
皮倩雯 committed
884
        setDataValue(form.getFieldsValue());
皮倩雯's avatar
皮倩雯 committed
885 886
        // 数据库不存在
        if (res.data === false) {
887
          setbeforeColor('green');
888
          setResult('通过');
皮倩雯's avatar
皮倩雯 committed
889 890
          setAppend('无需追加');
          setMsg('');
891
          if (keepNumber && keepNumber != '已使用') {
皮倩雯's avatar
皮倩雯 committed
892 893
            setMsg('');
          }
894
        } else {
皮倩雯's avatar
皮倩雯 committed
895 896 897 898 899
          if (aa) {
            setbeforeColor('green');
            setResult('检测到License,当前环境需要追加产品');
            setMsg('检测到License,当前环境需要追加产品');
            setAppend('');
900
            setAppendType('no');
皮倩雯's avatar
皮倩雯 committed
901 902 903
            setAppendVisible(true);
            setDataValue(form.getFieldsValue());
          } else {
904 905 906 907 908 909 910
            setbeforeColor('green');
            setAppendType('yes');
            setResult('当前数据库为非授权初始化数据库,可使用授权码升级到授权码模式');
            setMsg('当前数据库为非授权初始化数据库,可使用授权码升级到授权码模式');
            setAppend('');
            setAppendVisible(true);
            setDataValue(form.getFieldsValue());
皮倩雯's avatar
皮倩雯 committed
911
          }
912 913
        }
      } else {
914 915
        setbeforeColor('red');
        setResult(`${res.msg}`);
皮倩雯's avatar
皮倩雯 committed
916
        setMsg(res.msg);
917 918 919 920 921
      }
    });
  };

  const Submit = () => {
922
    setAppendType('no');
923
    let obj = form.getFieldsValue();
924
    if (obj.ip && obj.userName && obj.password && obj.dbName && obj.providerType) {
皮倩雯's avatar
皮倩雯 committed
925 926 927 928
      let pwd = obj.password;
      if (obj.password.length < 32 || !isAlphanumeric(obj.password)) {
        pwd = Encrypt(obj.password);
      }
929
      GetProductList({ ...obj, password: pwd }).then(res => {
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947
        setCardLoading(false);
        if (res.code === 0) {
          GetDbChange(1);
          setKeepData(res.data);
          let arr = formateArrDataA(res.data, 'productName');
          let aa = Object.keys(arr);
          aa.map(i => {
            let list = [];
            arr[i].map(j => {
              list.push(j.name);
            });
            arr[i] = list;
          });
          setAllLength(res.data.length);
          setTitle(aa);
          setData(arr);
        }
      });
948 949 950 951 952 953
      setCardLoading(true);
    } else {
      setbeforeColor('red');
      setResult('请输入完整数据库信息');
      setMsg('请输入完整数据库信息');
    }
954 955
  };

皮倩雯's avatar
皮倩雯 committed
956
  const findCheck = aa => {
957
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
958 959 960 961
    let pwd = obj.password;
    if (obj.password.length < 32 || !isAlphanumeric(obj.password)) {
      pwd = Encrypt(obj.password);
    }
962
    CheckDatabaseIsExist({ ...obj, password: pwd }).then(res => {
963 964
      setCardLoading(false);
      if (res.code === 0) {
皮倩雯's avatar
皮倩雯 committed
965
        setDataValue(form.getFieldsValue());
966
        if (res.data === true) {
皮倩雯's avatar
皮倩雯 committed
967 968 969 970 971
          if (aa) {
            setbeforeColor('green');
            setResult('检测到License,当前环境需要追加产品');
            setMsg('检测到License,当前环境需要追加产品');
            setAppend('');
972
            setAppendType('no');
皮倩雯's avatar
皮倩雯 committed
973 974 975
            setAppendVisible(true);
            setDataValue(form.getFieldsValue());
          } else {
976 977 978 979 980 981 982
            setbeforeColor('green');
            setAppendType('yes');
            setResult('当前数据库为非授权初始化数据库,可使用授权码升级到授权码模式');
            setMsg('当前数据库为非授权初始化数据库,可使用授权码升级到授权码模式');
            setAppend('');
            setAppendVisible(true);
            setDataValue(form.getFieldsValue());
皮倩雯's avatar
皮倩雯 committed
983
          }
984 985 986 987 988
        } else {
          setPassword(true);
          setbeforeColor('green');
          setResult('通过');
          setMsg('');
皮倩雯's avatar
皮倩雯 committed
989 990 991 992 993 994 995
          setAppend('无需追加');

          let arr = [];

          keepData.map(i => {
            if (keepCode.indexOf(i.name) != -1) {
              arr.push(i);
996
            }
皮倩雯's avatar
皮倩雯 committed
997 998 999
          });

          onOK(arr);
1000 1001 1002 1003 1004 1005 1006 1007 1008
        }
      } else {
        setbeforeColor('red');
        setResult(`${res.msg}`);
        setMsg(res.msg);
      }
    });
  };

皮倩雯's avatar
皮倩雯 committed
1009 1010
  const findCheck1 = aa => {
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
1011 1012 1013 1014
    let pwd = obj.password;
    if (obj.password.length < 32 || !isAlphanumeric(obj.password)) {
      pwd = Encrypt(obj.password);
    }
1015
    CheckDatabaseIsExist({ ...obj, password: pwd }).then(res => {
皮倩雯's avatar
皮倩雯 committed
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
      setCardLoading(false);
      if (res.code === 0) {
        setDataValue(form.getFieldsValue());
        if (res.data === true) {
          if (aa) {
            setbeforeColor('green');
            setResult('检测到License,当前环境需要追加产品');
            setMsg('检测到License,当前环境需要追加产品');
            setAppend('');
            setAppendVisible(true);
            setDataValue(form.getFieldsValue());
1027
            setAppendType('no');
皮倩雯's avatar
皮倩雯 committed
1028
          } else {
1029 1030 1031 1032 1033 1034 1035
            setbeforeColor('green');
            setResult('当前数据库为非授权初始化数据库,可使用授权码升级到授权码模式');
            setMsg('当前数据库为非授权初始化数据库,可使用授权码升级到授权码模式');
            setAppendType('yes');
            setAppend('');
            setAppendVisible(true);
            setDataValue(form.getFieldsValue());
皮倩雯's avatar
皮倩雯 committed
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
          }
        } else {
          setPassword(true);
          setbeforeColor('green');
          setResult('通过');
          setMsg('');
          setAppend('无需追加');

          let arr = [];

          keepData.map(i => {
            if (keepCode.indexOf(i.name) != -1) {
              arr.push(i);
            }
          });
        }
      } else {
        setbeforeColor('red');
        setResult(`${res.msg}`);
        setMsg(res.msg);
      }
    });
  };

1060
  const save = () => {
1061
    setAppendType('no');
1062
    flagChange();
1063 1064
  };

1065
  useEffect(() => {
皮倩雯's avatar
皮倩雯 committed
1066
    if (!initVisible && !initVisibledetail) {
1067 1068 1069 1070
      setShow('hidden');
    }
  }, [initVisible]);

1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
  const simple = e => {
    let aa = 0;
    if (keepValue && keepValue[e]) {
      aa = keepValue[e].length;
    }
    return aa;
  };

  const total = e => {
    let aa = 0;
    if (data && data[e]) {
      aa = data[e].length;
    }
    return aa;
  };

皮倩雯's avatar
皮倩雯 committed
1087 1088 1089
  const onOk = () => {
    setAppendVisible(false);
    initDatabaseProAppend();
皮倩雯's avatar
皮倩雯 committed
1090 1091 1092 1093 1094
    // GetDbChangeAppend();
  };

  const onHistory = () => {
    setHistoryVisible(true);
皮倩雯's avatar
皮倩雯 committed
1095
  };
皮倩雯's avatar
皮倩雯 committed
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125

  const columns = [
    {
      title: '授权码',
      dataIndex: 'license',
      key: 'license',
    },
    {
      title: '项目名',
      dataIndex: 'projectName',
      key: 'projectName',
    },
    {
      title: '授权人',
      dataIndex: 'applicantName',
      key: 'applicantName',
    },
    {
      title: '使用时间',
      dataIndex: 'createTime',
      key: 'createTime',
    },
    {
      title: '部署产品',
      dataIndex: 'productSolutions',
      key: 'productSolutions',
      render: text => {
        let aa = [];
        if (text) {
          text.map(i => {
1126
            aa.push(i.name);
皮倩雯's avatar
皮倩雯 committed
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
          });
          return (
            <Tooltip title={aa.toString()} arrowPointAtCenter placement="rightTop">
              <span>{text.length}</span>
            </Tooltip>
          );
        }
      },
    },
  ];

  useEffect(() => {
    if (!initVisibledetail && !initVisible) {
      deleteInitDBLogNew();
    }
  }, [initVisibledetail, initVisible]);

1144 1145 1146 1147 1148 1149
  return (
    <>
      <PageContainer className={styles.InitDataBaseContainer}>
        <div style={{ display: 'flex', alignItems: 'center', width: '100%' }}>
          <div style={{ width: '30%' }}>
            <Card>
1150
              <div style={{ height: 'calc(100vh - 98px)', paddingTop: '13px' }}>
1151 1152 1153 1154 1155 1156 1157 1158
                <Form
                  className={styles.mgTop20}
                  layout="horizontal"
                  labelAlign="left"
                  labelCol={{ span: 6 }}
                  form={form}
                  onValuesChange={onValuesChange}
                >
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177
                  <Form.Item
                    label="数据库类型"
                    name="providerType"
                    rules={[
                      {
                        validator: (rule, value) => {
                          if (form.getFieldValue().providerType == '') {
                            return Promise.reject('ip必填');
                          }
                          return Promise.resolve();
                        },
                      },
                    ]}
                  >
                    <Select placeholder="请选择数据库类型">
                      <Select.Option value="SqlServer">SqlServer</Select.Option>
                      <Select.Option value="Dm">Dm</Select.Option>
                    </Select>
                  </Form.Item>
1178 1179 1180 1181 1182 1183
                  <Form.Item
                    label={`${formLables.ip}:`}
                    name="ip"
                    rules={[
                      {
                        validator: (rule, value) => {
1184
                          let regCn = /^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/;
1185 1186 1187
                          if (form.getFieldValue().ip == '') {
                            return Promise.reject('ip必填');
                          }
1188 1189 1190
                          if (!regCn.test(form.getFieldValue().ip)) {
                            return Promise.reject('ip格式不正确');
                          }
1191
                          setbeforeColor('gray');
1192 1193 1194
                          setfirstColor('gray');
                          setsecordColor('gray');
                          setLastColor('gray');
1195 1196 1197
                          setSimpleProduct('');
                          setTotalProduct('');
                          setResult('');
1198 1199 1200 1201 1202
                          return Promise.resolve();
                        },
                      },
                    ]}
                  >
皮倩雯's avatar
皮倩雯 committed
1203
                    <Input placeholder="请输入服务器名或IP地址" />
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
                  </Form.Item>
                  <Form.Item
                    label={`${formLables.userName}:`}
                    name="userName"
                    rules={[
                      {
                        validator: (rule, value) => {
                          if (form.getFieldValue().userName == '') {
                            return Promise.reject('用户名称必填');
                          }
1214
                          setbeforeColor('gray');
1215 1216 1217
                          setfirstColor('gray');
                          setsecordColor('gray');
                          setLastColor('gray');
1218 1219 1220
                          setSimpleProduct('');
                          setTotalProduct('');
                          setResult('');
1221 1222 1223 1224 1225
                          return Promise.resolve();
                        },
                      },
                    ]}
                  >
皮倩雯's avatar
皮倩雯 committed
1226
                    <Input placeholder="请输入用户名称" />
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
                  </Form.Item>
                  <Form.Item
                    label={`${formLables.password}:`}
                    name="password"
                    rules={[
                      {
                        validator: (rule, value) => {
                          if (form.getFieldValue().password == '') {
                            return Promise.reject('用户密码必填');
                          }
1237
                          setbeforeColor('gray');
1238 1239 1240
                          setfirstColor('gray');
                          setsecordColor('gray');
                          setLastColor('gray');
1241 1242 1243
                          setSimpleProduct('');
                          setTotalProduct('');
                          setResult('');
1244 1245 1246 1247 1248
                          return Promise.resolve();
                        },
                      },
                    ]}
                  >
皮倩雯's avatar
皮倩雯 committed
1249
                    <Input placeholder="请输入用户密码" type="password" />
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
                  </Form.Item>
                  <Form.Item
                    label={`${formLables.dbName}:`}
                    name="dbName"
                    rules={[
                      {
                        validator: (rule, value) => {
                          if (
                            form.getFieldValue().dbName == '' ||
                            form.getFieldValue().dbName == undefined
                          ) {
                            return Promise.reject('数据库名称必填');
                          }
1263
                          setbeforeColor('gray');
1264 1265 1266
                          setfirstColor('gray');
                          setsecordColor('gray');
                          setLastColor('gray');
1267 1268 1269
                          setSimpleProduct('');
                          setTotalProduct('');
                          setResult('');
1270 1271 1272 1273 1274
                          return Promise.resolve();
                        },
                      },
                    ]}
                  >
皮倩雯's avatar
皮倩雯 committed
1275
                    <Input placeholder="请输入数据库名称" />
1276 1277
                  </Form.Item>
                </Form>
皮倩雯's avatar
皮倩雯 committed
1278
                <div style={{ float: 'right' }}>
1279
                  <Button onClick={save}>环境检查</Button>
皮倩雯's avatar
皮倩雯 committed
1280 1281
                </div>
                <div style={{ marginTop: '100px', transform: 'scal(1.5)' }}>
1282
                  <Timeline>
1283
                    <Timeline.Item color={beforeColor}>
1284
                      环境检查
1285 1286 1287 1288 1289 1290 1291 1292
                      {(() => {
                        switch (result) {
                          case '':
                            return <></>;
                          case '通过':
                            return (
                              <CheckCircleOutlined style={{ color: 'green', marginLeft: '10px' }} />
                            );
皮倩雯's avatar
皮倩雯 committed
1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
                          case '检测到License,当前环境需要追加产品':
                            return (
                              <>
                                <CheckCircleOutlined
                                  style={{ color: 'green', marginLeft: '10px' }}
                                />
                                <span style={{ color: 'rgb(24 144 255)', marginLeft: '5px' }}>
                                  {result}
                                </span>
                              </>
                            );
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
                          case '当前数据库为非授权初始化数据库,可使用授权码升级到授权码模式':
                            return (
                              <>
                                <CheckCircleOutlined
                                  style={{ color: 'green', marginLeft: '10px' }}
                                />
                                <span style={{ color: 'rgb(24 144 255)', marginLeft: '5px' }}>
                                  {result}
                                </span>
                              </>
                            );
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357
                          default:
                            return (
                              <>
                                <CloseCircleOutlined style={{ color: 'red', marginLeft: '10px' }} />
                                <span style={{ color: 'rgb(24 144 255)', marginLeft: '5px' }}>
                                  {result}
                                </span>
                              </>
                            );
                        }
                      })()}
                    </Timeline.Item>
                    <Timeline.Item color={firstColor}>
                      <span>数据库初始化</span>
                      {(() => {
                        switch (firstColor) {
                          case 'gray':
                            return <></>;
                          case 'green':
                            return (
                              <>
                                <CheckCircleOutlined
                                  style={{ color: 'green', marginLeft: '10px' }}
                                />
                                <Tooltip title="查看初始化日志">
                                  <ZoomInOutlined
                                    style={{ color: 'rgb(24 144 255)', marginLeft: '10px' }}
                                    onClick={() => setKeepInitVisible(true)}
                                  />
                                </Tooltip>
                              </>
                            );
                          default:
                            return (
                              <>
                                <CloseCircleOutlined style={{ color: 'red', marginLeft: '10px' }} />
                                <span style={{ color: 'rgb(24 144 255)', marginLeft: '5px' }}>
                                  {dataResult}
                                </span>
                              </>
                            );
                        }
                      })()}
1358
                    </Timeline.Item>
1359
                    <Timeline.Item color={secordColor}>
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399
                      <span>产品授权开启已初始化产品</span>
                      {(() => {
                        switch (secordColor) {
                          case 'gray':
                            return <></>;
                          case 'green':
                            return (
                              <>
                                <CheckCircleOutlined
                                  style={{ color: 'green', marginLeft: '10px' }}
                                />
                                <p>
                                  已开启
                                  <span style={{ color: 'rgb(24 144 255)' }}>{simpleProduct}</span>/
                                  <span style={{ color: 'rgb(24 144 255)' }}>{totalProduct}</span>
                                  个产品
                                </p>
                              </>
                            );
                          case '#eda625':
                            return (
                              <>
                                <ExclamationCircleOutlined
                                  style={{ color: '#eda625', marginLeft: '10px' }}
                                />
                                <span style={{ color: 'rgb(24 144 255)', marginLeft: '10px' }}>
                                  {productResult}
                                </span>
                                <p>
                                  已开启
                                  <span style={{ color: 'rgb(24 144 255)' }}>{simpleProduct}</span>/
                                  <span style={{ color: 'rgb(24 144 255)' }}>{totalProduct}</span>
                                  个产品
                                </p>
                              </>
                            );
                          default:
                            return <></>;
                        }
                      })()}
1400 1401
                    </Timeline.Item>
                    <Timeline.Item color={lastColor}>
1402
                      <span>平台管理员赋权使用</span>
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
                      {(() => {
                        switch (lastColor) {
                          case 'gray':
                            return <></>;
                          case 'green':
                            return (
                              <>
                                <CheckCircleOutlined
                                  style={{ color: 'green', marginLeft: '10px' }}
                                />
                                <br />
                                <spsn>登录名:panda</spsn>
                                <br />
                                {password ? <span>初始密码:panda666</span> : <></>}
                              </>
                            );
                          default:
                            return (
                              <>
                                <CloseCircleOutlined style={{ color: 'red', marginLeft: '10px' }} />
                                <span style={{ color: 'rgb(24 144 255)', marginLeft: '5px' }}>
                                  {keepLast}
                                </span>
                              </>
                            );
                        }
                      })()}
1430 1431 1432 1433 1434 1435 1436 1437
                    </Timeline.Item>
                  </Timeline>
                </div>
              </div>
            </Card>
          </div>
          <div style={{ width: '70%' }}>
            <Card className={styles.mgTop20}>
1438 1439 1440 1441 1442 1443
              <div
                style={{
                  height: '50px',
                  display: 'flex',
                  justifyContent: 'space-between',
                  alignItems: 'center',
1444
                  // color: 'rgb(137 67 67 / 85%)',
1445 1446 1447
                }}
              >
                <div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
皮倩雯's avatar
皮倩雯 committed
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
                  {keepHistroy.length > 0 ? (
                    <Tooltip title="查看数据库授权记录">
                      <EyeOutlined
                        style={{ color: 'rgb(24 144 255)', marginRight: '5px' }}
                        onClick={onHistory}
                      />
                    </Tooltip>
                  ) : (
                    <></>
                  )}
1458
                  <BarcodeOutlined style={{ color: 'rgb(227 168 96)', marginRight: '5px' }} />
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471
                  授权码:
                  {keepNumber ? (
                    <>{keepNumber}</>
                  ) : (
                    <span>
                      --
                      {/* <EditOutlined
                        style={{ color: 'rgb(24 144 255)', marginLeft: '20px', marginTop: '10px' }}
                        onClick={}
                      /> */}
                    </span>
                  )}
                </div>
1472 1473
                <div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
                  <CalendarOutlined style={{ color: '#8466cb', marginRight: '5px' }} />
1474 1475
                  项目名:{keepMsg ? <>{keepMsg}</> : '--'}
                </div>
1476 1477
                <div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
                  <UserOutlined style={{ color: 'green', marginRight: '5px' }} />
1478
                  授权人:{keepNa ? <>{keepNa}</> : '-'}
1479 1480
                  {keepCo ? <>{keepCo}</> : '-'}
                </div>
1481
                <div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
皮倩雯's avatar
皮倩雯 committed
1482 1483 1484 1485 1486
                  <div style={{ float: 'right' }}>
                    (已选
                    <span style={{ color: 'rgb(24 144 255)' }}>{keepProduct.length}</span>/
                    <span style={{ color: 'rgb(24 144 255)' }}>{allLength}</span>个产品)
                  </div>
1487 1488 1489 1490 1491 1492
                </div>
              </div>
              <Spin tip="loading..." spinning={cardLoading}>
                <div className={styles1.initItemData}>
                  {title &&
                    title.map((item, index) => (
1493
                      <div key={index} style={{ marginBottom: '10px' }}>
1494 1495 1496 1497 1498 1499 1500 1501
                        <Divider
                          orientation="center"
                          style={{
                            margin: '0 0 20px 0',
                            color: '#15428b',
                            borderTopColor: '#99bbe8',
                          }}
                        >
1502
                          {`${item}(${simple(item)}/${total(item)})`}
1503
                        </Divider>
1504 1505 1506
                        {data[item] &&
                          data[item].map((i, j) => {
                            if (keepProduct.indexOf(i) != -1) {
皮倩雯's avatar
皮倩雯 committed
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531
                              if (keepStatus.indexOf(i) != -1) {
                                return (
                                  <span
                                    style={{
                                      width: '250px',
                                      marginLeft: '24px',
                                      display: 'inline-block',
                                      marginBottom: '20px',
                                    }}
                                  >
                                    <CheckOutlined style={{ color: 'green', marginRight: '5px' }} />
                                    {i}
                                  </span>
                                );
                              } else {
                                return (
                                  <span
                                    style={{
                                      width: '250px',
                                      marginLeft: '24px',
                                      display: 'inline-block',
                                      marginBottom: '20px',
                                    }}
                                  >
                                    <PlusOutlined
1532
                                      style={{ color: 'rgb(24, 144, 255)', marginRight: '5px' }}
皮倩雯's avatar
皮倩雯 committed
1533 1534 1535 1536 1537
                                    />
                                    {i}
                                  </span>
                                );
                              }
1538 1539
                            } else {
                              return (
皮倩雯's avatar
皮倩雯 committed
1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551
                                <span
                                  style={{
                                    width: '250px',
                                    marginLeft: '24px',
                                    display: 'inline-block',
                                    marginBottom: '20px',
                                    color: '#c3c3c3',
                                  }}
                                >
                                  {/* <MinusSquareOutlined
                                    style={{ color: 'gray', marginTop: '-6px', marginRight: '5px' }}
                                  /> */}
1552
                                  {i}
皮倩雯's avatar
皮倩雯 committed
1553
                                </span>
1554 1555 1556
                              );
                            }
                          })}
1557 1558 1559 1560 1561 1562
                      </div>
                    ))}
                </div>
              </Spin>
              <div>
                <Space size="large" className={styles.btnBox}>
皮倩雯's avatar
皮倩雯 committed
1563 1564 1565 1566 1567
                  {/* {append == '' ? (
                    <Button onClick={() => setAppendVisible(true)}>追加</Button>
                  ) : (
                    <></>
                  )} */}
1568 1569
                  <Popconfirm
                    placement="topLeft"
皮倩雯's avatar
皮倩雯 committed
1570
                    disabled={msg != ''}
1571 1572 1573 1574 1575
                    title={<span style={{ color: 'rgb(24 144 255)' }}>是否确认初始化!</span>}
                    okText="确认"
                    cancelText="取消"
                    onConfirm={() => {
                      Submit();
皮倩雯's avatar
皮倩雯 committed
1576
                      // deleteInitDBLogNew();
1577 1578
                    }}
                  >
皮倩雯's avatar
皮倩雯 committed
1579
                    <Button type="primary" disabled={msg != ''}>
1580
                      初始化
1581
                    </Button>
1582 1583 1584
                    {/* <Button type="primary" disabled={isAuthorize && msg == '' ? false : true}>
                      初始化
                    </Button> */}
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
                  </Popconfirm>
                </Space>
              </div>
            </Card>
          </div>
        </div>
        <Modal
          title="初始化数据库"
          visible={initVisible}
          onCancel={() => {
            setInitVisible(false);
            setInitContent('');
1597
            setInitContentdetail('');
皮倩雯's avatar
皮倩雯 committed
1598
            // deleteInitDBLogNew();
1599 1600 1601 1602 1603
          }}
          width={800}
          maskClosable={false}
          bodyStyle={{
            height: '500px',
1604
            // overflowY: 'scroll',
1605 1606
          }}
          footer={[
1607 1608 1609 1610 1611 1612
            <Button
              style={{ visibility: show }}
              onClick={() => {
                handlelook();
              }}
            >
皮倩雯's avatar
皮倩雯 committed
1613
              查看详细信息
1614
            </Button>,
1615 1616 1617 1618 1619 1620
            <Button
              onClick={() => {
                handleClick();
              }}
              key="back"
              type="primary"
1621
              loading={initLoading}
1622 1623 1624 1625 1626 1627 1628 1629
            >
              关闭窗口
            </Button>,
          ]}
        >
          <div
            ref={scroll}
            style={{
1630
              height: '470px',
1631
              overflowY: 'scroll',
1632 1633
            }}
          >
皮倩雯's avatar
皮倩雯 committed
1634 1635 1636 1637 1638 1639 1640 1641 1642 1643
            <Spin
              spinning={initLoading}
              tip="loading..."
              style={{ width: '100%', marginTop: '40px' }}
            >
              <span>{initContent}</span>
              <div style={{ height: '40px' }}>
                <div style={{ position: 'relative' }}>
                  {/* {initLoading ? <span>加载中...</span> : <></>} */}
                  {/* <Spin
1644 1645 1646
                  spinning={initLoading}
                  tip="loading..."
                  style={{ width: '100%', marginTop: '40px' }}
皮倩雯's avatar
皮倩雯 committed
1647 1648
                /> */}
                </div>
1649
              </div>
皮倩雯's avatar
皮倩雯 committed
1650
              {/* <br />
皮倩雯's avatar
皮倩雯 committed
1651
            {showDetali ? <span>{initContentdetail}</span> : <></>} */}
皮倩雯's avatar
皮倩雯 committed
1652
            </Spin>
1653 1654
          </div>
        </Modal>
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
        <Modal
          title="日志信息"
          visible={keepinitVisible}
          onCancel={() => {
            setKeepInitVisible(false);
            // setKeepInitContent('');
          }}
          width={800}
          maskClosable={false}
          bodyStyle={{
            height: '500px',
          }}
          footer={[
皮倩雯's avatar
皮倩雯 committed
1668 1669 1670 1671 1672 1673 1674 1675
            <Button
              onClick={() => {
                setKeepInitDetailVisible(true);
                setKeepInitVisible(false);
              }}
            >
              查看详细日志
            </Button>,
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696
            <Button
              onClick={() => {
                setKeepInitVisible(false);
              }}
              key="back"
              type="primary"
            >
              关闭窗口
            </Button>,
          ]}
        >
          <div
            ref={scroll}
            style={{
              maxHeight: '470px',
              overflowY: 'auto',
            }}
          >
            {keepInitContent}
          </div>
        </Modal>
皮倩雯's avatar
皮倩雯 committed
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738
        <Modal
          title="详细日志信息"
          visible={keepInitDetailVisible}
          onCancel={() => {
            setKeepInitDetailVisible(false);
          }}
          width={800}
          maskClosable={false}
          bodyStyle={{
            height: '500px',
          }}
          footer={[
            <Button
              onClick={() => {
                setKeepInitDetailVisible(false);
                setKeepInitVisible(true);
              }}
            >
              查看日志
            </Button>,
            <Button
              onClick={() => {
                setKeepInitDetailVisible(false);
              }}
              key="back"
              type="primary"
            >
              关闭窗口
            </Button>,
          ]}
        >
          <div
            ref={scroll}
            style={{
              maxHeight: '470px',
              overflowY: 'auto',
            }}
          >
            {keepInitContentDetail}
          </div>
        </Modal>

皮倩雯's avatar
皮倩雯 committed
1739 1740 1741 1742 1743
        <AppendModal
          visible={appendVisible}
          onCancel={() => {
            setAppendVisible(false);
          }}
1744
          appendType={appendType}
皮倩雯's avatar
皮倩雯 committed
1745 1746
          value={dataValue}
          callBackSubmit={onOk}
皮倩雯's avatar
皮倩雯 committed
1747
          keepHistroy={keepHistroy}
皮倩雯's avatar
皮倩雯 committed
1748
        />
皮倩雯's avatar
皮倩雯 committed
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
        <Modal
          title="数据库授权记录"
          visible={historyVisible}
          onCancel={() => {
            setHistoryVisible(false);
          }}
          width={1000}
          bodyStyle={{
            height: '500px',
            overflowY: 'scroll',
          }}
          footer={[
            <Button
              onClick={() => {
                setHistoryVisible(false);
              }}
              key="back"
            >
              关闭
            </Button>,
          ]}
        >
          <Table
            size="small"
            rowKey={record => record.userID}
            bordered
            columns={columns}
            dataSource={keepHistroy}
            pagination={false}
            scroll={{ x: 'max-content' }}
          />
        </Modal>
1781 1782 1783 1784 1785 1786 1787
        <Modal
          title="初始化数据库详细日志"
          visible={initVisibledetail}
          onCancel={() => {
            setinitVisibledetail(false);
            setInitContentdetail('');
          }}
1788
          width={800}
1789 1790
          maskClosable={false}
          bodyStyle={{
1791
            height: '500px',
1792 1793 1794
            // overflowY: 'auto',
          }}
          footer={[
皮倩雯's avatar
皮倩雯 committed
1795 1796 1797 1798 1799 1800 1801 1802
            <Button
              onClick={() => {
                setInitVisible(true);
                setinitVisibledetail(false);
              }}
            >
              查看初始化日志
            </Button>,
1803 1804 1805 1806 1807
            <Button
              onClick={() => {
                handleClickdetail();
              }}
              key="back"
1808
              type="primary"
1809 1810 1811 1812 1813 1814 1815 1816
            >
              关闭窗口
            </Button>,
          ]}
        >
          <div
            ref={scroll}
            style={{
皮倩雯's avatar
皮倩雯 committed
1817
              maxHeight: '470px',
1818 1819 1820 1821 1822
              overflowY: 'auto',
            }}
          >
            {initContentdetail || (
              <Spin tip="loading..." style={{ width: '100%', marginTop: '40px' }} />
1823 1824 1825 1826 1827 1828 1829 1830 1831
            )}
          </div>
        </Modal>
      </PageContainer>
    </>
  );
};

export default connect()(DatabaseInitialization);