UNPKG

@riil-frontend/component-page-config

Version:

page config components,include components list,component attribute panel and page canvas

338 lines (302 loc) 9.92 kB
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _extends from "@babel/runtime/helpers/extends"; import React from 'react'; import { getUUID } from '@riil-frontend/utils'; import _ from 'lodash'; import { CONTAINER_COM_TYPE } from './constant'; import Template from './uicbb-container/index'; import MicroCom from './micro'; import NoDataCom from '@riil-frontend/component-no-data-page'; var NoComPage = function NoComPage() { return /*#__PURE__*/React.createElement(NoDataCom, { statusCode: "\u6B64\u7EC4\u4EF6\u4E0D\u5B58\u5728" }); }; export var getComRequire = function getComRequire(comName, comDict, customGetComRequire) { if (customGetComRequire === void 0) { customGetComRequire = undefined; } if (comName === 'uicbb-container') { return Template; } if (customGetComRequire) { return customGetComRequire(comName, comDict); } var dict = comDict[comName]; var importFrom = dict === null || dict === void 0 ? void 0 : dict.importFrom; if (importFrom) { if (importFrom === 'micro') { try { return MicroCom; } catch (error) { console.error("\u4E1A\u52A1\u7EC4\u4EF6npm\u5305\u96C6\u5408\u4E2D\u4E0D\u5B58\u5728" + comName + "\u7EC4\u4EF6\uFF0C\u8BF7\u786E\u4FDDnpm\u5305\u4EE5@riil-uicbb/\u5F00\u5934\uFF0C\u5E76\u5DF2\u5B89\u88C5\u5230\u5DE5\u7A0B\u4E2D"); return NoComPage; } } else { try { return MicroCom; } catch (error) { console.error("\u4E1A\u52A1\u7EC4\u4EF6npm\u5305\u96C6\u5408\u4E2D\u4E0D\u5B58\u5728" + comName + "\u7EC4\u4EF6\uFF0C\u8BF7\u786E\u4FDDnpm\u5305\u4EE5@riil-uicbb/\u5F00\u5934\uFF0C\u5E76\u5DF2\u5B89\u88C5\u5230\u5DE5\u7A0B\u4E2D"); return NoComPage; } } } else { return NoComPage; } }; export var getBaseAttributes = function getBaseAttributes() { return _.cloneDeep({ paddingLeft: 6, paddingTop: 6, paddingRight: 6, paddingBottom: 6 }); }; /** * 撑满外层容器高度功能 * 根据pageConfig.layoutConfig.isFitHeight 和 parentDOM 和是否是编辑模式 判定是否执行适配高度操作 * 此操作会改写pageConfig.widgets中每个组件配置数据layouts.h layouts.y * @param {*} pageConfig * @param {*} parentDOM * @param {*} isEdit * @returns -pageConfig */ export var fitHeight = function fitHeight(pageConfig, parentDOM, isEdit) { var widgets = pageConfig.widgets; var isFitHeight = pageConfig.layoutConfig && pageConfig.layoutConfig.isFitHeight; if (!parentDOM || !isFitHeight || isEdit) { return pageConfig; } var rowH = pageConfig.layoutConfig.rowHeight; var domH = parentDOM.offsetHeight; var bottoms = []; widgets.forEach(function (item) { var _item$layouts = item.layouts, y = _item$layouts.y, h = _item$layouts.h; bottoms.push(y + h); }); var maxHeight = Math.max.apply(Math, bottoms); var scale = domH / (maxHeight * rowH); var _widgets = widgets.map(function (item) { var _item$layouts2 = item.layouts, y = _item$layouts2.y, h = _item$layouts2.h; var _y = Math.floor(y * scale * rowH) / rowH; var _h = Math.floor(h * scale * rowH) / rowH; return _extends({}, item, { layouts: _extends({}, item.layouts, { y: _y, h: _h }) }); }); return _extends({}, pageConfig, { widgets: _widgets }); }; export var dispatchResizeEvent = function dispatchResizeEvent(time) { if (time === void 0) { time = 1000; } if (!window.uicbbResizeEvent) { window.uicbbResizeEvent = document.createEvent('HTMLEvents'); window.uicbbResizeEvent.initEvent('resize', true, true); } setTimeout(function () { window.uicbbResizeEvent && window.dispatchEvent(window.uicbbResizeEvent); }, time); }; export var validateToPromis = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(valid) { var promise, pageResult; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: if (!valid) { _context.next = 8; break; } promise = function promise() { return new Promise(function (resolve, reject) { valid(null, function (errors) { resolve(errors); }); }); }; _context.next = 4; return promise(); case 4: pageResult = _context.sent; return _context.abrupt("return", pageResult); case 8: return _context.abrupt("return", null); case 9: case "end": return _context.stop(); } } }, _callee); })); return function validateToPromis(_x) { return _ref.apply(this, arguments); }; }(); /** * 查找包含指定组件的pageId * @param {object} pageconfig * @returns */ export var findComPageByType = function findComPageByType(pageconfig, comType) { var targetIndex = -1; var target = pageconfig.configs.find(function (item, index) { var targetCom = item.widgets.find(function (ele) { return ele.type === comType; }); if (!!targetCom) { targetIndex = index; } return !!targetCom; }); if (target) { return { fixId: target.pageId, fixIndex: targetIndex }; } else { return { fixId: null, fixIndex: targetIndex }; } }; /** * 查找匹配pageId页签 * @param {*} pageconfig * @param {*} pageId * @returns */ export var findComPageByPageId = function findComPageByPageId(pageconfig, pageId) { var targetIndex = -1; var target = pageconfig.configs.find(function (item, index) { if (item.pageId === pageId) { targetIndex = index; return true; } else { return false; } }); if (target) { return { fixId: target.pageId, fixIndex: targetIndex }; } else { return { fixId: null, fixIndex: targetIndex }; } }; /** * 重新给模板赋值id * @param {object} template */ export var templateReId = function templateReId(template, pageId) { var newTemplate = _.cloneDeep(template); newTemplate.pageId = pageId; newTemplate.widgets.forEach(function (item) { var newId = getUUID(); item.id = newId; item.layouts.i = newId; }); return newTemplate; }; /** * 绘制格子背景 * @param {*} param0 -格子线样式入参配置 * @param {*} isAbs -是否绝对布局 * @returns */ export var getGridBackgroundStyle = function getGridBackgroundStyle(_ref2, isAbs) { var line1Color = _ref2.line1Color, line1Size = _ref2.line1Size, line2Color = _ref2.line2Color, line2Size = _ref2.line2Size, line1W = _ref2.line1W, line1H = _ref2.line1H, line2W = _ref2.line2W, line2H = _ref2.line2H; if (isAbs === void 0) { isAbs = true; } return isAbs ? { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, borderBottom: line1Size + " inset " + line1Color, borderRight: line1Size + " inset " + line1Color, backgroundImage: "linear-gradient(180deg," + line1Color + " " + line1Size + ", transparent 0),linear-gradient(90deg," + line1Color + " " + line1Size + ", transparent 0),linear-gradient(0deg," + line2Color + " " + line2Size + ", transparent 0), linear-gradient(90deg," + line2Color + " " + line2Size + ", transparent 0)", backgroundSize: line1W + " " + line1H + "," + line1W + " " + line1H + "," + line2W + " " + line2H + "," + line2W + " " + line2H } : { borderBottom: line1Size + " inset " + line1Color, borderRight: line1Size + " inset " + line1Color, backgroundImage: "linear-gradient(180deg," + line1Color + " " + line1Size + ", transparent 0),linear-gradient(90deg," + line1Color + " " + line1Size + ", transparent 0),linear-gradient(0deg," + line2Color + " " + line2Size + ", transparent 0), linear-gradient(90deg," + line2Color + " " + line2Size + ", transparent 0)", backgroundSize: line1W + " " + line1H + "," + line1W + " " + line1H + "," + line2W + " " + line2H + "," + line2W + " " + line2H }; }; export var fixWidget = function fixWidget(wd) { var category = wd.category, createdAt = wd.createdAt, icon = wd.icon, importFrom = wd.importFrom, module = wd.module, name = wd.name, path = wd.path, status = wd.status, title = wd.title, updatedAt = wd.updatedAt, version = wd.version, other = _objectWithoutPropertiesLoose(wd, ["category", "createdAt", "icon", "importFrom", "module", "name", "path", "status", "title", "updatedAt", "version"]); return other; }; /** * 组件字典数据转换 * @param {Array} dict * @returns */ export var convertComDictList = function convertComDictList(dict) { var newDictList = dict.map(function (ele) { var _ele$config = ele.config, icon = _ele$config.icon, path = _ele$config.path, importFrom = _ele$config.importFrom, other = _objectWithoutPropertiesLoose(_ele$config, ["icon", "path", "importFrom"]); return _extends({}, ele, { icon: icon, path: path, importFrom: importFrom, config: other }); }); var comDict = {}; newDictList.forEach(function (ele) { comDict[ele.type] = ele; }); return { dictList: newDictList, dictObj: comDict }; }; export var checkVisibility = function checkVisibility(dom) { if (dom === null || dom === void 0 ? void 0 : dom.checkVisibility) { return dom.checkVisibility(); } else { return dom.offsetWidth > 0 && dom.offsetHeight > 0; } };