@bos-alpha/data
Version:
数据管理
432 lines (431 loc) • 23.6 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 };
}
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useEffect, useState, useRef } from 'react';
import { Button, Select, Checkbox, Form, message, Table } from 'antd';
import { Modal, uuid, prefixCls } from '@bos-alpha/common';
import * as api from '@bos-alpha/common/lib/services';
import { SearchInput } from './search-input';
import styled from '@emotion/styled';
import relIcon from '../../assets/data-relation-icon.png';
var operatorOptions = [
{
value: '==',
label: '=='
},
{
value: '!=',
label: '!='
},
{
value: '<',
label: '<'
},
{
value: '<=',
label: '<='
},
{
value: '>',
label: '>'
},
{
value: '>=',
label: '>='
},
{
value: 'like',
label: 'like'
}
];
var logicOprions = [
{
label: 'AND',
value: 'And'
},
{
label: 'OR',
value: 'Or'
}
];
var tableDataInit = function () {
var list = [];
list.push({
key: uuid(),
type: 'formItem'
});
list.push({
key: uuid(),
type: 'addBtn'
});
return list;
};
/**
* 批量创建关联关系
*/
export var EdgeBatch = function (_a) {
var onConfirm = _a.onConfirm;
// 是否弹窗
var _b = useState(false), visible = _b[0], setVisible = _b[1];
// 是否覆盖当前关联关系数据
var _c = useState(false), isUpdate = _c[0], setIsUpdate = _c[1];
// 是否正在请求中
var _d = useState(false), fetching = _d[0], setFetching = _d[1];
// 所有对象类
var _e = useState([]), docList = _e[0], setDocList = _e[1];
// 已选择的左对象
var _f = useState(''), leftClass = _f[0], setLeftClass = _f[1];
// 已选择的右对象
var _g = useState(''), rightClass = _g[0], setRightClass = _g[1];
// 所有关系类
var _h = useState([]), edgeList = _h[0], setEdgeList = _h[1];
// 左对象所有属性对象
var _j = useState([]), leftAttrList = _j[0], setLeftAttrList = _j[1];
var leftAttrs = useRef([]);
// 右对象所有属性字段
var _k = useState([]), rightAttrList = _k[0], setRightAttrList = _k[1];
var rightAttrs = useRef([]);
// 匹配列表
var _l = useState(tableDataInit()), conditions = _l[0], setConditions = _l[1];
var form = Form.useForm()[0];
useEffect(function () {
if (!visible)
return;
form.resetFields();
fetchData();
}, [visible]); // eslint-disable-line
// 选择左右对象 清空关系类
useEffect(function () {
form.resetFields(['className']);
}, [leftClass, rightClass]); // eslint-disable-line
// 获取所有关系类
var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
var _a, docRes, edgeRes;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, Promise.all([
api.getDatamodelBaseTree('doc'),
api.getDatamodelBaseTree('edge')
])];
case 1:
_a = _b.sent(), docRes = _a[0], edgeRes = _a[1];
setDocList((docRes || []).map(function (item) { return (__assign(__assign({}, item.classDefinition), { label: item.classDefinition.objectName
? "".concat(item.classDefinition.className, "\uFF08").concat(item.classDefinition.objectName, "\uFF09")
: item.classDefinition.className, value: item.classDefinition.className })); }));
setEdgeList((edgeRes || []).map(function (item) { return (__assign(__assign({}, item.classDefinition), { label: item.classDefinition.relType
? "".concat(item.classDefinition.className, "\uFF08").concat(item.classDefinition.relType, "\uFF09")
: item.classDefinition.className, value: item.classDefinition.className })); }));
setLeftClass('');
setRightClass('');
return [2 /*return*/];
}
});
}); };
// 选中关系类 查询左右对象属性字段
var onClassSelected = function (value) { return __awaiter(void 0, void 0, void 0, function () {
var option, _a, leftRes, rightRes;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
option = edgeList.find(function (item) { return item.className === value; });
return [4 /*yield*/, Promise.all([
api.getDatamodelDetail(option.leftObjectClass),
api.getDatamodelDetail(option.rightObjectClass)
])];
case 1:
_a = _b.sent(), leftRes = _a[0], rightRes = _a[1];
leftAttrs.current = (leftRes.attributes || [])
.filter(function (_a) {
var code = _a.code;
return code !== 'bosclass';
})
.map(function (_a) {
var code = _a.code, description = _a.description;
return ({
value: code,
label: description ? "".concat(code, "\uFF08").concat(description, "\uFF09") : code
});
});
rightAttrs.current = (rightRes.attributes || [])
.filter(function (_a) {
var code = _a.code;
return code !== 'bosclass';
})
.map(function (_a) {
var code = _a.code, description = _a.description;
return ({
value: code,
label: description ? "".concat(code, "\uFF08").concat(description, "\uFF09") : code
});
});
setLeftAttrList(leftAttrs.current);
setRightAttrList(rightAttrs.current);
form.setFieldsValue({ logic_0: 'And' });
form.resetFields(['from_0', 'operator_0', 'to_0']);
return [2 /*return*/];
}
});
}); };
// 确定
var onSubmit = function () { return __awaiter(void 0, void 0, void 0, function () {
var vals, curEdge, conditionAll, res, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, form.validateFields()];
case 1:
vals = _a.sent();
curEdge = edgeList.find(function (item) { return item.className === vals.className; });
conditionAll = conditions
.filter(function (_a) {
var type = _a.type;
return type !== 'addBtn';
})
.map(function (item, index) {
return {
from: vals["from_".concat(index)],
operator: vals["operator_".concat(index)],
to: vals["to_".concat(index)],
logic: vals["logic_".concat(index)],
number: 'false'
};
});
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 5]);
if (fetching)
return [2 /*return*/];
setFetching(true);
return [4 /*yield*/, api.byMapping({
data: {
updateType: isUpdate ? 'replace' : 'ignore',
relationship: {
bosclass: 'irTagWbs',
condition: conditionAll
},
from: {
bosclass: curEdge.leftObjectClass
},
to: {
bosclass: curEdge.rightObjectClass
}
}
}, {
noErrorHandle: true
})];
case 3:
res = _a.sent();
setFetching(false);
if (res.code === 'SUCCESS') {
message.success('关联关系创建成功!');
// onConfirm && onConfirm();
return [2 /*return*/];
}
if (res.code === 'OBJECT_FIELD_DATA_WRONG') {
if (/to/.test(res.message)) {
return [2 /*return*/, message.info('右对象属性填写错误')];
}
else if (/from/.test(res.message)) {
return [2 /*return*/, message.info('左对象属性填写错误')];
}
return [2 /*return*/, message.error(res.message)];
}
return [3 /*break*/, 5];
case 4:
err_1 = _a.sent();
if (err_1.code === 'INTERNAL_ERROR') {
message.error('查询超时');
}
else {
message.error(err_1.message);
}
setFetching(false);
return [3 /*break*/, 5];
case 5: return [2 /*return*/];
}
});
}); };
// 校验属性函数是否合法
var checkAttrFunc = function (rule, val, msg) {
if (!val || val.trim() === '') {
return Promise.reject(msg);
}
else if (/^CONCAT\(/.test(val) &&
!/^CONCAT\((\w+,)+(\w+\))$/.test(val)) {
return Promise.reject('请输入正确的CONCAT函数');
}
else if (/^CONCAT_SEPARATOR\(/.test(val) &&
!/^CONCAT_SEPARATOR\('.*',(\w+,)+(\w+\))$/.test(val)) {
return Promise.reject('请输入正确的CONCAT_SEPARATOR函数');
}
return Promise.resolve();
};
var columns = [
{
dataIndex: 'from',
title: '左对象属性',
width: 300,
render: function (_, record, index) {
return record.type !== 'addBtn' ? (_jsx(Form.Item, __assign({ name: "from_".concat(index), rules: [
{
validator: function (rule, val) {
return checkAttrFunc(rule, val, '请选择左对象属性');
}
}
] }, { children: _jsx(SearchInput, { options: leftAttrList, placeholder: "\u8BF7\u9009\u62E9\u5DE6\u5BF9\u8C61\u5C5E\u6027" }, void 0) }), void 0)) : (_jsx(Button, __assign({ type: "link", style: { height: 'inherit', padding: 0 }, onClick: function () {
setConditions(__spreadArray(__spreadArray([], conditions.filter(function (_a) {
var type = _a.type;
return type !== 'addBtn';
}), true), tableDataInit(), true));
} }, { children: "\u65B0\u5EFA..." }), void 0));
}
},
{
dataIndex: 'operator',
title: '关系',
width: 80,
render: function (_, record, index) {
return record.type !== 'addBtn' ? (_jsx(Form.Item, __assign({ name: "operator_".concat(index), rules: [
{
required: true,
message: '请选择关系'
}
] }, { children: _jsx(Select, { options: operatorOptions, placeholder: "\u5173\u7CFB", style: { width: '80px' } }, void 0) }), void 0)) : ('');
}
},
{
dataIndex: 'to',
title: '右对象属性',
width: 300,
render: function (_, record, index) {
return record.type !== 'addBtn' ? (_jsx(Form.Item, __assign({ name: "to_".concat(index), rules: [
{
validator: function (rule, val) {
return checkAttrFunc(rule, val, '请选择右对象属性');
}
}
] }, { children: _jsx(SearchInput, { options: rightAttrList, placeholder: "\u8BF7\u9009\u62E9\u53F3\u5BF9\u8C61\u5C5E\u6027" }, void 0) }), void 0)) : ('');
}
},
{
dataIndex: 'logic',
title: '连接条件',
width: 100,
render: function (_, record, index) {
return record.type !== 'addBtn' ? (_jsx(Form.Item, __assign({ name: "logic_".concat(index), rules: [
{
required: true,
message: '请选择连接条件'
}
] }, { children: _jsx(Select, { options: logicOprions, placeholder: "\u8FDE\u63A5\u6761\u4EF6", style: { width: '100px' } }, void 0) }), void 0)) : ('');
}
},
{
dataIndex: 'option',
title: '操作',
width: 50,
render: function (_, record) {
return record.type !== 'addBtn' ? (_jsx(Button, __assign({ type: "link", style: { padding: '0 0 8px 0' }, onClick: function () {
if (conditions.length === 2) {
form.setFieldsValue({ logic_0: 'And' });
form.resetFields([
'from_0',
'operator_0',
'to_0'
]);
return;
}
setConditions(conditions.filter(function (_a) {
var key = _a.key;
return key !== record.key;
}));
} }, { children: "\u5220\u9664" }), void 0)) : ('');
}
}
];
return (_jsxs(_Fragment, { children: [_jsxs("span", __assign({ className: "func-btn", onClick: function () { return setVisible(true); } }, { children: [_jsx("img", { className: "icon", src: relIcon, alt: "" }, void 0), "\u6279\u91CF\u521B\u5EFA\u5173\u8054\u5173\u7CFB"] }), void 0), _jsx(Modal, __assign({ width: 900, title: "\u6279\u91CF\u521B\u5EFA\u5173\u8054\u5173\u7CFB", visible: visible, maskClosable: false, onCancel: function () { return setVisible(false); }, confirmLoading: fetching, centered: false, onOk: function () { return onSubmit(); } }, { children: _jsxs(Container, { children: [_jsxs(Form, __assign({ form: form, labelCol: { span: 3 }, labelAlign: "left" }, { children: [_jsx("div", __assign({ className: "title" }, { children: "\u9009\u62E9\u5BF9\u8C61\u7C7B\u548C\u5173\u7CFB\u7C7B" }), void 0), _jsxs("div", __assign({ className: "class-select" }, { children: [_jsx(Form.Item, __assign({ label: "\u5DE6\u5BF9\u8C61\u7C7B", name: "leftClassName", rules: [
{
required: true,
message: '请选择左对象类'
}
] }, { children: _jsx(Select, __assign({ onChange: setLeftClass, placeholder: "\u8BF7\u9009\u62E9\u5173\u7CFB\u7C7B", style: { width: '400px' } }, { children: docList.map(function (item) { return (_jsx(Select.Option, __assign({ value: item.value }, { children: item.label }), item.value)); }) }), void 0) }), void 0), _jsx(Form.Item, __assign({ label: "\u53F3\u5BF9\u8C61\u7C7B", name: "rightClassName", rules: [
{
required: true,
message: '请选择右对象类'
}
] }, { children: _jsx(Select, __assign({ onChange: setRightClass, placeholder: "\u8BF7\u9009\u62E9\u53F3\u5BF9\u8C61\u7C7B", style: { width: '400px' } }, { children: docList.map(function (item) { return (_jsx(Select.Option, __assign({ value: item.value, disabled: item.value === leftClass }, { children: item.label }), item.value)); }) }), void 0) }), void 0), _jsx(Form.Item, __assign({ label: "BOS\u5173\u7CFB\u7C7B", name: "className", rules: [
{
required: true,
message: '请选择关系类'
}
] }, { children: _jsx(Select, __assign({ onChange: onClassSelected, placeholder: "\u8BF7\u9009\u62E9\u5173\u7CFB\u7C7B", style: { width: '400px' } }, { children: edgeList
.filter(function (item) {
return item.leftObjectClass ===
leftClass &&
item.rightObjectClass ===
rightClass;
})
.map(function (item) { return (_jsx(Select.Option, __assign({ value: item.value, disabled: !(item.leftObjectClass ===
leftClass &&
item.rightObjectClass ===
rightClass) }, { children: item.label }), item.value)); }) }), void 0) }), void 0)] }), void 0), _jsx("div", __assign({ className: "title" }, { children: "\u5C5E\u6027\u5339\u914D" }), void 0), _jsx(Table, { size: "small", bordered: true, dataSource: conditions, columns: columns, pagination: false }, void 0)] }), void 0), _jsx("div", __assign({ className: "title" }, { children: "\u8BBE\u7F6E" }), void 0), _jsx("div", __assign({ className: "checkbox" }, { children: _jsx(Checkbox, __assign({ checked: isUpdate, onChange: function (e) { return setIsUpdate(e.target.checked); } }, { children: "\u66F4\u65B0\u5DF2\u7ECF\u5B58\u5728\u7684\u5BF9\u8C61\u7C7B\u6570\u636E" }), void 0) }), void 0)] }, void 0) }), void 0)] }, void 0));
};
var Container = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n .title {\n font-size: 16px;\n font-weight: 700;\n padding: 15px 0;\n }\n .", "-table {\n .", "-table-tbody > tr.", "-table-row:hover > td {\n background: none;\n }\n .", "-form-item {\n margin-bottom: 8px;\n .", "-form-item-explain {\n position: absolute;\n bottom: -20px;\n }\n }\n }\n"], ["\n .title {\n font-size: 16px;\n font-weight: 700;\n padding: 15px 0;\n }\n .", "-table {\n .", "-table-tbody > tr.", "-table-row:hover > td {\n background: none;\n }\n .", "-form-item {\n margin-bottom: 8px;\n .", "-form-item-explain {\n position: absolute;\n bottom: -20px;\n }\n }\n }\n"])), prefixCls, prefixCls, prefixCls, prefixCls, prefixCls);
var templateObject_1;