@bos-alpha/data
Version:
数据管理
169 lines (168 loc) • 14.2 kB
JavaScript
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 { useState } from 'react';
import { Input, Button, Upload, Checkbox, message } from 'antd';
import styled from '@emotion/styled';
import { Icon } from '@bos-alpha/common/lib/components';
import * as api from '@bos-alpha/common/lib/services';
import { downFile } from '@bos-alpha/common/lib/utils';
import { prefixCls, cookieToken } from '@bos-alpha/common';
import { ModalTitle, FooterButtons, exitConfirm } from '../import-steps';
import store from '../../store';
export var DbImport = function () {
var _a = useState(), file = _a[0], setFile = _a[1];
// 正在导入
var _b = useState(false), fetching = _b[0], setFetching = _b[1];
var _c = store(), status = _c.status, taskId = _c.taskId, authInfo = _c.authInfo, scheduleInfo = _c.scheduleInfo, setVisible = _c.setVisible, preStep = _c.preStep, insert = _c.insert, update = _c.update, setState = _c.setState;
var getTemp = function () { return __awaiter(void 0, void 0, void 0, function () {
var res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, api.getTemplate({
params: {
name: '第三方数据库数据导入配置文件.xlsx',
access_token: cookieToken()
}
})];
case 1:
res = _a.sent();
downFile(res.data, '第三方数据库数据导入配置文件.xlsx');
return [2 /*return*/];
}
});
}); };
var onImportChange = function (file) {
setFile(file);
return false;
};
// 确定
var onSave = function (type) { return __awaiter(void 0, void 0, void 0, function () {
var name, description, scheduleType, scheduleValue;
return __generator(this, function (_a) {
// 任务为非配置中时 配置模板非必填 不传后端采用旧配置
if (status === '-2') {
if (!file || (file && !file.name)) {
return [2 /*return*/, message.error('请选择导入配置文件')];
}
if (file.name.indexOf('xls') === -1) {
return [2 /*return*/, message.error('选择文件格式不正确')];
}
}
name = scheduleInfo.name, description = scheduleInfo.description, scheduleType = scheduleInfo.scheduleType, scheduleValue = scheduleInfo.scheduleValue;
setFetching(true);
api.importDatabaseFile({
data: __assign(__assign(__assign(__assign(__assign({}, (taskId
? {
taskId: taskId
}
: {})), (file
? {
file: file
}
: {})), { connect: JSON.stringify(authInfo), insert: insert, update: update,
// delete: deleteChecked,
name: name, description: description, enabled: true, status: type === 'execute' ? '0.5' : '0', scheduleType: scheduleType }), (scheduleType !== 'manual'
? {
scheduleValue: scheduleValue
}
: {})), { rollback: 'none' })
}, {
noErrorHandle: true
})
.then(function (res) {
if (res.code !== 'SUCCESS')
return message.error(res.message);
if (type === 'save') {
message.success('保存成功');
}
else {
setVisible(false);
}
})
.finally(function () {
setFetching(false);
});
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: 2, onClose: function () { return onExit('close'); } }, { children: "\u4ECE\u7B2C\u4E09\u65B9\u6570\u636E\u5E93\u5BFC\u5165\u6570\u636E" }), void 0), _jsxs(TempSelect, { children: [_jsx("label", { children: "\u9009\u62E9\u6570\u636E\u5BFC\u5165\u914D\u7F6E\u6587\u4EF6\uFF1A" }, void 0), _jsxs("div", __assign({ className: "upload-ipt" }, { children: [_jsx(Input, { className: "file-ipt", type: "text", disabled: true, value: file === null || file === void 0 ? void 0 : file.name, placeholder: "\u8BF7\u9009\u62E9\u6570\u636E\u5BFC\u5165\u914D\u7F6E\u6587\u4EF6" }, void 0), _jsx(Upload, __assign({ accept: ".xls,.xlsx", showUploadList: false, beforeUpload: onImportChange }, { children: _jsx(Button, __assign({ className: "upload-btn", type: "primary" }, { children: "\u9009\u62E9" }), void 0) }), void 0)] }), void 0)] }, void 0), _jsx("div", __assign({ className: "download-btn" }, { children: _jsx(Button, __assign({ type: "link", icon: _jsx(Icon, { type: "iconicon_download" }, void 0), onClick: getTemp }, { children: "\u4E0B\u8F7D\u6A21\u677F" }), void 0) }), void 0), _jsx("div", __assign({ className: "import-option-title" }, { children: "\u5BFC\u5165\u9009\u9879" }), void 0), _jsxs("div", __assign({ className: "import-options" }, { children: [_jsx("div", __assign({ className: "import-check" }, { children: _jsx(Checkbox, __assign({ checked: insert, onChange: function (e) {
return setState({
insert: e.target.checked
});
} }, { children: "\u65B0\u589EBOS\u5B9E\u4F8B\u6570\u636E\uFF08\u53C2\u8003\u6765\u6E90\u6570\u636E\uFF0C\u65B0\u589EBOS\u5BF9\u8C61\u548C\u5173\u7CFB\u5B9E\u4F8B\u6570\u636E\uFF09" }), void 0) }), void 0), _jsx("div", __assign({ className: "import-check" }, { children: _jsx(Checkbox, __assign({ checked: update, onChange: function (e) {
return setState({
update: e.target.checked
});
} }, { children: "\u66F4\u65B0BOS\u5B9E\u4F8B\u6570\u636E\uFF08\u53C2\u8003\u6765\u6E90\u6570\u636E\uFF0C\u66F4\u65B0BOS\u4E2D\u5DF2\u5B58\u5728\u7684\u5BF9\u8C61\u548C\u5173\u7CFB\u5B9E\u4F8B\u6570\u636E\uFF09" }), void 0) }), void 0)] }), void 0), _jsxs(FooterButtons, { children: [_jsx(Button, __assign({ type: "default", shape: "round", className: "btn pre-step", onClick: function () { return onExit('preStep'); } }, { children: "\u4E0A\u4E00\u6B65" }), void 0), _jsx(Button, __assign({ type: "primary", shape: "round", className: "btn", ghost: true, loading: fetching, disabled: fetching, onClick: function () { return onSave('save'); } }, { children: "\u4FDD\u5B58" }), void 0), _jsx(Button, __assign({ type: "primary", shape: "round", className: "btn", loading: fetching, disabled: fetching, onClick: function () { return onSave('execute'); } }, { children: "\u4FDD\u5B58\u5E76\u6267\u884C" }), void 0)] }, void 0)] }, void 0));
};
var ImportModal = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n color: rgba(0, 0, 0, 0.85);\n .download-btn {\n text-align: right;\n padding-top: 12px;\n .", "-btn {\n padding: 0;\n }\n }\n .import-option-title {\n padding: 50px 0 12px;\n font-weight: 500;\n }\n .import-options {\n padding: 10px;\n background-color: #f8f8f8;\n border-radius: 3px;\n .", "-checkbox-wrapper {\n color: rgba(0, 0, 0, 0.65);\n }\n .import-check {\n margin-bottom: 10px;\n }\n }\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 .config-form {\n padding: 0 120px;\n .form-ipt {\n width: 334px;\n }\n }\n .progress-bar {\n padding-top: 30px;\n height: 80px;\n .progress-tip {\n display: flex;\n justify-content: center;\n align-items: center;\n color: rgba(0, 0, 0, 0.6);\n & > .progress-icon {\n color: #888;\n font-size: 18px;\n }\n }\n .progress-icon {\n margin-right: 5px;\n }\n }\n"], ["\n color: rgba(0, 0, 0, 0.85);\n .download-btn {\n text-align: right;\n padding-top: 12px;\n .", "-btn {\n padding: 0;\n }\n }\n .import-option-title {\n padding: 50px 0 12px;\n font-weight: 500;\n }\n .import-options {\n padding: 10px;\n background-color: #f8f8f8;\n border-radius: 3px;\n .", "-checkbox-wrapper {\n color: rgba(0, 0, 0, 0.65);\n }\n .import-check {\n margin-bottom: 10px;\n }\n }\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 .config-form {\n padding: 0 120px;\n .form-ipt {\n width: 334px;\n }\n }\n .progress-bar {\n padding-top: 30px;\n height: 80px;\n .progress-tip {\n display: flex;\n justify-content: center;\n align-items: center;\n color: rgba(0, 0, 0, 0.6);\n & > .progress-icon {\n color: #888;\n font-size: 18px;\n }\n }\n .progress-icon {\n margin-right: 5px;\n }\n }\n"])), prefixCls, prefixCls, prefixCls, prefixCls, prefixCls);
var TempSelect = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n color: rgba(0, 0, 0, 0.6);\n & > .upload-ipt {\n flex: 1;\n display: flex;\n .upload-btn {\n border-radius: 0;\n }\n }\n"], ["\n display: flex;\n align-items: center;\n color: rgba(0, 0, 0, 0.6);\n & > .upload-ipt {\n flex: 1;\n display: flex;\n .upload-btn {\n border-radius: 0;\n }\n }\n"])));
var templateObject_1, templateObject_2;