DatabaseInitialization.jsx 58.5 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 26 27 28 29 30 31 32 33 34 35
} from 'antd';
import PageContainer from '@/components/BasePageContainer';
import { connect } from 'react-redux';
import {
  getInitDBLogNew,
  deleteInitDBLogNew,
  GetProductList, // 获取产品列表
  GetDbProduct, // 获取产品方案配置
  SetAdminMenuToRole,
  CheckDatabaseIsExist,
  NewInitAddDataBase,
皮倩雯's avatar
皮倩雯 committed
36
  InitEditDataBase,
皮倩雯's avatar
皮倩雯 committed
37
  getDataBaseConfigNew,
38
} from '@/services/database/api';
39 40 41 42 43 44 45 46
import {
  CloseCircleOutlined,
  CheckCircleOutlined,
  ZoomInOutlined,
  ExclamationCircleOutlined,
  BarcodeOutlined,
  UserOutlined,
  CalendarOutlined,
皮倩雯's avatar
皮倩雯 committed
47 48 49 50
  CheckOutlined,
  MinusSquareOutlined,
  PlusOutlined,
  EyeOutlined,
51
} from '@ant-design/icons';
皮倩雯's avatar
皮倩雯 committed
52
import CryptoJS from 'crypto-js';
53 54
import styles from './DatabaseInitialization.less';
import styles1 from '../InitDataBase/InitDataBase.less';
皮倩雯's avatar
皮倩雯 committed
55
import AppendModal from './AppendModal';
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

const CheckboxGroup = Checkbox.Group;
const formLables = {
  ip: '服务器地址',
  userName: '用户名称',
  password: '用户密码',
  dbName: '数据库名称',
};
let time = null;
const DatabaseInitialization = props => {
  const [form] = Form.useForm();
  const [modalVisible, setModalVisible] = useState({
    describeVisible: false, // 描述弹窗
    versionVisible: false, // 检查版本弹窗
    initVisible: false, // 初始化选择产品弹窗
  }); // 修改弹窗
  const [initVisible, setInitVisible] = useState(false); // 数据库初始化弹窗
73
  const [initVisibledetail, setinitVisibledetail] = useState(false); // 数据库初始化详细信息弹窗
74
  const [initContent, setInitContent] = useState(''); // 数据库初始化内容
75
  const [initContentdetail, setInitContentdetail] = useState(''); // 数据库初始化详细内容
76 77 78 79 80
  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
81
  const [keepStatus, setKeepStatus] = useState([]);
82 83 84 85 86 87 88 89 90
  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([]);
91
  const [msg, setMsg] = useState('null');
92 93 94 95 96
  const [keepNumber, setkeepNumber] = useState('');
  const [keepNa, setkeepNa] = useState('');
  const [keepCo, setkeepCo] = useState('');
  const [keepMsg, setkeepMsg] = useState('');
  const [allLength, setAllLength] = useState('');
97
  const [oldColor, setOldColor] = useState('gray');
98
  const [beforeColor, setbeforeColor] = useState('gray');
99 100 101 102
  const [firstColor, setfirstColor] = useState('gray');
  const [secordColor, setsecordColor] = useState('gray');
  const [lastColor, setLastColor] = useState('gray');
  const [totalProduct, setTotalProduct] = useState('');
皮倩雯's avatar
皮倩雯 committed
103
  const [simpleProduct, setSimpleProduct] = useState('');
104
  const [show, setShow] = useState('hidden');
105 106
  const [keepInline, setKeepInline] = useState([]);
  const [ifInline, setIfInline] = useState('hidden');
107
  const [result, setResult] = useState('');
108
  const [license, setLicense] = useState('');
109 110 111
  const [dataResult, setDataResult] = useState('');
  const [productResult, setProductResult] = useState('');
  const [keepInitContent, setKeepInitContent] = useState('');
皮倩雯's avatar
皮倩雯 committed
112
  const [keepInitContentDetail, setKeepInitContentDetail] = useState('');
113 114
  const [keepinitVisible, setKeepInitVisible] = useState(false);
  const [password, setPassword] = useState(false);
115 116 117
  const [isAuthorize, setIsAuthorize] = useState(false);
  const [licen, setLicen] = useState('');
  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

皮倩雯's avatar
皮倩雯 committed
126 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
  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();
  };

153 154 155 156 157 158
  // 获取数据库配置信息
  useEffect(() => {
    setCardLoading(true);
    getProductList();
    // form.setFieldsValue({ ip: '127.0.0.1', password: 'sa', userName: 'sa' });
  }, []);
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
          if (!res.data.finish) {
245
            // if (!finish) {
246 247 248
            time = setTimeout(() => {
              doInitLog();
            }, 600);
249 250 251 252 253 254 255 256
            // } else {
            //   setInitLoading(false);
            //   setShow('visible');
            //   if (time) {
            //     clearTimeout(time);
            //     time = null;
            //   }
            // }
257 258
          } else {
            setInitLoading(false);
259
            setShow('visible');
260 261 262 263 264 265 266 267
            if (time) {
              clearTimeout(time);
              time = null;
            }
          }
        }
      })
      .catch(err => {
268 269 270 271 272
        if (time) {
          clearTimeout(time);
          time = null;
        }
        message.error(err);
273 274 275 276
        setFinish(true);
      });
  };

277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
  // 获取详细日志
  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
292
            setKeepInitContentDetail(arr);
293
            setShowDetali(true);
294 295 296 297 298 299 300 301 302
            scroll.current.scrollTop = scroll.current.scrollHeight;
          }
        }
      })
      .catch(err => {
        console.log(err);
      });
  };

303 304 305 306
  const onValuesChange = (value, b) => {
    form.setFieldsValue(value);
  };

307
  const handlelook = () => {
皮倩雯's avatar
皮倩雯 committed
308 309
    setInitVisible(false);
    setinitVisibledetail(true);
310 311 312 313 314 315
    doInitLogdetali();
  };

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

323 324 325
  // 关闭弹窗
  const handleClick = () => {
    setInitVisible(false);
皮倩雯's avatar
皮倩雯 committed
326 327
    // setInitContent('');
    // setInitContentdetail('');
328
    setFinish(false);
皮倩雯's avatar
皮倩雯 committed
329
    // deleteInitDBLogNew();
330
    setShowDetali(false);
331 332
  };

333
  const GetDb = kk => {
皮倩雯's avatar
皮倩雯 committed
334 335 336 337 338
    getDataBaseConfigNew().then(resdata => {
      GetDbProduct({
        ip: resdata.data.ip,
        dbName: resdata.data.dbName,
        userName: resdata.data.userName,
邓超's avatar
邓超 committed
339
        password: resdata.data.password,
皮倩雯's avatar
皮倩雯 committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
      }).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
362

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

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

501
  const GetDbChange = e => {
502
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
503
    GetDbProduct({ ...obj, password: Encrypt(obj.password) }).then(res => {
504
      setCardLoading(false);
505
      if (res.code === 0) {
506
        if (res.data.IsAuthorize) {
507 508
          // setMsg('');
          if (e) {
皮倩雯's avatar
皮倩雯 committed
509
            findCheck(res.data.IsAppend);
510
          } else {
皮倩雯's avatar
皮倩雯 committed
511
            onCheckLaster(res.data.IsAppend);
512
          }
513
        } else {
皮倩雯's avatar
皮倩雯 committed
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
          let obj1 = form.getFieldsValue();
          CheckDatabaseIsExist({ ...obj1, password: Encrypt(obj.password) }).then(res1 => {
            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);
            }
          });
537
        }
538
        if (res.data.Project && res.data.Project.length > 0) {
皮倩雯's avatar
皮倩雯 committed
539 540 541 542 543
          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);
544
        } else {
皮倩雯's avatar
皮倩雯 committed
545 546
          // setKeepProductData('');
          setKeepHistroy([]);
547 548 549 550 551
          setkeepNumber('');
          setkeepMsg('');
          setkeepNa('');
          setkeepCo('');
        }
552
        if (res.data.Product.length > 0) {
553
          let aa = [];
皮倩雯's avatar
皮倩雯 committed
554
          let gg = [];
555
          res.data.Product.map(i => {
556 557 558 559 560
            if (i.name !== null) {
              if (i.status == 1) {
                gg.push(i.name);
              }
              aa.push(i.name);
皮倩雯's avatar
皮倩雯 committed
561
            }
562 563 564 565 566 567 568 569 570
          });
          if (aa.length > 0) {
            let dd = [];
            aa.map(i => {
              keepData.map(j => {
                if (j.name === i) {
                  dd.push(j);
                }
              });
571
            });
572 573 574 575 576 577 578 579 580
            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;
581
            });
582
            setProduct(arr);
583
            console.log(arr);
584
            setKeepValue(arr);
585
          }
586
          let newArr = Array.from(new Set(aa));
587
          // 当前数据库已存在和上一个已存在数据库值重新赋值
皮倩雯's avatar
皮倩雯 committed
588
          if (newArr.length > 0) {
589
            console.log(newArr);
皮倩雯's avatar
皮倩雯 committed
590
            setKeepProduct(newArr);
皮倩雯's avatar
皮倩雯 committed
591
            setKeepStatus(gg);
皮倩雯's avatar
皮倩雯 committed
592 593 594 595
            setKeepCode(newArr);
            setValue(newArr);
          } else {
            setKeepProduct([]);
皮倩雯's avatar
皮倩雯 committed
596
            setKeepStatus([]);
皮倩雯's avatar
皮倩雯 committed
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
            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
618
    GetDbProduct({ ...obj, password: Encrypt(obj.password) }).then(res => {
皮倩雯's avatar
皮倩雯 committed
619 620
      setCardLoading(false);
      if (res.code === 0) {
621
        if (res.data.Product.length > 0) {
皮倩雯's avatar
皮倩雯 committed
622
          let aa = [];
皮倩雯's avatar
皮倩雯 committed
623
          let gg = [];
皮倩雯's avatar
皮倩雯 committed
624
          res.data.Product.map(i => {
625 626 627 628 629
            if (i.name !== null) {
              if (i.status == 1) {
                gg.push(i.name);
              }
              aa.push(i.name);
皮倩雯's avatar
皮倩雯 committed
630
            }
皮倩雯's avatar
皮倩雯 committed
631
          });
632
          // 后端返回出局的分组名可能发生改变,前端处理数据展示新分组名
皮倩雯's avatar
皮倩雯 committed
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
          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) {
658
            console.log(newArr);
659
            setKeepProduct(newArr);
皮倩雯's avatar
皮倩雯 committed
660
            setKeepStatus(gg);
661 662
            setKeepCode(newArr);
            setValue(newArr);
皮倩雯's avatar
皮倩雯 committed
663 664
          } else {
            setKeepProduct([]);
皮倩雯's avatar
皮倩雯 committed
665
            setKeepStatus([]);
皮倩雯's avatar
皮倩雯 committed
666 667
            setKeepCode([]);
            setValue([]);
668
          }
669 670 671
          if (res.data.Product.length == 0) {
            setKeepValue([]);
          }
672
        }
皮倩雯's avatar
皮倩雯 committed
673 674 675 676 677
        if (res.data.Project && res.data.Project.length > 0) {
          setKeepHistroy(res.data.Project);
        } else {
          setKeepHistroy([]);
        }
678
        setKeepDb(res.data);
679
        setIsAuthorize(res.data.IsAuthorize);
680
      } else {
681
        notification.error({
682
          message: '提示',
683
          duration: 3,
684 685 686 687 688 689
          description: res.msg,
        });
      }
    });
  };

690 691
  const onOK = arr => {
    initDatabasePro(arr);
692 693 694
  };

  // 数据库初始化
695
  const initDatabasePro = e => {
696 697 698 699 700 701
    let productSetting = e;
    let obj = form.getFieldsValue();
    // 数据库存在调用编辑接口否则调用新增接口
    handleShowModal('initVisible', false);
    setInitVisible(true);
    doInitLog();
皮倩雯's avatar
皮倩雯 committed
702
    NewInitAddDataBase({ ...obj, productSetting, password: Encrypt(obj.password) }).then(res => {
703
      if (res.code === 0) {
704
        GetDbChangeAppend(); // 刷星已初始化的产品勾选
705
        setMsg('未检测到可用License');
706
        setfirstColor('green');
707 708

        setDataResult('成功');
709 710
        notification.success({
          message: '提示',
711
          duration: 3,
712 713
          description: '数据库初始化成功',
        });
714 715 716
        if (keepNumber != '') {
          setkeepNumber('已使用');
        }
皮倩雯's avatar
皮倩雯 committed
717 718 719 720 721 722 723 724
        if (res.data.productPackageCount == 0) {
          setProductResult('产品授权不包含已初始化的产品');
          setsecordColor('#eda625');
        } else {
          setsecordColor('green');
        }
        setTotalProduct(res.data.productPackageSumCount);
        setSimpleProduct(res.data.productPackageCount);
725
        // 给平台管理员赋值所有菜单权限
皮倩雯's avatar
皮倩雯 committed
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
        SetAdminMenuToRole().then(resdata => {
          if (resdata.code === 0) {
            setLastColor('green');
            setKeepLast('');
          } else {
            setLastColor('red');
            setKeepLast(res.data.msg);
          }
        });
      } 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
757
    InitEditDataBase({ ...obj, password: Encrypt(obj.password) }).then(res => {
皮倩雯's avatar
皮倩雯 committed
758
      if (res.code === 0) {
皮倩雯's avatar
皮倩雯 committed
759
        GetDbChangeAppend();
760
        setMsg('未检测到可用License');
皮倩雯's avatar
皮倩雯 committed
761 762 763 764 765 766 767 768 769 770
        setfirstColor('green');
        setDataResult('成功');
        notification.success({
          message: '提示',
          duration: 3,
          description: '数据库初始化追加成功',
        });
        if (keepNumber != '') {
          setkeepNumber('已使用');
        }
771 772 773 774 775 776
        if (res.data.productPackageCount == 0) {
          setProductResult('产品授权不包含已初始化的产品');
          setsecordColor('#eda625');
        } else {
          setsecordColor('green');
        }
皮倩雯's avatar
皮倩雯 committed
777 778
        setTotalProduct(res.data.productPackageSumCount);
        setSimpleProduct(res.data.productPackageCount);
779 780
        setLastColor('green');
        setKeepLast('');
781
      } else {
782
        setDataResult(res.msg);
783 784 785 786 787 788
        setFinish(true);
        setfirstColor('red');
        setsecordColor('gray');
        setLastColor('gray');
        notification.error({
          message: '提示',
789
          duration: 3,
790 791 792 793 794 795 796
          description: res.msg,
        });
      }
    });
  };

  const flagChange = () => {
797 798 799 800
    setbeforeColor('gray');
    setfirstColor('gray');
    setsecordColor('gray');
    setLastColor('gray');
皮倩雯's avatar
皮倩雯 committed
801 802
    setSimpleProduct('');
    setTotalProduct('');
803 804 805 806 807 808 809 810 811 812 813 814 815 816
    onCheck();
  };

  const onChange1 = (e, item) => {
    if (product[item]) {
      // 过滤已初始化的产品但不存在于产品列表中的数据,避免组件出错
      product[item].map(i => {
        if (data[item].indexOf(i) == -1) {
          product[item].splice(product[item].findIndex(j => j === i), 1);
        }
      });

      let arr = product[item].find(i => e.indexOf(i) == -1);
      let bb = keepProduct.indexOf(arr);
817 818 819 820 821 822 823
      let aa = keepValue;
      aa[item] = e;
      let a = Object.keys(aa);
      let list = [];
      a.map(i => {
        aa[i].map(j => {
          list.push(j);
824
        });
825 826 827
      });
      setKeepValue(aa);
      setValue(list);
828 829 830 831 832 833 834 835 836 837
    } else {
      let aa = keepValue;
      aa[item] = e;
      let a = Object.keys(aa);
      let list = [];
      a.map(i => {
        aa[i].map(j => {
          list.push(j);
        });
      });
838
      setKeepValue(aa);
839 840 841 842 843 844
      setValue(list);
    }
  };

  const onCheck = () => {
    let obj = form.getFieldsValue();
845 846 847
    if (obj.ip && obj.userName && obj.password && obj.dbName) {
      // setKeepValue([]);
      setProduct([]);
848
      setCardLoading(true);
皮倩雯's avatar
皮倩雯 committed
849
      GetProductList({ ...obj, password: Encrypt(obj.password) }).then(res => {
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
        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
871
      // deleteInitDBLogNew();
872 873 874 875 876 877
    } else {
      setbeforeColor('red');
      setResult('请输入完整数据库信息');
      setMsg('请输入完整数据库信息');
    }
  };
皮倩雯's avatar
皮倩雯 committed
878 879 880 881 882 883 884 885 886 887 888 889 890
  // 非授权模式下环境检查
  const checkUnLicense = () => {
    let obj = form.getFieldsValue();
    CheckDatabaseIsExist({ ...obj, password: Encrypt(obj.password) }).then(res => {
      setCardLoading(false);
      if (res.code !== 0) {
        setbeforeColor('red');
        setResult(`${res.msg}`);
        setMsg(res.msg);
      }
    });
  };

皮倩雯's avatar
皮倩雯 committed
891 892
  const onCheckLaster = aa => {
    // 此时有授权码才能进入
893
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
894
    CheckDatabaseIsExist({ ...obj, password: Encrypt(obj.password) }).then(res => {
895
      setCardLoading(false);
皮倩雯's avatar
皮倩雯 committed
896
      if (res.code == 0) {
皮倩雯's avatar
皮倩雯 committed
897
        setDataValue(form.getFieldsValue());
皮倩雯's avatar
皮倩雯 committed
898 899
        // 数据库不存在
        if (res.data === false) {
900
          setbeforeColor('green');
901
          setResult('通过');
皮倩雯's avatar
皮倩雯 committed
902 903
          setAppend('无需追加');
          setMsg('');
904
          if (keepNumber && keepNumber != '已使用') {
皮倩雯's avatar
皮倩雯 committed
905 906
            setMsg('');
          }
907
        } else {
皮倩雯's avatar
皮倩雯 committed
908 909 910 911 912 913 914 915 916 917 918 919 920 921
          if (aa) {
            setbeforeColor('green');
            setResult('检测到License,当前环境需要追加产品');
            setMsg('检测到License,当前环境需要追加产品');
            setAppend('');
            setAppendVisible(true);
            console.log(form.getFieldsValue());
            setDataValue(form.getFieldsValue());
          } else {
            setbeforeColor('red');
            setResult('无法追加,该数据库为非授权初始化数据库,请直接升级数据库!');
            setMsg('无法追加,该数据库为非授权初始化数据库,请直接升级数据库!');
            setAppend('无需追加');
          }
922 923
        }
      } else {
924 925
        setbeforeColor('red');
        setResult(`${res.msg}`);
皮倩雯's avatar
皮倩雯 committed
926
        setMsg(res.msg);
927 928 929 930 931 932
      }
    });
  };

  const Submit = () => {
    let obj = form.getFieldsValue();
933
    if (obj.ip && obj.userName && obj.password && obj.dbName) {
皮倩雯's avatar
皮倩雯 committed
934
      GetProductList({ ...obj, password: Encrypt(obj.password) }).then(res => {
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
        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);
        }
      });

954 955 956 957 958 959
      setCardLoading(true);
    } else {
      setbeforeColor('red');
      setResult('请输入完整数据库信息');
      setMsg('请输入完整数据库信息');
    }
960 961
  };

皮倩雯's avatar
皮倩雯 committed
962
  const findCheck = aa => {
963
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
964
    CheckDatabaseIsExist({ ...obj, password: Encrypt(obj.password) }).then(res => {
965 966
      setCardLoading(false);
      if (res.code === 0) {
皮倩雯's avatar
皮倩雯 committed
967
        setDataValue(form.getFieldsValue());
968
        if (res.data === true) {
皮倩雯's avatar
皮倩雯 committed
969 970 971 972 973 974 975 976 977 978 979 980 981
          if (aa) {
            setbeforeColor('green');
            setResult('检测到License,当前环境需要追加产品');
            setMsg('检测到License,当前环境需要追加产品');
            setAppend('');
            setAppendVisible(true);
            setDataValue(form.getFieldsValue());
          } else {
            setbeforeColor('red');
            setPassword(false);
            setResult('无法追加,该数据库为非授权初始化数据库,请直接升级数据库! ');
            setMsg('无法追加,该数据库为非授权初始化数据库,请直接升级数据库!');
            setAppend('无需追加');
皮倩雯's avatar
皮倩雯 committed
982
            // deleteInitDBLogNew();
皮倩雯'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
    CheckDatabaseIsExist({ ...obj, password: Encrypt(obj.password) }).then(res => {
皮倩雯's avatar
皮倩雯 committed
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
      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());
          } else {
            setbeforeColor('red');
            setPassword(false);
            setResult('无法追加,该数据库为非授权初始化数据库,请直接升级数据库! ');
            setMsg('无法追加,该数据库为非授权初始化数据库,请直接升级数据库!');
            setAppend('无需追加');
            // deleteInitDBLogNew();
          }
        } 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);
      }
    });
  };

1054
  const save = () => {
1055
    flagChange();
1056 1057
  };

1058
  useEffect(() => {
皮倩雯's avatar
皮倩雯 committed
1059
    if (!initVisible && !initVisibledetail) {
1060 1061 1062 1063
      setShow('hidden');
    }
  }, [initVisible]);

1064
  const wirthValue = () => {
1065 1066 1067 1068 1069 1070 1071
    setResult('');
    setbeforeColor('gray');
    setfirstColor('gray');
    setsecordColor('gray');
    setLastColor('gray');
    setSimpleProduct('');
    setTotalProduct('');
1072 1073 1074
    form.setFieldsValue(keepInline);
  };

1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
  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
1091 1092 1093
  const onOk = () => {
    setAppendVisible(false);
    initDatabaseProAppend();
皮倩雯's avatar
皮倩雯 committed
1094 1095 1096 1097 1098
    // GetDbChangeAppend();
  };

  const onHistory = () => {
    setHistoryVisible(true);
皮倩雯's avatar
皮倩雯 committed
1099
  };
皮倩雯's avatar
皮倩雯 committed
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 1126 1127 1128 1129

  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 => {
1130
            aa.push(i.name);
皮倩雯's avatar
皮倩雯 committed
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
          });
          return (
            <Tooltip title={aa.toString()} arrowPointAtCenter placement="rightTop">
              <span>{text.length}</span>
            </Tooltip>
          );
        }
      },
    },
  ];

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

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

皮倩雯's avatar
皮倩雯 committed
1716 1717 1718 1719 1720 1721 1722
        <AppendModal
          visible={appendVisible}
          onCancel={() => {
            setAppendVisible(false);
          }}
          value={dataValue}
          callBackSubmit={onOk}
皮倩雯's avatar
皮倩雯 committed
1723
          keepHistroy={keepHistroy}
皮倩雯's avatar
皮倩雯 committed
1724
        />
皮倩雯's avatar
皮倩雯 committed
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
        <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>
1757 1758 1759 1760 1761 1762 1763
        <Modal
          title="初始化数据库详细日志"
          visible={initVisibledetail}
          onCancel={() => {
            setinitVisibledetail(false);
            setInitContentdetail('');
          }}
1764
          width={800}
1765 1766
          maskClosable={false}
          bodyStyle={{
1767
            height: '500px',
1768 1769 1770
            // overflowY: 'auto',
          }}
          footer={[
皮倩雯's avatar
皮倩雯 committed
1771 1772 1773 1774 1775 1776 1777 1778
            <Button
              onClick={() => {
                setInitVisible(true);
                setinitVisibledetail(false);
              }}
            >
              查看初始化日志
            </Button>,
1779 1780 1781 1782 1783
            <Button
              onClick={() => {
                handleClickdetail();
              }}
              key="back"
1784
              type="primary"
1785 1786 1787 1788 1789 1790 1791 1792
            >
              关闭窗口
            </Button>,
          ]}
        >
          <div
            ref={scroll}
            style={{
皮倩雯's avatar
皮倩雯 committed
1793
              maxHeight: '470px',
1794 1795 1796 1797 1798 1799
              overflowY: 'auto',
              marginRight: ' -24px',
            }}
          >
            {initContentdetail || (
              <Spin tip="loading..." style={{ width: '100%', marginTop: '40px' }} />
1800 1801 1802 1803 1804 1805 1806 1807 1808
            )}
          </div>
        </Modal>
      </PageContainer>
    </>
  );
};

export default connect()(DatabaseInitialization);