InitDataBase.jsx 31.1 KB
Newer Older
皮倩雯's avatar
皮倩雯 committed
1 2
/* eslint-disable spaced-comment */
/* eslint-disable eqeqeq */
3
import React, { useEffect, useRef, useState } from 'react';
张烨's avatar
张烨 committed
4 5 6 7 8 9 10 11 12
import {
  Card,
  Form,
  Input,
  Button,
  Select,
  Table,
  Space,
  notification,
13 14
  Modal,
  Row,
张烨's avatar
张烨 committed
15
  Col,
Maofei94's avatar
Maofei94 committed
16
  Popconfirm,
17
  Spin,
18 19
  Tabs,
  Radio,
张烨's avatar
张烨 committed
20
} from 'antd';
21
import PageContainer from '@/components/BasePageContainer';
22
import RadioBox from '@/components/RadioGroup';
23
import { connect } from 'react-redux';
Maofei94's avatar
Maofei94 committed
24 25
import {
  setTableSQLDirName,
26 27 28 29 30 31
  deleteConnNew,
  initDBv4new,
  getInitDBLogNew,
  getConnRecordNew,
  getDataBaseConfigNew,
  saveConnectionNew,
Maofei94's avatar
Maofei94 committed
32
  getDataBaseList,
33 34
  updateConnDescNew,
  deleteInitDBLogNew,
Maofei94's avatar
Maofei94 committed
35
  connectionTest,
36 37 38
  GetProductList, // 获取产品列表
  GetDbProduct, // 获取产品方案配置
  InitAddDataBase, // 数据库初始化
39
  InitEditDataBase, // 二次初始化
Maofei94's avatar
Maofei94 committed
40
} from '@/services/database/api';
皮倩雯's avatar
皮倩雯 committed
41
import CryptoJS from 'crypto-js';
张烨's avatar
张烨 committed
42
import styles from './InitDataBase.less';
皮倩雯's avatar
皮倩雯 committed
43
import InitModal from './initModal';
44

45
const { TabPane } = Tabs;
张烨's avatar
张烨 committed
46
const { Option } = Select;
赵吉's avatar
赵吉 committed
47
const formLables = {
张烨's avatar
张烨 committed
48 49 50 51 52
  ip: '服务器名或IP地址',
  userName: '数据库用户名称',
  password: '数据库用户密码',
  dbName: '数据库名称',
};
53
let time = null;
张烨's avatar
张烨 committed
54 55
const InitDataBase = props => {
  const [form] = Form.useForm();
张烨's avatar
张烨 committed
56
  const [tableLoading, setTableLoading] = useState(false); // 连接记录
张烨's avatar
张烨 committed
57 58 59 60 61 62 63
  const [dbForm, setDbForm] = useState({
    ip: '',
    dbName: '',
    password: '',
    userName: '',
    inUse: '',
  });
张烨's avatar
张烨 committed
64 65 66 67
  const [data, setData] = useState([]); // 数据库链接记录
  const [upData, setUpData] = useState(1); // 列表刷新标记
  const [option, setOption] = useState([]); // 下拉列表数据
  const [desc, setDesc] = useState(''); // 修改描述
Maofei94's avatar
Maofei94 committed
68 69
  const [allSqlDir, setAllSqulDir] = useState([]); // 修改产品方案
  const [defaultSqlDir, setDefaultSqlDir] = useState(''); // 修改产品方案默认值
70 71 72 73 74
  const [modalVisible, setModalVisible] = useState({
    describeVisible: false, // 描述弹窗
    versionVisible: false, // 检查版本弹窗
    initVisible: false, // 初始化选择产品弹窗
  }); // 修改弹窗
75 76 77
  const [initVisible, setInitVisible] = useState(false); // 数据库初始化弹窗
  const [initContent, setInitContent] = useState(''); // 数据库初始化内容
  const [cardLoading, setCardLoading] = useState(false); // 初始化card Loading
Maofei94's avatar
Maofei94 committed
78
  const [finish, setFinish] = useState(false);
79
  const [initLoading, setInitLoading] = useState(false);
80 81
  const [initList, setInitList] = useState([]); // 数据库初始化产品数据
  const [dbExists, setDbExists] = useState(false); // 数据库是否存在
皮倩雯's avatar
皮倩雯 committed
82 83 84
  const [visibleModel, setVisibleModel] = useState(false);
  const [keepDb, setKeepDb] = useState([]);
  const [keepProduct, setKeepProduct] = useState([]);
85
  const scroll = useRef(null);
皮倩雯's avatar
皮倩雯 committed
86 87 88
  const [keep, setKeep] = useState([]);
  const [flag, setFlag] = useState(0);
  const [keepData, setKeepData] = useState({});
皮倩雯's avatar
皮倩雯 committed
89 90
  const key = CryptoJS.enc.Utf8.parse('1p2a3n4d5a6o7m8s9a10n1e2t3c4o5re'); //十六位十六进制数作为密钥
  const iv = CryptoJS.enc.Utf8.parse('1234567890000000');
91 92

  // 获取数据库配置信息
张烨's avatar
张烨 committed
93
  useEffect(() => {
94 95 96 97 98 99
    setCardLoading(true);
    // 数据库连接记录初始化
    getConnRecordData();
    getDataBaseConfigNew().then(resnew => {
      setCardLoading(false);
      let res = resnew.data;
100
      if (resnew.code === 0) {
101 102 103 104 105
        const { inUse } = res;

        let obj = {};
        Object.keys(dbForm).forEach(k => {
          obj[k] = res[k];
106
        });
邓超's avatar
邓超 committed
107
        console.log(obj, 'objohjfaosdjf');
皮倩雯's avatar
皮倩雯 committed
108 109 110 111 112 113 114

        console.log(Decrypt(obj.password));
        let aa = Decrypt(obj.password);
        console.log(Encrypt(aa));

        form.setFieldsValue({ ...obj, password: Decrypt(obj.password) });
        setDbForm(val => ({ ...val, ...obj, password: Decrypt(obj.password) }));
115 116 117 118 119 120 121 122
        setAllSqulDir(res.allSqlDir);
        if (res.allSqlDir.some(item => item === inUse)) {
          setDefaultSqlDir(res.tableSQLDirName);
        } else {
          // 默认切换到第一个产品方案
          handeleChangeSQLDirName(res.allSqlDir[0]);
          setDefaultSqlDir(res.allSqlDir[0]);
        }
123 124
      }
    });
125 126
    return () => {
      if (time) {
127 128
        clearTimeout(time);
        time = null;
129
      }
130 131
    };
  }, []);
皮倩雯's avatar
皮倩雯 committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

  // 解密
  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();
  };

157 158 159 160
  // 弹出模态框
  const handleShowModal = (key, value) => {
    setModalVisible({ ...modalVisible, [key]: value });
  };
161 162 163 164 165 166
  // 获取数据库连接记录
  const getConnRecordData = () => {
    setTableLoading(true);
    getConnRecordNew()
      .then(resnew => {
        setTableLoading(false);
167
        if (resnew.code === 0) {
168 169 170 171
          let res = resnew.data;
          let arr = res.map((item, index) => {
            item.key = index;
            return item;
张烨's avatar
张烨 committed
172
          });
173
          setData(arr);
张烨's avatar
张烨 committed
174
        }
175 176 177 178 179 180
      })
      .catch(err => {
        setTableLoading(false);
        console.error(err);
      });
  };
Maofei94's avatar
Maofei94 committed
181 182
  // 获取日志
  const doInitLog = () => {
183
    setInitLoading(true);
184
    getInitDBLogNew()
Maofei94's avatar
Maofei94 committed
185
      .then(res => {
186
        if (res.code === 0) {
187
          if (res.data.content) {
188
            setInitLoading(false);
Maofei94's avatar
Maofei94 committed
189 190
            let arr = [];
            arr.push(
191 192 193 194
              res.data.content.split(/(\r\n)|(\n)/).map((item, index) => (
                // eslint-disable-next-line react/no-danger
                <p key={index} dangerouslySetInnerHTML={{ __html: item }} />
              )),
Maofei94's avatar
Maofei94 committed
195
            );
196
            console.log(arr);
Maofei94's avatar
Maofei94 committed
197 198 199
            setInitContent(arr);
            scroll.current.scrollTop = scroll.current.scrollHeight;
          }
200 201
          if (!res.data.finish) {
            time = setTimeout(() => {
202 203
              doInitLog();
            }, 600);
204 205
          } else {
            setInitLoading(false);
206
            if (time) {
207 208
              clearTimeout(time);
              time = null;
209 210
            }
          }
Maofei94's avatar
Maofei94 committed
211 212 213 214 215 216
        }
      })
      .catch(err => {
        setFinish(true);
      });
  };
张烨's avatar
张烨 committed
217
  // 数据库初始化
Maofei94's avatar
Maofei94 committed
218
  const initClick = () => {
Maofei94's avatar
Maofei94 committed
219 220 221
    setInitContent('');
    setCardLoading(true);
    setInitVisible(true);
Maofei94's avatar
Maofei94 committed
222
    let obj = form.getFieldsValue();
Maofei94's avatar
Maofei94 committed
223
    doInitLog();
224
    initDBv4new({
225
      ...obj,
226
    })
227 228 229 230 231 232 233 234 235 236 237 238
      .then(res => {
        setCardLoading(false);
        if (res.code == 0) {
          console.log(res);
        } else {
          notification.error({
            message: '提示',
            duration: 15,
            description: res.msg || '初始化失败',
          });
        }
      })
tianfen's avatar
tianfen committed
239 240 241 242
      .catch(err => {
        setCardLoading(false);
        console.log(err);
      });
Maofei94's avatar
Maofei94 committed
243
  };
张烨's avatar
张烨 committed
244 245 246 247
  const onValuesChange = (value, b) => {
    form.setFieldsValue(value);
  };
  const onChange = value => {
248
    const { length } = value;
张烨's avatar
张烨 committed
249
    form.setFieldsValue({
250
      dbName: value[length - 1],
张烨's avatar
张烨 committed
251 252
    });
  };
张烨's avatar
张烨 committed
253
  // 保存连接
254
  const onFinish = values => {
255
    setCardLoading(true);
张烨's avatar
张烨 committed
256
    const obj = values;
257 258

    saveConnectionNew({
张烨's avatar
张烨 committed
259 260 261
      ip: obj.ip,
      dbName: obj.dbName,
      userName: obj.userName,
皮倩雯's avatar
皮倩雯 committed
262
      password: Encrypt(obj.password),
263 264
    })
      .then(resnew => {
265
        setCardLoading(false);
266
        if (resnew.code === 0) {
皮倩雯's avatar
皮倩雯 committed
267 268 269 270 271
          setFlag(flag + 1);
          setKeepData({
            ip: obj.ip,
            dbName: obj.dbName,
            userName: obj.userName,
皮倩雯's avatar
皮倩雯 committed
272
            password: Encrypt(obj.password),
皮倩雯's avatar
皮倩雯 committed
273
          });
274 275
          // setUpData(upData + 1);
          getConnRecordData();
张烨's avatar
张烨 committed
276
          notification.success({
Maofei94's avatar
Maofei94 committed
277
            message: '提示',
张烨's avatar
张烨 committed
278 279 280 281 282 283
            duration: 3,
            description: '保存成功',
          });
        } else {
          notification.error({
            message: '提示',
Maofei94's avatar
Maofei94 committed
284
            duration: 15,
285
            description: resnew.msg,
张烨's avatar
张烨 committed
286 287
          });
        }
288 289 290 291 292
      })
      .catch(err => {
        setCardLoading(false);
        console.log(err);
      });
293
  };
294
  // 测试连接
张烨's avatar
张烨 committed
295 296
  const onCheck = e => {
    console.log(dbForm);
297
    setCardLoading(true);
张烨's avatar
张烨 committed
298
    const obj = form.getFieldsValue();
299
    connectionTest({
皮倩雯's avatar
皮倩雯 committed
300 301
      // _version: 9999,
      // _dc: new Date().getTime(),
302 303 304
      ip: obj.ip,
      dbName: obj.dbName,
      userName: obj.userName,
皮倩雯's avatar
皮倩雯 committed
305
      password: Encrypt(obj.password),
306 307
      // Type:"SQLServer",
      // name:obj.dbName,
张烨's avatar
张烨 committed
308 309
    })
      .then(res => {
310
        setCardLoading(false);
皮倩雯's avatar
皮倩雯 committed
311
        if (res.code == 0 && res.data == true) {
张烨's avatar
张烨 committed
312
          notification.success({
Maofei94's avatar
Maofei94 committed
313
            message: '提示',
张烨's avatar
张烨 committed
314 315 316 317 318 319
            duration: 3,
            description: '连接成功',
          });
        } else {
          notification.error({
            message: '提示',
Maofei94's avatar
Maofei94 committed
320
            duration: 15,
皮倩雯's avatar
皮倩雯 committed
321
            description: res.msg,
张烨's avatar
张烨 committed
322 323 324 325
          });
        }
      })
      .catch(err => {
326
        setCardLoading(false);
张烨's avatar
张烨 committed
327
        console.log(err);
328
      });
张烨's avatar
张烨 committed
329
  };
Maofei94's avatar
Maofei94 committed
330
  // 获取数据库列表
张烨's avatar
张烨 committed
331
  const selectFocus = e => {
皮倩雯's avatar
皮倩雯 committed
332
    //setOption([]);
张烨's avatar
张烨 committed
333
    let params = form.getFieldsValue();
Maofei94's avatar
Maofei94 committed
334
    getDataBaseList({
皮倩雯's avatar
皮倩雯 committed
335 336
      // _version: 9999,
      // _dc: Date.now(),
张烨's avatar
张烨 committed
337
      userName: params.userName || '',
皮倩雯's avatar
皮倩雯 committed
338
      password: Encrypt(params.password) || '',
张烨's avatar
张烨 committed
339
      ip: params.ip || '',
张烨's avatar
张烨 committed
340 341
    })
      .then(res => {
皮倩雯's avatar
皮倩雯 committed
342
        if (res.code == 0) {
皮倩雯's avatar
皮倩雯 committed
343
          console.log(res.data.root);
皮倩雯's avatar
皮倩雯 committed
344
          setOption(res.data.root);
张烨's avatar
张烨 committed
345 346
        } else {
          notification.error({
Maofei94's avatar
Maofei94 committed
347
            message: '提示',
Maofei94's avatar
Maofei94 committed
348
            duration: 15,
皮倩雯's avatar
皮倩雯 committed
349
            description: res.msg,
张烨's avatar
张烨 committed
350 351 352 353 354 355 356 357
          });
          setOption([]);
        }
      })
      .catch(err => {
        console.error(err);
      });
  };
张烨's avatar
张烨 committed
358
  // 点击表格回显到表单
张烨's avatar
张烨 committed
359 360
  const tableClick = item => {
    let obj = { ...dbForm };
张烨's avatar
张烨 committed
361
    Object.keys(obj).forEach(k => {
张烨's avatar
张烨 committed
362
      obj[k] = item[k];
张烨's avatar
张烨 committed
363
    });
皮倩雯's avatar
皮倩雯 committed
364
    form.setFieldsValue({ ...obj, password: Decrypt(obj.password) });
张烨's avatar
张烨 committed
365
  };
366
  // 产品方案选择框回调
Maofei94's avatar
Maofei94 committed
367
  const handleSelect = value => {
Maofei94's avatar
Maofei94 committed
368 369 370
    handeleChangeSQLDirName(value);
  };
  const handeleChangeSQLDirName = val => {
371
    setTableSQLDirName({
Maofei94's avatar
Maofei94 committed
372
      dirName: val,
373
    })
Maofei94's avatar
Maofei94 committed
374
      .then(res => {
375
        if (res.code === 0) {
Maofei94's avatar
Maofei94 committed
376 377 378
          notification.success({
            message: '提示',
            duration: 3,
Maofei94's avatar
Maofei94 committed
379
            description: `已切换初始化脚本为:${val}`,
Maofei94's avatar
Maofei94 committed
380 381 382 383
          });
        } else {
          notification.error({
            message: '提示',
Maofei94's avatar
Maofei94 committed
384
            duration: 15,
Maofei94's avatar
Maofei94 committed
385 386 387 388 389 390 391 392
            description: res.message,
          });
        }
      })
      .catch(err => {
        console.error(err);
      });
  };
张烨's avatar
张烨 committed
393
  // 展示修改描述
Maofei94's avatar
Maofei94 committed
394 395
  const changeDesc = val => {
    setDesc(val);
396
    handleShowModal('describeVisible', true);
张烨's avatar
张烨 committed
397 398 399 400 401
  };
  const descChange = e => {
    const { value } = e.target;
    setDesc(value);
  };
Maofei94's avatar
Maofei94 committed
402 403 404 405 406
  // 关闭弹窗
  const handleClick = () => {
    setInitVisible(false);
    setInitContent('');
    setFinish(false);
407 408 409 410
    // deleteInitDBLog({
    //   _version: 9999,
    //   _dc: Date.now(),
    // });
411
    deleteInitDBLogNew();
Maofei94's avatar
Maofei94 committed
412
  };
张烨's avatar
张烨 committed
413 414 415 416
  // 弹窗确认回调
  const modalOkCallback = () => {
    const obj = form.getFieldsValue();
    // 更新描述
417
    updateConnDescNew({
张烨's avatar
张烨 committed
418 419 420
      ip: obj.ip,
      dbName: obj.dbName,
      userName: obj.userName,
皮倩雯's avatar
皮倩雯 committed
421
      password: Encrypt(obj.password),
张烨's avatar
张烨 committed
422
      desc,
423
    })
424
      .then(res => {
425
        handleShowModal('describeVisible', false);
426 427
        // setUpData(upData + 1);
        getConnRecordData();
428 429 430
      })
      .catch(err => {
        console.error(err);
431
        handleShowModal('describeVisible', false);
432
      });
张烨's avatar
张烨 committed
433
  };
Maofei94's avatar
Maofei94 committed
434
  // 删除数据库连接记录
Maofei94's avatar
Maofei94 committed
435
  const delConfirm = value => {
Maofei94's avatar
Maofei94 committed
436
    const { key = '' } = value;
Maofei94's avatar
Maofei94 committed
437
    setTableLoading(true);
438
    deleteConnNew({
Maofei94's avatar
Maofei94 committed
439 440 441 442
      rowIndex: key,
    })
      .then(res => {
        setTableLoading(false);
443
        if (res.code === 0) {
444 445
          // setUpData(upData + 1);
          getConnRecordData();
Maofei94's avatar
Maofei94 committed
446 447 448 449 450 451 452 453
          notification.success({
            message: '提示',
            duration: 3,
            description: '操作成功',
          });
        } else {
          notification.error({
            message: '提示',
Maofei94's avatar
Maofei94 committed
454
            duration: 15,
455
            description: res.msg,
Maofei94's avatar
Maofei94 committed
456 457 458 459 460 461 462 463
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        console.error(err);
      });
  };
皮倩雯's avatar
皮倩雯 committed
464 465 466

  const GetDb = () => {
    let obj = form.getFieldsValue();
皮倩雯's avatar
皮倩雯 committed
467
    GetDbProduct({ ...obj, password: Encrypt(obj.password) }).then(res => {
皮倩雯's avatar
皮倩雯 committed
468 469 470 471 472 473 474 475 476
      if (res.code === 0) {
        console.log(res.data);
        if (res.data.Product) {
          console.log(res.data.Product);
          let aa = [];
          res.data.Product.map(i => {
            aa.push(i.name);
          });
          console.log(aa);
477
          setKeep(res.data.IsAuthorize);
皮倩雯's avatar
皮倩雯 committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
          setKeepProduct(aa);
        }
        setDbExists(res.data.DBExists);
        setKeepDb(res.data);
        if (!res.data.DBExists) {
          setVisibleModel(true);
        } else if (res.data.DBExists && res.data.Product.length > 0) {
          setVisibleModel(true);
        } else {
          notification.warning({
            message: '提示',
            duration: 15,
            description: '当前数据库不可初始化',
          });
        }
      } else {
        notification.warning({
          message: '提示',
          duration: 15,
          description: res.msg,
        });
      }
    });
  };
502 503 504 505 506 507 508
  // 获取数据库初始化回显列表
  const getInitList = () => {
    setInitList([]);
    handleShowModal('initVisible', true);
    setInitLoading(true);
    let obj = form.getFieldsValue();
    let req1 = GetProductList();
皮倩雯's avatar
皮倩雯 committed
509
    let req2 = GetDbProduct({ ...obj, password: Encrypt(obj.password) });
510 511 512 513 514 515 516 517 518 519 520
    Promise.all([req1, req2])
      .then(res => {
        if (res[1].code !== 0 || res[0].code !== 0) {
          setInitLoading(false);
          notification.error({
            message: '提示',
            duration: 3,
            description: '连接失败',
          });
          return;
        }
521
        setDbExists(res[1].data.DBExists);
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
        let fileList = res[0].data ? res[0].data : [];
        let dataList = res[1].data.Product ? res[1].data.Product : [];
        // 没有库或者dataList为[]直接用fileList作为回显
        if (!res[1].data.DBExists || dataList.length === 0) {
          setInitList(fileList);
          setInitLoading(false);
          return;
        }
        let mapList = new Map();
        // 通过map给数据库中中的节点中的key的值当作key,checkVersion当作value进行存储
        dataList.forEach(element => {
          // 存入一级目录是否有选中项的key
          mapList.set(element.key, element.check);
          element.modularSolutions.forEach(item => {
            // 存入二级目录对应的选中的checkVersion跟check
            mapList.set(item.key, {
              checkVersion: item.checkVersion,
              check: item.check,
            });
            item.functionrSolutions.forEach(val => {
              // 存入三级目录对应的选中的checkVersion跟check
              mapList.set(val.key, val.isCheck);
            });
          });
        });
547
        console.log(mapList, 'mapList');
548 549 550 551 552 553
        fileList.forEach(element => {
          // 根据key来获取第一级目录tab的check
          let tabKey = mapList.get(element.key);
          element.check = tabKey === undefined ? null : tabKey;
          element.modularSolutions.forEach(item => {
            let mapCheckVersion = mapList.get(item.key);
554 555 556
            if (mapCheckVersion === undefined) {
              mapCheckVersion = { checkVersion: null, check: null };
            }
557 558
            // 根据key值去匹配对应的checkVersion
            item.checkVersion =
559
              mapCheckVersion.checkVersion === undefined ? null : mapCheckVersion.checkVersion;
560
            // 根据key值去匹配对应的二级目录的check
561
            item.check = mapCheckVersion.check === undefined ? null : mapCheckVersion.check;
562 563 564
            if (item.check) {
              item.hasCheck = true;
            }
565 566 567 568
            item.functionrSolutions.forEach(val => {
              // 根据三级目录对应的选中key匹配isCheck
              let isCheck = mapList.get(val.key);
              val.isCheck = isCheck === undefined ? null : isCheck;
569 570 571 572 573 574
              // 版本号低于当前版本号禁止选用
              if (item.checkVersion && val.version < item.checkVersion) {
                val.disabled = true;
              } else {
                val.disabled = false;
              }
575 576 577 578 579 580
            });
          });
        });
        setInitList(fileList);
        setInitLoading(false);
      })
581 582
      .catch(err => {
        console.log(err, 'err');
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
        notification.error({
          message: '提示',
          duration: 3,
          description: '连接失败',
        });
        setInitLoading(false);
      });
  };
  // 初始化产品列表渲染
  const renderInitListItem = (tabItem, index) => (
    <TabPane tab={tabItem.productName} key={index}>
      <div className={styles.tabContainer}>
        {tabItem.modularSolutions.map((item, num) => (
          <React.Fragment key={item.key}>
            {item.functionrSolutions.length > 0 ? (
              <RadioBox
                radioTitle={item.modularName}
                radioOptions={item.functionrSolutions}
                currentVal={item.checkVersion}
                currentIndex={{ tabIndex: index, radioIndex: num }}
                callBack={radioChange}
              />
            ) : null}
          </React.Fragment>
        ))}
      </div>
    </TabPane>
  );
  // 单选选后的回调,改变数据
  const radioChange = (index, value) => {
    setInitList(val => {
      const list = JSON.parse(JSON.stringify(val));
615
      const secondList = list[index.tabIndex].modularSolutions[index.radioIndex];
616 617 618 619 620 621 622 623 624 625 626
      // 取消功能 一开始未选中的才能取消
      if (value === secondList.checkVersion && !secondList.hasCheck) {
        secondList.checkVersion = null;
        value = null;
        secondList.check = false;
      } else {
        // 修改选中的checkVersion值
        secondList.checkVersion = value;
        // 修改二级菜单的check字段
        secondList.check = true;
      }
627
      // 修改一级菜单的check字段
628 629 630
      list[index.tabIndex].check = !list[index.tabIndex].modularSolutions.every(
        version => version.checkVersion === null,
      );
631
      // 修改单选isCheck字段
632
      secondList.functionrSolutions.forEach(item => {
633 634 635 636 637 638 639 640 641
        if (item.version === value) {
          item.isCheck = true;
        } else {
          item.isCheck = false;
        }
      });
      return list;
    });
  };
皮倩雯's avatar
皮倩雯 committed
642 643 644
  const onOK = (arr, code) => {
    initDatabasePro(arr, code);
  };
645
  // 数据库初始化
皮倩雯's avatar
皮倩雯 committed
646 647
  const initDatabasePro = (e, j) => {
    let productSetting = e;
648 649 650
    let obj = form.getFieldsValue();
    // 数据库存在调用编辑接口否则调用新增接口
    setInitLoading(true);
皮倩雯's avatar
皮倩雯 committed
651
    setVisibleModel(false);
652 653 654
    handleShowModal('initVisible', false);
    setInitVisible(true);
    doInitLog();
655
    if (dbExists) {
皮倩雯's avatar
皮倩雯 committed
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
      InitEditDataBase({
        ...obj,
        productSetting,
        license: j,
        password: Encrypt(obj.password),
      }).then(res => {
        setInitLoading(false);
        if (res.code === 0) {
          notification.success({
            message: '提示',
            duration: 3,
            description: '数据库初始化成功',
          });
        } else {
          notification.error({
            message: '提示',
            duration: 5,
            description: res.msg,
          });
        }
      });
677 678
      return;
    }
皮倩雯's avatar
皮倩雯 committed
679
    InitAddDataBase({ ...obj, productSetting, license: j }).then(res => {
680 681 682 683 684
      setInitLoading(false);
      if (res.code === 0) {
        notification.success({
          message: '提示',
          duration: 3,
685
          description: '数据库初始化成功',
686 687 688 689
        });
      } else {
        notification.error({
          message: '提示',
皮倩雯's avatar
皮倩雯 committed
690
          duration: 5,
691 692 693 694 695
          description: res.msg,
        });
      }
    });
  };
张烨's avatar
张烨 committed
696 697 698 699 700
  const columns = [
    {
      title: '服务器名或IP地址',
      dataIndex: 'ip',
      key: 'ip',
Maofei94's avatar
Maofei94 committed
701 702
      width: 180,
      ellipsis: true,
张烨's avatar
张烨 committed
703 704 705 706 707
    },
    {
      title: '数据库名称',
      dataIndex: 'dbName',
      key: 'dbName',
Maofei94's avatar
Maofei94 committed
708 709
      width: 180,
      ellipsis: true,
张烨's avatar
张烨 committed
710 711 712 713 714
    },
    {
      title: '数据库用户名称',
      dataIndex: 'userName',
      key: 'userName',
Maofei94's avatar
Maofei94 committed
715 716
      width: 180,
      ellipsis: true,
张烨's avatar
张烨 committed
717 718 719 720 721
    },
    {
      title: '保存时间',
      dataIndex: 'saveTime',
      key: 'saveTime',
Maofei94's avatar
Maofei94 committed
722 723
      width: 180,
      ellipsis: true,
张烨's avatar
张烨 committed
724 725 726 727 728
    },
    {
      title: '描述',
      dataIndex: 'desc',
      key: 'desc',
Maofei94's avatar
Maofei94 committed
729
      ellipsis: true,
张烨's avatar
张烨 committed
730 731
    },
    {
Maofei94's avatar
Maofei94 committed
732 733 734
      title: '操作',
      dataIndex: 'action',
      key: 'action',
Maofei94's avatar
Maofei94 committed
735 736
      width: 250,
      ellipsis: true,
Maofei94's avatar
Maofei94 committed
737 738 739 740 741 742
      render: (text, record) => (
        <Space>
          <Button
            type="primary"
            size="small"
            onClick={() => {
Maofei94's avatar
Maofei94 committed
743
              changeDesc(record.desc);
Maofei94's avatar
Maofei94 committed
744 745 746 747
            }}
          >
            修改描述
          </Button>
748
          {/* <div onClick={e => e.stopPropagation()}>
Maofei94's avatar
Maofei94 committed
749 750 751 752 753 754 755 756 757 758 759 760
            <Popconfirm
              title="是否删除该连接的历史记录?"
              okText="确认"
              cancelText="取消"
              onConfirm={() => {
                delConfirm(record);
              }}
            >
              <Button size="small" danger>
                删除
              </Button>
            </Popconfirm>
761
          </div> */}
Maofei94's avatar
Maofei94 committed
762
        </Space>
张烨's avatar
张烨 committed
763
      ),
张烨's avatar
张烨 committed
764 765
    },
  ];
皮倩雯's avatar
皮倩雯 committed
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786

  const flagChange = () => {
    const obj = form.getFieldsValue();
    console.log(keepData);
    console.log(obj);
    if (
      keepData.ip == obj.ip &&
      keepData.dbName == obj.dbName &&
      keepData.userName == obj.userName &&
      keepData.password == obj.password
    ) {
      GetDb();
      deleteInitDBLogNew();
    } else {
      notification.warning({
        message: '提示',
        duration: 15,
        description: '请先保存连接',
      });
    }
  };
张烨's avatar
张烨 committed
787 788
  return (
    <>
789
      <PageContainer className={styles.InitDataBaseContainer}>
张烨's avatar
张烨 committed
790
        <Card>
791
          <Spin tip="loading..." spinning={cardLoading}>
792
            {/* <div className={styles.tableTitle}>数据库初始化</div> */}
793 794 795 796 797 798 799 800 801
            <Form
              className={styles.mgTop20}
              layout="horizontal"
              labelAlign="left"
              labelCol={{ span: 3 }}
              form={form}
              onFinish={onFinish}
              onValuesChange={onValuesChange}
            >
皮倩雯's avatar
皮倩雯 committed
802 803 804 805 806 807 808 809 810 811 812 813 814 815
              <Form.Item
                label={`${formLables.ip}:`}
                name="ip"
                rules={[
                  {
                    validator: (rule, value) => {
                      if (form.getFieldValue().ip == '') {
                        return Promise.reject('ip必填');
                      }
                      return Promise.resolve();
                    },
                  },
                ]}
              >
816 817
                <Input placeholder="请输入服务器名或IP地址" />
              </Form.Item>
皮倩雯's avatar
皮倩雯 committed
818 819 820 821 822 823 824 825 826 827 828 829 830 831
              <Form.Item
                label={`${formLables.userName}:`}
                name="userName"
                rules={[
                  {
                    validator: (rule, value) => {
                      if (form.getFieldValue().userName == '') {
                        return Promise.reject('用户名称必填');
                      }
                      return Promise.resolve();
                    },
                  },
                ]}
              >
832 833
                <Input placeholder="请输入用户名称" />
              </Form.Item>
皮倩雯's avatar
皮倩雯 committed
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848
              <Form.Item
                label={`${formLables.password}:`}
                name="password"
                rules={[
                  {
                    validator: (rule, value) => {
                      console.log(form.getFieldValue().password);
                      if (form.getFieldValue().password == '') {
                        return Promise.reject('用户密码必填');
                      }
                      return Promise.resolve();
                    },
                  },
                ]}
              >
皮倩雯's avatar
皮倩雯 committed
849
                <Input placeholder="请输入用户密码" type="password" />
850
              </Form.Item>
皮倩雯's avatar
皮倩雯 committed
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
              <Form.Item
                label={`${formLables.dbName}:`}
                name="dbName"
                rules={[
                  {
                    validator: (rule, value) => {
                      console.log(form.getFieldValue().dbName);
                      if (
                        form.getFieldValue().dbName == '' ||
                        form.getFieldValue().dbName == undefined
                      ) {
                        return Promise.reject('数据库名称必填');
                      }
                      return Promise.resolve();
                    },
                  },
                ]}
              >
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
                <Select
                  showSearch
                  mode="tags"
                  placeholder="请选择数据库"
                  optionFilterProp="children"
                  onFocus={() => {
                    selectFocus();
                  }}
                  onChange={e => {
                    onChange(e);
                  }}
                  // eslint-disable-next-line no-shadow
                  filterOption={(input, option) => {
                    console.log(option);
                    return (
                      option.children &&
885
                      option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
886 887 888 889 890 891 892 893 894 895 896 897
                    );
                  }}
                >
                  {option &&
                    option.length > 0 &&
                    option.map((item, index) => (
                      <Option value={item.value} key={item.value + index}>
                        {item.value}
                      </Option>
                    ))}
                </Select>
              </Form.Item>
Maofei94's avatar
Maofei94 committed
898
              <Form.Item wrapperCol={{ offset: 3 }}>
899 900 901 902
                <div className={styles.tCenter}>
                  <Space size="large" className={styles.btnBox}>
                    <Space>
                      <Button onClick={onCheck}>测试连接</Button>
903
                      <Button type="primary" htmlType="submit" loading={tableLoading}>
904 905 906 907
                        保存连接
                      </Button>
                    </Space>
                    <Space>
908
                      {/* <Button
909
                        type="primary"
皮倩雯's avatar
皮倩雯 committed
910 911 912 913
                        // onClick={() => {
                        //   getInitList();
                        //   deleteInitDBLogNew();
                        // }}
914
                        onClick={() => {
皮倩雯's avatar
皮倩雯 committed
915
                          flagChange();
Maofei94's avatar
Maofei94 committed
916
                        }}
917
                      >
918
                        数据库初始化
919
                      </Button> */}
920
                    </Space>
Maofei94's avatar
Maofei94 committed
921
                  </Space>
922 923 924 925
                </div>
              </Form.Item>
            </Form>
          </Spin>
张烨's avatar
张烨 committed
926 927
        </Card>

928
        <Card className={styles.mgTop20}>
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947
          <div className={styles.recordBox}>
            <div className={styles.tableTitle}>近期保存的数据库连接</div>
            <Table
              style={{ marginTop: '20px', marginBottom: '20px' }}
              scroll={{ x: 'max-content', y: 'calc(100vh - 550px)' }}
              columns={columns}
              dataSource={data}
              pagination={false}
              bordered
              loading={tableLoading}
              size="small"
              onRow={record => ({
                onClick: () => {
                  tableClick(record);
                  setFlag(0);
                }, // 点击行
              })}
            />
          </div>
张烨's avatar
张烨 committed
948
        </Card>
Maofei94's avatar
Maofei94 committed
949 950 951 952 953 954
        <Modal
          title="初始化数据库"
          visible={initVisible}
          onCancel={() => {
            setInitVisible(false);
            setInitContent('');
955 956 957 958
            // deleteInitDBLog({
            //   _version: 9999,
            //   _dc: Date.now(),
            // });
959
            deleteInitDBLogNew();
Maofei94's avatar
Maofei94 committed
960
          }}
961
          width={800}
Maofei94's avatar
Maofei94 committed
962
          maskClosable={false}
963
          bodyStyle={{
964
            height: '500px',
965
            // overflowY: 'auto',
966
          }}
Maofei94's avatar
Maofei94 committed
967 968 969
          footer={[
            <Button
              onClick={() => {
Maofei94's avatar
Maofei94 committed
970
                handleClick();
Maofei94's avatar
Maofei94 committed
971
              }}
972
              key="back"
Maofei94's avatar
Maofei94 committed
973 974 975 976 977 978
              type="primary"
            >
              关闭窗口
            </Button>,
          ]}
        >
tianfen's avatar
tianfen committed
979 980 981
          <div
            ref={scroll}
            style={{
982
              maxHeight: '470px',
tianfen's avatar
tianfen committed
983 984 985 986
              overflowY: 'auto',
              marginRight: ' -24px',
            }}
          >
Maofei94's avatar
Maofei94 committed
987
            {initContent || (
Maofei94's avatar
Maofei94 committed
988
              <Spin
989
                spinning={initLoading}
Maofei94's avatar
Maofei94 committed
990 991 992
                tip="loading..."
                style={{ width: '100%', marginTop: '40px' }}
              />
Maofei94's avatar
Maofei94 committed
993
            )}
994
          </div>
Maofei94's avatar
Maofei94 committed
995 996
        </Modal>

997
        <Modal
张烨's avatar
张烨 committed
998
          title="修改链接描述"
999
          visible={modalVisible.describeVisible}
张烨's avatar
张烨 committed
1000
          onOk={() => modalOkCallback()}
1001
          onCancel={() => handleShowModal('describeVisible', false)}
1002
          width="800px"
1003
          bodyStyle={{
张烨's avatar
张烨 committed
1004
            minHeight: '100px',
1005
          }}
张烨's avatar
张烨 committed
1006
          cancelText="取消"
Maofei94's avatar
Maofei94 committed
1007
          okText="确认"
Maofei94's avatar
Maofei94 committed
1008
          destroyOnClose
1009
        >
张烨's avatar
张烨 committed
1010
          <Row>
1011
            <Col span={2} className={styles.decsBox}>
Maofei94's avatar
Maofei94 committed
1012
              描述:
张烨's avatar
张烨 committed
1013
            </Col>
Maofei94's avatar
Maofei94 committed
1014

1015
            <Col span={22}>
张烨's avatar
张烨 committed
1016 1017
              <Input
                placeholder="请输入描述"
Maofei94's avatar
Maofei94 committed
1018 1019
                allowClear
                defaultValue={desc}
张烨's avatar
张烨 committed
1020 1021 1022 1023 1024
                onChange={value => {
                  descChange(value);
                }}
              />
            </Col>
1025
          </Row>
1026
        </Modal>
皮倩雯's avatar
皮倩雯 committed
1027 1028 1029 1030 1031 1032 1033 1034
        <InitModal
          visible={visibleModel}
          onCancel={() => setVisibleModel(false)}
          keepDb={keepDb}
          callBackSubmit={onOK}
          keepProduct={keepProduct}
          keep={keep}
        />
1035 1036 1037 1038 1039 1040 1041
        {/* 初始化选择产品弹窗 */}
        <Modal
          title="初始化"
          maskClosable={false}
          visible={modalVisible.initVisible}
          onCancel={() => handleShowModal('initVisible', false)}
          footer={[
1042
            <Button key="back" onClick={() => handleShowModal('initVisible', false)}>
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
              取消
            </Button>,
            <Popconfirm
              placement="topLeft"
              title="是否确认初始化"
              onConfirm={initDatabasePro}
              okText="确认"
              key="submit"
              cancelText="取消"
            >
              <Button type="primary" loading={initLoading}>
                确认
              </Button>
            </Popconfirm>,
          ]}
          width={900}
        >
          <Spin spinning={initLoading}>
            <div className={styles.cardContainer}>
              <Tabs defaultActiveKey="1" type="card" tabBarGutter={-1}>
                {initList.map((item, index) => renderInitListItem(item, index))}
              </Tabs>
            </div>
          </Spin>
        </Modal>
张烨's avatar
张烨 committed
1068 1069 1070 1071
      </PageContainer>
    </>
  );
};
1072

张烨's avatar
张烨 committed
1073
export default connect()(InitDataBase);