@bos-alpha/data
Version:
数据管理
261 lines (260 loc) • 18.1 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 { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { Form, Input, Select, Radio, Button, message } from 'antd';
import styled from '@emotion/styled';
import { useEffect, useState, useRef } from 'react';
import dayjs from 'dayjs';
import store from '../../store';
import { FooterButtons, ModalTitle, exitConfirm } from '../import-steps';
import { getScheduleParams, parseScheduleParams } from '../../utils/schedule';
import { schedules } from './schedules';
import { prefixCls, cookieUserInfo } from '@bos-alpha/common';
import * as api from '@bos-alpha/common/lib/services';
var Item = Form.Item;
/**
* 导入任务基础配置
* @returns
*/
export var StepOne = function () {
var _a;
var _b = useState('once'), scheduleType = _b[0], setScheduleType = _b[1];
// 是否已保存
var isSaved = useRef(false);
var form = Form.useForm()[0];
var _c = store(), type = _c.type, nextStep = _c.nextStep, visible = _c.visible, setVisible = _c.setVisible, isEdit = _c.isEdit, scheduleInfo = _c.scheduleInfo, siteId = _c.siteId, taskId = _c.taskId, setState = _c.setState;
useEffect(function () {
form.resetFields();
var userInfo = cookieUserInfo();
var creator = '';
if (userInfo) {
var fullName = userInfo.fullName, name_1 = userInfo.name;
creator = fullName ? "".concat(fullName, "\uFF08").concat(name_1, "\uFF09") : name_1;
}
if (isEdit || scheduleInfo.scheduleType) {
var scheduleType_1 = scheduleInfo.scheduleType === 'minutes' ||
scheduleInfo.scheduleType === 'hours'
? 'cycle'
: scheduleInfo.scheduleType;
var scheduleValue = parseScheduleParams(scheduleInfo.scheduleType, scheduleInfo.scheduleValue);
setScheduleType(scheduleType_1);
form.setFieldsValue(__assign({ type: type, name: scheduleInfo.name, description: scheduleInfo.description, creator: scheduleInfo.creator, createTime: scheduleInfo.createTime, scheduleType: scheduleType_1, guser: scheduleInfo.guser, gtime: scheduleInfo.gtime }, scheduleValue));
return;
}
form.setFieldsValue({
name: '',
description: '',
type: type,
creator: creator,
createTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
scheduleType: scheduleType
});
// 关闭时 重置state
if (!visible) {
setScheduleType('once');
}
}, [visible]); //eslint-disable-line
var onExit = function () {
if (isSaved.current) {
setVisible(false);
return;
}
exitConfirm({
centered: true,
title: '提示',
content: '数据未保存,是否退出?',
onOk: function () { return setVisible(false); }
});
};
/**
* 保存任务
* 一次性:年:月:日:时:分:秒
每天:时:分:秒
每周:周一,周二:时:分:秒
每月:日,日:时:分:秒 最后一天L
每年:月,月:日,日:时:分:秒
*/
var onSave = function (next) { return __awaiter(void 0, void 0, void 0, function () {
var vals, newScheduleType, scheduleValue, diff, name, description, res, data, userInfo, creator, createTime, siteRes, curSiteId, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, form.validateFields()];
case 1:
vals = _a.sent();
newScheduleType = scheduleType;
scheduleValue = getScheduleParams(vals, newScheduleType);
// 一次性执行 时间不能早于当前时间
if (newScheduleType === 'once') {
diff = dayjs(vals.date).diff(dayjs(), 'seconds');
if (diff < 0)
return [2 /*return*/, message.error('一次执行时间需大于当前时间')];
}
if (newScheduleType === 'cycle') {
// setScheduleType(vals.cycleType);
newScheduleType = vals.cycleType;
}
console.log('==========', newScheduleType);
name = vals.name, description = vals.description;
if (!(type === 'db')) return [3 /*break*/, 3];
return [4 /*yield*/, api.importDatabaseFile({
data: __assign(__assign(__assign(__assign(__assign({}, (taskId
? {
taskId: taskId
}
: {})), { name: name, description: description, enabled: isEdit }), (isEdit
? {}
: {
status: '-2'
})), { scheduleType: newScheduleType }), (scheduleType !== 'manual'
? {
scheduleValue: scheduleValue
}
: {}))
})];
case 2:
res = _a.sent();
setState({
taskId: res.taskId,
scheduleInfo: __assign(__assign({}, scheduleInfo), { name: name, description: description, scheduleType: newScheduleType, scheduleValue: scheduleValue })
});
next && nextStep();
if (!next)
message.success('保存成功');
return [2 /*return*/];
case 3:
data = __assign(__assign(__assign({ name: name, description: description, enabled: isEdit }, (isEdit
? {}
: {
status: '-2'
})), { scheduleType: newScheduleType }), (scheduleType !== 'manual'
? {
scheduleValue: scheduleValue
}
: {}));
if (!!taskId) return [3 /*break*/, 6];
userInfo = cookieUserInfo();
creator = userInfo ? userInfo.guser : '';
createTime = new Date().getTime().toString();
return [4 /*yield*/, api.addEntity('importSites', {
data: {
bosclass: 'importSites',
name: name,
description: description,
type: type,
creator: creator,
createTime: createTime
}
})];
case 4:
siteRes = _a.sent();
curSiteId = (siteRes || '').split('/').slice(-1)[0];
return [4 /*yield*/, api.postDataImportTasks({
data: __assign({ extra: curSiteId }, data)
})];
case 5:
res = _a.sent();
setState({
siteId: curSiteId,
taskId: res.taskId,
scheduleInfo: __assign(__assign({}, scheduleInfo), { creator: creator, createTime: createTime })
});
isSaved.current = true;
return [3 /*break*/, 8];
case 6: return [4 /*yield*/, api.postDataImportTasks({
data: __assign({ extra: siteId, taskId: taskId }, data)
})];
case 7:
_a.sent();
isSaved.current = true;
_a.label = 8;
case 8:
if (!next)
message.success('保存成功');
// 到下一步 也暂存配置信息
setState({
scheduleInfo: __assign(__assign({}, scheduleInfo), { name: name, description: description, scheduleType: newScheduleType, scheduleValue: scheduleValue })
});
next && nextStep();
return [2 /*return*/];
}
});
}); };
return (_jsxs(Form, __assign({ form: form, labelCol: { span: 6 }, wrapperCol: { span: 18 }, labelAlign: "left", colon: false }, { children: [_jsxs(ModalTitle, __assign({ type: type, current: 0, onClose: onExit }, { children: ["".concat(isEdit ? '编辑' : '新建'), "\u914D\u7F6E\u548C\u4EFB\u52A1"] }), void 0), _jsxs(Container, { children: [_jsxs("div", __assign({ className: "page-left" }, { children: [_jsx("div", __assign({ className: "title" }, { children: "\u57FA\u672C\u4FE1\u606F" }), void 0), _jsx(Item, __assign({ name: "name", label: "\u914D\u7F6E\u540D\u79F0", rules: [
{
required: true,
message: '请输入配置名称'
}
] }, { children: _jsx(Input, { maxLength: 50, placeholder: "\u8BF7\u8F93\u5165\u914D\u7F6E\u540D\u79F0" }, void 0) }), void 0), _jsx(Item, __assign({ name: "type", label: "\u5BF9\u63A5\u65B9\u5F0F" }, { children: _jsx(Select, { options: [
{
label: 'API',
value: 'api'
},
{
label: '数据库',
value: 'db'
}
], disabled: true }, void 0) }), void 0), _jsx(Item, __assign({ name: "creator", label: "\u521B\u5EFA\u8005" }, { children: _jsx(Input, { disabled: true }, void 0) }), void 0), _jsx(Item, __assign({ name: "createTime", label: "\u521B\u5EFA\u65F6\u95F4" }, { children: _jsx(Input, { disabled: true }, void 0) }), void 0), _jsx(Item, __assign({ name: "guser", label: "\u6700\u540E\u4FEE\u6539\u4EBA" }, { children: _jsx(Input, { disabled: true }, void 0) }), void 0), _jsx(Item, __assign({ name: "gtime", label: "\u6700\u540E\u4FEE\u6539\u65F6\u95F4" }, { children: _jsx(Input, { disabled: true }, void 0) }), void 0), _jsx(Item, __assign({ name: "description", label: "\u914D\u7F6E\u63CF\u8FF0" }, { children: _jsx(Input.TextArea, { rows: 3, maxLength: 255, autoSize: {
minRows: 3,
maxRows: 3
}, showCount: false, placeholder: "\u8BF7\u8F93\u5165\u914D\u7F6E\u63CF\u8FF0\uFF0C\u5C11\u4E8E255\u5B57" }, void 0) }), void 0)] }), void 0), _jsxs("div", __assign({ className: "page-right" }, { children: [_jsxs("div", { children: [_jsx("div", __assign({ className: "title" }, { children: "\u6267\u884C\u8BBE\u7F6E" }), void 0), _jsx("div", { children: "\u89E6\u53D1\u6761\u4EF6" }, void 0), _jsx(Item, __assign({ name: "scheduleType", wrapperCol: { span: 24 } }, { children: _jsx(Radio.Group, __assign({ onChange: function (e) {
setScheduleType(e.target.value);
form.setFieldsValue({
date: null,
time: null,
day: null,
week: null,
month: null
});
} }, { children: schedules.map(function (item, index) { return (_jsx(Radio, __assign({ value: item.code }, { children: item.label }), index)); }) }), void 0) }), void 0)] }, void 0), _jsxs("div", __assign({ className: "schedule-param" }, { children: [scheduleType !== 'manual' ? (_jsx("div", __assign({ className: "label" }, { children: "\u6267\u884C\u65F6\u95F4" }), void 0)) : null, _jsx("div", __assign({ className: "param-picker" }, { children: (_a = schedules.find(function (item) { return item.code === scheduleType; })) === null || _a === void 0 ? void 0 : _a.picker }), void 0)] }), void 0)] }), void 0), _jsxs(FooterButtons, { children: [_jsx(Button, __assign({ type: "primary", shape: "round", onClick: function () { return onSave(); } }, { children: "\u4FDD\u5B58" }), void 0), _jsx(Button, __assign({ type: "primary", shape: "round", onClick: function () { return onSave(true); } }, { children: "\u4FDD\u5B58\u5E76\u4E0B\u4E00\u6B65" }), void 0)] }, void 0)] }, void 0)] }), void 0));
};
var Container = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n border: 1px solid #dedede;\n .page-left {\n width: 50%;\n padding: 20px 10px 10px 20px;\n border-right: 1px solid #dedede;\n }\n .page-right {\n width: 50%;\n padding: 20px 10px 10px 20px;\n .schedule-param {\n display: flex;\n flex-flow: wrap;\n & > .label {\n padding-right: 10px;\n padding-top: 4px;\n }\n & > .param-picker {\n flex: 1;\n }\n }\n .", "-radio-wrapper {\n margin-right: 30px;\n margin-top: 12px;\n }\n .manual-tip {\n padding-top: 5px;\n .blue-link {\n color: #2878ff;\n }\n }\n }\n .title {\n font-size: 16px;\n font-weight: 500;\n padding-bottom: 15px;\n }\n"], ["\n display: flex;\n border: 1px solid #dedede;\n .page-left {\n width: 50%;\n padding: 20px 10px 10px 20px;\n border-right: 1px solid #dedede;\n }\n .page-right {\n width: 50%;\n padding: 20px 10px 10px 20px;\n .schedule-param {\n display: flex;\n flex-flow: wrap;\n & > .label {\n padding-right: 10px;\n padding-top: 4px;\n }\n & > .param-picker {\n flex: 1;\n }\n }\n .", "-radio-wrapper {\n margin-right: 30px;\n margin-top: 12px;\n }\n .manual-tip {\n padding-top: 5px;\n .blue-link {\n color: #2878ff;\n }\n }\n }\n .title {\n font-size: 16px;\n font-weight: 500;\n padding-bottom: 15px;\n }\n"])), prefixCls);
var templateObject_1;