InitDataBase.jsx 25.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 styles from './InitDataBase.less';
42

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

  // 获取数据库配置信息
张烨's avatar
张烨 committed
83
  useEffect(() => {
84 85 86 87 88 89
    setCardLoading(true);
    // 数据库连接记录初始化
    getConnRecordData();
    getDataBaseConfigNew().then(resnew => {
      setCardLoading(false);
      let res = resnew.data;
90
      if (resnew.code === 0) {
91 92 93 94 95
        const { inUse } = res;

        let obj = {};
        Object.keys(dbForm).forEach(k => {
          obj[k] = res[k];
96
        });
97 98 99 100 101 102 103 104 105 106
        form.setFieldsValue(obj);
        setDbForm(val => ({ ...val, ...obj }));
        setAllSqulDir(res.allSqlDir);
        if (res.allSqlDir.some(item => item === inUse)) {
          setDefaultSqlDir(res.tableSQLDirName);
        } else {
          // 默认切换到第一个产品方案
          handeleChangeSQLDirName(res.allSqlDir[0]);
          setDefaultSqlDir(res.allSqlDir[0]);
        }
107 108
      }
    });
109 110
    return () => {
      if (time) {
111 112
        clearTimeout(time);
        time = null;
113
      }
114 115
    };
  }, []);
116 117 118 119
  // 弹出模态框
  const handleShowModal = (key, value) => {
    setModalVisible({ ...modalVisible, [key]: value });
  };
120 121 122 123 124 125
  // 获取数据库连接记录
  const getConnRecordData = () => {
    setTableLoading(true);
    getConnRecordNew()
      .then(resnew => {
        setTableLoading(false);
126
        if (resnew.code === 0) {
127 128 129 130
          let res = resnew.data;
          let arr = res.map((item, index) => {
            item.key = index;
            return item;
张烨's avatar
张烨 committed
131
          });
132
          setData(arr);
张烨's avatar
张烨 committed
133
        }
134 135 136 137 138 139
      })
      .catch(err => {
        setTableLoading(false);
        console.error(err);
      });
  };
Maofei94's avatar
Maofei94 committed
140 141
  // 获取日志
  const doInitLog = () => {
142
    setInitLoading(true);
143
    getInitDBLogNew()
Maofei94's avatar
Maofei94 committed
144
      .then(res => {
145
        if (res.code === 0) {
146
          if (res.data.content) {
147
            setInitLoading(false);
Maofei94's avatar
Maofei94 committed
148 149
            let arr = [];
            arr.push(
150 151 152 153
              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
154
            );
155
            console.log(arr);
Maofei94's avatar
Maofei94 committed
156 157 158
            setInitContent(arr);
            scroll.current.scrollTop = scroll.current.scrollHeight;
          }
159 160
          if (!res.data.finish) {
            time = setTimeout(() => {
161 162
              doInitLog();
            }, 600);
163 164
          } else {
            setInitLoading(false);
165
            if (time) {
166 167
              clearTimeout(time);
              time = null;
168 169
            }
          }
Maofei94's avatar
Maofei94 committed
170 171 172 173 174 175
        }
      })
      .catch(err => {
        setFinish(true);
      });
  };
张烨's avatar
张烨 committed
176
  // 数据库初始化
Maofei94's avatar
Maofei94 committed
177
  const initClick = () => {
Maofei94's avatar
Maofei94 committed
178 179 180
    setInitContent('');
    setCardLoading(true);
    setInitVisible(true);
Maofei94's avatar
Maofei94 committed
181
    let obj = form.getFieldsValue();
Maofei94's avatar
Maofei94 committed
182
    doInitLog();
183
    initDBv4new({
184
      ...obj,
185
    })
186 187 188 189 190 191 192 193 194 195 196 197
      .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
198 199 200 201
      .catch(err => {
        setCardLoading(false);
        console.log(err);
      });
Maofei94's avatar
Maofei94 committed
202
  };
张烨's avatar
张烨 committed
203 204 205 206
  const onValuesChange = (value, b) => {
    form.setFieldsValue(value);
  };
  const onChange = value => {
207
    const { length } = value;
张烨's avatar
张烨 committed
208
    form.setFieldsValue({
209
      dbName: value[length - 1],
张烨's avatar
张烨 committed
210 211
    });
  };
张烨's avatar
张烨 committed
212
  // 保存连接
213
  const onFinish = values => {
214
    setCardLoading(true);
张烨's avatar
张烨 committed
215
    const obj = values;
216 217

    saveConnectionNew({
张烨's avatar
张烨 committed
218 219 220 221
      ip: obj.ip,
      dbName: obj.dbName,
      userName: obj.userName,
      password: obj.password,
222 223
    })
      .then(resnew => {
224
        setCardLoading(false);
225
        if (resnew.code === 0) {
226 227
          // setUpData(upData + 1);
          getConnRecordData();
张烨's avatar
张烨 committed
228
          notification.success({
Maofei94's avatar
Maofei94 committed
229
            message: '提示',
张烨's avatar
张烨 committed
230 231 232 233 234 235
            duration: 3,
            description: '保存成功',
          });
        } else {
          notification.error({
            message: '提示',
Maofei94's avatar
Maofei94 committed
236
            duration: 15,
237
            description: resnew.msg,
张烨's avatar
张烨 committed
238 239
          });
        }
240 241 242 243 244
      })
      .catch(err => {
        setCardLoading(false);
        console.log(err);
      });
245
  };
246
  // 测试连接
张烨's avatar
张烨 committed
247 248
  const onCheck = e => {
    console.log(dbForm);
249
    setCardLoading(true);
张烨's avatar
张烨 committed
250
    const obj = form.getFieldsValue();
251
    connectionTest({
皮倩雯's avatar
皮倩雯 committed
252 253
      // _version: 9999,
      // _dc: new Date().getTime(),
254 255 256 257 258 259
      ip: obj.ip,
      dbName: obj.dbName,
      userName: obj.userName,
      password: obj.password,
      // Type:"SQLServer",
      // name:obj.dbName,
张烨's avatar
张烨 committed
260 261
    })
      .then(res => {
262
        setCardLoading(false);
皮倩雯's avatar
皮倩雯 committed
263
        if (res.code == 0 && res.data == true) {
张烨's avatar
张烨 committed
264
          notification.success({
Maofei94's avatar
Maofei94 committed
265
            message: '提示',
张烨's avatar
张烨 committed
266 267 268 269 270 271
            duration: 3,
            description: '连接成功',
          });
        } else {
          notification.error({
            message: '提示',
Maofei94's avatar
Maofei94 committed
272
            duration: 15,
皮倩雯's avatar
皮倩雯 committed
273
            description: res.msg,
张烨's avatar
张烨 committed
274 275 276 277
          });
        }
      })
      .catch(err => {
278
        setCardLoading(false);
张烨's avatar
张烨 committed
279
        console.log(err);
280
      });
张烨's avatar
张烨 committed
281
  };
Maofei94's avatar
Maofei94 committed
282
  // 获取数据库列表
张烨's avatar
张烨 committed
283
  const selectFocus = e => {
皮倩雯's avatar
皮倩雯 committed
284
    //setOption([]);
张烨's avatar
张烨 committed
285
    let params = form.getFieldsValue();
Maofei94's avatar
Maofei94 committed
286
    getDataBaseList({
皮倩雯's avatar
皮倩雯 committed
287 288
      // _version: 9999,
      // _dc: Date.now(),
张烨's avatar
张烨 committed
289 290 291
      userName: params.userName || '',
      password: params.password || '',
      ip: params.ip || '',
张烨's avatar
张烨 committed
292 293
    })
      .then(res => {
皮倩雯's avatar
皮倩雯 committed
294
        if (res.code == 0) {
皮倩雯's avatar
皮倩雯 committed
295
          console.log(res.data.root);
皮倩雯's avatar
皮倩雯 committed
296
          setOption(res.data.root);
张烨's avatar
张烨 committed
297 298
        } else {
          notification.error({
Maofei94's avatar
Maofei94 committed
299
            message: '提示',
Maofei94's avatar
Maofei94 committed
300
            duration: 15,
皮倩雯's avatar
皮倩雯 committed
301
            description: res.msg,
张烨's avatar
张烨 committed
302 303 304 305 306 307 308 309
          });
          setOption([]);
        }
      })
      .catch(err => {
        console.error(err);
      });
  };
张烨's avatar
张烨 committed
310
  // 点击表格回显到表单
张烨's avatar
张烨 committed
311 312
  const tableClick = item => {
    let obj = { ...dbForm };
张烨's avatar
张烨 committed
313
    Object.keys(obj).forEach(k => {
张烨's avatar
张烨 committed
314
      obj[k] = item[k];
张烨's avatar
张烨 committed
315
    });
张烨's avatar
张烨 committed
316 317
    form.setFieldsValue(obj);
  };
318
  // 产品方案选择框回调
Maofei94's avatar
Maofei94 committed
319
  const handleSelect = value => {
Maofei94's avatar
Maofei94 committed
320 321 322
    handeleChangeSQLDirName(value);
  };
  const handeleChangeSQLDirName = val => {
323
    setTableSQLDirName({
Maofei94's avatar
Maofei94 committed
324
      dirName: val,
325
    })
Maofei94's avatar
Maofei94 committed
326
      .then(res => {
327
        if (res.code === 0) {
Maofei94's avatar
Maofei94 committed
328 329 330
          notification.success({
            message: '提示',
            duration: 3,
Maofei94's avatar
Maofei94 committed
331
            description: `已切换初始化脚本为:${val}`,
Maofei94's avatar
Maofei94 committed
332 333 334 335
          });
        } else {
          notification.error({
            message: '提示',
Maofei94's avatar
Maofei94 committed
336
            duration: 15,
Maofei94's avatar
Maofei94 committed
337 338 339 340 341 342 343 344
            description: res.message,
          });
        }
      })
      .catch(err => {
        console.error(err);
      });
  };
张烨's avatar
张烨 committed
345
  // 展示修改描述
Maofei94's avatar
Maofei94 committed
346 347
  const changeDesc = val => {
    setDesc(val);
348
    handleShowModal('describeVisible', true);
张烨's avatar
张烨 committed
349 350 351 352 353
  };
  const descChange = e => {
    const { value } = e.target;
    setDesc(value);
  };
Maofei94's avatar
Maofei94 committed
354 355 356 357 358
  // 关闭弹窗
  const handleClick = () => {
    setInitVisible(false);
    setInitContent('');
    setFinish(false);
359 360 361 362
    // deleteInitDBLog({
    //   _version: 9999,
    //   _dc: Date.now(),
    // });
363
    deleteInitDBLogNew();
Maofei94's avatar
Maofei94 committed
364
  };
张烨's avatar
张烨 committed
365 366 367 368
  // 弹窗确认回调
  const modalOkCallback = () => {
    const obj = form.getFieldsValue();
    // 更新描述
369
    updateConnDescNew({
张烨's avatar
张烨 committed
370 371 372 373 374
      ip: obj.ip,
      dbName: obj.dbName,
      userName: obj.userName,
      password: obj.password,
      desc,
375
    })
376
      .then(res => {
377
        handleShowModal('describeVisible', false);
378 379
        // setUpData(upData + 1);
        getConnRecordData();
380 381 382
      })
      .catch(err => {
        console.error(err);
383
        handleShowModal('describeVisible', false);
384
      });
张烨's avatar
张烨 committed
385
  };
Maofei94's avatar
Maofei94 committed
386
  // 删除数据库连接记录
Maofei94's avatar
Maofei94 committed
387
  const delConfirm = value => {
Maofei94's avatar
Maofei94 committed
388
    const { key = '' } = value;
Maofei94's avatar
Maofei94 committed
389
    setTableLoading(true);
390
    deleteConnNew({
Maofei94's avatar
Maofei94 committed
391 392 393 394
      rowIndex: key,
    })
      .then(res => {
        setTableLoading(false);
395
        if (res.code === 0) {
396 397
          // setUpData(upData + 1);
          getConnRecordData();
Maofei94's avatar
Maofei94 committed
398 399 400 401 402 403 404 405
          notification.success({
            message: '提示',
            duration: 3,
            description: '操作成功',
          });
        } else {
          notification.error({
            message: '提示',
Maofei94's avatar
Maofei94 committed
406
            duration: 15,
407
            description: res.msg,
Maofei94's avatar
Maofei94 committed
408 409 410 411 412 413 414 415
          });
        }
      })
      .catch(err => {
        setTableLoading(false);
        console.error(err);
      });
  };
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
  // 获取数据库初始化回显列表
  const getInitList = () => {
    setInitList([]);
    handleShowModal('initVisible', true);
    setInitLoading(true);
    let obj = form.getFieldsValue();
    let req1 = GetProductList();
    let req2 = GetDbProduct({ ...obj });
    Promise.all([req1, req2])
      .then(res => {
        if (res[1].code !== 0 || res[0].code !== 0) {
          setInitLoading(false);
          notification.error({
            message: '提示',
            duration: 3,
            description: '连接失败',
          });
          return;
        }
435
        setDbExists(res[1].data.DBExists);
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
        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);
            });
          });
        });
        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);
            // 根据key值去匹配对应的checkVersion
            item.checkVersion =
469
              mapCheckVersion.checkVersion === undefined ? null : mapCheckVersion.checkVersion;
470
            // 根据key值去匹配对应的二级目录的check
471
            item.check = mapCheckVersion.check === undefined ? null : mapCheckVersion.check;
472 473 474
            if (item.check) {
              item.hasCheck = true;
            }
475 476 477 478
            item.functionrSolutions.forEach(val => {
              // 根据三级目录对应的选中key匹配isCheck
              let isCheck = mapList.get(val.key);
              val.isCheck = isCheck === undefined ? null : isCheck;
479 480 481 482 483 484
              // 版本号低于当前版本号禁止选用
              if (item.checkVersion && val.version < item.checkVersion) {
                val.disabled = true;
              } else {
                val.disabled = false;
              }
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
            });
          });
        });
        setInitList(fileList);
        setInitLoading(false);
      })
      .catch(() => {
        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));
524
      const secondList = list[index.tabIndex].modularSolutions[index.radioIndex];
525 526 527 528 529 530 531 532 533 534 535
      // 取消功能 一开始未选中的才能取消
      if (value === secondList.checkVersion && !secondList.hasCheck) {
        secondList.checkVersion = null;
        value = null;
        secondList.check = false;
      } else {
        // 修改选中的checkVersion值
        secondList.checkVersion = value;
        // 修改二级菜单的check字段
        secondList.check = true;
      }
536
      // 修改一级菜单的check字段
537 538 539
      list[index.tabIndex].check = !list[index.tabIndex].modularSolutions.every(
        version => version.checkVersion === null,
      );
540
      // 修改单选isCheck字段
541
      secondList.functionrSolutions.forEach(item => {
542 543 544 545 546 547 548 549 550
        if (item.version === value) {
          item.isCheck = true;
        } else {
          item.isCheck = false;
        }
      });
      return list;
    });
  };
551
  // 数据库初始化
552 553 554 555 556
  const initDatabasePro = () => {
    let productSetting = initList;
    let obj = form.getFieldsValue();
    // 数据库存在调用编辑接口否则调用新增接口
    setInitLoading(true);
557 558 559
    handleShowModal('initVisible', false);
    setInitVisible(true);
    doInitLog();
560
    if (dbExists) {
561
      InitEditDataBase({ ...obj, productSetting }).then(res => {
562 563 564 565 566
        setInitLoading(false);
        if (res.code === 0) {
          notification.success({
            message: '提示',
            duration: 3,
567
            description: '数据库初始化成功',
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
          });
        } else {
          notification.error({
            message: '提示',
            duration: 15,
            description: res.msg,
          });
        }
      });
      return;
    }
    InitAddDataBase({ ...obj, productSetting }).then(res => {
      setInitLoading(false);
      if (res.code === 0) {
        notification.success({
          message: '提示',
          duration: 3,
585
          description: '数据库初始化成功',
586 587 588 589 590 591 592 593 594 595
        });
      } else {
        notification.error({
          message: '提示',
          duration: 15,
          description: res.msg,
        });
      }
    });
  };
张烨's avatar
张烨 committed
596 597 598 599 600
  const columns = [
    {
      title: '服务器名或IP地址',
      dataIndex: 'ip',
      key: 'ip',
Maofei94's avatar
Maofei94 committed
601 602
      width: 180,
      ellipsis: true,
张烨's avatar
张烨 committed
603 604 605 606 607
    },
    {
      title: '数据库名称',
      dataIndex: 'dbName',
      key: 'dbName',
Maofei94's avatar
Maofei94 committed
608 609
      width: 180,
      ellipsis: true,
张烨's avatar
张烨 committed
610 611 612 613 614
    },
    {
      title: '数据库用户名称',
      dataIndex: 'userName',
      key: 'userName',
Maofei94's avatar
Maofei94 committed
615 616
      width: 180,
      ellipsis: true,
张烨's avatar
张烨 committed
617 618 619 620 621
    },
    {
      title: '保存时间',
      dataIndex: 'saveTime',
      key: 'saveTime',
Maofei94's avatar
Maofei94 committed
622 623
      width: 180,
      ellipsis: true,
张烨's avatar
张烨 committed
624 625 626 627 628
    },
    {
      title: '描述',
      dataIndex: 'desc',
      key: 'desc',
Maofei94's avatar
Maofei94 committed
629
      ellipsis: true,
张烨's avatar
张烨 committed
630 631
    },
    {
Maofei94's avatar
Maofei94 committed
632 633 634
      title: '操作',
      dataIndex: 'action',
      key: 'action',
Maofei94's avatar
Maofei94 committed
635 636
      width: 250,
      ellipsis: true,
Maofei94's avatar
Maofei94 committed
637 638 639 640 641 642
      render: (text, record) => (
        <Space>
          <Button
            type="primary"
            size="small"
            onClick={() => {
Maofei94's avatar
Maofei94 committed
643
              changeDesc(record.desc);
Maofei94's avatar
Maofei94 committed
644 645 646 647
            }}
          >
            修改描述
          </Button>
648
          {/* <div onClick={e => e.stopPropagation()}>
Maofei94's avatar
Maofei94 committed
649 650 651 652 653 654 655 656 657 658 659 660
            <Popconfirm
              title="是否删除该连接的历史记录?"
              okText="确认"
              cancelText="取消"
              onConfirm={() => {
                delConfirm(record);
              }}
            >
              <Button size="small" danger>
                删除
              </Button>
            </Popconfirm>
661
          </div> */}
Maofei94's avatar
Maofei94 committed
662
        </Space>
张烨's avatar
张烨 committed
663
      ),
张烨's avatar
张烨 committed
664 665 666 667
    },
  ];
  return (
    <>
668
      <PageContainer className={styles.InitDataBaseContainer}>
张烨's avatar
张烨 committed
669
        <Card>
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
          <Spin tip="loading..." spinning={cardLoading}>
            <div className={styles.tableTitle}>数据库初始化</div>
            <Form
              className={styles.mgTop20}
              layout="horizontal"
              labelAlign="left"
              labelCol={{ span: 3 }}
              form={form}
              onFinish={onFinish}
              onValuesChange={onValuesChange}
            >
              <Form.Item label={`${formLables.ip}:`} name="ip">
                <Input placeholder="请输入服务器名或IP地址" />
              </Form.Item>
              <Form.Item label={`${formLables.userName}:`} name="userName">
                <Input placeholder="请输入用户名称" />
              </Form.Item>
              <Form.Item label={`${formLables.password}:`} name="password">
皮倩雯's avatar
皮倩雯 committed
688
                <Input placeholder="请输入用户密码" type="password" />
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
              </Form.Item>
              <Form.Item label={`${formLables.dbName}:`} name="dbName">
                <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 &&
707
                      option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
708 709 710 711 712 713 714 715 716 717 718 719
                    );
                  }}
                >
                  {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
720
              <Form.Item wrapperCol={{ offset: 3 }}>
721 722 723 724
                <div className={styles.tCenter}>
                  <Space size="large" className={styles.btnBox}>
                    <Space>
                      <Button onClick={onCheck}>测试连接</Button>
725
                      <Button type="primary" htmlType="submit" loading={tableLoading}>
726 727 728 729
                        保存连接
                      </Button>
                    </Space>
                    <Space>
730 731 732 733 734
                      <Button
                        type="primary"
                        onClick={() => {
                          getInitList();
                          deleteInitDBLogNew();
Maofei94's avatar
Maofei94 committed
735
                        }}
736
                      >
737 738
                        数据库初始化
                      </Button>
739
                    </Space>
Maofei94's avatar
Maofei94 committed
740
                  </Space>
741 742 743 744
                </div>
              </Form.Item>
            </Form>
          </Spin>
张烨's avatar
张烨 committed
745 746
        </Card>

747 748
        <Card className={styles.mgTop20}>
          <div className={styles.tableTitle}>近期保存的数据库连接</div>
张烨's avatar
张烨 committed
749
          <Table
皮倩雯's avatar
皮倩雯 committed
750
            style={{ marginTop: '20px' }}
751
            scroll={{ x: 'max-content', y: 'calc(100vh - 580px)' }}
张烨's avatar
张烨 committed
752 753
            columns={columns}
            dataSource={data}
754
            pagination={false}
张烨's avatar
张烨 committed
755 756
            bordered
            loading={tableLoading}
张烨's avatar
张烨 committed
757 758 759 760 761 762
            size="small"
            onRow={record => ({
              onClick: () => {
                tableClick(record);
              }, // 点击行
            })}
张烨's avatar
张烨 committed
763 764
          />
        </Card>
Maofei94's avatar
Maofei94 committed
765 766 767 768 769 770
        <Modal
          title="初始化数据库"
          visible={initVisible}
          onCancel={() => {
            setInitVisible(false);
            setInitContent('');
771 772 773 774
            // deleteInitDBLog({
            //   _version: 9999,
            //   _dc: Date.now(),
            // });
775
            deleteInitDBLogNew();
Maofei94's avatar
Maofei94 committed
776
          }}
777
          width={800}
Maofei94's avatar
Maofei94 committed
778
          maskClosable={false}
779
          bodyStyle={{
780
            height: '500px',
781
            // overflowY: 'auto',
782
          }}
Maofei94's avatar
Maofei94 committed
783 784 785
          footer={[
            <Button
              onClick={() => {
Maofei94's avatar
Maofei94 committed
786
                handleClick();
Maofei94's avatar
Maofei94 committed
787
              }}
788
              key="back"
Maofei94's avatar
Maofei94 committed
789 790 791 792 793 794
              type="primary"
            >
              关闭窗口
            </Button>,
          ]}
        >
tianfen's avatar
tianfen committed
795 796 797
          <div
            ref={scroll}
            style={{
798
              maxHeight: '470px',
tianfen's avatar
tianfen committed
799 800 801 802
              overflowY: 'auto',
              marginRight: ' -24px',
            }}
          >
Maofei94's avatar
Maofei94 committed
803
            {initContent || (
Maofei94's avatar
Maofei94 committed
804
              <Spin
805
                spinning={initLoading}
Maofei94's avatar
Maofei94 committed
806 807 808
                tip="loading..."
                style={{ width: '100%', marginTop: '40px' }}
              />
Maofei94's avatar
Maofei94 committed
809
            )}
810
          </div>
Maofei94's avatar
Maofei94 committed
811 812
        </Modal>

813
        <Modal
张烨's avatar
张烨 committed
814
          title="修改链接描述"
815
          visible={modalVisible.describeVisible}
张烨's avatar
张烨 committed
816
          onOk={() => modalOkCallback()}
817
          onCancel={() => handleShowModal('describeVisible', false)}
818
          width="800px"
819
          bodyStyle={{
张烨's avatar
张烨 committed
820
            minHeight: '100px',
821
          }}
张烨's avatar
张烨 committed
822
          cancelText="取消"
Maofei94's avatar
Maofei94 committed
823
          okText="确认"
Maofei94's avatar
Maofei94 committed
824
          destroyOnClose
825
        >
张烨's avatar
张烨 committed
826
          <Row>
827
            <Col span={2} className={styles.decsBox}>
Maofei94's avatar
Maofei94 committed
828
              描述:
张烨's avatar
张烨 committed
829
            </Col>
Maofei94's avatar
Maofei94 committed
830

831
            <Col span={22}>
张烨's avatar
张烨 committed
832 833
              <Input
                placeholder="请输入描述"
Maofei94's avatar
Maofei94 committed
834 835
                allowClear
                defaultValue={desc}
张烨's avatar
张烨 committed
836 837 838 839 840
                onChange={value => {
                  descChange(value);
                }}
              />
            </Col>
841
          </Row>
842
        </Modal>
843 844 845 846 847 848 849
        {/* 初始化选择产品弹窗 */}
        <Modal
          title="初始化"
          maskClosable={false}
          visible={modalVisible.initVisible}
          onCancel={() => handleShowModal('initVisible', false)}
          footer={[
850
            <Button key="back" onClick={() => handleShowModal('initVisible', false)}>
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
              取消
            </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
876 877 878 879
      </PageContainer>
    </>
  );
};
880

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