DatabaseInitialization.jsx 58.1 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 373 374 375 376 377 378 379 380
          GetDbChangeFirst(kk);
          // 有License的情况下首次进入展示数据
          // if (res.data.IsAuthorize) {
          if (res.data.Product) {
            let aa = [];
            let gg = [];
            res.data.Product.map(i => {
              if (i.status == 1) {
                gg.push(i.name);
              }
              aa.push(i.name);
381
            });
皮倩雯's avatar
皮倩雯 committed
382 383 384 385 386 387 388 389
            if (aa.length > 0) {
              let dd = [];
              aa.map(i => {
                kk.map(j => {
                  if (j.name === i) {
                    dd.push(j);
                  }
                });
390
              });
皮倩雯's avatar
皮倩雯 committed
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
              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);
            setKeepProduct(newArr);
            setKeepCode(newArr);
            setValue(newArr);
409
          }
皮倩雯's avatar
皮倩雯 committed
410 411 412 413
          setKeepDb(res.data);
          setIsAuthorize(res.data.IsAuthorize);
          if (res.data.IsAuthorize) {
            setMsg('');
皮倩雯's avatar
皮倩雯 committed
414
          } else {
皮倩雯's avatar
皮倩雯 committed
415 416 417
            if (
              res.data.Project &&
              res.data.Project[0] &&
418
              res.data.Project[res.data.Project.length - 1].license == '已使用'
皮倩雯's avatar
皮倩雯 committed
419 420
            ) {
              setbeforeColor('red');
421 422
              setResult('未检测到可用License');
              setMsg('未检测到可用License');
皮倩雯's avatar
皮倩雯 committed
423 424 425 426 427
            } else {
              setbeforeColor('red');
              setResult('未检测到License');
              setMsg('未检测到License');
            }
皮倩雯's avatar
皮倩雯 committed
428
          }
皮倩雯's avatar
皮倩雯 committed
429 430 431 432 433 434
        } else {
          notification.error({
            message: '提示',
            duration: 3,
            description: res.msg,
          });
皮倩雯's avatar
皮倩雯 committed
435
        }
皮倩雯's avatar
皮倩雯 committed
436
      });
皮倩雯's avatar
皮倩雯 committed
437 438 439 440 441
    });
  };

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

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

672 673
  const onOK = arr => {
    initDatabasePro(arr);
674 675 676
  };

  // 数据库初始化
677
  const initDatabasePro = e => {
678 679 680 681 682 683
    let productSetting = e;
    let obj = form.getFieldsValue();
    // 数据库存在调用编辑接口否则调用新增接口
    handleShowModal('initVisible', false);
    setInitVisible(true);
    doInitLog();
皮倩雯's avatar
皮倩雯 committed
684
    NewInitAddDataBase({ ...obj, productSetting, password: Encrypt(obj.password) }).then(res => {
685
      if (res.code === 0) {
皮倩雯's avatar
皮倩雯 committed
686
        GetDbChangeAppend();
687
        setMsg('未检测到可用License');
688
        setfirstColor('green');
689 690

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

  const flagChange = () => {
787 788 789 790
    setbeforeColor('gray');
    setfirstColor('gray');
    setsecordColor('gray');
    setLastColor('gray');
皮倩雯's avatar
皮倩雯 committed
791 792
    setSimpleProduct('');
    setTotalProduct('');
793 794 795 796 797 798 799 800 801 802 803 804 805 806
    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);
807 808 809 810 811 812 813
      let aa = keepValue;
      aa[item] = e;
      let a = Object.keys(aa);
      let list = [];
      a.map(i => {
        aa[i].map(j => {
          list.push(j);
814
        });
815 816 817
      });
      setKeepValue(aa);
      setValue(list);
818 819 820 821 822 823 824 825 826 827
    } else {
      let aa = keepValue;
      aa[item] = e;
      let a = Object.keys(aa);
      let list = [];
      a.map(i => {
        aa[i].map(j => {
          list.push(j);
        });
      });
828
      setKeepValue(aa);
829 830 831 832 833 834
      setValue(list);
    }
  };

  const onCheck = () => {
    let obj = form.getFieldsValue();
835 836 837
    if (obj.ip && obj.userName && obj.password && obj.dbName) {
      // setKeepValue([]);
      setProduct([]);
838
      setCardLoading(true);
皮倩雯's avatar
皮倩雯 committed
839
      GetProductList({ ...obj, password: Encrypt(obj.password) }).then(res => {
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
        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
861
      // deleteInitDBLogNew();
862 863 864 865 866 867
    } else {
      setbeforeColor('red');
      setResult('请输入完整数据库信息');
      setMsg('请输入完整数据库信息');
    }
  };
皮倩雯's avatar
皮倩雯 committed
868 869 870 871 872 873 874 875 876 877 878 879 880
  // 非授权模式下环境检查
  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
881 882
  const onCheckLaster = aa => {
    // 此时有授权码才能进入
883
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
884
    CheckDatabaseIsExist({ ...obj, password: Encrypt(obj.password) }).then(res => {
885
      setCardLoading(false);
皮倩雯's avatar
皮倩雯 committed
886
      if (res.code == 0) {
皮倩雯's avatar
皮倩雯 committed
887
        setDataValue(form.getFieldsValue());
皮倩雯's avatar
皮倩雯 committed
888 889
        // 数据库不存在
        if (res.data === false) {
890
          setbeforeColor('green');
891
          setResult('通过');
皮倩雯's avatar
皮倩雯 committed
892 893
          setAppend('无需追加');
          setMsg('');
894
          if (keepNumber && keepNumber != '已使用') {
皮倩雯's avatar
皮倩雯 committed
895 896
            setMsg('');
          }
897
        } else {
皮倩雯's avatar
皮倩雯 committed
898 899 900 901 902 903 904 905 906 907 908 909 910 911
          if (aa) {
            setbeforeColor('green');
            setResult('检测到License,当前环境需要追加产品');
            setMsg('检测到License,当前环境需要追加产品');
            setAppend('');
            setAppendVisible(true);
            console.log(form.getFieldsValue());
            setDataValue(form.getFieldsValue());
          } else {
            setbeforeColor('red');
            setResult('无法追加,该数据库为非授权初始化数据库,请直接升级数据库!');
            setMsg('无法追加,该数据库为非授权初始化数据库,请直接升级数据库!');
            setAppend('无需追加');
          }
912 913
        }
      } else {
914 915
        setbeforeColor('red');
        setResult(`${res.msg}`);
皮倩雯's avatar
皮倩雯 committed
916
        setMsg(res.msg);
917 918 919 920 921 922
      }
    });
  };

  const Submit = () => {
    let obj = form.getFieldsValue();
923
    if (obj.ip && obj.userName && obj.password && obj.dbName) {
皮倩雯's avatar
皮倩雯 committed
924
      GetProductList({ ...obj, password: Encrypt(obj.password) }).then(res => {
925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
        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);
        }
      });

944 945 946 947 948 949
      setCardLoading(true);
    } else {
      setbeforeColor('red');
      setResult('请输入完整数据库信息');
      setMsg('请输入完整数据库信息');
    }
950 951
  };

皮倩雯's avatar
皮倩雯 committed
952
  const findCheck = aa => {
953
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
954
    CheckDatabaseIsExist({ ...obj, password: Encrypt(obj.password) }).then(res => {
955 956
      setCardLoading(false);
      if (res.code === 0) {
皮倩雯's avatar
皮倩雯 committed
957
        setDataValue(form.getFieldsValue());
958
        if (res.data === true) {
皮倩雯's avatar
皮倩雯 committed
959 960 961 962 963 964 965 966 967 968 969 970 971
          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
972
            // deleteInitDBLogNew();
皮倩雯's avatar
皮倩雯 committed
973
          }
974 975 976 977 978
        } else {
          setPassword(true);
          setbeforeColor('green');
          setResult('通过');
          setMsg('');
皮倩雯's avatar
皮倩雯 committed
979 980 981 982 983 984 985
          setAppend('无需追加');

          let arr = [];

          keepData.map(i => {
            if (keepCode.indexOf(i.name) != -1) {
              arr.push(i);
986
            }
皮倩雯's avatar
皮倩雯 committed
987 988 989
          });

          onOK(arr);
990 991 992 993 994 995 996 997 998
        }
      } else {
        setbeforeColor('red');
        setResult(`${res.msg}`);
        setMsg(res.msg);
      }
    });
  };

皮倩雯's avatar
皮倩雯 committed
999 1000
  const findCheck1 = aa => {
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
1001
    CheckDatabaseIsExist({ ...obj, password: Encrypt(obj.password) }).then(res => {
皮倩雯's avatar
皮倩雯 committed
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 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
      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);
      }
    });
  };

1044
  const save = () => {
1045
    flagChange();
1046 1047
  };

1048
  useEffect(() => {
皮倩雯's avatar
皮倩雯 committed
1049
    if (!initVisible && !initVisibledetail) {
1050 1051 1052 1053
      setShow('hidden');
    }
  }, [initVisible]);

1054
  const wirthValue = () => {
1055 1056 1057 1058 1059 1060 1061
    setResult('');
    setbeforeColor('gray');
    setfirstColor('gray');
    setsecordColor('gray');
    setLastColor('gray');
    setSimpleProduct('');
    setTotalProduct('');
1062 1063 1064
    form.setFieldsValue(keepInline);
  };

1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
  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
1081 1082 1083
  const onOk = () => {
    setAppendVisible(false);
    initDatabaseProAppend();
皮倩雯's avatar
皮倩雯 committed
1084 1085 1086 1087 1088
    // GetDbChangeAppend();
  };

  const onHistory = () => {
    setHistoryVisible(true);
皮倩雯's avatar
皮倩雯 committed
1089
  };
皮倩雯's avatar
皮倩雯 committed
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119

  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 => {
1120
            aa.push(i.name);
皮倩雯's avatar
皮倩雯 committed
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
          });
          return (
            <Tooltip title={aa.toString()} arrowPointAtCenter placement="rightTop">
              <span>{text.length}</span>
            </Tooltip>
          );
        }
      },
    },
  ];

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

1138 1139 1140 1141 1142 1143
  return (
    <>
      <PageContainer className={styles.InitDataBaseContainer}>
        <div style={{ display: 'flex', alignItems: 'center', width: '100%' }}>
          <div style={{ width: '30%' }}>
            <Card>
1144
              <div style={{ height: 'calc(100vh - 101px)', paddingTop: '13px' }}>
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
                <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) => {
1159
                          let regCn = /^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/;
1160 1161 1162
                          if (form.getFieldValue().ip == '') {
                            return Promise.reject('ip必填');
                          }
1163 1164 1165
                          if (!regCn.test(form.getFieldValue().ip)) {
                            return Promise.reject('ip格式不正确');
                          }
1166
                          setbeforeColor('gray');
1167 1168 1169
                          setfirstColor('gray');
                          setsecordColor('gray');
                          setLastColor('gray');
1170 1171 1172
                          setSimpleProduct('');
                          setTotalProduct('');
                          setResult('');
1173 1174 1175 1176 1177
                          return Promise.resolve();
                        },
                      },
                    ]}
                  >
皮倩雯's avatar
皮倩雯 committed
1178
                    <Input placeholder="请输入服务器名或IP地址" />
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
                  </Form.Item>
                  <Form.Item
                    label={`${formLables.userName}:`}
                    name="userName"
                    rules={[
                      {
                        validator: (rule, value) => {
                          if (form.getFieldValue().userName == '') {
                            return Promise.reject('用户名称必填');
                          }
1189
                          setbeforeColor('gray');
1190 1191 1192
                          setfirstColor('gray');
                          setsecordColor('gray');
                          setLastColor('gray');
1193 1194 1195
                          setSimpleProduct('');
                          setTotalProduct('');
                          setResult('');
1196 1197 1198 1199 1200
                          return Promise.resolve();
                        },
                      },
                    ]}
                  >
皮倩雯's avatar
皮倩雯 committed
1201
                    <Input placeholder="请输入用户名称" />
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
                  </Form.Item>
                  <Form.Item
                    label={`${formLables.password}:`}
                    name="password"
                    rules={[
                      {
                        validator: (rule, value) => {
                          if (form.getFieldValue().password == '') {
                            return Promise.reject('用户密码必填');
                          }
1212
                          setbeforeColor('gray');
1213 1214 1215
                          setfirstColor('gray');
                          setsecordColor('gray');
                          setLastColor('gray');
1216 1217 1218
                          setSimpleProduct('');
                          setTotalProduct('');
                          setResult('');
1219 1220 1221 1222 1223
                          return Promise.resolve();
                        },
                      },
                    ]}
                  >
皮倩雯's avatar
皮倩雯 committed
1224
                    <Input placeholder="请输入用户密码" type="password" />
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
                  </Form.Item>
                  <Form.Item
                    label={`${formLables.dbName}:`}
                    name="dbName"
                    rules={[
                      {
                        validator: (rule, value) => {
                          if (
                            form.getFieldValue().dbName == '' ||
                            form.getFieldValue().dbName == undefined
                          ) {
                            return Promise.reject('数据库名称必填');
                          }
1238
                          setbeforeColor('gray');
1239 1240 1241
                          setfirstColor('gray');
                          setsecordColor('gray');
                          setLastColor('gray');
1242 1243 1244
                          setSimpleProduct('');
                          setTotalProduct('');
                          setResult('');
1245 1246 1247 1248 1249
                          return Promise.resolve();
                        },
                      },
                    ]}
                  >
皮倩雯's avatar
皮倩雯 committed
1250
                    <Input placeholder="请输入数据库名称" />
1251 1252
                  </Form.Item>
                </Form>
皮倩雯's avatar
皮倩雯 committed
1253
                <div style={{ float: 'right' }}>
1254
                  <Button onClick={save}>环境检查</Button>
皮倩雯's avatar
皮倩雯 committed
1255 1256
                </div>
                <div style={{ marginTop: '100px', transform: 'scal(1.5)' }}>
1257
                  <Timeline>
1258
                    <Timeline.Item color={beforeColor}>
1259
                      环境检查
1260 1261 1262 1263 1264 1265 1266 1267
                      {(() => {
                        switch (result) {
                          case '':
                            return <></>;
                          case '通过':
                            return (
                              <CheckCircleOutlined style={{ color: 'green', marginLeft: '10px' }} />
                            );
皮倩雯's avatar
皮倩雯 committed
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
                          case '检测到License,当前环境需要追加产品':
                            return (
                              <>
                                <CheckCircleOutlined
                                  style={{ color: 'green', marginLeft: '10px' }}
                                />
                                <span style={{ color: 'rgb(24 144 255)', marginLeft: '5px' }}>
                                  {result}
                                </span>
                              </>
                            );
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 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
                          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>
                              </>
                            );
                        }
                      })()}
1322
                    </Timeline.Item>
1323
                    <Timeline.Item color={secordColor}>
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 1358 1359 1360 1361 1362 1363
                      <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 <></>;
                        }
                      })()}
1364 1365
                    </Timeline.Item>
                    <Timeline.Item color={lastColor}>
1366
                      <span>平台管理员赋权使用</span>
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
                      {(() => {
                        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>
                              </>
                            );
                        }
                      })()}
1394 1395 1396 1397 1398 1399 1400 1401
                    </Timeline.Item>
                  </Timeline>
                </div>
              </div>
            </Card>
          </div>
          <div style={{ width: '70%' }}>
            <Card className={styles.mgTop20}>
1402 1403 1404 1405 1406 1407
              <div
                style={{
                  height: '50px',
                  display: 'flex',
                  justifyContent: 'space-between',
                  alignItems: 'center',
1408
                  // color: 'rgb(137 67 67 / 85%)',
1409 1410 1411
                }}
              >
                <div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
皮倩雯's avatar
皮倩雯 committed
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
                  {keepHistroy.length > 0 ? (
                    <Tooltip title="查看数据库授权记录">
                      <EyeOutlined
                        style={{ color: 'rgb(24 144 255)', marginRight: '5px' }}
                        onClick={onHistory}
                      />
                    </Tooltip>
                  ) : (
                    <></>
                  )}
1422
                  <BarcodeOutlined style={{ color: 'rgb(227 168 96)', marginRight: '5px' }} />
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
                  授权码:
                  {keepNumber ? (
                    <>{keepNumber}</>
                  ) : (
                    <span>
                      --
                      {/* <EditOutlined
                        style={{ color: 'rgb(24 144 255)', marginLeft: '20px', marginTop: '10px' }}
                        onClick={}
                      /> */}
                    </span>
                  )}
                </div>
1436 1437
                <div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
                  <CalendarOutlined style={{ color: '#8466cb', marginRight: '5px' }} />
1438 1439
                  项目名:{keepMsg ? <>{keepMsg}</> : '--'}
                </div>
1440 1441
                <div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
                  <UserOutlined style={{ color: 'green', marginRight: '5px' }} />
1442
                  授权人:{keepNa ? <>{keepNa}</> : '-'}
1443 1444
                  {keepCo ? <>{keepCo}</> : '-'}
                </div>
1445
                <div style={{ display: 'inline-block', backgroundColor: 'aliceblue' }}>
皮倩雯's avatar
皮倩雯 committed
1446 1447 1448 1449 1450
                  <div style={{ float: 'right' }}>
                    (已选
                    <span style={{ color: 'rgb(24 144 255)' }}>{keepProduct.length}</span>/
                    <span style={{ color: 'rgb(24 144 255)' }}>{allLength}</span>个产品)
                  </div>
1451 1452 1453 1454 1455 1456
                </div>
              </div>
              <Spin tip="loading..." spinning={cardLoading}>
                <div className={styles1.initItemData}>
                  {title &&
                    title.map((item, index) => (
1457
                      <div key={index} style={{ marginBottom: '10px' }}>
1458 1459 1460 1461 1462 1463 1464 1465
                        <Divider
                          orientation="center"
                          style={{
                            margin: '0 0 20px 0',
                            color: '#15428b',
                            borderTopColor: '#99bbe8',
                          }}
                        >
1466
                          {`${item}(${simple(item)}/${total(item)})`}
1467
                        </Divider>
1468 1469 1470
                        {data[item] &&
                          data[item].map((i, j) => {
                            if (keepProduct.indexOf(i) != -1) {
皮倩雯's avatar
皮倩雯 committed
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
                              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
1496
                                      style={{ color: 'rgb(24, 144, 255)', marginRight: '5px' }}
皮倩雯's avatar
皮倩雯 committed
1497 1498 1499 1500 1501
                                    />
                                    {i}
                                  </span>
                                );
                              }
1502 1503
                            } else {
                              return (
皮倩雯's avatar
皮倩雯 committed
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515
                                <span
                                  style={{
                                    width: '250px',
                                    marginLeft: '24px',
                                    display: 'inline-block',
                                    marginBottom: '20px',
                                    color: '#c3c3c3',
                                  }}
                                >
                                  {/* <MinusSquareOutlined
                                    style={{ color: 'gray', marginTop: '-6px', marginRight: '5px' }}
                                  /> */}
1516
                                  {i}
皮倩雯's avatar
皮倩雯 committed
1517
                                </span>
1518 1519 1520
                              );
                            }
                          })}
1521 1522 1523 1524 1525 1526
                      </div>
                    ))}
                </div>
              </Spin>
              <div>
                <Space size="large" className={styles.btnBox}>
皮倩雯's avatar
皮倩雯 committed
1527 1528 1529 1530 1531
                  {/* {append == '' ? (
                    <Button onClick={() => setAppendVisible(true)}>追加</Button>
                  ) : (
                    <></>
                  )} */}
1532 1533
                  <Popconfirm
                    placement="topLeft"
皮倩雯's avatar
皮倩雯 committed
1534
                    disabled={msg != ''}
1535 1536 1537 1538 1539
                    title={<span style={{ color: 'rgb(24 144 255)' }}>是否确认初始化!</span>}
                    okText="确认"
                    cancelText="取消"
                    onConfirm={() => {
                      Submit();
皮倩雯's avatar
皮倩雯 committed
1540
                      // deleteInitDBLogNew();
1541 1542
                    }}
                  >
皮倩雯's avatar
皮倩雯 committed
1543
                    <Button type="primary" disabled={msg != ''}>
1544
                      初始化
1545
                    </Button>
1546 1547 1548
                    {/* <Button type="primary" disabled={isAuthorize && msg == '' ? false : true}>
                      初始化
                    </Button> */}
1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
                  </Popconfirm>
                </Space>
              </div>
            </Card>
          </div>
        </div>
        <Modal
          title="初始化数据库"
          visible={initVisible}
          onCancel={() => {
            setInitVisible(false);
            setInitContent('');
1561
            setInitContentdetail('');
皮倩雯's avatar
皮倩雯 committed
1562
            // deleteInitDBLogNew();
1563 1564 1565 1566 1567
          }}
          width={800}
          maskClosable={false}
          bodyStyle={{
            height: '500px',
1568
            // overflowY: 'scroll',
1569 1570
          }}
          footer={[
1571 1572 1573 1574 1575 1576
            <Button
              style={{ visibility: show }}
              onClick={() => {
                handlelook();
              }}
            >
皮倩雯's avatar
皮倩雯 committed
1577
              查看详细信息
1578
            </Button>,
1579 1580 1581 1582 1583 1584
            <Button
              onClick={() => {
                handleClick();
              }}
              key="back"
              type="primary"
1585
              loading={initLoading}
1586 1587 1588 1589 1590 1591 1592 1593
            >
              关闭窗口
            </Button>,
          ]}
        >
          <div
            ref={scroll}
            style={{
1594
              height: '470px',
1595
              overflowY: 'scroll',
1596 1597 1598
              marginRight: ' -24px',
            }}
          >
皮倩雯's avatar
皮倩雯 committed
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
            <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
1609 1610 1611
                  spinning={initLoading}
                  tip="loading..."
                  style={{ width: '100%', marginTop: '40px' }}
皮倩雯's avatar
皮倩雯 committed
1612 1613
                /> */}
                </div>
1614
              </div>
皮倩雯's avatar
皮倩雯 committed
1615
              {/* <br />
皮倩雯's avatar
皮倩雯 committed
1616
            {showDetali ? <span>{initContentdetail}</span> : <></>} */}
皮倩雯's avatar
皮倩雯 committed
1617
            </Spin>
1618 1619
          </div>
        </Modal>
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632
        <Modal
          title="日志信息"
          visible={keepinitVisible}
          onCancel={() => {
            setKeepInitVisible(false);
            // setKeepInitContent('');
          }}
          width={800}
          maskClosable={false}
          bodyStyle={{
            height: '500px',
          }}
          footer={[
皮倩雯's avatar
皮倩雯 committed
1633 1634 1635 1636 1637 1638 1639 1640
            <Button
              onClick={() => {
                setKeepInitDetailVisible(true);
                setKeepInitVisible(false);
              }}
            >
              查看详细日志
            </Button>,
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
            <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
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 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
        <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
1706 1707 1708 1709 1710 1711 1712
        <AppendModal
          visible={appendVisible}
          onCancel={() => {
            setAppendVisible(false);
          }}
          value={dataValue}
          callBackSubmit={onOk}
皮倩雯's avatar
皮倩雯 committed
1713
          keepHistroy={keepHistroy}
皮倩雯's avatar
皮倩雯 committed
1714
        />
皮倩雯's avatar
皮倩雯 committed
1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746
        <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>
1747 1748 1749 1750 1751 1752 1753
        <Modal
          title="初始化数据库详细日志"
          visible={initVisibledetail}
          onCancel={() => {
            setinitVisibledetail(false);
            setInitContentdetail('');
          }}
1754
          width={800}
1755 1756
          maskClosable={false}
          bodyStyle={{
1757
            height: '500px',
1758 1759 1760
            // overflowY: 'auto',
          }}
          footer={[
皮倩雯's avatar
皮倩雯 committed
1761 1762 1763 1764 1765 1766 1767 1768
            <Button
              onClick={() => {
                setInitVisible(true);
                setinitVisibledetail(false);
              }}
            >
              查看初始化日志
            </Button>,
1769 1770 1771 1772 1773
            <Button
              onClick={() => {
                handleClickdetail();
              }}
              key="back"
1774
              type="primary"
1775 1776 1777 1778 1779 1780 1781 1782
            >
              关闭窗口
            </Button>,
          ]}
        >
          <div
            ref={scroll}
            style={{
皮倩雯's avatar
皮倩雯 committed
1783
              maxHeight: '470px',
1784 1785 1786 1787 1788 1789
              overflowY: 'auto',
              marginRight: ' -24px',
            }}
          >
            {initContentdetail || (
              <Spin tip="loading..." style={{ width: '100%', marginTop: '40px' }} />
1790 1791 1792 1793 1794 1795 1796 1797 1798
            )}
          </div>
        </Modal>
      </PageContainer>
    </>
  );
};

export default connect()(DatabaseInitialization);