UNPKG

@bos-model-alpha/data

Version:

数据管理

163 lines (162 loc) 11.2 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 { useState, useEffect } from 'react'; import { Tree } from 'antd'; import styled from '@emotion/styled'; import * as services from '@bos-alpha/common/lib/services'; import { prefixCls } from '@bos-alpha/common'; export var LeftTree = function (_a) { var onSelect = _a.onSelect; // 已选择的节点 var _b = useState([]), selectedKeys = _b[0], setSelectedKeys = _b[1]; // 树结构 var _c = useState([]), treeData = _c[0], setTreeData = _c[1]; // 展开的节点 var _d = useState([]), expandedKeys = _d[0], setExpandedKeys = _d[1]; // 已异步加载的keys var _e = useState([]), loadedKeys = _e[0], setLoadedKeys = _e[1]; useEffect(function () { getTreeRootData(); }, []); // eslint-disable-line react-hooks/exhaustive-deps // 获取根节点 var getTreeRootData = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { Promise.all([ services.getDatamodelBaseTree('doc'), services.getDatamodelBaseTree('edge') ]).then(function (_a) { var docRes = _a[0], edgeRes = _a[1]; var list = [ { title: '对象类', key: 'doc', children: docRes.map(function (item) { return ({ title: item.classDefinition.className, key: item.classDefinition.className, isLeaf: !item.classDefinition.hasChild, info: item.classDefinition }); }) }, { title: '关系类', key: 'edge', children: edgeRes.map(function (item) { return ({ title: item.classDefinition.className, key: item.classDefinition.className, isLeaf: !item.classDefinition.hasChild, info: item.classDefinition }); }) } ]; setTreeData(list); setExpandedKeys(['doc']); // 默认选择对象类第一个 var defaultNode = docRes[0].classDefinition; onNodeSelect([defaultNode.className], { selected: true, node: { info: defaultNode } }); }); return [2 /*return*/]; }); }); }; // 展开节点 获取数据 var getTreeData = function (node) { return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () { var res, loop; return __generator(this, function (_a) { switch (_a.label) { case 0: if (node.key === 'doc' || node.key === 'edge') { resolve(); return [2 /*return*/]; } return [4 /*yield*/, services.getDatamodelChildren(node.key)]; case 1: res = _a.sent(); loop = function (list) { return list.map(function (item) { if (item.key === node.key) { return __assign(__assign({}, item), { children: res.map(function (item) { return ({ title: item.classDefinition.className, key: item.classDefinition.className, isLeaf: !item.classDefinition.hasChild, info: item.classDefinition }); }) }); } if (item.children) { return __assign(__assign({}, item), { children: loop(item.children) }); } return item; }); }; setTreeData(loop(treeData)); resolve(); return [2 /*return*/]; } }); }); }); }; // 被选中 var onNodeSelect = function (keys, _a) { var selected = _a.selected, node = _a.node; setSelectedKeys(keys); var rootKeys = ['doc', 'edge']; onSelect(selected ? (rootKeys.indexOf(node.key) >= 0 ? node : node.info) : {}); }; return (_jsxs(Container, { children: [_jsx("div", __assign({ className: "head-title" }, { children: "\u6570\u636E\u7BA1\u7406" })), _jsx("div", __assign({ className: "tree-list" }, { children: _jsx(Tree, { treeData: treeData, selectedKeys: selectedKeys, onSelect: onNodeSelect, expandedKeys: expandedKeys, onExpand: setExpandedKeys, loadData: getTreeData, loadedKeys: loadedKeys, onLoad: setLoadedKeys }) }))] })); }; var Container = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 200px;\n border-right: 1px solid #dfdfdf;\n & > .head-title {\n height: 50px;\n line-height: 50px;\n padding-left: 24px;\n color: #444;\n background-color: #fff;\n cursor: pointer;\n font-size: 14px;\n font-family: PingFangSC-Semibold, PingFang SC;\n font-weight: 600;\n border-bottom: 1px solid #e8e8e8;\n position: relative;\n }\n & > .tree-list {\n height: calc(100vh - 145px);\n overflow: auto scroll;\n .", "-tree {\n color: rgba(0, 0, 0, 0.65);\n }\n .", "-tree .", "-tree-node-content-wrapper.", "-tree-node-selected {\n color: #2878ff;\n background-color: rgba(40, 120, 255, 0.1);\n }\n &::-webkit-scrollbar {\n -webkit-appearance: none;\n }\n ::-webkit-scrollbar-track-piece {\n width: 6px;\n background-color: #eee;\n }\n &::-webkit-scrollbar:vertical {\n width: 6px;\n }\n &::-webkit-scrollbar:horizontal {\n height: 6px;\n }\n &::-webkit-scrollbar-thumb {\n border-radius: 8px;\n border: 6px solid rgba(255, 255, 255, 0.4);\n background-color: rgba(0, 0, 0, 0.5);\n }\n }\n"], ["\n width: 200px;\n border-right: 1px solid #dfdfdf;\n & > .head-title {\n height: 50px;\n line-height: 50px;\n padding-left: 24px;\n color: #444;\n background-color: #fff;\n cursor: pointer;\n font-size: 14px;\n font-family: PingFangSC-Semibold\\, PingFang SC;\n font-weight: 600;\n border-bottom: 1px solid #e8e8e8;\n position: relative;\n }\n & > .tree-list {\n height: calc(100vh - 145px);\n overflow: auto scroll;\n .", "-tree {\n color: rgba(0, 0, 0, 0.65);\n }\n .", "-tree .", "-tree-node-content-wrapper.", "-tree-node-selected {\n color: #2878ff;\n background-color: rgba(40, 120, 255, 0.1);\n }\n &::-webkit-scrollbar {\n -webkit-appearance: none;\n }\n ::-webkit-scrollbar-track-piece {\n width: 6px;\n background-color: #eee;\n }\n &::-webkit-scrollbar:vertical {\n width: 6px;\n }\n &::-webkit-scrollbar:horizontal {\n height: 6px;\n }\n &::-webkit-scrollbar-thumb {\n border-radius: 8px;\n border: 6px solid rgba(255, 255, 255, 0.4);\n background-color: rgba(0, 0, 0, 0.5);\n }\n }\n"])), prefixCls, prefixCls, prefixCls, prefixCls); var templateObject_1;