UNPKG

@bos-alpha/data

Version:

数据管理

258 lines (257 loc) 14.1 kB
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useEffect, useState } from 'react'; import { Form, Select, Input, Button, message } from 'antd'; import styled from '@emotion/styled'; import * as services from '@bos-alpha/common/lib/services'; import { prefixCls } from '@bos-alpha/common'; import * as api from '@bos-alpha/common/lib/services'; import store from '../../store'; import { ModalTitle, FooterButtons, exitConfirm } from '../import-steps'; import { getSiteAuth } from '../step-two/queryConfig'; // 支持的数据库类型 var databaseTypes = [ { label: 'MySQL(TCP/IP)', value: 'MySQL' }, { label: 'Oracle', value: 'Oracle' }, { label: 'MongoDB', value: 'MongoDB' }, { label: 'PgSQL', value: 'PgSQL' }, { label: 'Microsoft SQL Server(TPC/IP)', value: 'SQLServer' }, { label: '达梦数据库', value: 'Dameng' } ]; // 数据库默认端口 var portMap = { MySQL: '3306', Oracle: '1521', MongoDB: '27017', PgSQL: '5432', SQLServer: '1433', DMDB: '5236' }; export var DbConfig = function () { var _a = store(), isEdit = _a.isEdit, taskId = _a.taskId, siteId = _a.siteId, authInfo = _a.authInfo, setVisible = _a.setVisible, preStep = _a.preStep, nextStep = _a.nextStep, setState = _a.setState; var form = Form.useForm()[0]; var _b = useState(false), testOk = _b[0], setTestOk = _b[1]; useEffect(function () { if (isEdit && siteId) { getSiteAuthInfo(); } else if (authInfo.type) { form.setFieldsValue(__assign({}, authInfo)); } else { // 默认第一种数据库类型 form.setFieldsValue({ type: databaseTypes[0].value, port: portMap[databaseTypes[0].value] }); } }, []); // eslint-disable-line react-hooks/exhaustive-deps // 获取当前任务连接配置 var getSiteAuthInfo = function () { return __awaiter(void 0, void 0, void 0, function () { var res, resInfo, config; return __generator(this, function (_a) { switch (_a.label) { case 0: if (!siteId) return [2 /*return*/]; return [4 /*yield*/, api.linkedQuery({ data: getSiteAuth(siteId) })]; case 1: res = _a.sent(); // 处理认证信息回显 if (res.count > 0) { resInfo = res.data[0].importAuths.params; console.log('authInfo', resInfo); if (!resInfo) return [2 /*return*/]; config = { type: resInfo.type, ip: resInfo.ip, port: resInfo.port, username: resInfo.username, password: resInfo.password, database: resInfo.database }; setState({ authInfo: config }); form.setFieldsValue(__assign({}, config)); } return [2 /*return*/]; } }); }); }; // 测试连接 var onTestConfirm = function () { return __awaiter(void 0, void 0, void 0, function () { var vals; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, form.validateFields()]; case 1: vals = _a.sent(); setTestOk(false); return [4 /*yield*/, services.connectDatabase({ data: { type: vals.type, // 输入去除空格 ip: vals.ip.trim(), port: vals.port.trim(), username: vals.username.trim(), password: vals.password, database: vals.database.trim() } })]; case 2: _a.sent(); message.success('数据库连接成功'); setState({ authInfo: vals }); setTestOk(true); return [2 /*return*/]; } }); }); }; var onSave = function (type) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, api.importDatabaseFile({ data: { taskId: taskId, connect: JSON.stringify(authInfo) } })]; case 1: _a.sent(); if (type === 'next') { nextStep(); } else { message.success('保存成功'); } return [2 /*return*/]; } }); }); }; var onExit = function (type) { exitConfirm(__assign(__assign({ centered: true }, (type === 'preStep' ? { title: '返回上一步', content: '未保存的配置将会丢失,确定返回上一步?' } : { title: '提示', content: '数据未保存,是否退出?' })), { onOk: function () { if (type === 'preStep') { preStep(); } else { setVisible(false); } } })); }; return (_jsxs(ImportModal, { children: [_jsx(ModalTitle, __assign({ type: "db", current: 1, onClose: function () { return onExit('close'); } }, { children: "\u8FDE\u63A5\u7B2C\u4E09\u65B9\u6570\u636E\u5E93" }), void 0), _jsxs(Form, __assign({ form: form, className: "config-form", labelCol: { span: 4 }, wrapperCol: { span: 20 }, labelAlign: "left", colon: false, onValuesChange: function () { return setTestOk(false); } }, { children: [_jsx(Form.Item, __assign({ label: "\u6570\u636E\u8FDE\u63A5\u7C7B\u578B", name: "type" }, { children: _jsx(Select, { className: "form-ipt", options: databaseTypes, placeholder: "\u8BF7\u9009\u62E9\u6570\u636E\u8FDE\u63A5\u7C7B\u578B", getPopupContainer: function (triggerNode) { return triggerNode.parentNode; }, onChange: function (val) { form.setFieldsValue({ port: portMap[val] }); } }, void 0) }), void 0), _jsx(Form.Item, __assign({ label: "\u4E3B\u673A\u540D/IP", name: "ip", rules: [ { required: true, message: '请输入主机名/IP' } ] }, { children: _jsx(Input, { className: "form-ipt", placeholder: "\u8BF7\u8F93\u5165\u4E3B\u673A\u540D/IP" }, void 0) }), void 0), _jsx(Form.Item, __assign({ label: "\u7AEF\u53E3", name: "port", rules: [ { required: true, message: '请输入端口' } ] }, { children: _jsx(Input, { className: "form-ipt", placeholder: "\u8BF7\u8F93\u5165\u7AEF\u53E3" }, void 0) }), void 0), _jsx(Form.Item, __assign({ label: "\u7528\u6237\u540D", name: "username", rules: [ { required: true, message: '请输入用户名' } ] }, { children: _jsx(Input, { className: "form-ipt", placeholder: "\u8BF7\u8F93\u5165\u7528\u6237\u540D" }, void 0) }), void 0), _jsx(Form.Item, __assign({ label: "\u5BC6\u7801", name: "password", rules: [ { required: true, message: '请输入密码' } ] }, { children: _jsx(Input.Password, { className: "form-ipt", placeholder: "\u8BF7\u8F93\u5165\u5BC6\u7801" }, void 0) }), void 0), _jsx(Form.Item, __assign({ label: "\u6570\u636E\u5E93", name: "database", rules: [ { required: true, message: '请输入数据库' } ] }, { children: _jsx(Input, { className: "form-ipt", placeholder: "\u8BF7\u8F93\u5165\u6570\u636E\u5E93" }, void 0) }), void 0)] }), void 0), _jsxs(FooterButtons, { children: [_jsx(Button, __assign({ type: "default", shape: "round", className: "pre-step btn", onClick: function () { return onExit('preStep'); } }, { children: "\u4E0A\u4E00\u6B65" }), void 0), _jsx(Button, __assign({ type: "primary", shape: "round", className: "btn", ghost: true, onClick: onTestConfirm }, { children: "\u6D4B\u8BD5\u8FDE\u63A5" }), void 0), _jsx(Button, __assign({ type: "primary", shape: "round", className: "btn", ghost: true, disabled: !testOk, onClick: function () { return onSave('save'); } }, { children: "\u4FDD\u5B58" }), void 0), _jsx(Button, __assign({ type: "primary", shape: "round", disabled: !testOk, className: "btn", onClick: function () { return onSave('next'); } }, { children: "\u4FDD\u5B58\u5E76\u4E0B\u4E00\u6B65" }), void 0)] }, void 0)] }, void 0)); }; var ImportModal = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n color: rgba(0, 0, 0, 0.85);\n .import-check {\n margin-bottom: 10px;\n }\n .", "-divider-inner-text {\n padding-left: 0;\n font-weight: 400;\n font-size: 14px;\n }\n .", "-divider-horizontal.", "-divider-with-text-left:before {\n display: none;\n }\n .progress-bar {\n padding-top: 30px;\n .progress-icon {\n margin-right: 5px;\n }\n }\n"], ["\n color: rgba(0, 0, 0, 0.85);\n .import-check {\n margin-bottom: 10px;\n }\n .", "-divider-inner-text {\n padding-left: 0;\n font-weight: 400;\n font-size: 14px;\n }\n .", "-divider-horizontal.", "-divider-with-text-left:before {\n display: none;\n }\n .progress-bar {\n padding-top: 30px;\n .progress-icon {\n margin-right: 5px;\n }\n }\n"])), prefixCls, prefixCls, prefixCls); var templateObject_1;