UNPKG

@bos-model-alpha/data

Version:

数据管理

203 lines (202 loc) 16.8 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, Fragment as _Fragment } from "react/jsx-runtime"; import { useState, createRef, useEffect } from 'react'; import { Input, message, Modal } from 'antd'; import { Button, Icon } from '@bos-alpha/common'; import * as api from '@bos-alpha/common/lib/services'; import styled from '@emotion/styled'; import { prefixCls } from '@bos-alpha/common'; import infoBg from '../img-base64/info-bg'; import infoIcon from '../img-base64/dingzi'; export var InfoCard = function (_a) { var curClass = _a.curClass, _b = _a.isDetail, isDetail = _b === void 0 ? false : _b, onSave = _a.onSave; var objNameIpt = createRef(); var objDescIpt = createRef(); var _c = useState(false), objNameEdit = _c[0], setObjNameEdit = _c[1]; var _d = useState(false), objDescEdit = _d[0], setObjDescEdit = _d[1]; // 编辑状态时切换类 useEffect(function () { var _a, _b; if (objNameEdit) { (_a = objNameIpt.current) === null || _a === void 0 ? void 0 : _a.setValue(curClass.type === 'doc' ? curClass.objectName : curClass.relType); } else if (objDescEdit) { (_b = objDescIpt.current) === null || _b === void 0 ? void 0 : _b.setValue(curClass.classDescription); } }, [curClass]); // eslint-disable-line react-hooks/exhaustive-deps // 修改类名称 须检查重名 var objectNameConfirm = function () { return __awaiter(void 0, void 0, void 0, function () { var value, isExist, data; return __generator(this, function (_a) { switch (_a.label) { case 0: value = objNameIpt.current.state.value; // 有修改才校验和保存 if ((curClass.type === 'doc' && curClass.objectName === value) || (curClass.type === 'edge' && curClass.relType === value)) { setObjNameEdit(false); return [2 /*return*/]; } return [4 /*yield*/, api.checkDatamodelExist({ params: { attr: curClass.type === 'doc' ? 'objectName' : 'relType', attrValue: value } })]; case 1: isExist = _a.sent(); if (isExist.exist) return [2 /*return*/, message.error("\u5DF2\u5B58\u5728\u540C\u540D".concat(curClass.type === 'doc' ? '对象名称' : '关系类型', "\uFF01"))]; data = __assign(__assign({}, curClass), (curClass.type === 'doc' ? { objectName: value } : { relType: value })); return [4 /*yield*/, api.updateDatamodel(curClass.className, { data: { classDefinition: data } })]; case 2: _a.sent(); setObjNameEdit(false); onSave && onSave(data); return [2 /*return*/]; } }); }); }; // 修改类描述 var objectDescConfirm = function () { return __awaiter(void 0, void 0, void 0, function () { var value, data; return __generator(this, function (_a) { switch (_a.label) { case 0: value = objDescIpt.current.state.value; // 有修改才保存 if (curClass.classDescription === value) { setObjDescEdit(false); return [2 /*return*/]; } data = __assign(__assign({}, curClass), { classDescription: value }); return [4 /*yield*/, api.updateDatamodel(curClass.className, { data: { classDefinition: data } })]; case 1: _a.sent(); setObjDescEdit(false); onSave && onSave(data); return [2 /*return*/]; } }); }); }; // 检验是否保存确认弹窗 var checkNotSave = function (type) { if (type === 'objName' && !objDescEdit) { setObjNameEdit(true); return; } else if (type === 'objDesc' && !objNameEdit) { setObjDescEdit(true); return; } Modal.confirm({ title: '是否保存修改的内容?', content: '当前页面存在未保存的内容,如不保存,切换视图后,未保存的内容会丢失', cancelText: '取消', okText: '确定,保存', cancelButtonProps: { shape: 'round', style: { width: '106px' } }, okButtonProps: { shape: 'round', style: { width: '106px' } }, onOk: function () { if (type === 'objName') { objectDescConfirm(); setObjNameEdit(true); } else { objectNameConfirm(); setObjDescEdit(true); } }, onCancel: function () { if (type === 'objName') { setObjDescEdit(false); setObjNameEdit(true); } else { setObjNameEdit(false); setObjDescEdit(true); } } }); }; return (_jsxs(Container, { children: [_jsx("img", { className: "bg-img", src: infoBg, alt: "" }), _jsxs("div", __assign({ className: "info-content" }, { children: [_jsx("div", __assign({ className: "info-icon" }, { children: _jsx("img", { className: "info-icon-img", src: infoIcon, alt: "" }) })), _jsx("div", __assign({ className: "class-name ".concat(isDetail ? 'detail' : 'base') }, { children: curClass === null || curClass === void 0 ? void 0 : curClass.className })), _jsx("div", __assign({ className: "class-info" }, { children: _jsxs("div", __assign({ className: "info-inner" }, { children: [_jsxs("div", __assign({ className: "info-row" }, { children: [_jsxs("label", { children: [curClass.type === 'doc' ? '对象名称' : '关系类型', "\uFF1A"] }), objNameEdit ? (_jsxs("div", __assign({ className: "edit-form" }, { children: [_jsx(Input, { ref: objNameIpt, className: "ipt", defaultValue: curClass.type === 'doc' ? curClass === null || curClass === void 0 ? void 0 : curClass.objectName : curClass.relType }), _jsx(Button, __assign({ type: "default", shape: "round", onClick: function () { return setObjNameEdit(false); } }, { children: "\u53D6\u6D88" })), _jsx(Button, __assign({ type: "primary", shape: "round", onClick: objectNameConfirm }, { children: "\u786E\u5B9A" }))] }))) : (_jsxs(_Fragment, { children: [_jsx("span", { children: curClass.type === 'doc' ? curClass === null || curClass === void 0 ? void 0 : curClass.objectName : curClass.relType }), !isDetail ? (_jsx(Icon, { onClick: function () { return checkNotSave('objName'); }, className: "edit-icon", type: "iconicon_edit" })) : null] }))] })), _jsxs("div", __assign({ className: "info-row" }, { children: [_jsxs("label", { children: [curClass.type === 'doc' ? '对象描述' : '关系描述', "\uFF1A"] }), objDescEdit ? (_jsxs("div", __assign({ className: "edit-form" }, { children: [_jsx(Input, { ref: objDescIpt, className: "ipt", defaultValue: curClass === null || curClass === void 0 ? void 0 : curClass.classDescription }), _jsx(Button, __assign({ type: "default", shape: "round", onClick: function () { return setObjDescEdit(false); } }, { children: "\u53D6\u6D88" })), _jsx(Button, __assign({ type: "primary", shape: "round", onClick: objectDescConfirm }, { children: "\u786E\u5B9A" }))] }))) : (_jsxs(_Fragment, { children: [_jsx("span", __assign({ className: isDetail ? 'info-text' : '' }, { children: curClass === null || curClass === void 0 ? void 0 : curClass.classDescription })), !isDetail ? (_jsx(Icon, { onClick: function () { return checkNotSave('objDesc'); }, className: "edit-icon", type: "iconicon_edit" })) : null] }))] }))] })) }))] }))] })); }; var Container = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n margin-top: 13px;\n position: relative;\n height: 88px;\n & > .bg-img {\n position: absolute;\n width: 100%;\n height: 100%;\n left: 0;\n top: 0;\n }\n & > .info-content {\n position: relative;\n display: flex;\n & > .info-icon {\n width: 100px;\n line-height: 88px;\n text-align: center;\n & > img {\n width: 64px;\n }\n }\n & > .class-name {\n width: 300px;\n font-size: 18px;\n font-weight: 400;\n color: #fff;\n line-height: 80px;\n text-shadow: 0 2px 2px hsl(0deg 0% 100% / 40%);\n &.detail {\n width: 200px;\n }\n }\n & > .class-info {\n flex: 1;\n padding: 8px;\n & > .info-inner {\n height: 72px;\n background: hsla(0, 0%, 100%, 0.9);\n padding: 4px 0 4px 16px;\n & > .info-row {\n font-size: 14px;\n line-height: 32px;\n color: #444;\n display: flex;\n align-items: center;\n & > label {\n color: #9ba0a7;\n margin-right: 8px;\n }\n & > .edit-icon {\n color: rgb(40, 120, 255);\n }\n & > .edit-form {\n flex: 1;\n display: flex;\n & > .ipt {\n width: 300px;\n border-radius: 4px;\n }\n & > .", "-btn {\n margin-left: 8px;\n }\n }\n & > .info-text {\n flex: 1;\n display: inline-block;\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n }\n }\n }\n }\n }\n"], ["\n margin-top: 13px;\n position: relative;\n height: 88px;\n & > .bg-img {\n position: absolute;\n width: 100%;\n height: 100%;\n left: 0;\n top: 0;\n }\n & > .info-content {\n position: relative;\n display: flex;\n & > .info-icon {\n width: 100px;\n line-height: 88px;\n text-align: center;\n & > img {\n width: 64px;\n }\n }\n & > .class-name {\n width: 300px;\n font-size: 18px;\n font-weight: 400;\n color: #fff;\n line-height: 80px;\n text-shadow: 0 2px 2px hsl(0deg 0% 100% / 40%);\n &.detail {\n width: 200px;\n }\n }\n & > .class-info {\n flex: 1;\n padding: 8px;\n & > .info-inner {\n height: 72px;\n background: hsla(0, 0%, 100%, 0.9);\n padding: 4px 0 4px 16px;\n & > .info-row {\n font-size: 14px;\n line-height: 32px;\n color: #444;\n display: flex;\n align-items: center;\n & > label {\n color: #9ba0a7;\n margin-right: 8px;\n }\n & > .edit-icon {\n color: rgb(40, 120, 255);\n }\n & > .edit-form {\n flex: 1;\n display: flex;\n & > .ipt {\n width: 300px;\n border-radius: 4px;\n }\n & > .", "-btn {\n margin-left: 8px;\n }\n }\n & > .info-text {\n flex: 1;\n display: inline-block;\n white-space: nowrap;\n text-overflow: ellipsis;\n overflow: hidden;\n }\n }\n }\n }\n }\n"])), prefixCls); var templateObject_1;