Showing
36 changed files
with
3477 additions
and
431 deletions
Too many changes to show.
To preserve performance only 36 of 112 files are displayed.
es/core/RenderChildren/RenderList/icon.js
0 → 100644
| 1 | +import { createFromIconfontCN } from '@ant-design/icons/lib'; | |
| 2 | +/** | |
| 3 | + * 使用: | |
| 4 | + * import QxIcon from '@/packages/qx-icon'; | |
| 5 | + * <QxIcon type="xxx"/> | |
| 6 | + * 说明: | |
| 7 | + * `xxx`为图标唯一标识,`iconfont.cn`对应图标下的“复制代码”所得,建议命名为“icon-xxx_yyy”, | |
| 8 | + * “icon-”为固定前缀,xxx为模块类型,yyy为图标名。公共类的xxx命名为“comm” | |
| 9 | + * eg: <QxIcon type="icon-flow_eye"/> | |
| 10 | + * | |
| 11 | + * @type {React.FC<IconFontProps<string>>} | |
| 12 | + */ | |
| 13 | + | |
| 14 | +var QxIcon = createFromIconfontCN({ | |
| 15 | + scriptUrl: 'https://lf1-cdn-tos.bytegoofy.com/obj/iconpark/icons_13749_95.b05de9dc2fbe8efffb150f83b64da806.es5.js' | |
| 16 | +}); | |
| 17 | +export default QxIcon; | |
| \ No newline at end of file | ... | ... |
es/core/RenderField/Title.js
deleted
100644 → 0
| 1 | -import React from 'react'; | |
| 2 | -import { useStore2 } from '../../hooks'; | |
| 3 | -import { isCheckBoxType } from '../../utils'; | |
| 4 | - | |
| 5 | -var Description = function Description(_ref) { | |
| 6 | - var displayType = _ref.displayType, | |
| 7 | - schema = _ref.schema; | |
| 8 | - var description = schema.description, | |
| 9 | - descType = schema.descType; | |
| 10 | - if (!description) return null; | |
| 11 | - | |
| 12 | - switch (displayType) { | |
| 13 | - case 'row': | |
| 14 | - return /*#__PURE__*/React.createElement("span", { | |
| 15 | - className: "fr-tooltip-toggle", | |
| 16 | - "aria-label": description | |
| 17 | - }, /*#__PURE__*/React.createElement("i", { | |
| 18 | - className: "fr-tooltip-icon" | |
| 19 | - }), /*#__PURE__*/React.createElement("div", { | |
| 20 | - className: "fr-tooltip-container" | |
| 21 | - }, /*#__PURE__*/React.createElement("i", { | |
| 22 | - className: "fr-tooltip-triangle" | |
| 23 | - }), description)); | |
| 24 | - | |
| 25 | - case 'inline': | |
| 26 | - return null; | |
| 27 | - | |
| 28 | - default: | |
| 29 | - if (descType === 'icon') { | |
| 30 | - return /*#__PURE__*/React.createElement("span", { | |
| 31 | - className: "fr-tooltip-toggle", | |
| 32 | - "aria-label": description | |
| 33 | - }, /*#__PURE__*/React.createElement("i", { | |
| 34 | - className: "fr-tooltip-icon" | |
| 35 | - }), /*#__PURE__*/React.createElement("div", { | |
| 36 | - className: "fr-tooltip-container" | |
| 37 | - }, /*#__PURE__*/React.createElement("i", { | |
| 38 | - className: "fr-tooltip-triangle" | |
| 39 | - }), description)); | |
| 40 | - } | |
| 41 | - | |
| 42 | - return /*#__PURE__*/React.createElement("span", { | |
| 43 | - className: "fr-desc ml2" | |
| 44 | - }, "( ".concat(description, " )")); | |
| 45 | - } | |
| 46 | -}; | |
| 47 | - | |
| 48 | -var Title = function Title(_ref2) { | |
| 49 | - var labelClass = _ref2.labelClass, | |
| 50 | - labelStyle = _ref2.labelStyle, | |
| 51 | - schema = _ref2.schema, | |
| 52 | - displayType = _ref2.displayType; | |
| 53 | - | |
| 54 | - var _useStore = useStore2(), | |
| 55 | - globalDisplayType = _useStore.displayType, | |
| 56 | - readOnly = _useStore.readOnly; | |
| 57 | - | |
| 58 | - var title = schema.title, | |
| 59 | - required = schema.required, | |
| 60 | - type = schema.type; | |
| 61 | - var isObjType = type === 'object'; | |
| 62 | - | |
| 63 | - var _displayType = schema.displayType || displayType || globalDisplayType || 'column'; | |
| 64 | - | |
| 65 | - return /*#__PURE__*/React.createElement("div", { | |
| 66 | - className: labelClass, | |
| 67 | - style: labelStyle | |
| 68 | - }, title ? /*#__PURE__*/React.createElement("label", { | |
| 69 | - className: "fr-label-title ".concat(isCheckBoxType(schema, readOnly) || _displayType === 'column' ? 'no-colon' : '') // checkbox不带冒号 | |
| 70 | - , | |
| 71 | - title: title | |
| 72 | - }, required === true && /*#__PURE__*/React.createElement("span", { | |
| 73 | - className: "fr-label-required" | |
| 74 | - }, " *"), /*#__PURE__*/React.createElement("span", { | |
| 75 | - className: "".concat(isObjType ? 'b' : '', " ").concat(_displayType === 'column' ? 'flex-none' : '') | |
| 76 | - }, /*#__PURE__*/React.createElement("span", { | |
| 77 | - dangerouslySetInnerHTML: { | |
| 78 | - __html: title | |
| 79 | - } | |
| 80 | - })), /*#__PURE__*/React.createElement(Description, { | |
| 81 | - schema: schema, | |
| 82 | - displayType: _displayType | |
| 83 | - })) : null); | |
| 84 | -}; | |
| 85 | - | |
| 86 | -export default Title; | |
| \ No newline at end of file |
es/form-render-core/src/Watcher.js
0 → 100644
| 1 | +/* eslint-disable react-hooks/exhaustive-deps */ | |
| 2 | +import { useEffect } from 'react'; | |
| 3 | +import { getValueByPath } from './utils'; | |
| 4 | + | |
| 5 | +var Watcher = function Watcher(_ref) { | |
| 6 | + var watchKey = _ref.watchKey, | |
| 7 | + watch = _ref.watch, | |
| 8 | + formData = _ref.formData, | |
| 9 | + firstMount = _ref.firstMount; | |
| 10 | + var value = getValueByPath(formData, watchKey); | |
| 11 | + var watchObj = watch[watchKey]; | |
| 12 | + useEffect(function () { | |
| 13 | + var runWatcher = function runWatcher() { | |
| 14 | + if (typeof watchObj === 'function') { | |
| 15 | + try { | |
| 16 | + watchObj(value); | |
| 17 | + } catch (error) { | |
| 18 | + console.log("".concat(watchKey, "\u5BF9\u5E94\u7684watch\u51FD\u6570\u6267\u884C\u62A5\u9519\uFF1A"), error); | |
| 19 | + } | |
| 20 | + } else if (watchObj && typeof watchObj.handler === 'function') { | |
| 21 | + try { | |
| 22 | + watchObj.handler(value); | |
| 23 | + } catch (error) { | |
| 24 | + console.log("".concat(watchKey, "\u5BF9\u5E94\u7684watch\u51FD\u6570\u6267\u884C\u62A5\u9519\uFF1A"), error); | |
| 25 | + } | |
| 26 | + } | |
| 27 | + }; | |
| 28 | + | |
| 29 | + if (firstMount) { | |
| 30 | + var immediate = watchObj && watchObj.immediate; | |
| 31 | + | |
| 32 | + if (immediate) { | |
| 33 | + runWatcher(); | |
| 34 | + } | |
| 35 | + } else { | |
| 36 | + runWatcher(); | |
| 37 | + } | |
| 38 | + }, [JSON.stringify(value), firstMount]); | |
| 39 | + return null; | |
| 40 | +}; | |
| 41 | + | |
| 42 | +export default Watcher; | |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/atom.css
renamed from
es/atom.css
| ... | ... | @@ -1066,7 +1066,7 @@ |
| 1066 | 1066 | outline: 1px solid black; |
| 1067 | 1067 | } |
| 1068 | 1068 | .fr-container .debug-grid { |
| 1069 | - background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVR4AWPAC97/9x0eCsAEPgwAVLshdpENIxcAAAAASUVORK5CYII= ) repeat top left; | |
| 1069 | + background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVR4AWPAC97/9x0eCsAEPgwAVLshdpENIxcAAAAASUVORK5CYII=) repeat top left; | |
| 1070 | 1070 | } |
| 1071 | 1071 | .fr-container .truncate { |
| 1072 | 1072 | white-space: nowrap; | ... | ... |
es/form-render-core/src/connectForm.js
renamed from
es/connectForm.js
es/form-render-core/src/core/RenderChildren/RenderList/CardList.js
renamed from
es/core/RenderChildren/RenderList/CardList.js
| 1 | 1 | import "antd/es/button/style"; |
| 2 | 2 | import _Button from "antd/es/button"; |
| 3 | -import "antd/es/space/style"; | |
| 4 | -import _Space from "antd/es/space"; | |
| 5 | -import _ArrowDownOutlined from "@ant-design/icons/es/icons/ArrowDownOutlined"; | |
| 6 | -import _ArrowUpOutlined from "@ant-design/icons/es/icons/ArrowUpOutlined"; | |
| 7 | -import _CopyOutlined from "@ant-design/icons/es/icons/CopyOutlined"; | |
| 8 | 3 | import "antd/es/popconfirm/style"; |
| 9 | 4 | import _Popconfirm from "antd/es/popconfirm"; |
| 10 | -import _DeleteOutlined from "@ant-design/icons/es/icons/DeleteOutlined"; | |
| 5 | +import _CloseOutlined from "@ant-design/icons/es/icons/CloseOutlined"; | |
| 6 | +import _CopyOutlined from "@ant-design/icons/es/icons/CopyOutlined"; | |
| 7 | +import _ArrowDownOutlined from "@ant-design/icons/es/icons/ArrowDownOutlined"; | |
| 8 | +import _ArrowUpOutlined from "@ant-design/icons/es/icons/ArrowUpOutlined"; | |
| 11 | 9 | |
| 12 | 10 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } |
| 13 | 11 | |
| ... | ... | @@ -19,8 +17,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope |
| 19 | 17 | |
| 20 | 18 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } |
| 21 | 19 | |
| 22 | -/* eslint-disable jsx-a11y/anchor-is-valid */ | |
| 23 | 20 | import React from 'react'; |
| 21 | +import { useTools } from '../../../hooks'; | |
| 24 | 22 | import Core from '../../index'; |
| 25 | 23 | |
| 26 | 24 | var CardList = function CardList(_ref) { |
| ... | ... | @@ -38,16 +36,33 @@ var CardList = function CardList(_ref) { |
| 38 | 36 | getFieldsProps = _ref.getFieldsProps; |
| 39 | 37 | var _schema$props = schema.props, |
| 40 | 38 | props = _schema$props === void 0 ? {} : _schema$props, |
| 41 | - itemProps = schema.itemProps; | |
| 39 | + itemProps = schema.itemProps, | |
| 40 | + _schema$min = schema.min, | |
| 41 | + min = _schema$min === void 0 ? 0 : _schema$min, | |
| 42 | + _schema$max = schema.max, | |
| 43 | + max = _schema$max === void 0 ? 9999 : _schema$max; | |
| 44 | + | |
| 45 | + var _useTools = useTools(), | |
| 46 | + methods = _useTools.methods; | |
| 47 | + | |
| 42 | 48 | var addBtnProps = { |
| 43 | 49 | type: 'dashed', |
| 44 | 50 | children: '新增一条' |
| 45 | 51 | }; |
| 52 | + var delConfirmProps = { | |
| 53 | + title: '确定删除?', | |
| 54 | + okText: '确定', | |
| 55 | + cancelText: '取消' | |
| 56 | + }; | |
| 46 | 57 | |
| 47 | 58 | if (props.addBtnProps && _typeof(props.addBtnProps) === 'object') { |
| 48 | 59 | addBtnProps = _objectSpread(_objectSpread({}, addBtnProps), props.addBtnProps); |
| 49 | 60 | } |
| 50 | 61 | |
| 62 | + if (props.delConfirmProps && _typeof(props.delConfirmProps) === 'object') { | |
| 63 | + delConfirmProps = _objectSpread(_objectSpread({}, delConfirmProps), props.delConfirmProps); | |
| 64 | + } | |
| 65 | + | |
| 51 | 66 | return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { |
| 52 | 67 | className: "fr-card-list" |
| 53 | 68 | }, displayList.map(function (item, idx) { |
| ... | ... | @@ -58,51 +73,60 @@ var CardList = function CardList(_ref) { |
| 58 | 73 | key: idx |
| 59 | 74 | }, /*#__PURE__*/React.createElement("div", { |
| 60 | 75 | className: "fr-card-index" |
| 61 | - }, idx + 1), /*#__PURE__*/React.createElement(Core, fieldsProps), /*#__PURE__*/React.createElement(_Space, { | |
| 76 | + }, idx + 1), /*#__PURE__*/React.createElement(Core, fieldsProps), /*#__PURE__*/React.createElement("div", { | |
| 62 | 77 | direction: "horizontal", |
| 63 | 78 | className: "fr-card-toolbar" |
| 64 | - }, !props.hideDelete && /*#__PURE__*/React.createElement(_Popconfirm, { | |
| 65 | - title: "\u786E\u5B9A\u5220\u9664?", | |
| 66 | - onConfirm: function onConfirm() { | |
| 67 | - return deleteItem(idx); | |
| 68 | - }, | |
| 69 | - okText: "\u786E\u5B9A", | |
| 70 | - cancelText: "\u53D6\u6D88" | |
| 71 | - }, /*#__PURE__*/React.createElement(_DeleteOutlined, { | |
| 72 | - style: { | |
| 73 | - fontSize: 17, | |
| 74 | - marginLeft: 8 | |
| 75 | - } | |
| 76 | - })), !props.hideAdd && !props.hideCopy && /*#__PURE__*/React.createElement(_CopyOutlined, { | |
| 79 | + }, !props.hideMove && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_ArrowUpOutlined, { | |
| 77 | 80 | style: { |
| 78 | 81 | fontSize: 16, |
| 79 | - marginLeft: 8 | |
| 82 | + marginLeft: 4 | |
| 80 | 83 | }, |
| 81 | 84 | onClick: function onClick() { |
| 82 | - return copyItem(idx); | |
| 85 | + return moveItemUp(idx); | |
| 83 | 86 | } |
| 84 | - }), !props.hideMove && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_ArrowUpOutlined, { | |
| 87 | + }), /*#__PURE__*/React.createElement(_ArrowDownOutlined, { | |
| 85 | 88 | style: { |
| 86 | 89 | fontSize: 16, |
| 87 | 90 | marginLeft: 4 |
| 88 | 91 | }, |
| 89 | 92 | onClick: function onClick() { |
| 90 | - return moveItemUp(idx); | |
| 93 | + return moveItemDown(idx); | |
| 91 | 94 | } |
| 92 | - }), /*#__PURE__*/React.createElement(_ArrowDownOutlined, { | |
| 95 | + })), !props.hideAdd && !props.hideCopy && /*#__PURE__*/React.createElement(_CopyOutlined, { | |
| 93 | 96 | style: { |
| 94 | 97 | fontSize: 16, |
| 95 | - marginLeft: 4 | |
| 98 | + marginLeft: 8 | |
| 96 | 99 | }, |
| 97 | 100 | onClick: function onClick() { |
| 98 | - return moveItemDown(idx); | |
| 101 | + return copyItem(idx); | |
| 102 | + } | |
| 103 | + }), !props.hideDelete && displayList.length > min && /*#__PURE__*/React.createElement(_Popconfirm, _extends({ | |
| 104 | + onConfirm: function onConfirm() { | |
| 105 | + if (props.onConfirm && typeof props.onConfirm === 'string') { | |
| 106 | + var cb = methods[props.onConfirm]; | |
| 107 | + | |
| 108 | + if (typeof cb === 'function') { | |
| 109 | + var result = cb(item, idx); | |
| 110 | + | |
| 111 | + if (!result) { | |
| 112 | + return; | |
| 113 | + } | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 117 | + deleteItem(idx); | |
| 118 | + } | |
| 119 | + }, delConfirmProps), /*#__PURE__*/React.createElement(_CloseOutlined, { | |
| 120 | + style: { | |
| 121 | + fontSize: 16, | |
| 122 | + marginLeft: 8 | |
| 99 | 123 | } |
| 100 | 124 | })))); |
| 101 | 125 | })), /*#__PURE__*/React.createElement("div", { |
| 102 | 126 | style: { |
| 103 | 127 | marginTop: displayList.length > 0 ? 0 : 8 |
| 104 | 128 | } |
| 105 | - }, !props.hideAdd && /*#__PURE__*/React.createElement(_Button, _extends({ | |
| 129 | + }, !props.hideAdd && displayList.length < max && /*#__PURE__*/React.createElement(_Button, _extends({ | |
| 106 | 130 | onClick: addItem |
| 107 | 131 | }, addBtnProps)), Array.isArray(props.buttons) ? props.buttons.map(function (item, idx) { |
| 108 | 132 | var callback = item.callback, | ... | ... |
es/form-render-core/src/core/RenderChildren/RenderList/DrawerList.js
renamed from
es/core/RenderChildren/RenderList/DrawerList.js
| ... | ... | @@ -4,8 +4,6 @@ import "antd/es/drawer/style"; |
| 4 | 4 | import _Drawer from "antd/es/drawer"; |
| 5 | 5 | import "antd/es/button/style"; |
| 6 | 6 | import _Button from "antd/es/button"; |
| 7 | -import "antd/es/space/style"; | |
| 8 | -import _Space from "antd/es/space"; | |
| 9 | 7 | import _ArrowDownOutlined from "@ant-design/icons/es/icons/ArrowDownOutlined"; |
| 10 | 8 | import _ArrowUpOutlined from "@ant-design/icons/es/icons/ArrowUpOutlined"; |
| 11 | 9 | import "antd/es/popconfirm/style"; |
| ... | ... | @@ -33,15 +31,16 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va |
| 33 | 31 | |
| 34 | 32 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
| 35 | 33 | |
| 34 | +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | |
| 35 | + | |
| 36 | 36 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } |
| 37 | 37 | |
| 38 | 38 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } |
| 39 | 39 | |
| 40 | -/* eslint-disable jsx-a11y/anchor-is-valid */ | |
| 41 | 40 | import React, { useRef } from 'react'; |
| 41 | +import { useSet, useTools } from '../../../hooks'; | |
| 42 | +import { getDataPath, getDisplayValue, getKeyFromPath } from '../../../utils'; | |
| 42 | 43 | import Core from '../../index'; |
| 43 | -import { useSet } from '../../../hooks'; | |
| 44 | -import { getDataPath, getKeyFromPath, getDisplayValue } from '../../../utils'; | |
| 45 | 44 | import ErrorMessage from '../../RenderField/ErrorMessage'; |
| 46 | 45 | var FIELD_LENGTH = 170; |
| 47 | 46 | |
| ... | ... | @@ -62,6 +61,10 @@ var DrawerList = function DrawerList(_ref) { |
| 62 | 61 | schema = _ref.schema, |
| 63 | 62 | changeList = _ref.changeList, |
| 64 | 63 | listData = _ref.listData; |
| 64 | + | |
| 65 | + var _useTools = useTools(), | |
| 66 | + widgets = _useTools.widgets; | |
| 67 | + | |
| 65 | 68 | var _schema$props = schema.props, |
| 66 | 69 | props = _schema$props === void 0 ? {} : _schema$props, |
| 67 | 70 | _schema$itemProps = schema.itemProps, |
| ... | ... | @@ -74,6 +77,34 @@ var DrawerList = function DrawerList(_ref) { |
| 74 | 77 | pagination = _props$pagination === void 0 ? {} : _props$pagination, |
| 75 | 78 | rest = _objectWithoutProperties(props, _excluded2); |
| 76 | 79 | |
| 80 | + var actionColumnProps = { | |
| 81 | + colHeaderText: '操作', | |
| 82 | + editText: '编辑', | |
| 83 | + delText: '删除' | |
| 84 | + }; | |
| 85 | + var delConfirmProps = { | |
| 86 | + title: '确定删除?', | |
| 87 | + okText: '确定', | |
| 88 | + cancelText: '取消' | |
| 89 | + }; | |
| 90 | + var addBtnProps = { | |
| 91 | + type: 'primary', | |
| 92 | + children: '新增一条', | |
| 93 | + size: 'small' | |
| 94 | + }; | |
| 95 | + | |
| 96 | + if (props.actionColumnProps && _typeof(props.actionColumnProps) === 'object') { | |
| 97 | + actionColumnProps = _objectSpread(_objectSpread({}, actionColumnProps), props.actionColumnProps); | |
| 98 | + } | |
| 99 | + | |
| 100 | + if (props.delConfirmProps && _typeof(props.delConfirmProps) === 'object') { | |
| 101 | + delConfirmProps = _objectSpread(_objectSpread({}, delConfirmProps), props.delConfirmProps); | |
| 102 | + } | |
| 103 | + | |
| 104 | + if (props.addBtnProps && _typeof(props.addBtnProps) === 'object') { | |
| 105 | + addBtnProps = _objectSpread(_objectSpread({}, addBtnProps), props.addBtnProps); | |
| 106 | + } | |
| 107 | + | |
| 77 | 108 | var paginationConfig = pagination && _objectSpread({ |
| 78 | 109 | size: 'small', |
| 79 | 110 | hideOnSinglePage: true |
| ... | ... | @@ -112,7 +143,11 @@ var DrawerList = function DrawerList(_ref) { |
| 112 | 143 | return item.name == childPath; |
| 113 | 144 | }) || {}; //TODO: 万一error在更深的层,这个办法是find不到的,会展示那一行没有提示。可以整一行加一个红线的方式处理 |
| 114 | 145 | |
| 115 | - return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", null, getDisplayValue(value, schema)), errorObj.error && /*#__PURE__*/React.createElement(ErrorMessage, { | |
| 146 | + var Widget = widgets[schema.readOnlyWidget]; | |
| 147 | + return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", null, Widget ? /*#__PURE__*/React.createElement(Widget, { | |
| 148 | + value: value, | |
| 149 | + schema: schema | |
| 150 | + }) : getDisplayValue(value, schema)), errorObj.error && /*#__PURE__*/React.createElement(ErrorMessage, { | |
| 116 | 151 | message: errorObj.error, |
| 117 | 152 | schema: schema |
| 118 | 153 | })); |
| ... | ... | @@ -120,40 +155,41 @@ var DrawerList = function DrawerList(_ref) { |
| 120 | 155 | }, columnProps); |
| 121 | 156 | }); |
| 122 | 157 | columns.push({ |
| 123 | - title: '操作', | |
| 158 | + title: actionColumnProps.colHeaderText, | |
| 124 | 159 | key: '$action', |
| 125 | 160 | fixed: 'right', |
| 126 | 161 | width: 120, |
| 127 | 162 | render: function render(value, record, idx) { |
| 128 | 163 | var index = value && value.$idx || 0; |
| 129 | - return /*#__PURE__*/React.createElement(_Space, null, /*#__PURE__*/React.createElement("a", { | |
| 164 | + return /*#__PURE__*/React.createElement("div", null, !props.hideEdit && /*#__PURE__*/React.createElement("a", { | |
| 130 | 165 | onClick: function onClick() { |
| 131 | 166 | return openDrawer(index); |
| 132 | 167 | } |
| 133 | - }, "\u7F16\u8F91"), !props.hideDelete && /*#__PURE__*/React.createElement(_Popconfirm, { | |
| 134 | - title: "\u786E\u5B9A\u5220\u9664?", | |
| 168 | + }, actionColumnProps.editText), !props.hideDelete && /*#__PURE__*/React.createElement(_Popconfirm, _extends({ | |
| 135 | 169 | onConfirm: function onConfirm() { |
| 136 | 170 | return deleteItem(index); |
| 137 | - }, | |
| 138 | - okText: "\u786E\u5B9A", | |
| 139 | - cancelText: "\u53D6\u6D88" | |
| 140 | - }, /*#__PURE__*/React.createElement("a", null, "\u5220\u9664")), !props.hideMove && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_ArrowUpOutlined, { | |
| 171 | + } | |
| 172 | + }, delConfirmProps), /*#__PURE__*/React.createElement("a", { | |
| 173 | + style: { | |
| 174 | + marginLeft: 8 | |
| 175 | + } | |
| 176 | + }, actionColumnProps.delText)), !props.hideMove && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_ArrowUpOutlined, { | |
| 141 | 177 | style: { |
| 142 | 178 | color: '#1890ff', |
| 143 | 179 | fontSize: 16, |
| 144 | - marginLeft: 4 | |
| 180 | + marginLeft: 8 | |
| 145 | 181 | }, |
| 146 | 182 | onClick: function onClick() { |
| 147 | - return moveItemUp(idx); | |
| 183 | + return moveItemUp(index); | |
| 148 | 184 | } |
| 149 | 185 | }), /*#__PURE__*/React.createElement(_ArrowDownOutlined, { |
| 150 | 186 | style: { |
| 151 | 187 | color: '#1890ff', |
| 152 | 188 | fontSize: 16, |
| 153 | - marginLeft: 4 | |
| 189 | + marginLeft: 8 | |
| 154 | 190 | }, |
| 155 | 191 | onClick: function onClick() { |
| 156 | - return moveItemDown(idx); | |
| 192 | + return moveItemDown(index); | |
| 157 | 193 | } |
| 158 | 194 | }))); |
| 159 | 195 | } |
| ... | ... | @@ -181,11 +217,9 @@ var DrawerList = function DrawerList(_ref) { |
| 181 | 217 | |
| 182 | 218 | return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { |
| 183 | 219 | className: "w-100 mb2 tr" |
| 184 | - }, !props.hideAdd && /*#__PURE__*/React.createElement(_Button, { | |
| 185 | - type: "primary", | |
| 186 | - size: "small", | |
| 220 | + }, !props.hideAdd && /*#__PURE__*/React.createElement(_Button, _extends({}, addBtnProps, { | |
| 187 | 221 | onClick: handleAdd |
| 188 | - }, "\u65B0\u589E"), Array.isArray(props.buttons) ? props.buttons.map(function (item, idx) { | |
| 222 | + })), Array.isArray(props.buttons) ? props.buttons.map(function (item, idx) { | |
| 189 | 223 | var callback = item.callback, |
| 190 | 224 | text = item.text, |
| 191 | 225 | html = item.html; |
| ... | ... | @@ -222,7 +256,7 @@ var DrawerList = function DrawerList(_ref) { |
| 222 | 256 | })); |
| 223 | 257 | }) : null), /*#__PURE__*/React.createElement(_Drawer, { |
| 224 | 258 | width: "600", |
| 225 | - title: "\u7F16\u8F91", | |
| 259 | + title: actionColumnProps.colHeaderText, | |
| 226 | 260 | placement: "right", |
| 227 | 261 | onClose: closeDrawer, |
| 228 | 262 | visible: showDrawer, | ... | ... |
| 1 | +import _PlusCircleFilled from "@ant-design/icons/es/icons/PlusCircleFilled"; | |
| 2 | +import _DownOutlined from "@ant-design/icons/es/icons/DownOutlined"; | |
| 3 | +import _UpOutlined from "@ant-design/icons/es/icons/UpOutlined"; | |
| 4 | +import _DeleteOutlined from "@ant-design/icons/es/icons/DeleteOutlined"; | |
| 5 | + | |
| 6 | +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | |
| 7 | + | |
| 8 | +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | |
| 9 | + | |
| 10 | +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | |
| 11 | + | |
| 12 | +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | |
| 13 | + | |
| 14 | +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | |
| 15 | + | |
| 16 | +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | |
| 17 | + | |
| 18 | +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | |
| 19 | + | |
| 20 | +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | |
| 21 | + | |
| 22 | +function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | |
| 23 | + | |
| 24 | +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | |
| 25 | + | |
| 26 | +/* eslint-disable jsx-a11y/anchor-is-valid */ | |
| 27 | +import React, { useEffect, useMemo, useState } from 'react'; | |
| 28 | +import Core from '../../index'; // import { Button, Space, Popconfirm } from 'antd'; | |
| 29 | +// import ArrowDown from '../../../components/ArrowDown'; | |
| 30 | +// import { Collapse } from 'antd-mobile' | |
| 31 | + | |
| 32 | +// 数字转汉字 | |
| 33 | +function convertToChinaNum(num) { | |
| 34 | + var arr1 = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']; | |
| 35 | + var arr2 = ['', '十', '百', '千', '万', '十', '百', '千', '亿', '十', '百', '千', '万', '十', '百', '千', '亿']; //可继续追加更高位转换值 | |
| 36 | + | |
| 37 | + if (!num || isNaN(num)) { | |
| 38 | + return "零"; | |
| 39 | + } | |
| 40 | + | |
| 41 | + var english = num.toString().split(""); | |
| 42 | + var result = ""; | |
| 43 | + | |
| 44 | + for (var i = 0; i < english.length; i++) { | |
| 45 | + var des_i = english.length - 1 - i; //倒序排列设值 | |
| 46 | + | |
| 47 | + result = arr2[i] + result; | |
| 48 | + var arr1_index = english[des_i]; | |
| 49 | + result = arr1[arr1_index] + result; | |
| 50 | + } | |
| 51 | + | |
| 52 | + result = result.replace(/零(千|百|十)/g, '零').replace(/十零/g, '十'); | |
| 53 | + result = result.replace(/零+/g, '零'); | |
| 54 | + result = result.replace(/零亿/g, '亿').replace(/零万/g, '万'); | |
| 55 | + result = result.replace(/亿万/g, '亿'); | |
| 56 | + result = result.replace(/零+$/, ''); | |
| 57 | + result = result.replace(/^一十/g, '十'); | |
| 58 | + return result; | |
| 59 | +} | |
| 60 | + | |
| 61 | +var ListForMobile = function ListForMobile(_ref) { | |
| 62 | + var _ref$displayList = _ref.displayList, | |
| 63 | + displayList = _ref$displayList === void 0 ? [] : _ref$displayList, | |
| 64 | + listData = _ref.listData, | |
| 65 | + changeList = _ref.changeList, | |
| 66 | + schema = _ref.schema, | |
| 67 | + deleteItem = _ref.deleteItem, | |
| 68 | + copyItem = _ref.copyItem, | |
| 69 | + addItem = _ref.addItem, | |
| 70 | + moveItemUp = _ref.moveItemUp, | |
| 71 | + moveItemDown = _ref.moveItemDown, | |
| 72 | + displayType = _ref.displayType, | |
| 73 | + getFieldsProps = _ref.getFieldsProps; | |
| 74 | + var _schema$props = schema.props, | |
| 75 | + props = _schema$props === void 0 ? {} : _schema$props, | |
| 76 | + itemProps = schema.itemProps; | |
| 77 | + | |
| 78 | + var _useState = useState([]), | |
| 79 | + _useState2 = _slicedToArray(_useState, 2), | |
| 80 | + allKeys = _useState2[0], | |
| 81 | + setKeys = _useState2[1]; // let addBtnProps = { | |
| 82 | + // type: 'dashed', | |
| 83 | + // children: '新增一条list', | |
| 84 | + // }; | |
| 85 | + // if (props.addBtnProps && typeof props.addBtnProps === 'object') { | |
| 86 | + // addBtnProps = { ...addBtnProps, ...props.addBtnProps }; | |
| 87 | + // } | |
| 88 | + | |
| 89 | + | |
| 90 | + useEffect(function () { | |
| 91 | + var _allKeys = []; | |
| 92 | + displayList.forEach(function (item, idx) { | |
| 93 | + if (item._active) { | |
| 94 | + _allKeys.push(String(idx)); | |
| 95 | + } | |
| 96 | + }); | |
| 97 | + setKeys(_allKeys); | |
| 98 | + }, [displayList]); | |
| 99 | + | |
| 100 | + var getTitle = function getTitle(id) { | |
| 101 | + return /*#__PURE__*/React.createElement("div", { | |
| 102 | + style: { | |
| 103 | + display: 'flex', | |
| 104 | + justifyContent: "space-between", | |
| 105 | + alignItems: 'center' | |
| 106 | + } | |
| 107 | + }, /*#__PURE__*/React.createElement("span", null, "\u6570\u636E", id + 1), /*#__PURE__*/React.createElement("a", { | |
| 108 | + onClick: function onClick(e) { | |
| 109 | + e.stopPropagation(); | |
| 110 | + deleteItem(id); | |
| 111 | + }, | |
| 112 | + style: { | |
| 113 | + display: 'inline-block', | |
| 114 | + padding: '0 10px' | |
| 115 | + } | |
| 116 | + }, /*#__PURE__*/React.createElement(_DeleteOutlined, { | |
| 117 | + style: { | |
| 118 | + fontSize: 16, | |
| 119 | + width: 16, | |
| 120 | + height: 16 | |
| 121 | + } | |
| 122 | + }))); | |
| 123 | + }; | |
| 124 | + | |
| 125 | + var handleArrow = function handleArrow(active) { | |
| 126 | + if (active) { | |
| 127 | + return /*#__PURE__*/React.createElement(_UpOutlined, { | |
| 128 | + onClick: function onClick() {} | |
| 129 | + }); | |
| 130 | + } else { | |
| 131 | + return /*#__PURE__*/React.createElement(_DownOutlined, null); | |
| 132 | + } | |
| 133 | + }; | |
| 134 | + | |
| 135 | + return null; | |
| 136 | + return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { | |
| 137 | + className: "fr-card-list qx-card-mobile" | |
| 138 | + }, /*#__PURE__*/React.createElement(Collapse, { | |
| 139 | + activeKey: allKeys | |
| 140 | + }, displayList.map(function (item, idx) { | |
| 141 | + var fieldsProps = getFieldsProps(idx); | |
| 142 | + fieldsProps.displayType = displayType; | |
| 143 | + return /*#__PURE__*/React.createElement(Collapse.Panel, { | |
| 144 | + key: String(idx), | |
| 145 | + title: getTitle(idx), | |
| 146 | + arrow: handleArrow, | |
| 147 | + onClick: function onClick() { | |
| 148 | + var _active = item._active || false; | |
| 149 | + | |
| 150 | + displayList[idx]._active = !_active; | |
| 151 | + changeList(_toConsumableArray(displayList)); | |
| 152 | + } | |
| 153 | + }, /*#__PURE__*/React.createElement("div", { | |
| 154 | + className: "fr-card-item qx-card-mobile-item ".concat(displayType === 'row' ? 'fr-card-item-row' : ''), | |
| 155 | + key: idx | |
| 156 | + }, /*#__PURE__*/React.createElement(Core, fieldsProps))); | |
| 157 | + }))), /*#__PURE__*/React.createElement("a", { | |
| 158 | + className: 'add-button', | |
| 159 | + onClick: function onClick() { | |
| 160 | + addItem(); | |
| 161 | + } | |
| 162 | + }, /*#__PURE__*/React.createElement(_PlusCircleFilled, { | |
| 163 | + style: { | |
| 164 | + marginRight: 2, | |
| 165 | + width: 14, | |
| 166 | + height: 14 | |
| 167 | + } | |
| 168 | + }), "\u70B9\u51FB\u65B0\u589E\u6570\u636E")); | |
| 169 | +}; | |
| 170 | + | |
| 171 | +export default ListForMobile; | |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/core/RenderChildren/RenderList/SimpleList.js
renamed from
es/core/RenderChildren/RenderList/SimpleList.js
| ... | ... | @@ -34,16 +34,29 @@ var SimpleList = function SimpleList(_ref) { |
| 34 | 34 | getFieldsProps = _ref.getFieldsProps; |
| 35 | 35 | var _schema$props = schema.props, |
| 36 | 36 | props = _schema$props === void 0 ? {} : _schema$props, |
| 37 | - itemProps = schema.itemProps; | |
| 37 | + itemProps = schema.itemProps, | |
| 38 | + _schema$min = schema.min, | |
| 39 | + min = _schema$min === void 0 ? 0 : _schema$min, | |
| 40 | + _schema$max = schema.max, | |
| 41 | + max = _schema$max === void 0 ? 99999 : _schema$max; | |
| 38 | 42 | var addBtnProps = { |
| 39 | 43 | type: 'dashed', |
| 40 | 44 | children: '新增一条' |
| 41 | 45 | }; |
| 46 | + var delConfirmProps = { | |
| 47 | + title: '确定删除?', | |
| 48 | + okText: '确定', | |
| 49 | + cancelText: '取消' | |
| 50 | + }; | |
| 42 | 51 | |
| 43 | 52 | if (props.addBtnProps && _typeof(props.addBtnProps) === 'object') { |
| 44 | 53 | addBtnProps = _objectSpread(_objectSpread({}, addBtnProps), props.addBtnProps); |
| 45 | 54 | } |
| 46 | 55 | |
| 56 | + if (props.delConfirmProps && _typeof(props.delConfirmProps) === 'object') { | |
| 57 | + delConfirmProps = _objectSpread(_objectSpread({}, delConfirmProps), props.delConfirmProps); | |
| 58 | + } | |
| 59 | + | |
| 47 | 60 | return /*#__PURE__*/React.createElement("div", { |
| 48 | 61 | className: "fr-list-1" |
| 49 | 62 | }, displayList.map(function (item, idx) { |
| ... | ... | @@ -63,14 +76,11 @@ var SimpleList = function SimpleList(_ref) { |
| 63 | 76 | style: { |
| 64 | 77 | marginTop: 6 |
| 65 | 78 | } |
| 66 | - }, !props.hideDelete && /*#__PURE__*/React.createElement(_Popconfirm, { | |
| 67 | - title: "\u786E\u5B9A\u5220\u9664?", | |
| 79 | + }, !props.hideDelete && displayList.length > min && /*#__PURE__*/React.createElement(_Popconfirm, _extends({ | |
| 68 | 80 | onConfirm: function onConfirm() { |
| 69 | 81 | return deleteItem(idx); |
| 70 | - }, | |
| 71 | - okText: "\u786E\u5B9A", | |
| 72 | - cancelText: "\u53D6\u6D88" | |
| 73 | - }, /*#__PURE__*/React.createElement(_DeleteOutlined, { | |
| 82 | + } | |
| 83 | + }, delConfirmProps), /*#__PURE__*/React.createElement(_DeleteOutlined, { | |
| 74 | 84 | style: { |
| 75 | 85 | fontSize: 17, |
| 76 | 86 | marginLeft: 8 |
| ... | ... | @@ -104,7 +114,7 @@ var SimpleList = function SimpleList(_ref) { |
| 104 | 114 | style: { |
| 105 | 115 | marginTop: displayList.length > 0 ? 0 : 8 |
| 106 | 116 | } |
| 107 | - }, !props.hideAdd && /*#__PURE__*/React.createElement(_Button, _extends({ | |
| 117 | + }, !props.hideAdd && displayList.length < max && /*#__PURE__*/React.createElement(_Button, _extends({ | |
| 108 | 118 | onClick: addItem |
| 109 | 119 | }, addBtnProps)), Array.isArray(props.buttons) ? props.buttons.map(function (item, idx) { |
| 110 | 120 | var callback = item.callback, | ... | ... |
| 1 | +import "antd/es/tabs/style"; | |
| 2 | +import _Tabs from "antd/es/tabs"; | |
| 3 | +var _excluded = ["tabName", "type", "draggable"]; | |
| 4 | + | |
| 5 | +function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | |
| 6 | + | |
| 7 | +function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | |
| 8 | + | |
| 9 | +function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | |
| 10 | + | |
| 11 | +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | |
| 12 | + | |
| 13 | +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | |
| 14 | + | |
| 15 | +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | |
| 16 | + | |
| 17 | +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | |
| 18 | + | |
| 19 | +function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | |
| 20 | + | |
| 21 | +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | |
| 22 | + | |
| 23 | +/* eslint-disable jsx-a11y/anchor-is-valid */ | |
| 24 | +import React, { useState, useRef } from 'react'; | |
| 25 | +import Core from '../../index'; | |
| 26 | +var TabPane = _Tabs.TabPane; | |
| 27 | +var dragType = 'DraggableTabNode'; | |
| 28 | + | |
| 29 | +var DraggableTabNode = function DraggableTabNode(_ref) { | |
| 30 | + var index = _ref.index, | |
| 31 | + children = _ref.children, | |
| 32 | + moveNode = _ref.moveNode; | |
| 33 | + var ref = useRef(null); | |
| 34 | + | |
| 35 | + var _useDrop = useDrop({ | |
| 36 | + accept: dragType, | |
| 37 | + collect: function collect(monitor) { | |
| 38 | + var _ref2 = monitor.getItem() || {}, | |
| 39 | + dragIndex = _ref2.index; | |
| 40 | + | |
| 41 | + if (dragIndex === index) { | |
| 42 | + return {}; | |
| 43 | + } | |
| 44 | + | |
| 45 | + return { | |
| 46 | + isOver: monitor.isOver(), | |
| 47 | + dropClassName: 'dropping' | |
| 48 | + }; | |
| 49 | + }, | |
| 50 | + drop: function drop(item) { | |
| 51 | + moveNode(item.index, index); | |
| 52 | + } | |
| 53 | + }), | |
| 54 | + _useDrop2 = _slicedToArray(_useDrop, 2), | |
| 55 | + _useDrop2$ = _useDrop2[0], | |
| 56 | + isOver = _useDrop2$.isOver, | |
| 57 | + dropClassName = _useDrop2$.dropClassName, | |
| 58 | + drop = _useDrop2[1]; | |
| 59 | + | |
| 60 | + var _useDrag = useDrag({ | |
| 61 | + type: dragType, | |
| 62 | + item: { | |
| 63 | + index: index | |
| 64 | + }, | |
| 65 | + collect: function collect(monitor) { | |
| 66 | + return { | |
| 67 | + isDragging: monitor.isDragging() | |
| 68 | + }; | |
| 69 | + } | |
| 70 | + }), | |
| 71 | + _useDrag2 = _slicedToArray(_useDrag, 2), | |
| 72 | + drag = _useDrag2[1]; | |
| 73 | + | |
| 74 | + drop(drag(ref)); | |
| 75 | + return /*#__PURE__*/React.createElement("div", { | |
| 76 | + ref: ref, | |
| 77 | + style: { | |
| 78 | + marginRight: 2 | |
| 79 | + }, | |
| 80 | + className: isOver ? dropClassName : '' | |
| 81 | + }, children); | |
| 82 | +}; | |
| 83 | + | |
| 84 | +var TabList = function TabList(_ref3) { | |
| 85 | + var _ref3$displayList = _ref3.displayList, | |
| 86 | + displayList = _ref3$displayList === void 0 ? [] : _ref3$displayList, | |
| 87 | + listData = _ref3.listData, | |
| 88 | + changeList = _ref3.changeList, | |
| 89 | + schema = _ref3.schema, | |
| 90 | + deleteItem = _ref3.deleteItem, | |
| 91 | + copyItem = _ref3.copyItem, | |
| 92 | + addItem = _ref3.addItem, | |
| 93 | + moveItemUp = _ref3.moveItemUp, | |
| 94 | + moveItemDown = _ref3.moveItemDown, | |
| 95 | + displayType = _ref3.displayType, | |
| 96 | + getFieldsProps = _ref3.getFieldsProps; | |
| 97 | + | |
| 98 | + var _useState = useState('0'), | |
| 99 | + _useState2 = _slicedToArray(_useState, 2), | |
| 100 | + activeKey = _useState2[0], | |
| 101 | + setActiveKey = _useState2[1]; | |
| 102 | + | |
| 103 | + var _schema$props = schema.props, | |
| 104 | + props = _schema$props === void 0 ? {} : _schema$props, | |
| 105 | + itemProps = schema.itemProps; | |
| 106 | + | |
| 107 | + var tabName = props.tabName, | |
| 108 | + type = props.type, | |
| 109 | + _props$draggable = props.draggable, | |
| 110 | + draggable = _props$draggable === void 0 ? false : _props$draggable, | |
| 111 | + restProps = _objectWithoutProperties(props, _excluded); | |
| 112 | + | |
| 113 | + var onEdit = function onEdit(targetKey, action) { | |
| 114 | + if (action === 'add') { | |
| 115 | + var currentKey = addItem(); | |
| 116 | + setActiveKey("".concat(currentKey)); | |
| 117 | + } else if (action === 'remove') { | |
| 118 | + deleteItem(Number(targetKey)); | |
| 119 | + setActiveKey("".concat(targetKey > 1 ? targetKey - 1 : 0)); | |
| 120 | + } else { | |
| 121 | + return null; | |
| 122 | + } | |
| 123 | + }; // 如果tabName传数组是可以「自定义」tab页的名字的。表单联动可以使用formrender的watch 配合 setSchemaByPath | |
| 124 | + | |
| 125 | + | |
| 126 | + var getCurrentTabPaneName = function getCurrentTabPaneName(idx) { | |
| 127 | + return tabName instanceof Array ? tabName[idx] || idx + 1 : "".concat(tabName || '项目', " ").concat(idx + 1); | |
| 128 | + }; | |
| 129 | + | |
| 130 | + return /*#__PURE__*/React.createElement(_Tabs, _extends({ | |
| 131 | + type: type || 'line', | |
| 132 | + onChange: setActiveKey, | |
| 133 | + activeKey: activeKey, | |
| 134 | + onEdit: onEdit | |
| 135 | + }, restProps), displayList.map(function (item, idx) { | |
| 136 | + var fieldsProps = getFieldsProps(idx); | |
| 137 | + fieldsProps.displayType = displayType; | |
| 138 | + return /*#__PURE__*/React.createElement(TabPane, { | |
| 139 | + tab: getCurrentTabPaneName(idx), | |
| 140 | + key: "".concat(idx) | |
| 141 | + }, /*#__PURE__*/React.createElement(Core, fieldsProps)); | |
| 142 | + })); | |
| 143 | +}; | |
| 144 | + | |
| 145 | +export default TabList; | |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/core/RenderChildren/RenderList/TableList.js
renamed from
es/core/RenderChildren/RenderList/TableList.js
| ... | ... | @@ -2,8 +2,6 @@ import "antd/es/table/style"; |
| 2 | 2 | import _Table from "antd/es/table"; |
| 3 | 3 | import "antd/es/button/style"; |
| 4 | 4 | import _Button from "antd/es/button"; |
| 5 | -import "antd/es/space/style"; | |
| 6 | -import _Space from "antd/es/space"; | |
| 7 | 5 | import _ArrowDownOutlined from "@ant-design/icons/es/icons/ArrowDownOutlined"; |
| 8 | 6 | import _ArrowUpOutlined from "@ant-design/icons/es/icons/ArrowUpOutlined"; |
| 9 | 7 | import "antd/es/popconfirm/style"; |
| ... | ... | @@ -31,14 +29,14 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va |
| 31 | 29 | |
| 32 | 30 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
| 33 | 31 | |
| 32 | +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | |
| 33 | + | |
| 34 | 34 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } |
| 35 | 35 | |
| 36 | 36 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } |
| 37 | 37 | |
| 38 | -/* eslint-disable jsx-a11y/anchor-is-valid */ | |
| 39 | 38 | import React from 'react'; |
| 40 | 39 | import Core from '../../index'; |
| 41 | -// import ArrowDown from '../../../components/ArrowDown'; | |
| 42 | 40 | var FIELD_LENGTH = 170; |
| 43 | 41 | |
| 44 | 42 | var TableList = function TableList(_ref) { |
| ... | ... | @@ -67,6 +65,34 @@ var TableList = function TableList(_ref) { |
| 67 | 65 | pagination = _props$pagination === void 0 ? {} : _props$pagination, |
| 68 | 66 | rest = _objectWithoutProperties(props, _excluded2); |
| 69 | 67 | |
| 68 | + var actionColumnProps = { | |
| 69 | + colHeaderText: '操作', | |
| 70 | + copyText: '复制', | |
| 71 | + delText: '删除' | |
| 72 | + }; | |
| 73 | + var delConfirmProps = { | |
| 74 | + title: '确定删除?', | |
| 75 | + okText: '确定', | |
| 76 | + cancelText: '取消' | |
| 77 | + }; | |
| 78 | + var addBtnProps = { | |
| 79 | + type: 'primary', | |
| 80 | + children: '新增一条', | |
| 81 | + size: 'small' | |
| 82 | + }; | |
| 83 | + | |
| 84 | + if (props.actionColumnProps && _typeof(props.actionColumnProps) === 'object') { | |
| 85 | + actionColumnProps = _objectSpread(_objectSpread({}, actionColumnProps), props.actionColumnProps); | |
| 86 | + } | |
| 87 | + | |
| 88 | + if (props.delConfirmProps && _typeof(props.delConfirmProps) === 'object') { | |
| 89 | + delConfirmProps = _objectSpread(_objectSpread({}, delConfirmProps), props.delConfirmProps); | |
| 90 | + } | |
| 91 | + | |
| 92 | + if (props.addBtnProps && _typeof(props.addBtnProps) === 'object') { | |
| 93 | + addBtnProps = _objectSpread(_objectSpread({}, addBtnProps), props.addBtnProps); | |
| 94 | + } | |
| 95 | + | |
| 70 | 96 | var paginationConfig = pagination && _objectSpread({ |
| 71 | 97 | size: 'small', |
| 72 | 98 | hideOnSinglePage: true |
| ... | ... | @@ -102,27 +128,29 @@ var TableList = function TableList(_ref) { |
| 102 | 128 | |
| 103 | 129 | if (!props.hideDelete || !props.hideAdd || !props.hideCopy || !props.hideMove) { |
| 104 | 130 | columns.push({ |
| 105 | - title: '操作', | |
| 131 | + title: actionColumnProps.colHeaderText, | |
| 106 | 132 | key: '$action', |
| 107 | 133 | fixed: 'right', |
| 108 | 134 | width: 120, |
| 109 | - render: function render(value, record, idx) { | |
| 110 | - return /*#__PURE__*/React.createElement(_Space, null, !props.hideAdd && !props.hideCopy && /*#__PURE__*/React.createElement("a", { | |
| 135 | + render: function render(value, record) { | |
| 136 | + var idx = record.index; | |
| 137 | + return /*#__PURE__*/React.createElement("div", null, !props.hideAdd && !props.hideCopy && /*#__PURE__*/React.createElement("a", { | |
| 111 | 138 | onClick: function onClick() { |
| 112 | 139 | return copyItem(idx); |
| 113 | 140 | } |
| 114 | - }, "\u590D\u5236"), !props.hideDelete && /*#__PURE__*/React.createElement(_Popconfirm, { | |
| 115 | - title: "\u786E\u5B9A\u5220\u9664?", | |
| 141 | + }, actionColumnProps.copyText), !props.hideDelete && /*#__PURE__*/React.createElement(_Popconfirm, _extends({ | |
| 116 | 142 | onConfirm: function onConfirm() { |
| 117 | 143 | return deleteItem(idx); |
| 118 | - }, | |
| 119 | - okText: "\u786E\u5B9A", | |
| 120 | - cancelText: "\u53D6\u6D88" | |
| 121 | - }, /*#__PURE__*/React.createElement("a", null, "\u5220\u9664")), !props.hideMove && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_ArrowUpOutlined, { | |
| 144 | + } | |
| 145 | + }, delConfirmProps), /*#__PURE__*/React.createElement("a", { | |
| 146 | + style: { | |
| 147 | + marginLeft: 8 | |
| 148 | + } | |
| 149 | + }, actionColumnProps.delText)), !props.hideMove && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_ArrowUpOutlined, { | |
| 122 | 150 | style: { |
| 123 | 151 | color: '#1890ff', |
| 124 | 152 | fontSize: 16, |
| 125 | - marginLeft: 4 | |
| 153 | + marginLeft: 8 | |
| 126 | 154 | }, |
| 127 | 155 | onClick: function onClick() { |
| 128 | 156 | return moveItemUp(idx); |
| ... | ... | @@ -131,7 +159,7 @@ var TableList = function TableList(_ref) { |
| 131 | 159 | style: { |
| 132 | 160 | color: '#1890ff', |
| 133 | 161 | fontSize: 16, |
| 134 | - marginLeft: 4 | |
| 162 | + marginLeft: 8 | |
| 135 | 163 | }, |
| 136 | 164 | onClick: function onClick() { |
| 137 | 165 | return moveItemDown(idx); |
| ... | ... | @@ -143,11 +171,9 @@ var TableList = function TableList(_ref) { |
| 143 | 171 | |
| 144 | 172 | return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { |
| 145 | 173 | className: "w-100 mb2 tr" |
| 146 | - }, !props.hideAdd && /*#__PURE__*/React.createElement(_Button, { | |
| 147 | - type: "primary", | |
| 148 | - size: "small", | |
| 174 | + }, !props.hideAdd && /*#__PURE__*/React.createElement(_Button, _extends({}, addBtnProps, { | |
| 149 | 175 | onClick: addItem |
| 150 | - }, "\u65B0\u589E"), Array.isArray(props.buttons) ? props.buttons.map(function (item, idx) { | |
| 176 | + })), Array.isArray(props.buttons) ? props.buttons.map(function (item, idx) { | |
| 151 | 177 | var callback = item.callback, |
| 152 | 178 | text = item.text, |
| 153 | 179 | html = item.html; | ... | ... |
es/form-render-core/src/core/RenderChildren/RenderList/VirtualList.js
renamed from
es/core/RenderChildren/RenderList/VirtualList.js
| ... | ... | @@ -10,8 +10,6 @@ import _DownOutlined from "@ant-design/icons/es/icons/DownOutlined"; |
| 10 | 10 | import "antd/es/input/style"; |
| 11 | 11 | import _Input from "antd/es/input"; |
| 12 | 12 | import _SearchOutlined from "@ant-design/icons/es/icons/SearchOutlined"; |
| 13 | -import _CloseOutlined from "@ant-design/icons/es/icons/CloseOutlined"; | |
| 14 | -import _CheckOutlined from "@ant-design/icons/es/icons/CheckOutlined"; | |
| 15 | 13 | import "antd/es/message/style"; |
| 16 | 14 | import _message from "antd/es/message"; |
| 17 | 15 | import "antd/es/tooltip/style"; |
| ... | ... | @@ -21,16 +19,28 @@ import "antd/es/menu/style"; |
| 21 | 19 | import _Menu from "antd/es/menu"; |
| 22 | 20 | import "antd/es/button/style"; |
| 23 | 21 | import _Button from "antd/es/button"; |
| 24 | -import _MinusOutlined from "@ant-design/icons/es/icons/MinusOutlined"; | |
| 25 | -import _SelectOutlined from "@ant-design/icons/es/icons/SelectOutlined"; | |
| 26 | -import _ExpandAltOutlined from "@ant-design/icons/es/icons/ExpandAltOutlined"; | |
| 22 | +import _AlertOutlined from "@ant-design/icons/es/icons/AlertOutlined"; | |
| 23 | +import _BarsOutlined from "@ant-design/icons/es/icons/BarsOutlined"; | |
| 24 | +import _AppstoreOutlined from "@ant-design/icons/es/icons/AppstoreOutlined"; | |
| 25 | +import _PauseCircleOutlined from "@ant-design/icons/es/icons/PauseCircleOutlined"; | |
| 26 | +import _PlayCircleOutlined from "@ant-design/icons/es/icons/PlayCircleOutlined"; | |
| 27 | +import _ExportOutlined from "@ant-design/icons/es/icons/ExportOutlined"; | |
| 28 | +import _ImportOutlined from "@ant-design/icons/es/icons/ImportOutlined"; | |
| 29 | +import _CopyOutlined from "@ant-design/icons/es/icons/CopyOutlined"; | |
| 30 | +import _ToolOutlined from "@ant-design/icons/es/icons/ToolOutlined"; | |
| 31 | +import _SettingOutlined from "@ant-design/icons/es/icons/SettingOutlined"; | |
| 32 | +import _EllipsisOutlined from "@ant-design/icons/es/icons/EllipsisOutlined"; | |
| 33 | +import _FileTextOutlined from "@ant-design/icons/es/icons/FileTextOutlined"; | |
| 27 | 34 | import _EditOutlined from "@ant-design/icons/es/icons/EditOutlined"; |
| 28 | 35 | import _EyeOutlined from "@ant-design/icons/es/icons/EyeOutlined"; |
| 29 | -import _CopyOutlined from "@ant-design/icons/es/icons/CopyOutlined"; | |
| 30 | -import _PlusOutlined from "@ant-design/icons/es/icons/PlusOutlined"; | |
| 31 | 36 | import _DeleteOutlined from "@ant-design/icons/es/icons/DeleteOutlined"; |
| 32 | -import _ImportOutlined from "@ant-design/icons/es/icons/ImportOutlined"; | |
| 33 | -import _ExportOutlined from "@ant-design/icons/es/icons/ExportOutlined"; | |
| 37 | +import _CheckOutlined from "@ant-design/icons/es/icons/CheckOutlined"; | |
| 38 | +import _CloseOutlined from "@ant-design/icons/es/icons/CloseOutlined"; | |
| 39 | +import _CloseCircleOutlined from "@ant-design/icons/es/icons/CloseCircleOutlined"; | |
| 40 | +import _MinusCircleOutlined from "@ant-design/icons/es/icons/MinusCircleOutlined"; | |
| 41 | +import _PlusCircleOutlined from "@ant-design/icons/es/icons/PlusCircleOutlined"; | |
| 42 | +import _MinusOutlined from "@ant-design/icons/es/icons/MinusOutlined"; | |
| 43 | +import _PlusOutlined from "@ant-design/icons/es/icons/PlusOutlined"; | |
| 34 | 44 | import "antd/es/modal/style"; |
| 35 | 45 | import _Modal from "antd/es/modal"; |
| 36 | 46 | var _excluded = ["scrollY", "summary", "batchKey", "type", "bar", "line", "searchKey", "rowSelection", "size"]; |
| ... | ... | @@ -78,17 +88,30 @@ import React, { useEffect, useMemo, useRef, useState } from 'react'; |
| 78 | 88 | import Core from '../../index'; |
| 79 | 89 | var confirm = _Modal.confirm; // import {useVT} from 'virtualizedtableforantd4'; |
| 80 | 90 | |
| 91 | +import QxIcon from './icon'; | |
| 81 | 92 | var BUTTON_ICONS_MAP = { |
| 82 | - ExportOutlined: /*#__PURE__*/React.createElement(_ExportOutlined, null), | |
| 83 | - ImportOutlined: /*#__PURE__*/React.createElement(_ImportOutlined, null), | |
| 84 | - DeleteOutlined: /*#__PURE__*/React.createElement(_DeleteOutlined, null), | |
| 85 | 93 | PlusOutlined: /*#__PURE__*/React.createElement(_PlusOutlined, null), |
| 86 | - CopyOutlined: /*#__PURE__*/React.createElement(_CopyOutlined, null), | |
| 94 | + MinusOutlined: /*#__PURE__*/React.createElement(_MinusOutlined, null), | |
| 95 | + PlusCircleOutlined: /*#__PURE__*/React.createElement(_PlusCircleOutlined, null), | |
| 96 | + MinusCircleOutlined: /*#__PURE__*/React.createElement(_MinusCircleOutlined, null), | |
| 97 | + CloseCircleOutlined: /*#__PURE__*/React.createElement(_CloseCircleOutlined, null), | |
| 98 | + CloseOutlined: /*#__PURE__*/React.createElement(_CloseOutlined, null), | |
| 99 | + CheckOutlined: /*#__PURE__*/React.createElement(_CheckOutlined, null), | |
| 100 | + DeleteOutlined: /*#__PURE__*/React.createElement(_DeleteOutlined, null), | |
| 87 | 101 | EyeOutlined: /*#__PURE__*/React.createElement(_EyeOutlined, null), |
| 88 | 102 | EditOutlined: /*#__PURE__*/React.createElement(_EditOutlined, null), |
| 89 | - remove: /*#__PURE__*/React.createElement(_ExpandAltOutlined, null), | |
| 90 | - SelectOutlined: /*#__PURE__*/React.createElement(_SelectOutlined, null), | |
| 91 | - MinusOutlined: /*#__PURE__*/React.createElement(_MinusOutlined, null) | |
| 103 | + FileTextOutlined: /*#__PURE__*/React.createElement(_FileTextOutlined, null), | |
| 104 | + EllipsisOutlined: /*#__PURE__*/React.createElement(_EllipsisOutlined, null), | |
| 105 | + SettingOutlined: /*#__PURE__*/React.createElement(_SettingOutlined, null), | |
| 106 | + ToolOutlined: /*#__PURE__*/React.createElement(_ToolOutlined, null), | |
| 107 | + CopyOutlined: /*#__PURE__*/React.createElement(_CopyOutlined, null), | |
| 108 | + ImportOutlined: /*#__PURE__*/React.createElement(_ImportOutlined, null), | |
| 109 | + ExportOutlined: /*#__PURE__*/React.createElement(_ExportOutlined, null), | |
| 110 | + PlayCircleOutlined: /*#__PURE__*/React.createElement(_PlayCircleOutlined, null), | |
| 111 | + PauseCircleOutlined: /*#__PURE__*/React.createElement(_PauseCircleOutlined, null), | |
| 112 | + AppstoreOutlined: /*#__PURE__*/React.createElement(_AppstoreOutlined, null), | |
| 113 | + BarsOutlined: /*#__PURE__*/React.createElement(_BarsOutlined, null), | |
| 114 | + AlertOutlined: /*#__PURE__*/React.createElement(_AlertOutlined, null) | |
| 92 | 115 | }; |
| 93 | 116 | var FIELD_LENGTH = 170; |
| 94 | 117 | var EXPORT_STATUS = { |
| ... | ... | @@ -124,7 +147,9 @@ var VirtualList = function VirtualList(_ref) { |
| 124 | 147 | fieldName = schema.fieldName, |
| 125 | 148 | _schema$qxProps = schema.qxProps, |
| 126 | 149 | qxProps = _schema$qxProps === void 0 ? {} : _schema$qxProps, |
| 127 | - subformMode = schema.subformMode; | |
| 150 | + subformMode = schema.subformMode, | |
| 151 | + subReadOnly = schema.subReadOnly, | |
| 152 | + isLoading = schema.isLoading; | |
| 128 | 153 | |
| 129 | 154 | var _props$scrollY = props.scrollY, |
| 130 | 155 | scrollY = _props$scrollY === void 0 ? 300 : _props$scrollY, |
| ... | ... | @@ -171,9 +196,19 @@ var VirtualList = function VirtualList(_ref) { |
| 171 | 196 | var _useState11 = useState(''), |
| 172 | 197 | _useState12 = _slicedToArray(_useState11, 2), |
| 173 | 198 | searchName = _useState12[0], |
| 174 | - setSearchName = _useState12[1]; | |
| 199 | + setSearchName = _useState12[1]; // const [dataSource, setDataSource] = useState([]); | |
| 200 | + // const [refresh, setRefresh] = useState('1'); | |
| 201 | + // const [authDisplayList, setAuthDisplayList] = useState([]) // 有权限展示的数据 | |
| 202 | + | |
| 203 | + | |
| 204 | + var _useState13 = useState(false), | |
| 205 | + _useState14 = _slicedToArray(_useState13, 2), | |
| 206 | + loading = _useState14[0], | |
| 207 | + setLoading = _useState14[1]; | |
| 175 | 208 | |
| 176 | - var btnMap = useRef({}); | |
| 209 | + useEffect(function () { | |
| 210 | + setLoading(!!isLoading); | |
| 211 | + }, [isLoading]); | |
| 177 | 212 | var padding = useMemo(function () { |
| 178 | 213 | return size === 'default' ? 32 : 16; |
| 179 | 214 | }, [size]); |
| ... | ... | @@ -220,7 +255,28 @@ var VirtualList = function VirtualList(_ref) { |
| 220 | 255 | }); |
| 221 | 256 | } else { |
| 222 | 257 | _displayList = _toConsumableArray(displayList); |
| 223 | - } // const _displayList = useMemo(() => { | |
| 258 | + } // useEffect(() => { | |
| 259 | + // 筛选展示的数据 | |
| 260 | + // if (props.originWidget === 'relSelector') { | |
| 261 | + // displayList.forEach((item, index) => { | |
| 262 | + // if (typeof item === 'object') { | |
| 263 | + // item.orginIdx = index; | |
| 264 | + // } | |
| 265 | + // if ((!item.hasOwnProperty('$auth') || item.$auth) && item.id) { | |
| 266 | + // _displayList.push(item) | |
| 267 | + // } | |
| 268 | + // }) | |
| 269 | + // } else { | |
| 270 | + // _displayList = [...displayList]; | |
| 271 | + // _displayList.forEach((item, index) => { | |
| 272 | + // if (typeof item === 'object') { | |
| 273 | + // item.orginIdx = index; | |
| 274 | + // } | |
| 275 | + // }) | |
| 276 | + // } | |
| 277 | + // setAuthDisplayList(_displayList) | |
| 278 | + // }, [displayList, props.originWidget]) | |
| 279 | + // const _displayList = useMemo(() => { | |
| 224 | 280 | // let arr = [] |
| 225 | 281 | // const cloneList = _.cloneDeep(displayList) |
| 226 | 282 | // cloneList.forEach((item, index) => { |
| ... | ... | @@ -242,21 +298,32 @@ var VirtualList = function VirtualList(_ref) { |
| 242 | 298 | var selectedIds = useMemo(function () { |
| 243 | 299 | var _selectedIds = []; |
| 244 | 300 | displayList.forEach(function (item) { |
| 245 | - if (selectedRowKeys.includes(item.orginIdx)) { | |
| 301 | + if (item && selectedRowKeys.includes(item.orginIdx)) { | |
| 246 | 302 | _selectedIds.push(item.id); |
| 247 | 303 | } |
| 248 | 304 | }); |
| 249 | 305 | return _selectedIds; |
| 250 | - }, [selectedRowKeys, displayList]); | |
| 306 | + }, [selectedRowKeys, displayList]); // useEffect(() => { | |
| 307 | + | |
| 251 | 308 | var dataSource = (keyWord.length ? _displayList.filter(function (item) { |
| 252 | 309 | var _String; |
| 253 | 310 | |
| 254 | 311 | return ((_String = String(item[searchKey])) === null || _String === void 0 ? void 0 : _String.indexOf(keyWord)) > -1; |
| 255 | 312 | }) : _displayList).map(function (item, idx) { |
| 256 | - return _objectSpread({ | |
| 313 | + return _objectSpread(_objectSpread({}, item), {}, { | |
| 257 | 314 | index: item.hasOwnProperty('orginIdx') ? item.orginIdx : idx |
| 258 | - }, item); | |
| 259 | - }); | |
| 315 | + }); | |
| 316 | + }); // useEffect(() => { | |
| 317 | + // setRefresh(refresh + '1') | |
| 318 | + // }, [JSON.stringify(dataSource)]) | |
| 319 | + // setDataSource(_dataSource) | |
| 320 | + // }, [keyWord, JSON.stringify(_displayList)]) | |
| 321 | + // useEffect(() => { | |
| 322 | + // const dataSource = (keyWord.length ? _displayList.filter(item => String(item[searchKey])?.indexOf(keyWord) > -1) : _displayList).map((item, idx) => { | |
| 323 | + // return {...item, index: item.hasOwnProperty('orginIdx') ? item.orginIdx : idx}; | |
| 324 | + // }) | |
| 325 | + // setDataSource(_dataSource) | |
| 326 | + // }, [keyWord, authDisplayList]) | |
| 260 | 327 | |
| 261 | 328 | var handleTotal = function handleTotal(total) { |
| 262 | 329 | if (!total) { |
| ... | ... | @@ -284,7 +351,8 @@ var VirtualList = function VirtualList(_ref) { |
| 284 | 351 | return handleTotal(total); |
| 285 | 352 | }, |
| 286 | 353 | defaultCurrent: 1, |
| 287 | - size: 'default' | |
| 354 | + size: size || 'small' // hideOnSinglePage: true | |
| 355 | + | |
| 288 | 356 | }; |
| 289 | 357 | }, [dataSource, props.limit]); |
| 290 | 358 | var barButtons = useMemo(function () { |
| ... | ... | @@ -383,7 +451,19 @@ var VirtualList = function VirtualList(_ref) { |
| 383 | 451 | border: 'none' |
| 384 | 452 | } |
| 385 | 453 | }, item, { |
| 386 | - icon: icon && bar.style !== 'TEXT' ? BUTTON_ICONS_MAP[icon] : null, | |
| 454 | + icon: icon && bar.style !== 'TEXT' ? String(icon).indexOf('http') > -1 ? /*#__PURE__*/React.createElement("img", { | |
| 455 | + src: String(icon), | |
| 456 | + style: { | |
| 457 | + width: '16px', | |
| 458 | + height: '16px', | |
| 459 | + marginRight: '4px', | |
| 460 | + verticalAlign: 'text-bottom', | |
| 461 | + borderRadius: '50%' | |
| 462 | + }, | |
| 463 | + alt: "" | |
| 464 | + }) : String(icon).indexOf('-') > -1 ? /*#__PURE__*/React.createElement(QxIcon, { | |
| 465 | + type: String(icon) | |
| 466 | + }) : BUTTON_ICONS_MAP[icon + ''] : null, | |
| 387 | 467 | onClick: function onClick() { |
| 388 | 468 | barBtnClick(code, needConfirm, confirmContent, action, item); |
| 389 | 469 | } |
| ... | ... | @@ -429,7 +509,8 @@ var VirtualList = function VirtualList(_ref) { |
| 429 | 509 | displayType: "inline", |
| 430 | 510 | key: index.toString(), |
| 431 | 511 | id: child, |
| 432 | - dataIndex: childIndex | |
| 512 | + dataIndex: childIndex // subReadOnly={subReadOnly} | |
| 513 | + | |
| 433 | 514 | }); |
| 434 | 515 | } |
| 435 | 516 | }; |
| ... | ... | @@ -506,7 +587,7 @@ var VirtualList = function VirtualList(_ref) { |
| 506 | 587 | |
| 507 | 588 | |
| 508 | 589 | var len = (line.buttons || []).length; |
| 509 | - var action = schema.isReadOnly ? {} : { | |
| 590 | + var action = schema.isReadOnly || subReadOnly ? {} : { | |
| 510 | 591 | title: '操作', |
| 511 | 592 | key: '$action', |
| 512 | 593 | fixed: fixed ? top ? 'left' : 'right' : props.originWidget === 'subform' ? 'right' : false, |
| ... | ... | @@ -535,7 +616,6 @@ var VirtualList = function VirtualList(_ref) { |
| 535 | 616 | style: { |
| 536 | 617 | marginLeft: 8 |
| 537 | 618 | }, |
| 538 | - size: "small", | |
| 539 | 619 | onClick: onClick |
| 540 | 620 | }, /*#__PURE__*/React.createElement("span", { |
| 541 | 621 | dangerouslySetInnerHTML: { |
| ... | ... | @@ -548,8 +628,10 @@ var VirtualList = function VirtualList(_ref) { |
| 548 | 628 | needConfirm = item.needConfirm, |
| 549 | 629 | confirmContent = item.confirmContent, |
| 550 | 630 | icon = item.icon; |
| 551 | - var display = handleState(record, code, props.originWidget); | |
| 552 | - btnMap.current[code] = display; | |
| 631 | + var display = handleState(record, code, props.originWidget); // if (display === '') { | |
| 632 | + // btnMap[code] = '' | |
| 633 | + // } | |
| 634 | + | |
| 553 | 635 | return /*#__PURE__*/React.createElement(_Tooltip, { |
| 554 | 636 | title: name |
| 555 | 637 | }, /*#__PURE__*/React.createElement(_Button, _extends({ |
| ... | ... | @@ -559,7 +641,19 @@ var VirtualList = function VirtualList(_ref) { |
| 559 | 641 | display: display |
| 560 | 642 | } |
| 561 | 643 | }, item, { |
| 562 | - icon: icon && style !== 'TEXT' ? BUTTON_ICONS_MAP[icon] : null, | |
| 644 | + icon: icon && style !== 'TEXT' ? String(icon).indexOf('http') > -1 ? /*#__PURE__*/React.createElement("img", { | |
| 645 | + src: String(icon), | |
| 646 | + style: { | |
| 647 | + width: '16px', | |
| 648 | + height: '16px', | |
| 649 | + marginRight: '4px', | |
| 650 | + verticalAlign: 'text-bottom', | |
| 651 | + borderRadius: '50%' | |
| 652 | + }, | |
| 653 | + alt: "" | |
| 654 | + }) : String(icon).indexOf('-') > -1 ? /*#__PURE__*/React.createElement(QxIcon, { | |
| 655 | + type: String(icon) | |
| 656 | + }) : BUTTON_ICONS_MAP[icon + ''] : null, | |
| 563 | 657 | type: 'link', |
| 564 | 658 | size: 'small' // disabled={props.originWidget === 'subform' ? false : handleAuth(record, code)} |
| 565 | 659 | , |
| ... | ... | @@ -603,34 +697,39 @@ var VirtualList = function VirtualList(_ref) { |
| 603 | 697 | } |
| 604 | 698 | } |
| 605 | 699 | } |
| 606 | - }), style !== 'ICON' || !item.icon ? name : null)); // } | |
| 700 | + }), style !== 'ICON' ? name : null)); // } | |
| 607 | 701 | }) : null); |
| 608 | 702 | } |
| 609 | 703 | }; |
| 610 | 704 | |
| 611 | 705 | if (style === "ICON" || props.originWidget === 'subform') { |
| 612 | - var effectiveLength = 0; | |
| 613 | - Object.keys(btnMap.current || {}).forEach(function (code) { | |
| 614 | - if (btnMap.current[code] !== 'none') { | |
| 615 | - effectiveLength += 1; | |
| 616 | - } | |
| 617 | - }); | |
| 618 | - action.width = effectiveLength * 32 + padding - 8; | |
| 706 | + // let effectiveLength = 0 | |
| 707 | + // console.log(line.buttons) | |
| 708 | + // line.buttons.forEach((btn) => { | |
| 709 | + // // console.log(btnMap) | |
| 710 | + // if (btnMap[btn.code] === '') { | |
| 711 | + // effectiveLength += 1 | |
| 712 | + // console.log(effectiveLength); | |
| 713 | + // } | |
| 714 | + // }) | |
| 715 | + // console.log(effectiveLength, padding); | |
| 716 | + action.width = len * 32 - 16 >= 30 ? len * 32 + padding - 8 : 30 + padding; | |
| 619 | 717 | } else { |
| 620 | - var div = document.createElement('div'); | |
| 621 | - div.style.position = 'absolute'; | |
| 622 | - div.style.visibility = 'hidden'; | |
| 623 | - div.style.fontSize = '14px'; | |
| 624 | - window.document.body.appendChild(div); | |
| 625 | 718 | var leng = 0; |
| 626 | 719 | line.buttons.map(function (item) { |
| 627 | - var _btnMap$current; | |
| 720 | + var div = document.createElement('div'); | |
| 721 | + div.style.position = 'absolute'; | |
| 722 | + div.style.visibility = 'hidden'; | |
| 723 | + div.style.fontSize = '14px'; | |
| 724 | + window.document.body.appendChild(div); | |
| 725 | + div.innerHTML = item.name; // leng += btnMap?.[item.code] === '' ? (div.clientWidth + (style !== 'TEXT' && item.icon ? 22 : 0)) : 0; | |
| 628 | 726 | |
| 629 | - div.innerHTML = item.name; | |
| 630 | - leng += ((_btnMap$current = btnMap.current) === null || _btnMap$current === void 0 ? void 0 : _btnMap$current[item.code]) === 'none' ? 0 : div.clientWidth + padding + (style !== 'TEXT' && item.icon ? 22 : 0); | |
| 631 | - }); | |
| 632 | - action.width = leng + padding - 8; | |
| 633 | - div.remove(); | |
| 727 | + leng += div.clientWidth + (style !== 'TEXT' && item.icon ? 22 : 0); // console.log(leng); | |
| 728 | + | |
| 729 | + div.remove(); | |
| 730 | + }); // console.log(leng + padding * 2 - 8, 'leng'); | |
| 731 | + | |
| 732 | + action.width = leng + padding * 2 - 8; | |
| 634 | 733 | } |
| 635 | 734 | |
| 636 | 735 | if (columns.findIndex(function (item) { |
| ... | ... | @@ -646,7 +745,7 @@ var VirtualList = function VirtualList(_ref) { |
| 646 | 745 | |
| 647 | 746 | var handleExport = /*#__PURE__*/function () { |
| 648 | 747 | var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { |
| 649 | - var queryParams, appCode, funCode, fieldName, result; | |
| 748 | + var queryParams, currentAppCode, currentFunCode, fieldName, result; | |
| 650 | 749 | return regeneratorRuntime.wrap(function _callee$(_context) { |
| 651 | 750 | while (1) { |
| 652 | 751 | switch (_context.prev = _context.next) { |
| ... | ... | @@ -658,9 +757,9 @@ var VirtualList = function VirtualList(_ref) { |
| 658 | 757 | queryParams = _defineProperty({ |
| 659 | 758 | dataId: props.dataId |
| 660 | 759 | }, searchKey, keyWord); |
| 661 | - appCode = qxProps.appCode, funCode = qxProps.funCode, fieldName = qxProps.fieldName; | |
| 760 | + currentAppCode = qxProps.currentAppCode, currentFunCode = qxProps.currentFunCode, fieldName = qxProps.fieldName; | |
| 662 | 761 | _context.next = 5; |
| 663 | - return props.exportChild(appCode, funCode, fieldName, queryParams); | |
| 762 | + return props.exportChild(currentAppCode, currentFunCode, fieldName, queryParams); | |
| 664 | 763 | |
| 665 | 764 | case 5: |
| 666 | 765 | result = _context.sent; |
| ... | ... | @@ -895,7 +994,19 @@ var VirtualList = function VirtualList(_ref) { |
| 895 | 994 | marginLeft: 8 |
| 896 | 995 | } |
| 897 | 996 | }, item, { |
| 898 | - icon: icon && bar.style !== 'TEXT' ? BUTTON_ICONS_MAP[icon] : null, | |
| 997 | + icon: icon && bar.style !== 'TEXT' ? String(icon).indexOf('http') > -1 ? /*#__PURE__*/React.createElement("img", { | |
| 998 | + src: String(icon), | |
| 999 | + style: { | |
| 1000 | + width: '16px', | |
| 1001 | + height: '16px', | |
| 1002 | + marginRight: '4px', | |
| 1003 | + verticalAlign: 'text-bottom', | |
| 1004 | + borderRadius: '50%' | |
| 1005 | + }, | |
| 1006 | + alt: "" | |
| 1007 | + }) : String(icon).indexOf('-') > -1 ? /*#__PURE__*/React.createElement(QxIcon, { | |
| 1008 | + type: String(icon) | |
| 1009 | + }) : BUTTON_ICONS_MAP[icon + ''] : null, | |
| 899 | 1010 | onClick: function onClick() { |
| 900 | 1011 | barBtnClick(code, needConfirm, confirmContent, action, item); |
| 901 | 1012 | } |
| ... | ... | @@ -954,15 +1065,19 @@ var VirtualList = function VirtualList(_ref) { |
| 954 | 1065 | handleCloseExport(exportProgressData.taskId); |
| 955 | 1066 | } |
| 956 | 1067 | }) : null, /*#__PURE__*/React.createElement(_Table, _extends({ |
| 1068 | + // key={props.originWidget === 'relSelector' ? refresh : ''} | |
| 957 | 1069 | id: 'qxVirtualList', |
| 958 | 1070 | className: 'qx-virtualList', |
| 959 | - rowKey: "index", | |
| 1071 | + rowKey: props.originWidget === 'relSelector' ? 'id' : 'orginIdx', | |
| 960 | 1072 | scroll: { |
| 961 | 1073 | y: scrollY, |
| 962 | 1074 | x: '100%' |
| 963 | 1075 | } // components={vt} |
| 964 | 1076 | , |
| 965 | - size: size || 'small', | |
| 1077 | + size: size || 'small' | |
| 1078 | + }, props.originWidget === 'relSelector' ? { | |
| 1079 | + loading: loading | |
| 1080 | + } : {}, { | |
| 966 | 1081 | columns: columns, |
| 967 | 1082 | dataSource: dataSource, |
| 968 | 1083 | pagination: pagination // style={{marginBottom: 25}} |
| ... | ... | @@ -975,7 +1090,7 @@ var VirtualList = function VirtualList(_ref) { |
| 975 | 1090 | |
| 976 | 1091 | return _summary(listData); |
| 977 | 1092 | } |
| 978 | - }, rest)), !props.hideAdd && props.originWidget === 'subform' && /*#__PURE__*/React.createElement(_Button, { | |
| 1093 | + }, rest)), !props.hideAdd && props.originWidget === 'subform' && !subReadOnly && /*#__PURE__*/React.createElement(_Button, { | |
| 979 | 1094 | type: "link", |
| 980 | 1095 | icon: /*#__PURE__*/React.createElement(_PlusOutlined, null), |
| 981 | 1096 | onClick: addItem | ... | ... |
| 1 | +import { createFromIconfontCN } from '@ant-design/icons/lib'; | |
| 2 | +/** | |
| 3 | + * 使用: | |
| 4 | + * import QxIcon from '@/packages/qx-icon'; | |
| 5 | + * <QxIcon type="xxx"/> | |
| 6 | + * 说明: | |
| 7 | + * `xxx`为图标唯一标识,`iconfont.cn`对应图标下的“复制代码”所得,建议命名为“icon-xxx_yyy”, | |
| 8 | + * “icon-”为固定前缀,xxx为模块类型,yyy为图标名。公共类的xxx命名为“comm” | |
| 9 | + * eg: <QxIcon type="icon-flow_eye"/> | |
| 10 | + * | |
| 11 | + * @type {React.FC<IconFontProps<string>>} | |
| 12 | + */ | |
| 13 | + | |
| 14 | +var QxIcon = createFromIconfontCN({ | |
| 15 | + scriptUrl: 'https://lf1-cdn-tos.bytegoofy.com/obj/iconpark/icons_13749_95.b05de9dc2fbe8efffb150f83b64da806.es5.js' | |
| 16 | +}); | |
| 17 | +export default QxIcon; | |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/core/RenderChildren/RenderList/index.js
renamed from
es/core/RenderChildren/RenderList/index.js
| ... | ... | @@ -20,13 +20,13 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len |
| 20 | 20 | import React from 'react'; |
| 21 | 21 | import { get } from 'lodash-es'; |
| 22 | 22 | import { useStore, useTools } from '../../../hooks'; |
| 23 | -import { getDataPath, getKeyFromPath, getDisplayValue } from '../../../utils'; // import ArrowDown from '../../../components/ArrowDown'; | |
| 24 | - | |
| 23 | +import { generateDataSkeleton, getDataPath, getSchemaFromFlatten } from '../../../utils'; | |
| 24 | +import CardList from './CardList'; | |
| 25 | +import DrawerList from './DrawerList'; | |
| 25 | 26 | import "./list.css"; |
| 26 | 27 | import SimpleList from './SimpleList'; |
| 27 | -import CardList from './CardList'; | |
| 28 | 28 | import TableList from './TableList'; |
| 29 | -import DrawerList from './DrawerList'; | |
| 29 | +import TabList from './TabList'; | |
| 30 | 30 | import VirtualList from './VirtualList'; |
| 31 | 31 | import ListForMobile from "./ListForMobile"; |
| 32 | 32 | |
| ... | ... | @@ -47,8 +47,12 @@ var RenderList = function RenderList(_ref) { |
| 47 | 47 | |
| 48 | 48 | var _useTools = useTools(), |
| 49 | 49 | onItemChange = _useTools.onItemChange, |
| 50 | - removeTouched = _useTools.removeTouched; | |
| 50 | + removeTouched = _useTools.removeTouched, | |
| 51 | + methods = _useTools.methods, | |
| 52 | + layoutWidgets = _useTools.layoutWidgets; | |
| 51 | 53 | |
| 54 | + var _schema$props = schema.props, | |
| 55 | + props = _schema$props === void 0 ? {} : _schema$props; | |
| 52 | 56 | var renderWidget = 'list'; |
| 53 | 57 | |
| 54 | 58 | try { |
| ... | ... | @@ -71,9 +75,13 @@ var RenderList = function RenderList(_ref) { |
| 71 | 75 | }; |
| 72 | 76 | |
| 73 | 77 | var addItem = function addItem() { |
| 74 | - var newList = [].concat(_toConsumableArray(displayList), [{ | |
| 78 | + // const newList = [...displayList, {_active: true}]; | |
| 79 | + var _schema = getSchemaFromFlatten(flatten, parentId); | |
| 80 | + | |
| 81 | + var newItem = generateDataSkeleton(_schema.items) || {}; | |
| 82 | + var newList = [].concat(_toConsumableArray(displayList), [_objectSpread(_objectSpread({}, newItem), {}, { | |
| 75 | 83 | _active: true |
| 76 | - }]); | |
| 84 | + })]); | |
| 77 | 85 | var newIndex = newList.length - 1; |
| 78 | 86 | onItemChange(dataPath, newList); |
| 79 | 87 | return newIndex; |
| ... | ... | @@ -98,10 +106,23 @@ var RenderList = function RenderList(_ref) { |
| 98 | 106 | }); |
| 99 | 107 | onItemChange(dataPath, newList); |
| 100 | 108 | removeTouched("".concat(dataPath, "[").concat(idx, "]")); |
| 109 | + }; | |
| 110 | + | |
| 111 | + var handleMoving = function handleMoving() { | |
| 112 | + if (props.onMove && typeof props.onMove === 'string') { | |
| 113 | + var cb = methods[props.onMove]; | |
| 114 | + | |
| 115 | + if (typeof cb === 'function') { | |
| 116 | + cb(); | |
| 117 | + } | |
| 118 | + } | |
| 101 | 119 | }; // 批量删除的方法 |
| 102 | 120 | |
| 103 | 121 | |
| 104 | 122 | var batchDelete = function batchDelete(ids) { |
| 123 | + displayList.forEach(function (item) { | |
| 124 | + return delete item.orginIdx; | |
| 125 | + }); | |
| 105 | 126 | var newList = displayList.filter(function (item, kdx) { |
| 106 | 127 | return !ids.includes(kdx); |
| 107 | 128 | }); |
| ... | ... | @@ -113,6 +134,7 @@ var RenderList = function RenderList(_ref) { |
| 113 | 134 | |
| 114 | 135 | |
| 115 | 136 | var moveItemUp = function moveItemUp(idx) { |
| 137 | + handleMoving(); | |
| 116 | 138 | if (idx === 0) return; |
| 117 | 139 | var currentItem = displayList[idx]; |
| 118 | 140 | var itemAbove = displayList[idx - 1]; |
| ... | ... | @@ -125,6 +147,7 @@ var RenderList = function RenderList(_ref) { |
| 125 | 147 | }; |
| 126 | 148 | |
| 127 | 149 | var moveItemDown = function moveItemDown(idx) { |
| 150 | + handleMoving(); | |
| 128 | 151 | if (idx >= displayList.length - 1) return; |
| 129 | 152 | var currentItem = displayList[idx]; |
| 130 | 153 | var itemBelow = displayList[idx + 1]; |
| ... | ... | @@ -138,7 +161,6 @@ var RenderList = function RenderList(_ref) { |
| 138 | 161 | |
| 139 | 162 | var itemSchema = { |
| 140 | 163 | type: 'object', |
| 141 | - // properties: (schema.items && schema.items.properties) || {}, | |
| 142 | 164 | properties: {}, |
| 143 | 165 | props: schema.props || {}, |
| 144 | 166 | $id: schema.$id |
| ... | ... | @@ -179,11 +201,12 @@ var RenderList = function RenderList(_ref) { |
| 179 | 201 | return /*#__PURE__*/React.createElement(ListForMobile, displayProps); |
| 180 | 202 | } |
| 181 | 203 | |
| 182 | - switch (renderWidget) { | |
| 183 | - case 'list0': | |
| 184 | - case 'cardList': | |
| 185 | - return /*#__PURE__*/React.createElement(CardList, displayProps); | |
| 204 | + if (layoutWidgets && layoutWidgets[renderWidget]) { | |
| 205 | + var Component = layoutWidgets[renderWidget]; | |
| 206 | + return /*#__PURE__*/React.createElement(Component, displayProps); | |
| 207 | + } | |
| 186 | 208 | |
| 209 | + switch (renderWidget) { | |
| 187 | 210 | case 'list1': |
| 188 | 211 | case 'simpleList': |
| 189 | 212 | return /*#__PURE__*/React.createElement(SimpleList, displayProps); |
| ... | ... | @@ -199,9 +222,12 @@ var RenderList = function RenderList(_ref) { |
| 199 | 222 | case 'list4': |
| 200 | 223 | case 'virtualList': |
| 201 | 224 | return /*#__PURE__*/React.createElement(VirtualList, displayProps); |
| 202 | - // case 'listForMobile': | |
| 203 | - // return <ListForMobile {...displayProps} /> | |
| 204 | 225 | |
| 226 | + case 'tabList': | |
| 227 | + return /*#__PURE__*/React.createElement(TabList, displayProps); | |
| 228 | + | |
| 229 | + case 'list0': | |
| 230 | + case 'cardList': | |
| 205 | 231 | default: |
| 206 | 232 | return /*#__PURE__*/React.createElement(CardList, displayProps); |
| 207 | 233 | } | ... | ... |
es/form-render-core/src/core/RenderChildren/RenderList/list.css
renamed from
es/core/RenderChildren/RenderList/list.css
es/form-render-core/src/core/RenderChildren/RenderObject.js
renamed from
es/core/RenderChildren/RenderObject.js
| ... | ... | @@ -9,10 +9,12 @@ var RenderObject = function RenderObject(_ref) { |
| 9 | 9 | _ref$dataIndex = _ref.dataIndex, |
| 10 | 10 | dataIndex = _ref$dataIndex === void 0 ? [] : _ref$dataIndex, |
| 11 | 11 | displayType = _ref.displayType, |
| 12 | + labelAlign = _ref.labelAlign, | |
| 12 | 13 | hideTitle = _ref.hideTitle; |
| 13 | 14 | return /*#__PURE__*/React.createElement(React.Fragment, null, children.map(function (child, i) { |
| 14 | 15 | var FRProps = { |
| 15 | 16 | displayType: displayType, |
| 17 | + labelAlign: labelAlign, | |
| 16 | 18 | id: child, |
| 17 | 19 | dataIndex: dataIndex, |
| 18 | 20 | hideTitle: hideTitle | ... | ... |
es/form-render-core/src/core/RenderField/ErrorMessage.css
renamed from
es/core/RenderField/ErrorMessage.css
es/form-render-core/src/core/RenderField/ErrorMessage.js
renamed from
es/core/RenderField/ErrorMessage.js
| ... | ... | @@ -14,7 +14,9 @@ var ErrorMessage = function ErrorMessage(_ref) { |
| 14 | 14 | msg = message[0] || ''; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - msg = translateMessage(msg, schema); | |
| 17 | + msg = translateMessage(msg, schema); // 无错误信息不渲染 msg 元素占位,表单之间的间隔通过 field-block 元素分隔 | |
| 18 | + | |
| 19 | + if (!msg) return null; | |
| 18 | 20 | if (hardHidden) return /*#__PURE__*/React.createElement("div", { |
| 19 | 21 | className: "error-message" |
| 20 | 22 | }); | ... | ... |
es/form-render-core/src/core/RenderField/ExtendedWidget.js
renamed from
es/core/RenderField/ExtendedWidget.js
| ... | ... | @@ -5,10 +5,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va |
| 5 | 5 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
| 6 | 6 | |
| 7 | 7 | import React, { Suspense } from 'react'; |
| 8 | -import { getWidgetName, extraSchemaList } from '../../mapping'; | |
| 9 | -import { useTools, useStore } from '../../hooks'; | |
| 10 | 8 | import { transformProps } from '../../createWidget'; |
| 11 | -import { isObjType, isListType, isObject } from '../../utils'; | |
| 9 | +import { useStore, useTools } from '../../hooks'; | |
| 10 | +import { extraSchemaList, getWidgetName } from '../../mapping'; | |
| 11 | +import { isListType, isObject, isObjType } from '../../utils'; | |
| 12 | 12 | |
| 13 | 13 | var ErrorSchema = function ErrorSchema(schema) { |
| 14 | 14 | return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", { |
| ... | ... | @@ -30,7 +30,9 @@ var ExtendedWidget = function ExtendedWidget(_ref) { |
| 30 | 30 | readOnly = _ref.readOnly, |
| 31 | 31 | dataPath = _ref.dataPath, |
| 32 | 32 | disabled = _ref.disabled, |
| 33 | - dataIndex = _ref.dataIndex; | |
| 33 | + dataIndex = _ref.dataIndex, | |
| 34 | + watch = _ref.watch, | |
| 35 | + hasError = _ref.hasError; | |
| 34 | 36 | |
| 35 | 37 | var _useTools = useTools(), |
| 36 | 38 | widgets = _useTools.widgets, |
| ... | ... | @@ -43,7 +45,15 @@ var ExtendedWidget = function ExtendedWidget(_ref) { |
| 43 | 45 | getValues = _useTools.getValues, |
| 44 | 46 | resetFields = _useTools.resetFields, |
| 45 | 47 | setErrorFields = _useTools.setErrorFields, |
| 46 | - removeErrorField = _useTools.removeErrorField; | |
| 48 | + removeErrorField = _useTools.removeErrorField, | |
| 49 | + validateFields = _useTools.validateFields, | |
| 50 | + isFieldTouched = _useTools.isFieldTouched, | |
| 51 | + isFieldsTouched = _useTools.isFieldsTouched, | |
| 52 | + isFieldValidating = _useTools.isFieldValidating, | |
| 53 | + scrollToPath = _useTools.scrollToPath, | |
| 54 | + getFieldError = _useTools.getFieldError, | |
| 55 | + getFieldsError = _useTools.getFieldsError, | |
| 56 | + setFields = _useTools.setFields; | |
| 47 | 57 | |
| 48 | 58 | var _useStore = useStore(), |
| 49 | 59 | globalProps = _useStore.globalProps; // if (isObjType(schema)) { |
| ... | ... | @@ -79,7 +89,7 @@ var ExtendedWidget = function ExtendedWidget(_ref) { |
| 79 | 89 | }); |
| 80 | 90 | } |
| 81 | 91 | |
| 82 | - var Widget = widgets[widgetName]; | |
| 92 | + var Widget = widgets[widgetName] || widgets['html']; | |
| 83 | 93 | var extraSchema = extraSchemaList[widgetName]; |
| 84 | 94 | |
| 85 | 95 | var widgetProps = _objectSpread(_objectSpread({ |
| ... | ... | @@ -88,7 +98,10 @@ var ExtendedWidget = function ExtendedWidget(_ref) { |
| 88 | 98 | value: value, |
| 89 | 99 | children: children, |
| 90 | 100 | disabled: disabled, |
| 91 | - readOnly: readOnly | |
| 101 | + readOnly: readOnly, | |
| 102 | + // dataPath, | |
| 103 | + // dataIndex, | |
| 104 | + className: hasError ? 'fr-item-status-error' : '' | |
| 92 | 105 | }, schema.props), globalProps); |
| 93 | 106 | |
| 94 | 107 | if (schema.type === 'string' && typeof schema.max === 'number') { |
| ... | ... | @@ -141,7 +154,16 @@ var ExtendedWidget = function ExtendedWidget(_ref) { |
| 141 | 154 | resetFields: resetFields, |
| 142 | 155 | setErrorFields: setErrorFields, |
| 143 | 156 | removeErrorField: removeErrorField, |
| 144 | - hideSelf: hideSelf | |
| 157 | + validateFields: validateFields, | |
| 158 | + isFieldTouched: isFieldTouched, | |
| 159 | + isFieldsTouched: isFieldsTouched, | |
| 160 | + isFieldValidating: isFieldValidating, | |
| 161 | + scrollToPath: scrollToPath, | |
| 162 | + getFieldError: getFieldError, | |
| 163 | + getFieldsError: getFieldsError, | |
| 164 | + setFields: setFields, | |
| 165 | + hideSelf: hideSelf, | |
| 166 | + watch: watch | |
| 145 | 167 | }; |
| 146 | 168 | var finalProps = transformProps(widgetProps); |
| 147 | 169 | return /*#__PURE__*/React.createElement(Suspense, { |
| ... | ... | @@ -149,34 +171,37 @@ var ExtendedWidget = function ExtendedWidget(_ref) { |
| 149 | 171 | }, /*#__PURE__*/React.createElement("div", { |
| 150 | 172 | className: "fr-item-wrapper" |
| 151 | 173 | }, /*#__PURE__*/React.createElement(Widget, finalProps))); |
| 152 | -}; | |
| 153 | - | |
| 154 | -var areEqual = function areEqual(prev, current) { | |
| 155 | - if (prev.schema && prev.schema.$id === '#') { | |
| 156 | - return false; | |
| 157 | - } | |
| 158 | - | |
| 159 | - if (prev.readOnly !== current.readOnly) { | |
| 160 | - return false; | |
| 161 | - } | |
| 162 | - | |
| 163 | - if (prev.disabled !== current.disabled) { | |
| 164 | - return false; | |
| 165 | - } | |
| 166 | - | |
| 167 | - if (JSON.stringify(prev.dependValues) !== JSON.stringify(current.dependValues)) { | |
| 168 | - return false; | |
| 169 | - } | |
| 170 | - | |
| 171 | - if (isObjType(prev.schema) && isObjType(current.schema)) { | |
| 172 | - return false; | |
| 173 | - } | |
| 174 | - | |
| 175 | - if (JSON.stringify(prev.value) === JSON.stringify(current.value) && JSON.stringify(prev.schema) === JSON.stringify(current.schema)) { | |
| 176 | - return true; | |
| 177 | - } | |
| 178 | - | |
| 179 | - return false; | |
| 180 | -}; | |
| 181 | - | |
| 182 | -export default /*#__PURE__*/React.memo(ExtendedWidget, areEqual); | |
| \ No newline at end of file | ||
| 174 | +}; // const areEqual = (prev, current) => { | |
| 175 | +// if (prev.schema && current.schema) { | |
| 176 | +// if (prev.schema.$id === '#') { | |
| 177 | +// return false; | |
| 178 | +// } | |
| 179 | +// if (prev.schema.hidden && current.schema.hidden) { | |
| 180 | +// return true; | |
| 181 | +// } | |
| 182 | +// } | |
| 183 | +// if (prev.readOnly !== current.readOnly) { | |
| 184 | +// return false; | |
| 185 | +// } | |
| 186 | +// if (prev.disabled !== current.disabled) { | |
| 187 | +// return false; | |
| 188 | +// } | |
| 189 | +// if ( | |
| 190 | +// JSON.stringify(prev.dependValues) !== JSON.stringify(current.dependValues) | |
| 191 | +// ) { | |
| 192 | +// return false; | |
| 193 | +// } | |
| 194 | +// if (isObjType(prev.schema) && isObjType(current.schema)) { | |
| 195 | +// return false; | |
| 196 | +// } | |
| 197 | +// if ( | |
| 198 | +// JSON.stringify(prev.value) === JSON.stringify(current.value) && | |
| 199 | +// JSON.stringify(prev.schema) === JSON.stringify(current.schema) | |
| 200 | +// ) { | |
| 201 | +// return true; | |
| 202 | +// } | |
| 203 | +// return false; | |
| 204 | +// }; | |
| 205 | + | |
| 206 | + | |
| 207 | +export default ExtendedWidget; | |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/core/RenderField/Extra.css
renamed from
es/core/RenderField/Extra.css
es/form-render-core/src/core/RenderField/Extra.js
renamed from
es/core/RenderField/Extra.js
| 1 | +import "antd/es/tooltip/style"; | |
| 2 | +import _Tooltip from "antd/es/tooltip"; | |
| 3 | +import React from 'react'; | |
| 4 | +import { useStore2, useTools } from '../../hooks'; | |
| 5 | +import { isCheckBoxType } from '../../utils'; | |
| 6 | + | |
| 7 | +var Description = function Description(_ref) { | |
| 8 | + var displayType = _ref.displayType, | |
| 9 | + schema = _ref.schema; | |
| 10 | + var description = schema.description, | |
| 11 | + descType = schema.descType, | |
| 12 | + descWidget = schema.descWidget; | |
| 13 | + if (!description && !descWidget) return null; | |
| 14 | + | |
| 15 | + var _useTools = useTools(), | |
| 16 | + widgets = _useTools.widgets; | |
| 17 | + | |
| 18 | + var _description = typeof description === 'string' && /(^<|\/>)/.test(description) ? /*#__PURE__*/React.createElement("div", { | |
| 19 | + dangerouslySetInnerHTML: { | |
| 20 | + __html: description | |
| 21 | + } | |
| 22 | + }) : description; | |
| 23 | + | |
| 24 | + var RenderDesc = function RenderDesc() { | |
| 25 | + var Widget = widgets[schema.descWidget]; | |
| 26 | + | |
| 27 | + if (Widget) { | |
| 28 | + return /*#__PURE__*/React.createElement(Widget, { | |
| 29 | + schema: schema | |
| 30 | + }); | |
| 31 | + } | |
| 32 | + | |
| 33 | + return null; | |
| 34 | + }; | |
| 35 | + | |
| 36 | + switch (displayType) { | |
| 37 | + case 'row': | |
| 38 | + if (descType === 'widget') { | |
| 39 | + return /*#__PURE__*/React.createElement(RenderDesc, null); | |
| 40 | + } | |
| 41 | + | |
| 42 | + return /*#__PURE__*/React.createElement(_Tooltip, { | |
| 43 | + title: _description | |
| 44 | + }, /*#__PURE__*/React.createElement("i", { | |
| 45 | + className: "fr-tooltip-icon" | |
| 46 | + })); | |
| 47 | + | |
| 48 | + case 'inline': | |
| 49 | + return null; | |
| 50 | + | |
| 51 | + default: | |
| 52 | + if (descType === 'widget') { | |
| 53 | + return /*#__PURE__*/React.createElement(RenderDesc, null); | |
| 54 | + } | |
| 55 | + | |
| 56 | + if (descType === 'icon') { | |
| 57 | + return /*#__PURE__*/React.createElement(_Tooltip, { | |
| 58 | + title: _description | |
| 59 | + }, /*#__PURE__*/React.createElement("i", { | |
| 60 | + className: "fr-tooltip-icon" | |
| 61 | + })); | |
| 62 | + } | |
| 63 | + | |
| 64 | + return /*#__PURE__*/React.createElement("span", { | |
| 65 | + className: "fr-desc ml2" | |
| 66 | + }, "( ".concat(description, " )")); | |
| 67 | + } | |
| 68 | +}; | |
| 69 | + | |
| 70 | +var Title = function Title(_ref2) { | |
| 71 | + var labelClass = _ref2.labelClass, | |
| 72 | + labelStyle = _ref2.labelStyle, | |
| 73 | + schema = _ref2.schema, | |
| 74 | + displayType = _ref2.displayType, | |
| 75 | + renderTitle = _ref2.renderTitle, | |
| 76 | + globalRequiredMark = _ref2.requiredMark; | |
| 77 | + | |
| 78 | + var _useStore = useStore2(), | |
| 79 | + globalDisplayType = _useStore.displayType, | |
| 80 | + readOnly = _useStore.readOnly, | |
| 81 | + colon = _useStore.colon; | |
| 82 | + | |
| 83 | + var title = schema.title, | |
| 84 | + required = schema.required, | |
| 85 | + type = schema.type, | |
| 86 | + schemaRequiredMark = schema.requiredMark; | |
| 87 | + var isObjType = type === 'object'; | |
| 88 | + | |
| 89 | + var _displayType = schema.displayType || displayType || globalDisplayType || 'column'; | |
| 90 | + | |
| 91 | + if (renderTitle) { | |
| 92 | + return renderTitle({ | |
| 93 | + labelClass: labelClass, | |
| 94 | + labelStyle: labelStyle, | |
| 95 | + schema: schema, | |
| 96 | + displayType: _displayType, | |
| 97 | + readOnly: readOnly, | |
| 98 | + colon: colon | |
| 99 | + }); | |
| 100 | + } | |
| 101 | + | |
| 102 | + var requiredMark = typeof schemaRequiredMark === 'undefined' ? globalRequiredMark : schemaRequiredMark; // 左侧的的 * 号提示 | |
| 103 | + | |
| 104 | + var TitleRequiredMark = null; // 左侧的 option 提示 | |
| 105 | + | |
| 106 | + var TitleTextMark = null; | |
| 107 | + | |
| 108 | + if (required) { | |
| 109 | + /** | |
| 110 | + * ant-design requiredMark 实现 | |
| 111 | + * https://ant.design/components/form-cn/ | |
| 112 | + */ | |
| 113 | + if (requiredMark !== false && requiredMark !== 'optional') { | |
| 114 | + TitleRequiredMark = /*#__PURE__*/React.createElement("span", { | |
| 115 | + className: "fr-label-required" | |
| 116 | + }, " *"); | |
| 117 | + TitleTextMark = null; | |
| 118 | + } | |
| 119 | + } else { | |
| 120 | + if (requiredMark === 'optional') { | |
| 121 | + TitleRequiredMark = null; | |
| 122 | + TitleTextMark = /*#__PURE__*/React.createElement("span", { | |
| 123 | + className: "fr-label-required-text" | |
| 124 | + }, "\uFF08\u53EF\u9009\uFF09"); | |
| 125 | + } | |
| 126 | + } // requiredMark 为 false 不展示必填符号 | |
| 127 | + | |
| 128 | + | |
| 129 | + if (requiredMark === false) { | |
| 130 | + TitleRequiredMark = null; | |
| 131 | + TitleTextMark = null; | |
| 132 | + } | |
| 133 | + | |
| 134 | + return /*#__PURE__*/React.createElement("div", { | |
| 135 | + className: labelClass, | |
| 136 | + style: labelStyle | |
| 137 | + }, title ? /*#__PURE__*/React.createElement("label", { | |
| 138 | + className: "fr-label-title ".concat(isCheckBoxType(schema, readOnly) || _displayType === 'column' || !colon ? 'no-colon' : '') // checkbox不带冒号 | |
| 139 | + , | |
| 140 | + title: title | |
| 141 | + }, TitleRequiredMark, /*#__PURE__*/React.createElement("span", { | |
| 142 | + className: "".concat(isObjType ? 'b' : '', " ").concat(_displayType === 'column' ? 'flex-none' : '') | |
| 143 | + }, /*#__PURE__*/React.createElement("span", { | |
| 144 | + dangerouslySetInnerHTML: { | |
| 145 | + __html: title | |
| 146 | + } | |
| 147 | + })), TitleTextMark, /*#__PURE__*/React.createElement(Description, { | |
| 148 | + schema: schema, | |
| 149 | + displayType: _displayType | |
| 150 | + })) : null); | |
| 151 | +}; | |
| 152 | + | |
| 153 | +export default Title; | |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/core/RenderField/index.js
renamed from
es/core/RenderField/index.js
| 1 | 1 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } |
| 2 | 2 | |
| 3 | +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | |
| 4 | + | |
| 5 | +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | |
| 6 | + | |
| 7 | +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | |
| 8 | + | |
| 9 | +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | |
| 10 | + | |
| 11 | +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | |
| 12 | + | |
| 13 | +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | |
| 14 | + | |
| 3 | 15 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
| 4 | 16 | |
| 5 | -import React, { useEffect, useRef } from 'react'; | |
| 17 | +import React, { useRef } from 'react'; | |
| 6 | 18 | import { useStore, useStore2, useTools } from '../../hooks'; |
| 7 | 19 | import useDebouncedCallback from '../../useDebounce'; |
| 8 | -import { getValueByPath, isCheckBoxType, isObjType } from '../../utils'; | |
| 20 | +import { getValueByPath, isCheckBoxType, isObjType, isBlockType } from '../../utils'; | |
| 21 | +import { validateField } from '../../validator'; | |
| 9 | 22 | import ErrorMessage from './ErrorMessage'; |
| 23 | +import ExtendedWidget from './ExtendedWidget'; | |
| 10 | 24 | import Extra from './Extra'; |
| 11 | -import FieldTitle from './Title'; | |
| 12 | -import ExtendedWidget from './ExtendedWidget'; // TODO: 之后不要直接用get,收口到一个内部方法getValue,便于全局 ctrl + f 查找 | |
| 25 | +import FieldTitle from './Title'; // TODO: 之后不要直接用get,收口到一个内部方法getValue,便于全局 ctrl + f 查找 | |
| 13 | 26 | |
| 14 | 27 | var RenderField = function RenderField(props) { |
| 15 | 28 | var $id = props.$id, |
| ... | ... | @@ -28,19 +41,28 @@ var RenderField = function RenderField(props) { |
| 28 | 41 | displayType = props.displayType; |
| 29 | 42 | |
| 30 | 43 | var _useStore = useStore(), |
| 31 | - formData = _useStore.formData; | |
| 44 | + formData = _useStore.formData, | |
| 45 | + flatten = _useStore.flatten; | |
| 32 | 46 | |
| 33 | 47 | var _useStore2 = useStore2(), |
| 34 | 48 | debounceInput = _useStore2.debounceInput, |
| 35 | 49 | readOnly = _useStore2.readOnly, |
| 36 | 50 | disabled = _useStore2.disabled, |
| 37 | - showValidate = _useStore2.showValidate; | |
| 51 | + showValidate = _useStore2.showValidate, | |
| 52 | + validateMessages = _useStore2.validateMessages, | |
| 53 | + locale = _useStore2.locale, | |
| 54 | + watch = _useStore2.watch; | |
| 38 | 55 | |
| 39 | 56 | var _useTools = useTools(), |
| 40 | 57 | onValuesChange = _useTools.onValuesChange, |
| 41 | 58 | onItemChange = _useTools.onItemChange, |
| 42 | 59 | setEditing = _useTools.setEditing, |
| 43 | - touchKey = _useTools.touchKey; | |
| 60 | + touchKey = _useTools.touchKey, | |
| 61 | + _setErrors = _useTools._setErrors, | |
| 62 | + renderTitle = _useTools.renderTitle, | |
| 63 | + requiredMark = _useTools.requiredMark, | |
| 64 | + setFieldValidating = _useTools.setFieldValidating, | |
| 65 | + removeFieldValidating = _useTools.removeFieldValidating; | |
| 44 | 66 | |
| 45 | 67 | var formDataRef = useRef(); |
| 46 | 68 | formDataRef.current = formData; // console.log('<renderField>', $id); |
| ... | ... | @@ -58,7 +80,38 @@ var RenderField = function RenderField(props) { |
| 58 | 80 | |
| 59 | 81 | var _readOnly = readOnly !== undefined ? readOnly : _schema.readOnly; |
| 60 | 82 | |
| 61 | - var _disabled = disabled !== undefined ? disabled : _schema.disabled; // TODO: 优化一下,只有touch还是false的时候,setTouched | |
| 83 | + var _disabled = disabled !== undefined ? disabled : _schema.disabled; | |
| 84 | + | |
| 85 | + var removeDupErrors = function removeDupErrors(arr) { | |
| 86 | + if (!Array.isArray(arr)) { | |
| 87 | + console.log('in removeDups: param is not an array'); | |
| 88 | + return; | |
| 89 | + } | |
| 90 | + | |
| 91 | + var array = []; | |
| 92 | + | |
| 93 | + for (var i = 0; i < arr.length; i++) { | |
| 94 | + var sameNameIndex = array.findIndex(function (item) { | |
| 95 | + return item.name === arr[i].name; | |
| 96 | + }); | |
| 97 | + | |
| 98 | + if (sameNameIndex > -1) { | |
| 99 | + var sameNameItem = array[sameNameIndex]; | |
| 100 | + var error1 = sameNameItem.error; | |
| 101 | + var error2 = arr[i].error; | |
| 102 | + array[sameNameIndex] = { | |
| 103 | + name: sameNameItem.name, | |
| 104 | + error: error1.length > 0 && error2.length > 0 ? error2 : [] | |
| 105 | + }; | |
| 106 | + } else { | |
| 107 | + array.push(arr[i]); | |
| 108 | + } | |
| 109 | + } | |
| 110 | + | |
| 111 | + return array.filter(function (item) { | |
| 112 | + return Array.isArray(item.error) && item.error.length > 0; | |
| 113 | + }); | |
| 114 | + }; // TODO: 优化一下,只有touch还是false的时候,setTouched | |
| 62 | 115 | |
| 63 | 116 | |
| 64 | 117 | var onChange = function onChange(value) { |
| ... | ... | @@ -78,13 +131,33 @@ var RenderField = function RenderField(props) { |
| 78 | 131 | if (typeof onValuesChange === 'function') { |
| 79 | 132 | onValuesChange(_defineProperty({}, dataPath, value), formDataRef.current); |
| 80 | 133 | } |
| 134 | + | |
| 135 | + validateField({ | |
| 136 | + path: dataPath, | |
| 137 | + formData: formDataRef.current, | |
| 138 | + flatten: flatten, | |
| 139 | + options: { | |
| 140 | + locale: locale, | |
| 141 | + validateMessages: validateMessages | |
| 142 | + }, | |
| 143 | + formInstance: { | |
| 144 | + setFieldValidating: setFieldValidating, | |
| 145 | + removeFieldValidating: removeFieldValidating | |
| 146 | + } | |
| 147 | + }).then(function (res) { | |
| 148 | + _setErrors(function (errors) { | |
| 149 | + return removeDupErrors([].concat(_toConsumableArray(errors), _toConsumableArray(res))); | |
| 150 | + }); | |
| 151 | + }); | |
| 81 | 152 | }; |
| 82 | 153 | |
| 83 | 154 | var titleProps = { |
| 84 | 155 | labelClass: labelClass, |
| 85 | 156 | labelStyle: labelStyle, |
| 86 | 157 | schema: _schema, |
| 87 | - displayType: displayType | |
| 158 | + displayType: displayType, | |
| 159 | + renderTitle: renderTitle, | |
| 160 | + requiredMark: requiredMark | |
| 88 | 161 | }; |
| 89 | 162 | var messageProps = { |
| 90 | 163 | message: errorMessage, |
| ... | ... | @@ -124,17 +197,31 @@ var RenderField = function RenderField(props) { |
| 124 | 197 | onItemChange: onItemChange, |
| 125 | 198 | dataIndex: dataIndex, |
| 126 | 199 | dataPath: dataPath, |
| 127 | - children: children | |
| 200 | + children: children, | |
| 201 | + watch: watch, | |
| 202 | + hasError: hasError | |
| 203 | + }; | |
| 204 | + | |
| 205 | + var displayBlock = function displayBlock() { | |
| 206 | + if (hasError && !_schema.extra) { | |
| 207 | + return false; | |
| 208 | + } | |
| 209 | + | |
| 210 | + return true; | |
| 128 | 211 | }; // if (_schema && _schema.default !== undefined) { |
| 129 | 212 | // widgetProps.value = _schema.default; |
| 130 | 213 | // } |
| 131 | 214 | // checkbox必须单独处理,布局太不同了 |
| 132 | 215 | |
| 216 | + | |
| 133 | 217 | if (isCheckBoxType(_schema, _readOnly)) { |
| 134 | 218 | return /*#__PURE__*/React.createElement(React.Fragment, null, _showTitle && /*#__PURE__*/React.createElement("div", placeholderTitleProps), /*#__PURE__*/React.createElement("div", { |
| 135 | 219 | className: contentClass, |
| 136 | - style: contentStyle | |
| 137 | - }, /*#__PURE__*/React.createElement(ExtendedWidget, widgetProps), /*#__PURE__*/React.createElement(Extra, widgetProps), /*#__PURE__*/React.createElement(ErrorMessage, messageProps))); | |
| 220 | + style: contentStyle, | |
| 221 | + datapath: dataPath | |
| 222 | + }, /*#__PURE__*/React.createElement(ExtendedWidget, widgetProps), /*#__PURE__*/React.createElement(ErrorMessage, messageProps), /*#__PURE__*/React.createElement(Extra, widgetProps), displayBlock() && /*#__PURE__*/React.createElement("div", { | |
| 223 | + className: "field-block" | |
| 224 | + }))); | |
| 138 | 225 | } |
| 139 | 226 | |
| 140 | 227 | var titleElement = /*#__PURE__*/React.createElement(FieldTitle, titleProps); |
| ... | ... | @@ -144,20 +231,30 @@ var RenderField = function RenderField(props) { |
| 144 | 231 | style: { |
| 145 | 232 | display: 'flex' |
| 146 | 233 | } |
| 147 | - }, titleElement, /*#__PURE__*/React.createElement(ErrorMessage, messageProps)); | |
| 234 | + }, titleElement, /*#__PURE__*/React.createElement(ErrorMessage, messageProps), displayBlock() && /*#__PURE__*/React.createElement("div", { | |
| 235 | + className: "field-block" | |
| 236 | + })); | |
| 148 | 237 | return /*#__PURE__*/React.createElement("div", { |
| 149 | 238 | className: contentClass, |
| 150 | - style: contentStyle | |
| 239 | + style: contentStyle, | |
| 240 | + datapath: dataPath | |
| 151 | 241 | }, /*#__PURE__*/React.createElement(ExtendedWidget, _extends({}, widgetProps, { |
| 152 | 242 | message: errorMessage, |
| 153 | 243 | title: _showTitle ? titleElement : undefined |
| 154 | 244 | })), /*#__PURE__*/React.createElement(Extra, widgetProps)); |
| 245 | + } else if (isBlockType(_schema)) { | |
| 246 | + return /*#__PURE__*/React.createElement("div", { | |
| 247 | + datapath: dataPath | |
| 248 | + }, /*#__PURE__*/React.createElement(ExtendedWidget, widgetProps)); | |
| 155 | 249 | } |
| 156 | 250 | |
| 157 | 251 | return /*#__PURE__*/React.createElement(React.Fragment, null, _showTitle && titleElement, /*#__PURE__*/React.createElement("div", { |
| 158 | 252 | className: "".concat(contentClass, " ").concat(hideTitle ? 'fr-content-no-title' : ''), |
| 159 | - style: contentStyle | |
| 160 | - }, /*#__PURE__*/React.createElement(ExtendedWidget, widgetProps), /*#__PURE__*/React.createElement(Extra, widgetProps), /*#__PURE__*/React.createElement(ErrorMessage, messageProps))); | |
| 253 | + style: contentStyle, | |
| 254 | + datapath: dataPath | |
| 255 | + }, /*#__PURE__*/React.createElement(ExtendedWidget, widgetProps), /*#__PURE__*/React.createElement(ErrorMessage, messageProps), /*#__PURE__*/React.createElement(Extra, widgetProps), displayBlock() && /*#__PURE__*/React.createElement("div", { | |
| 256 | + className: "field-block" | |
| 257 | + }))); | |
| 161 | 258 | }; |
| 162 | 259 | |
| 163 | 260 | export default RenderField; |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/core/index.js
renamed from
es/core/index.js
| 1 | 1 | var _excluded = ["id", "_item", "dataIndex", "hideTitle", "hideValidation", "debugCss"], |
| 2 | - _excluded2 = ["id", "item", "dataIndex", "dataPath", "hideTitle", "hideValidation", "debugCss", "schema", "_value", "dependValues", "displayType", "column", "labelWidth", "readOnly", "errorFields", "effectiveLabelWidth"]; | |
| 2 | + _excluded2 = ["id", "item", "dataIndex", "dataPath", "hideTitle", "hideValidation", "debugCss", "schema", "_value", "dependValues", "displayType", "labelAlign", "column", "labelWidth", "readOnly", "errorFields", "effectiveLabelWidth"]; | |
| 3 | 3 | |
| 4 | 4 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } |
| 5 | 5 | |
| ... | ... | @@ -12,11 +12,11 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return |
| 12 | 12 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } |
| 13 | 13 | |
| 14 | 14 | import React, { useRef } from 'react'; |
| 15 | +import { useStore, useStore2 } from '../hooks'; | |
| 16 | +import { clone, getDataPath, getParentPath, getParentProps, getValueByPath, isCheckBoxType, isCssLength, isListType, isLooselyNumber, isObjType, parseRootValueInSchema } from '../utils'; | |
| 15 | 17 | import RenderList from './RenderChildren/RenderList'; |
| 16 | 18 | import RenderObject from './RenderChildren/RenderObject'; |
| 17 | 19 | import RenderField from './RenderField'; |
| 18 | -import { useStore, useStore2 } from '../hooks'; | |
| 19 | -import { isLooselyNumber, isCssLength, getParentProps, getParentPath, isListType, isCheckBoxType, isObjType, getValueByPath, getDataPath, parseRootValueInSchema, clone } from '../utils'; | |
| 20 | 20 | |
| 21 | 21 | var Core = function Core(_ref) { |
| 22 | 22 | var _ref$id = _ref.id, |
| ... | ... | @@ -31,7 +31,6 @@ var Core = function Core(_ref) { |
| 31 | 31 | debugCss = _ref.debugCss, |
| 32 | 32 | rest = _objectWithoutProperties(_ref, _excluded); |
| 33 | 33 | |
| 34 | - // console.log('<Core>', id); | |
| 35 | 34 | var snapShot = useRef(); |
| 36 | 35 | |
| 37 | 36 | var _useStore = useStore(), |
| ... | ... | @@ -45,7 +44,8 @@ var Core = function Core(_ref) { |
| 45 | 44 | displayType = _useStore2.displayType, |
| 46 | 45 | column = _useStore2.column, |
| 47 | 46 | labelWidth = _useStore2.labelWidth, |
| 48 | - readOnly = _useStore2.readOnly; | |
| 47 | + readOnly = _useStore2.readOnly, | |
| 48 | + labelAlign = _useStore2.labelAlign; | |
| 49 | 49 | |
| 50 | 50 | var item = _item ? _item : flatten[id]; |
| 51 | 51 | if (!item) return null; |
| ... | ... | @@ -54,7 +54,8 @@ var Core = function Core(_ref) { |
| 54 | 54 | |
| 55 | 55 | var _value = getValueByPath(formData, dataPath); |
| 56 | 56 | |
| 57 | - var schema = clone(item.schema); | |
| 57 | + var schema = clone(item.schema); // schema.disabled = !!subReadOnly; | |
| 58 | + | |
| 58 | 59 | var dependencies = schema.dependencies; |
| 59 | 60 | var dependValues = []; |
| 60 | 61 | var rootValue; |
| ... | ... | @@ -73,6 +74,10 @@ var Core = function Core(_ref) { |
| 73 | 74 | |
| 74 | 75 | try { |
| 75 | 76 | rootValue = getValueByPath(formData, parentPath); |
| 77 | + | |
| 78 | + if (dataIndex.length) { | |
| 79 | + rootValue.index = dataIndex[dataIndex.length - 1]; | |
| 80 | + } | |
| 76 | 81 | } catch (error) {} // 节流部分逻辑,编辑时不执行 |
| 77 | 82 | |
| 78 | 83 | |
| ... | ... | @@ -108,7 +113,8 @@ var Core = function Core(_ref) { |
| 108 | 113 | readOnly: readOnly, |
| 109 | 114 | errorFields: errorFields, |
| 110 | 115 | effectiveLabelWidth: effectiveLabelWidth, |
| 111 | - allTouched: allTouched | |
| 116 | + allTouched: allTouched, | |
| 117 | + labelAlign: labelAlign | |
| 112 | 118 | }, rest); |
| 113 | 119 | |
| 114 | 120 | return /*#__PURE__*/React.createElement(CoreRender, dataProps); |
| ... | ... | @@ -126,6 +132,7 @@ var CoreRender = function CoreRender(_ref2) { |
| 126 | 132 | _value = _ref2._value, |
| 127 | 133 | dependValues = _ref2.dependValues, |
| 128 | 134 | displayType = _ref2.displayType, |
| 135 | + labelAlign = _ref2.labelAlign, | |
| 129 | 136 | column = _ref2.column, |
| 130 | 137 | labelWidth = _ref2.labelWidth, |
| 131 | 138 | readOnly = _ref2.readOnly, |
| ... | ... | @@ -133,13 +140,16 @@ var CoreRender = function CoreRender(_ref2) { |
| 133 | 140 | effectiveLabelWidth = _ref2.effectiveLabelWidth, |
| 134 | 141 | rest = _objectWithoutProperties(_ref2, _excluded2); |
| 135 | 142 | |
| 136 | - // if (schema.hidden) { | |
| 137 | - // return null; | |
| 138 | - // } | |
| 139 | - // 样式的逻辑全放在这层 | |
| 143 | + if (schema.hidden) { | |
| 144 | + return null; | |
| 145 | + } // 样式的逻辑全放在这层 | |
| 140 | 146 | // displayType 一层层网上找值 |
| 147 | + | |
| 148 | + | |
| 141 | 149 | var _displayType = schema.displayType || rest.displayType || displayType || 'column'; |
| 142 | 150 | |
| 151 | + var _labelAlign = schema.labelAlign || rest.labelAlign || labelAlign || 'right'; | |
| 152 | + | |
| 143 | 153 | var isList = isListType(schema); |
| 144 | 154 | var isObj = isObjType(schema); |
| 145 | 155 | var isComplex = isObj || isList; |
| ... | ... | @@ -215,7 +225,7 @@ var CoreRender = function CoreRender(_ref2) { |
| 215 | 225 | } else if (_displayType === 'row') { |
| 216 | 226 | // row specific className |
| 217 | 227 | containerClass += ''; |
| 218 | - labelClass += ' fr-label-row'; | |
| 228 | + labelClass += " fr-label-row ".concat(_labelAlign === 'right' ? 'fr-label-align-right' : 'fr-label-align-left'); | |
| 219 | 229 | contentClass += ' fr-content-row'; |
| 220 | 230 | |
| 221 | 231 | if (!isObj && !isCheckBox) { |
| ... | ... | @@ -293,6 +303,7 @@ var CoreRender = function CoreRender(_ref2) { |
| 293 | 303 | dataIndex: dataIndex, |
| 294 | 304 | errorFields: errorFields, |
| 295 | 305 | displayType: _displayType, |
| 306 | + labelAlign: _labelAlign, | |
| 296 | 307 | hideTitle: hideTitle |
| 297 | 308 | }, item.children)); |
| 298 | 309 | var listChildren = /*#__PURE__*/React.createElement(RenderList, { |
| ... | ... | @@ -320,7 +331,8 @@ var CoreRender = function CoreRender(_ref2) { |
| 320 | 331 | style: columnStyle, |
| 321 | 332 | className: "".concat(containerClass, " ").concat(debugCss ? 'debug' : '') |
| 322 | 333 | }, /*#__PURE__*/React.createElement(RenderField, fieldProps, _children)); |
| 323 | -}; | |
| 334 | +}; // haven't used | |
| 335 | + | |
| 324 | 336 | |
| 325 | 337 | var areEqual = function areEqual(prev, current) { |
| 326 | 338 | if (prev.allTouched !== current.allTouched) { |
| ... | ... | @@ -339,6 +351,24 @@ var areEqual = function areEqual(prev, current) { |
| 339 | 351 | return false; |
| 340 | 352 | } |
| 341 | 353 | |
| 354 | + if (prev.readOnly !== current.readOnly) { | |
| 355 | + return false; | |
| 356 | + } | |
| 357 | + | |
| 358 | + if (prev.disabled !== current.disabled) { | |
| 359 | + return false; | |
| 360 | + } | |
| 361 | + | |
| 362 | + if (prev.schema && current.schema) { | |
| 363 | + if (prev.schema.$id === '#') { | |
| 364 | + return false; | |
| 365 | + } | |
| 366 | + } | |
| 367 | + | |
| 368 | + if (isObjType(prev.schema) && isObjType(current.schema)) { | |
| 369 | + return false; | |
| 370 | + } | |
| 371 | + | |
| 342 | 372 | if (JSON.stringify(prev.dependValues) !== JSON.stringify(current.dependValues)) { |
| 343 | 373 | return false; |
| 344 | 374 | } |
| ... | ... | @@ -350,5 +380,4 @@ var areEqual = function areEqual(prev, current) { |
| 350 | 380 | return false; |
| 351 | 381 | }; |
| 352 | 382 | |
| 353 | -var MCore = /*#__PURE__*/React.memo(CoreRender, areEqual); | |
| 354 | 383 | export default Core; |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/createWidget.js
renamed from
es/createWidget.js
es/form-render-core/src/hooks.js
renamed from
es/hooks.js
| ... | ... | @@ -16,7 +16,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy |
| 16 | 16 | |
| 17 | 17 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } |
| 18 | 18 | |
| 19 | -import { useReducer, useContext, useRef, useEffect, useState, createContext } from 'react'; | |
| 19 | +import { createContext, useContext, useEffect, useReducer, useRef, useState } from 'react'; | |
| 20 | 20 | export var Ctx = /*#__PURE__*/createContext(function () {}); |
| 21 | 21 | export var StoreCtx = /*#__PURE__*/createContext({}); |
| 22 | 22 | export var Store2Ctx = /*#__PURE__*/createContext({}); | ... | ... |
es/form-render-core/src/index.css
renamed from
es/index.css
| ... | ... | @@ -29,13 +29,56 @@ |
| 29 | 29 | align-items: center; |
| 30 | 30 | min-height: 32px; |
| 31 | 31 | } |
| 32 | +.fr-container .fr-item-has-error { | |
| 33 | + border-color: #ff4d4f; | |
| 34 | +} | |
| 35 | +.fr-container .fr-item-has-error:focus { | |
| 36 | + border-color: #ff7875 !important; | |
| 37 | + box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.2) !important; | |
| 38 | +} | |
| 39 | +.fr-container .fr-item-has-error:hover { | |
| 40 | + border-color: #ff7875 !important; | |
| 41 | + box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.2) !important; | |
| 42 | +} | |
| 43 | +.fr-container .fr-item-status-error { | |
| 44 | + border-color: #ff4d4f; | |
| 45 | +} | |
| 46 | +.fr-container .fr-item-status-error:focus { | |
| 47 | + border-color: #ff7875 !important; | |
| 48 | + box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.2) !important; | |
| 49 | +} | |
| 50 | +.fr-container .fr-item-status-error:hover { | |
| 51 | + border-color: #ff7875 !important; | |
| 52 | + box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.2) !important; | |
| 53 | +} | |
| 54 | +.fr-container .fr-item-status-error input[class~='ant-input'] { | |
| 55 | + border-color: #ff4d4f; | |
| 56 | +} | |
| 57 | +.fr-container .fr-item-status-error input[class~='ant-input']:focus { | |
| 58 | + border-color: #ff7875 !important; | |
| 59 | + box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.2) !important; | |
| 60 | +} | |
| 61 | +.fr-container .fr-item-status-error input[class~='ant-input']:hover { | |
| 62 | + border-color: #ff7875 !important; | |
| 63 | + box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.2) !important; | |
| 64 | +} | |
| 65 | +.fr-container .fr-item-status-error div[class~='ant-select-selector'] { | |
| 66 | + border-color: #ff4d4f; | |
| 67 | +} | |
| 68 | +.fr-container .fr-item-status-error div[class~='ant-select-selector']:focus { | |
| 69 | + border-color: #ff7875 !important; | |
| 70 | + box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.2) !important; | |
| 71 | +} | |
| 72 | +.fr-container .fr-item-status-error div[class~='ant-select-selector']:hover { | |
| 73 | + border-color: #ff7875 !important; | |
| 74 | + box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.2) !important; | |
| 75 | +} | |
| 32 | 76 | .fr-container .ant-table-cell .fr-field { |
| 33 | 77 | margin-bottom: 0; |
| 34 | 78 | } |
| 35 | 79 | .fr-container .fr-collapse-object { |
| 36 | 80 | margin-bottom: 8px; |
| 37 | 81 | overflow: hidden; |
| 38 | - background: #f7f7f7; | |
| 39 | 82 | border-radius: 2px; |
| 40 | 83 | } |
| 41 | 84 | .fr-container .fr-collapse-object .ant-collapse-header { |
| ... | ... | @@ -48,14 +91,25 @@ |
| 48 | 91 | .fr-container .fr-collapse-object .ant-collapse-arrow { |
| 49 | 92 | padding-top: 5px !important; |
| 50 | 93 | } |
| 94 | +.fr-container .fr-collapse-object .fr-collapse-object-child-column { | |
| 95 | + padding: 0 20px; | |
| 96 | +} | |
| 97 | +.fr-container .fr-collapse-object .fr-collapse-object-child-row { | |
| 98 | + padding: 0 32px; | |
| 99 | +} | |
| 51 | 100 | .fr-container .fr-label { |
| 52 | 101 | display: block; |
| 53 | 102 | } |
| 54 | 103 | .fr-container .fr-label-row { |
| 55 | - text-align: right; | |
| 56 | 104 | flex-shrink: 0; |
| 57 | 105 | margin-top: 5px; |
| 58 | 106 | } |
| 107 | +.fr-container .fr-label-align-right { | |
| 108 | + text-align: right; | |
| 109 | +} | |
| 110 | +.fr-container .fr-label-align-left { | |
| 111 | + text-align: left; | |
| 112 | +} | |
| 59 | 113 | .fr-container .fr-label-column { |
| 60 | 114 | margin-bottom: 4px; |
| 61 | 115 | } |
| ... | ... | @@ -73,6 +127,12 @@ |
| 73 | 127 | font-size: 14px; |
| 74 | 128 | font-family: SimSun, sans-serif; |
| 75 | 129 | } |
| 130 | +.fr-container .fr-label-required-text { | |
| 131 | + margin: 0 4px 0 0; | |
| 132 | + color: rgba(0, 0, 0, 0.45); | |
| 133 | + font-size: 14px; | |
| 134 | + font-family: SimSun, sans-serif; | |
| 135 | +} | |
| 76 | 136 | .fr-container .fr-label-title::after { |
| 77 | 137 | content: ':'; |
| 78 | 138 | position: relative; |
| ... | ... | @@ -80,8 +140,8 @@ |
| 80 | 140 | margin: 0 10px 0 2px; |
| 81 | 141 | } |
| 82 | 142 | .fr-container .fr-label-title.no-colon::after { |
| 83 | - content: ''; | |
| 84 | - margin: 0; | |
| 143 | + content: ' '; | |
| 144 | + margin: 0 10px 0 2px; | |
| 85 | 145 | } |
| 86 | 146 | .fr-container .fr-label-object .fr-label-title { |
| 87 | 147 | font-size: 16px; |
| ... | ... | @@ -235,10 +295,6 @@ |
| 235 | 295 | cursor: pointer; |
| 236 | 296 | position: relative; |
| 237 | 297 | } |
| 238 | -.fr-container .fr-tooltip-toggle:hover .fr-tooltip-container { | |
| 239 | - opacity: 1; | |
| 240 | - visibility: visible; | |
| 241 | -} | |
| 242 | 298 | .fr-container .fr-tooltip-icon { |
| 243 | 299 | height: 14px; |
| 244 | 300 | width: 14px; |
| ... | ... | @@ -247,57 +303,6 @@ |
| 247 | 303 | display: block; |
| 248 | 304 | margin: 4px 0 0 4px; |
| 249 | 305 | } |
| 250 | -.fr-container .fr-tooltip-container { | |
| 251 | - position: absolute; | |
| 252 | - width: 160px; | |
| 253 | - white-space: initial !important; | |
| 254 | - top: -4px; | |
| 255 | - left: 0; | |
| 256 | - bottom: unset; | |
| 257 | - transform: translateY(-100%); | |
| 258 | - text-align: left; | |
| 259 | - background: #2b222a; | |
| 260 | - padding: 4px; | |
| 261 | - margin-left: -69px; | |
| 262 | - border-radius: 4px; | |
| 263 | - color: #efefef; | |
| 264 | - font-size: 13px; | |
| 265 | - cursor: auto; | |
| 266 | - z-index: 99999; | |
| 267 | - transition: all 0.5s ease; | |
| 268 | - opacity: 0; | |
| 269 | - visibility: hidden; | |
| 270 | - word-wrap: break-word; | |
| 271 | -} | |
| 272 | -.fr-container .fr-tooltip-triangle { | |
| 273 | - position: absolute; | |
| 274 | - left: 50%; | |
| 275 | - border-left: 5px solid transparent; | |
| 276 | - border-right: 5px solid transparent; | |
| 277 | - border-top: 5px solid #2b222a; | |
| 278 | - transition: all 0.5s ease; | |
| 279 | - content: ' '; | |
| 280 | - font-size: 0; | |
| 281 | - line-height: 0; | |
| 282 | - margin-left: -5px; | |
| 283 | - width: 0; | |
| 284 | - bottom: -5px; | |
| 285 | -} | |
| 286 | -.fr-container .fr-tooltip-toggle::before, | |
| 287 | -.fr-container .fr-tooltip-toggle::after { | |
| 288 | - color: #efefef; | |
| 289 | - font-size: 13px; | |
| 290 | - opacity: 0; | |
| 291 | - pointer-events: none; | |
| 292 | - text-align: center; | |
| 293 | -} | |
| 294 | -.fr-container .fr-tooltip-toggle:focus::before, | |
| 295 | -.fr-container .fr-tooltip-toggle:focus::after, | |
| 296 | -.fr-container .fr-tooltip-toggle:hover::before, | |
| 297 | -.fr-container .fr-tooltip-toggle:hover::after { | |
| 298 | - opacity: 1; | |
| 299 | - transition: all 0.75s ease; | |
| 300 | -} | |
| 301 | 306 | .fr-container .fr-slider { |
| 302 | 307 | display: flex; |
| 303 | 308 | width: 100%; |
| ... | ... | @@ -314,14 +319,6 @@ |
| 314 | 319 | background-color: rgba(255, 77, 79, 0.2); |
| 315 | 320 | } |
| 316 | 321 | .fr-container .fr-theme-card-wrap { |
| 317 | - background-color: #fff; | |
| 318 | - padding: 36px 40px; | |
| 319 | - margin-bottom: 24px; | |
| 320 | - border-radius: 4px; | |
| 321 | - display: flex; | |
| 322 | - justify-content: space-between; | |
| 323 | -} | |
| 324 | -.fr-container .fr-theme-card-wrap .fr-theme-card-title { | |
| 325 | - font-size: 16px; | |
| 326 | 322 | margin-bottom: 16px; |
| 323 | + width: 100%; | |
| 327 | 324 | } | ... | ... |
es/form-render-core/src/index.d.ts
0 → 100644
| 1 | +import * as React from 'react'; | |
| 2 | +export interface Error { | |
| 3 | + /** 错误的数据路径 */ | |
| 4 | + name: string; | |
| 5 | + /** 错误的内容 */ | |
| 6 | + error: string[]; | |
| 7 | +} | |
| 8 | +export interface FormParams { | |
| 9 | + formData?: any; | |
| 10 | + onChange?: (data: any) => void; | |
| 11 | + onValidate?: (valid: any) => void; | |
| 12 | + showValidate?: boolean; | |
| 13 | + /** 数据分析接口,表单展示完成渲染时触发 */ | |
| 14 | + logOnMount?: (stats: any) => void; | |
| 15 | + /** 数据分析接口,表单提交成功时触发,获得本次表单填写的总时长 */ | |
| 16 | + logOnSubmit?: (stats: any) => void; | |
| 17 | +} | |
| 18 | + | |
| 19 | +export interface ValidateParams { | |
| 20 | + formData: any; | |
| 21 | + schema: any; | |
| 22 | + error: Error[]; | |
| 23 | + [k: string]: any; | |
| 24 | +} | |
| 25 | + | |
| 26 | +export interface ResetParams { | |
| 27 | + formData?: any; | |
| 28 | + submitData?: any; | |
| 29 | + errorFields?: Error[]; | |
| 30 | + touchedKeys?: any[]; | |
| 31 | + allTouched?: boolean; | |
| 32 | + [k: string]: any; | |
| 33 | +} | |
| 34 | + | |
| 35 | +export interface FormInstance { | |
| 36 | + formData: any; | |
| 37 | + schema: any; | |
| 38 | + flatten: any; | |
| 39 | + touchedKeys: string[]; | |
| 40 | + touchKey: (key: string) => void; | |
| 41 | + onItemChange: (path: string, value: any) => void; | |
| 42 | + setValueByPath: (path: string, value: any) => void; | |
| 43 | + getSchemaByPath: (path: string) => object; | |
| 44 | + setSchemaByPath: (path: string, value: any) => void; | |
| 45 | + setSchema: (settings: any) => void; | |
| 46 | + setValues: (formData: any) => void; | |
| 47 | + getValues: () => any; | |
| 48 | + resetFields: (options?: ResetParams) => void; | |
| 49 | + submit: () => Promise<void> | Promise<any[]>; | |
| 50 | + submitData: any; | |
| 51 | + errorFields: Error[]; | |
| 52 | + isValidating: boolean; | |
| 53 | + outsideValidating: boolean; | |
| 54 | + isSubmitting: boolean; | |
| 55 | + endValidating: () => void; | |
| 56 | + endSubmitting: () => void; | |
| 57 | + setErrorFields: (error: Error[]) => void; | |
| 58 | + removeErrorField: (path: string) => void; | |
| 59 | + removeTouched: (path: string) => void; | |
| 60 | + changeTouchedKeys: (pathArray: string[]) => void; | |
| 61 | + isEditing: boolean; | |
| 62 | + setEditing: (status: boolean) => void; | |
| 63 | + syncStuff: (args: any) => void; | |
| 64 | + /** 折中升级方案中使用到,正常用不到 */ | |
| 65 | + init: () => void; | |
| 66 | + /** 数据分析接口,表单展示完成渲染时触发 */ | |
| 67 | + logOnMount: (args: any) => void; | |
| 68 | + /** 数据分析接口,表单提交成功时触发,获得本次表单填写的总时长 */ | |
| 69 | + logOnSubmit: (args: any) => void; | |
| 70 | + _setErrors: (args: any) => void; | |
| 71 | + validateFields: (nameList?: string[]) => Promise<any>; | |
| 72 | + isFieldTouched: (name: string) => boolean; | |
| 73 | + isFieldsTouched: (nameList?: string[], allTouched?: boolean) => boolean; | |
| 74 | + isFieldValidating: (name: string) => boolean; | |
| 75 | + scrollToPath: (name: string) => void; | |
| 76 | + getFieldError: (name: string) => string[]; | |
| 77 | + getFieldsError: (nameList?: string[]) => Error[]; | |
| 78 | + setFields: (nameList: string[]) => void; | |
| 79 | +} | |
| 80 | + | |
| 81 | +export type WatchProperties = { | |
| 82 | + [path: string]: | |
| 83 | + | { | |
| 84 | + handler: (value: any) => void; | |
| 85 | + immediate?: boolean; | |
| 86 | + } | |
| 87 | + | ((value: any) => void); | |
| 88 | +}; | |
| 89 | + | |
| 90 | +export interface FRProps { | |
| 91 | + /** 表单 id */ | |
| 92 | + id?: string | number; | |
| 93 | + /** 表单顶层的className */ | |
| 94 | + className?: string; | |
| 95 | + /** 表单顶层的样式 */ | |
| 96 | + style?: any; | |
| 97 | + /** 表单 schema */ | |
| 98 | + schema: any; | |
| 99 | + /** form单例 */ | |
| 100 | + form: FormInstance; | |
| 101 | + /** 组件和schema的映射规则 */ | |
| 102 | + mapping?: any; | |
| 103 | + /** 自定义组件 */ | |
| 104 | + widgets?: any; | |
| 105 | + /** 表单提交前钩子 */ | |
| 106 | + displayType?: string; | |
| 107 | + /** 只读模式 */ | |
| 108 | + readOnly?: boolean; | |
| 109 | + /** 禁用模式 */ | |
| 110 | + disabled?: boolean; | |
| 111 | + /** 标签宽度 */ | |
| 112 | + labelWidth?: string | number; | |
| 113 | + /** antd的全局config */ | |
| 114 | + configProvider?: any; | |
| 115 | + theme?: string | number; | |
| 116 | + /** 覆盖默认的校验信息 */ | |
| 117 | + validateMessages?: any; | |
| 118 | + /** 显示当前表单内部状态 */ | |
| 119 | + debug?: boolean; | |
| 120 | + /** 显示css布局提示线 */ | |
| 121 | + debugCss?: boolean; | |
| 122 | + locale?: string; | |
| 123 | + column?: number; | |
| 124 | + debounceInput?: boolean; | |
| 125 | + size?: string; | |
| 126 | + // 数据会作为 beforeFinish 的第四个参数传入 | |
| 127 | + config?: any; | |
| 128 | + // 类似于 vuejs 的 watch 的用法,监控值的变化,触发 callback | |
| 129 | + watch?: WatchProperties; | |
| 130 | + /** 对象组件是否折叠(全局的控制) */ | |
| 131 | + allCollapsed?: boolean; | |
| 132 | + /** 表单的全局共享属性 */ | |
| 133 | + globalProps?: any; | |
| 134 | + /** 表单首次加载钩子 */ | |
| 135 | + onMount?: () => void; | |
| 136 | + /** 表单提交前钩子 */ | |
| 137 | + beforeFinish?: (params: ValidateParams) => Error[] | Promise<Error[]>; | |
| 138 | + /** 表单提交后钩子 */ | |
| 139 | + onFinish?: (formData: any, error: Error[]) => void; | |
| 140 | + /** 时时与外部更新同步的钩子 */ | |
| 141 | + onValuesChange?: (changedValues: any, formData: any) => void; | |
| 142 | + /** 隐藏的数据是否去掉,默认不去掉(false) */ | |
| 143 | + removeHiddenData?: boolean; | |
| 144 | +} | |
| 145 | + | |
| 146 | +declare const FR: React.FC<FRProps>; | |
| 147 | + | |
| 148 | +export declare function useForm(params?: FormParams): FormInstance; | |
| 149 | + | |
| 150 | +export type ConnectedForm<T> = T & { | |
| 151 | + form: FormInstance; | |
| 152 | +}; | |
| 153 | + | |
| 154 | +export declare function connectForm<T extends {} = any>( | |
| 155 | + component: React.ComponentType<ConnectedForm<T>> | |
| 156 | +): React.ComponentType<T>; | |
| 157 | + | |
| 158 | +export default FR; | ... | ... |
es/form-render-core/src/index.js
0 → 100644
| 1 | +var _excluded = ["id", "widgets", "layoutWidgets", "mapping", "form", "className", "style", "beforeFinish", "onFinish", "displayType", "labelAlign", "colon", "schema", "debug", "debugCss", "locale", "debounceInput", "size", "configProvider", "theme", "validateMessages", "watch", "config", "onMount", "labelWidth", "readOnly", "disabled", "allCollapsed", "onValuesChange", "column", "removeHiddenData", "globalProps", "methods", "renderTitle", "requiredMark"], | |
| 2 | + _excluded2 = ["onItemChange", "setEditing", "touchKey", "setValueByPath", "getSchemaByPath", "setSchemaByPath", "setSchema", "setValues", "getValues", "resetFields", "submit", "endValidating", "endSubmitting", "setErrorFields", "removeErrorField", "removeTouched", "changeTouchedKeys", "syncStuff", "logOnMount", "logOnSubmit", "setFirstMount", "_setErrors"], | |
| 3 | + _excluded3 = ["isOldVersion", "schema"]; | |
| 4 | + | |
| 5 | +function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | |
| 6 | + | |
| 7 | +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | |
| 8 | + | |
| 9 | +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | |
| 10 | + | |
| 11 | +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | |
| 12 | + | |
| 13 | +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | |
| 14 | + | |
| 15 | +function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | |
| 16 | + | |
| 17 | +function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | |
| 18 | + | |
| 19 | +/* eslint-disable react-hooks/exhaustive-deps */ | |
| 20 | +import React, { useEffect, useMemo, useRef } from 'react'; | |
| 21 | +import "./atom.css"; | |
| 22 | +import Core from './core'; | |
| 23 | +import { Ctx, Store2Ctx, StoreCtx } from './hooks'; | |
| 24 | +import "./index.css"; | |
| 25 | +import { mapping as defaultMapping } from './mapping'; | |
| 26 | +import { getParamByName, msToTime, updateSchemaToNewVersion, yymmdd } from './utils'; | |
| 27 | +import Watcher from './Watcher'; | |
| 28 | + | |
| 29 | +var defaultFinish = function defaultFinish(data, errors) { | |
| 30 | + console.log('onFinish:', { | |
| 31 | + data: data, | |
| 32 | + errors: errors | |
| 33 | + }); | |
| 34 | +}; | |
| 35 | + | |
| 36 | +export { default as connectForm } from './connectForm'; | |
| 37 | +export { createWidget } from './createWidget'; | |
| 38 | +export { default as useForm } from './useForm'; | |
| 39 | +export { defaultMapping as mapping }; | |
| 40 | + | |
| 41 | +function App(_ref) { | |
| 42 | + var id = _ref.id, | |
| 43 | + widgets = _ref.widgets, | |
| 44 | + layoutWidgets = _ref.layoutWidgets, | |
| 45 | + mapping = _ref.mapping, | |
| 46 | + form = _ref.form, | |
| 47 | + className = _ref.className, | |
| 48 | + style = _ref.style, | |
| 49 | + beforeFinish = _ref.beforeFinish, | |
| 50 | + _ref$onFinish = _ref.onFinish, | |
| 51 | + onFinish = _ref$onFinish === void 0 ? defaultFinish : _ref$onFinish, | |
| 52 | + _ref$displayType = _ref.displayType, | |
| 53 | + displayType = _ref$displayType === void 0 ? 'column' : _ref$displayType, | |
| 54 | + _ref$labelAlign = _ref.labelAlign, | |
| 55 | + labelAlign = _ref$labelAlign === void 0 ? 'right' : _ref$labelAlign, | |
| 56 | + _ref$colon = _ref.colon, | |
| 57 | + colon = _ref$colon === void 0 ? true : _ref$colon, | |
| 58 | + schema = _ref.schema, | |
| 59 | + debug = _ref.debug, | |
| 60 | + debugCss = _ref.debugCss, | |
| 61 | + _ref$locale = _ref.locale, | |
| 62 | + locale = _ref$locale === void 0 ? 'cn' : _ref$locale, | |
| 63 | + _ref$debounceInput = _ref.debounceInput, | |
| 64 | + debounceInput = _ref$debounceInput === void 0 ? false : _ref$debounceInput, | |
| 65 | + size = _ref.size, | |
| 66 | + configProvider = _ref.configProvider, | |
| 67 | + theme = _ref.theme, | |
| 68 | + validateMessages = _ref.validateMessages, | |
| 69 | + _ref$watch = _ref.watch, | |
| 70 | + watch = _ref$watch === void 0 ? {} : _ref$watch, | |
| 71 | + config = _ref.config, | |
| 72 | + onMount = _ref.onMount, | |
| 73 | + labelWidth = _ref.labelWidth, | |
| 74 | + readOnly = _ref.readOnly, | |
| 75 | + disabled = _ref.disabled, | |
| 76 | + _ref$allCollapsed = _ref.allCollapsed, | |
| 77 | + allCollapsed = _ref$allCollapsed === void 0 ? false : _ref$allCollapsed, | |
| 78 | + onValuesChange = _ref.onValuesChange, | |
| 79 | + column = _ref.column, | |
| 80 | + _ref$removeHiddenData = _ref.removeHiddenData, | |
| 81 | + removeHiddenData = _ref$removeHiddenData === void 0 ? false : _ref$removeHiddenData, | |
| 82 | + _ref$globalProps = _ref.globalProps, | |
| 83 | + globalProps = _ref$globalProps === void 0 ? {} : _ref$globalProps, | |
| 84 | + _ref$methods = _ref.methods, | |
| 85 | + methods = _ref$methods === void 0 ? {} : _ref$methods, | |
| 86 | + renderTitle = _ref.renderTitle, | |
| 87 | + requiredMark = _ref.requiredMark, | |
| 88 | + rest = _objectWithoutProperties(_ref, _excluded); | |
| 89 | + | |
| 90 | + try { | |
| 91 | + var _ = form.submit; | |
| 92 | + } catch (error) { | |
| 93 | + console.error('form 为必填 props,<FormRender /> 没有接收到 form 属性!'); | |
| 94 | + } | |
| 95 | + | |
| 96 | + var _column = schema && schema.column || column; | |
| 97 | + | |
| 98 | + var onItemChange = form.onItemChange, | |
| 99 | + setEditing = form.setEditing, | |
| 100 | + touchKey = form.touchKey, | |
| 101 | + setValueByPath = form.setValueByPath, | |
| 102 | + getSchemaByPath = form.getSchemaByPath, | |
| 103 | + setSchemaByPath = form.setSchemaByPath, | |
| 104 | + setSchema = form.setSchema, | |
| 105 | + setValues = form.setValues, | |
| 106 | + getValues = form.getValues, | |
| 107 | + resetFields = form.resetFields, | |
| 108 | + submit = form.submit, | |
| 109 | + endValidating = form.endValidating, | |
| 110 | + endSubmitting = form.endSubmitting, | |
| 111 | + setErrorFields = form.setErrorFields, | |
| 112 | + removeErrorField = form.removeErrorField, | |
| 113 | + removeTouched = form.removeTouched, | |
| 114 | + changeTouchedKeys = form.changeTouchedKeys, | |
| 115 | + syncStuff = form.syncStuff, | |
| 116 | + logOnMount = form.logOnMount, | |
| 117 | + logOnSubmit = form.logOnSubmit, | |
| 118 | + setFirstMount = form.setFirstMount, | |
| 119 | + _setErrors = form._setErrors, | |
| 120 | + valuesThatWillChange = _objectWithoutProperties(form, _excluded2); | |
| 121 | + | |
| 122 | + var submitData = valuesThatWillChange.submitData, | |
| 123 | + errorFields = valuesThatWillChange.errorFields, | |
| 124 | + isValidating = valuesThatWillChange.isValidating, | |
| 125 | + outsideValidating = valuesThatWillChange.outsideValidating, | |
| 126 | + isSubmitting = valuesThatWillChange.isSubmitting, | |
| 127 | + formData = valuesThatWillChange.formData, | |
| 128 | + flatten = valuesThatWillChange.flatten, | |
| 129 | + showValidate = valuesThatWillChange.showValidate, | |
| 130 | + firstMount = valuesThatWillChange.firstMount; | |
| 131 | + useEffect(function () { | |
| 132 | + // Schema最外层的type是object来判断,没有的话,认为schema没有传 | |
| 133 | + if (schema && schema.type) { | |
| 134 | + setFirstMount(true); | |
| 135 | + syncStuff({ | |
| 136 | + schema: schema, | |
| 137 | + locale: locale, | |
| 138 | + validateMessages: validateMessages, | |
| 139 | + beforeFinish: beforeFinish, | |
| 140 | + onMount: onMount, | |
| 141 | + removeHiddenData: removeHiddenData | |
| 142 | + }); | |
| 143 | + } else {} | |
| 144 | + }, [JSON.stringify(schema)]); | |
| 145 | + useEffect(function () { | |
| 146 | + if (!firstMount && schema && schema.type) { | |
| 147 | + if (typeof onMount === 'function') { | |
| 148 | + // 等一下 useForm 里接到第一份schema时,计算第一份data的骨架 | |
| 149 | + setTimeout(function () { | |
| 150 | + onMount(); | |
| 151 | + }, 0); | |
| 152 | + } | |
| 153 | + | |
| 154 | + setTimeout(onMountLogger, 0); | |
| 155 | + } | |
| 156 | + }, [JSON.stringify(schema), firstMount]); | |
| 157 | + | |
| 158 | + var onMountLogger = function onMountLogger() { | |
| 159 | + var start = new Date().getTime(); | |
| 160 | + | |
| 161 | + if (typeof logOnMount === 'function' || typeof logOnSubmit === 'function') { | |
| 162 | + sessionStorage.setItem('FORM_MOUNT_TIME', start); | |
| 163 | + sessionStorage.setItem('FORM_START', start); | |
| 164 | + } | |
| 165 | + | |
| 166 | + if (typeof logOnMount === 'function') { | |
| 167 | + var logParams = { | |
| 168 | + schema: schema, | |
| 169 | + url: location.href, | |
| 170 | + formData: JSON.stringify(form.getValues()), | |
| 171 | + formMount: yymmdd(start) | |
| 172 | + }; | |
| 173 | + | |
| 174 | + if (id) { | |
| 175 | + logParams.id = id; | |
| 176 | + } | |
| 177 | + | |
| 178 | + logOnMount(logParams); | |
| 179 | + } // 如果是要计算时间,在 onMount 时存一个时间戳 | |
| 180 | + | |
| 181 | + | |
| 182 | + if (typeof logOnSubmit === 'function') { | |
| 183 | + sessionStorage.setItem('NUMBER_OF_SUBMITS', 0); | |
| 184 | + sessionStorage.setItem('FAILED_ATTEMPTS', 0); | |
| 185 | + } | |
| 186 | + }; // 组件 destroy 的时候,destroy form,因为useForm可能在上层,所以不一定会跟着destroy | |
| 187 | + | |
| 188 | + | |
| 189 | + useEffect(function () { | |
| 190 | + return function () { | |
| 191 | + form.resetFields(); | |
| 192 | + }; | |
| 193 | + }, []); | |
| 194 | + var store = useMemo(function () { | |
| 195 | + return _objectSpread(_objectSpread({}, valuesThatWillChange), {}, { | |
| 196 | + globalProps: globalProps | |
| 197 | + }, rest); | |
| 198 | + }, [JSON.stringify(flatten), JSON.stringify(formData), JSON.stringify(errorFields), JSON.stringify(globalProps)]); // 不常用的context单独放一个地方 | |
| 199 | + | |
| 200 | + var store2 = useMemo(function () { | |
| 201 | + return { | |
| 202 | + displayType: displayType, | |
| 203 | + labelAlign: labelAlign, | |
| 204 | + colon: colon, | |
| 205 | + theme: theme, | |
| 206 | + column: _column, | |
| 207 | + debounceInput: debounceInput, | |
| 208 | + debug: debug, | |
| 209 | + labelWidth: labelWidth, | |
| 210 | + locale: locale, | |
| 211 | + validateMessages: validateMessages, | |
| 212 | + readOnly: readOnly, | |
| 213 | + disabled: disabled, | |
| 214 | + allCollapsed: allCollapsed, | |
| 215 | + showValidate: showValidate, | |
| 216 | + watch: watch | |
| 217 | + }; | |
| 218 | + }, [displayType, labelAlign, colon, theme, _column, debounceInput, debug, labelWidth, locale, validateMessages, readOnly, disabled, allCollapsed, showValidate, watch]); | |
| 219 | + var tools = useMemo(function () { | |
| 220 | + return _objectSpread({ | |
| 221 | + widgets: widgets, | |
| 222 | + layoutWidgets: layoutWidgets, | |
| 223 | + mapping: _objectSpread(_objectSpread({}, defaultMapping), mapping), | |
| 224 | + onValuesChange: onValuesChange, | |
| 225 | + renderTitle: renderTitle, | |
| 226 | + requiredMark: requiredMark, | |
| 227 | + methods: methods | |
| 228 | + }, form); | |
| 229 | + }, [widgets]); | |
| 230 | + useEffect(function () { | |
| 231 | + // 需要外部校验的情况,此时 submitting 还是 false | |
| 232 | + if (outsideValidating === true) { | |
| 233 | + Promise.resolve(beforeFinish(_objectSpread({ | |
| 234 | + data: submitData, | |
| 235 | + schema: schema, | |
| 236 | + errors: errorFields | |
| 237 | + }, config))).then(function (error) { | |
| 238 | + if (error) { | |
| 239 | + setErrorFields(error); | |
| 240 | + } | |
| 241 | + | |
| 242 | + endValidating(); | |
| 243 | + }); | |
| 244 | + return; | |
| 245 | + } // 如果validation结束,submitting开始 | |
| 246 | + | |
| 247 | + | |
| 248 | + if (isValidating === false && isSubmitting === true) { | |
| 249 | + endSubmitting(); | |
| 250 | + onFinish(submitData, errorFields); | |
| 251 | + | |
| 252 | + if (typeof logOnSubmit === 'function') { | |
| 253 | + var start = sessionStorage.getItem('FORM_START'); | |
| 254 | + var mount = sessionStorage.getItem('FORM_MOUNT_TIME'); | |
| 255 | + var numberOfSubmits = Number(sessionStorage.getItem('NUMBER_OF_SUBMITS')) + 1; | |
| 256 | + var end = new Date().getTime(); | |
| 257 | + var failedAttempts = Number(sessionStorage.getItem('FAILED_ATTEMPTS')); | |
| 258 | + | |
| 259 | + if (errorFields.length > 0) { | |
| 260 | + failedAttempts = failedAttempts + 1; | |
| 261 | + } | |
| 262 | + | |
| 263 | + var logParams = { | |
| 264 | + formMount: yymmdd(mount), | |
| 265 | + ms: end - start, | |
| 266 | + duration: msToTime(end - start), | |
| 267 | + numberOfSubmits: numberOfSubmits, | |
| 268 | + failedAttempts: failedAttempts, | |
| 269 | + url: location.href, | |
| 270 | + formData: JSON.stringify(submitData), | |
| 271 | + errors: JSON.stringify(errorFields), | |
| 272 | + schema: JSON.stringify(schema) | |
| 273 | + }; | |
| 274 | + | |
| 275 | + if (id) { | |
| 276 | + logParams.id = id; | |
| 277 | + } | |
| 278 | + | |
| 279 | + logOnSubmit(logParams); | |
| 280 | + sessionStorage.setItem('FORM_START', end); | |
| 281 | + sessionStorage.setItem('NUMBER_OF_SUBMITS', numberOfSubmits); | |
| 282 | + sessionStorage.setItem('FAILED_ATTEMPTS', failedAttempts); | |
| 283 | + } | |
| 284 | + } | |
| 285 | + }, [isValidating, isSubmitting, outsideValidating]); // TODO: fk doesn't work | |
| 286 | + | |
| 287 | + var sizeCls = ''; | |
| 288 | + | |
| 289 | + if (size === 'small') { | |
| 290 | + sizeCls = 'fr-form-small'; | |
| 291 | + } else if (size === 'large') { | |
| 292 | + sizeCls = 'fr-form-large'; | |
| 293 | + } | |
| 294 | + | |
| 295 | + var rootProps = { | |
| 296 | + className: "fr-container ".concat(sizeCls, " ").concat(className || '') | |
| 297 | + }; | |
| 298 | + | |
| 299 | + if (style && _typeof(style) === 'object') { | |
| 300 | + rootProps.style = style; | |
| 301 | + } | |
| 302 | + | |
| 303 | + if (id && ['number', 'string'].indexOf(_typeof(id)) > -1) { | |
| 304 | + rootProps.id = id; | |
| 305 | + } | |
| 306 | + | |
| 307 | + var debugForm = getParamByName('_debug_form'); | |
| 308 | + var debugFormCss = getParamByName('_debug_form_css'); | |
| 309 | + var isPre = location.href.indexOf('pre') > -1; | |
| 310 | + var watchList = Object.keys(watch); | |
| 311 | + return /*#__PURE__*/React.createElement(StoreCtx.Provider, { | |
| 312 | + value: store | |
| 313 | + }, /*#__PURE__*/React.createElement(Store2Ctx.Provider, { | |
| 314 | + value: store2 | |
| 315 | + }, /*#__PURE__*/React.createElement(Ctx.Provider, { | |
| 316 | + value: tools | |
| 317 | + }, /*#__PURE__*/React.createElement("div", rootProps, isPre && debugForm || debug ? /*#__PURE__*/React.createElement("div", { | |
| 318 | + className: "mv2 bg-black-05 pa2 br2" | |
| 319 | + }, /*#__PURE__*/React.createElement("div", { | |
| 320 | + style: { | |
| 321 | + display: 'flex' | |
| 322 | + } | |
| 323 | + }, /*#__PURE__*/React.createElement("span", null, "formData:"), /*#__PURE__*/React.createElement("span", { | |
| 324 | + style: { | |
| 325 | + display: 'inline-block', | |
| 326 | + wordBreak: 'break-all', | |
| 327 | + whiteSpace: 'pre-wrap', | |
| 328 | + maxWidth: 600 | |
| 329 | + } | |
| 330 | + }, JSON.stringify(form.formData, null, 4))), /*#__PURE__*/React.createElement("div", null, 'errorFields:' + JSON.stringify(form.errorFields)), /*#__PURE__*/React.createElement("div", null, 'touchedKeys:' + JSON.stringify(form.touchedKeys)), /*#__PURE__*/React.createElement("div", null, 'allTouched:' + JSON.stringify(form.allTouched)), /*#__PURE__*/React.createElement("div", null, 'descriptor:' + JSON.stringify(window.descriptor))) : null, watchList.length > 0 ? watchList.map(function (item, idx) { | |
| 331 | + return /*#__PURE__*/React.createElement(Watcher, { | |
| 332 | + key: idx.toString(), | |
| 333 | + watchKey: item, | |
| 334 | + watch: watch, | |
| 335 | + formData: formData, | |
| 336 | + firstMount: firstMount | |
| 337 | + }); | |
| 338 | + }) : null, /*#__PURE__*/React.createElement(Core, { | |
| 339 | + debugCss: isPre && debugFormCss || debugCss | |
| 340 | + }))))); | |
| 341 | +} | |
| 342 | + | |
| 343 | +var Wrapper = function Wrapper(props) { | |
| 344 | + var _ref2 = props || {}, | |
| 345 | + _ref2$isOldVersion = _ref2.isOldVersion, | |
| 346 | + isOldVersion = _ref2$isOldVersion === void 0 ? true : _ref2$isOldVersion, | |
| 347 | + schema = _ref2.schema, | |
| 348 | + rest = _objectWithoutProperties(_ref2, _excluded3); | |
| 349 | + | |
| 350 | + var _schema = useRef(schema); | |
| 351 | + | |
| 352 | + if (isOldVersion) { | |
| 353 | + _schema.current = updateSchemaToNewVersion(schema); | |
| 354 | + } | |
| 355 | + | |
| 356 | + return /*#__PURE__*/React.createElement(App, _extends({ | |
| 357 | + schema: _schema.current | |
| 358 | + }, rest)); | |
| 359 | +}; | |
| 360 | + | |
| 361 | +export default Wrapper; | |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/mapping.js
0 → 100644
| 1 | +export var mapping = { | |
| 2 | + default: 'input', | |
| 3 | + string: 'input', | |
| 4 | + array: 'list', | |
| 5 | + boolean: 'checkbox', | |
| 6 | + integer: 'number', | |
| 7 | + number: 'number', | |
| 8 | + object: 'map', | |
| 9 | + html: 'html', | |
| 10 | + 'string:upload': 'upload', | |
| 11 | + 'string:url': 'url', | |
| 12 | + 'string:dateTime': 'date', | |
| 13 | + 'string:date': 'date', | |
| 14 | + 'string:year': 'date', | |
| 15 | + 'string:month': 'date', | |
| 16 | + 'string:week': 'date', | |
| 17 | + 'string:quarter': 'date', | |
| 18 | + 'string:time': 'time', | |
| 19 | + 'string:textarea': 'textarea', | |
| 20 | + 'string:color': 'color', | |
| 21 | + 'string:image': 'imageInput', | |
| 22 | + 'range:time': 'timeRange', | |
| 23 | + 'range:dateTime': 'dateRange', | |
| 24 | + 'range:date': 'dateRange', | |
| 25 | + 'range:year': 'dateRange', | |
| 26 | + 'range:month': 'dateRange', | |
| 27 | + 'range:week': 'dateRange', | |
| 28 | + 'range:quarter': 'dateRange', | |
| 29 | + '*?enum': 'radio', | |
| 30 | + '*?enum_long': 'select', | |
| 31 | + 'array?enum': 'checkboxes', | |
| 32 | + 'array?enum_long': 'multiSelect', | |
| 33 | + '*?readOnly': 'html' // TODO: html widgets for list / object | |
| 34 | + | |
| 35 | +}; | |
| 36 | +export function getWidgetName(schema) { | |
| 37 | + var _mapping = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mapping; | |
| 38 | + | |
| 39 | + var type = schema.type, | |
| 40 | + format = schema.format, | |
| 41 | + enums = schema.enum, | |
| 42 | + readOnly = schema.readOnly, | |
| 43 | + widget = schema.widget; // 如果已经注明了渲染widget,那最好 | |
| 44 | + // if (schema['ui:widget']) { | |
| 45 | + // return schema['ui:widget']; | |
| 46 | + // } | |
| 47 | + | |
| 48 | + var list = []; | |
| 49 | + | |
| 50 | + if (readOnly) { | |
| 51 | + list.push("".concat(type, "?readOnly")); | |
| 52 | + list.push('*?readOnly'); | |
| 53 | + } | |
| 54 | + | |
| 55 | + if (enums) { | |
| 56 | + // 根据enum长度来智能选择控件 | |
| 57 | + if (Array.isArray(enums) && (type === 'array' && enums.length > 6 || type !== 'array' && enums.length > 2)) { | |
| 58 | + list.push("".concat(type, "?enum_long")); | |
| 59 | + list.push('*?enum_long'); | |
| 60 | + } else { | |
| 61 | + list.push("".concat(type, "?enum")); // array 默认使用list,array?enum 默认使用checkboxes,*?enum 默认使用select | |
| 62 | + | |
| 63 | + list.push('*?enum'); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + var _widget = widget || format; | |
| 68 | + | |
| 69 | + if (_widget) { | |
| 70 | + list.push("".concat(type, ":").concat(_widget)); | |
| 71 | + } | |
| 72 | + | |
| 73 | + list.push(type); // 放在最后兜底,其他都不match时使用type默认的组件 | |
| 74 | + | |
| 75 | + var found = ''; | |
| 76 | + list.some(function (item) { | |
| 77 | + found = _mapping[item]; | |
| 78 | + return !!found; | |
| 79 | + }); | |
| 80 | + return found; | |
| 81 | +} | |
| 82 | +export var extraSchemaList = { | |
| 83 | + checkbox: { | |
| 84 | + valuePropName: 'checked' | |
| 85 | + }, | |
| 86 | + switch: { | |
| 87 | + valuePropName: 'checked' | |
| 88 | + } | |
| 89 | +}; | |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/processData.js
renamed from
es/processData.js
| ... | ... | @@ -4,13 +4,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va |
| 4 | 4 | |
| 5 | 5 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } |
| 6 | 6 | |
| 7 | -import { removeEmptyItemFromList, cleanEmpty, removeHiddenFromResult } from './utils'; | |
| 8 | -import { unset, get, set } from 'lodash-es'; | |
| 9 | -import { isObject, clone } from './utils'; // 提交前需要先处理formData的逻辑 | |
| 7 | +import { get, set, unset } from 'lodash-es'; | |
| 8 | +import { cleanEmpty, clone, isObject, removeEmptyItemFromList, removeHiddenFromResult } from './utils'; // 提交前需要先处理formData的逻辑 | |
| 10 | 9 | |
| 11 | 10 | export var processData = function processData(data, flatten, removeHiddenData) { |
| 12 | - // 1. 去掉 hidden = true 的元素 | |
| 13 | - var _data = clone(data); | |
| 11 | + var _data = clone(data); // 1. 去掉 hidden = true 的元素 | |
| 12 | + | |
| 14 | 13 | |
| 15 | 14 | if (removeHiddenData) { |
| 16 | 15 | _data = removeHiddenFromResult(data, flatten); | ... | ... |
es/form-render-core/src/useDebounce.js
renamed from
es/useDebounce.js
es/form-render-core/src/useForm.js
renamed from
es/useForm.js
| ... | ... | @@ -25,12 +25,13 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy |
| 25 | 25 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } |
| 26 | 26 | |
| 27 | 27 | /* eslint-disable react-hooks/exhaustive-deps */ |
| 28 | -import { useEffect, useRef, useMemo, useState } from 'react'; | |
| 29 | -import { validateAll } from './validator'; | |
| 28 | +import { set, sortedUniqBy, get, isEmpty, isFunction } from 'lodash-es'; | |
| 29 | +import { useEffect, useMemo, useRef, useState } from 'react'; | |
| 30 | 30 | import { useSet } from './hooks'; |
| 31 | -import { set, sortedUniqBy } from 'lodash-es'; | |
| 32 | 31 | import { processData, transformDataWithBind2 } from './processData'; |
| 33 | -import { generateDataSkeleton, flattenSchema, clone, schemaContainsExpression, parseAllExpression } from './utils'; | |
| 32 | +import SmoothScroll from 'smooth-scroll'; | |
| 33 | +import { clone, flattenSchema, generateDataSkeleton, parseAllExpression, schemaContainsExpression, getHiddenData } from './utils'; | |
| 34 | +import { validateAll } from './validator'; | |
| 34 | 35 | |
| 35 | 36 | var useForm = function useForm(props) { |
| 36 | 37 | var _ref = props || {}, |
| ... | ... | @@ -69,7 +70,9 @@ var useForm = function useForm(props) { |
| 69 | 70 | // schema 的转换结构,便于处理 |
| 70 | 71 | finalFlatten: {}, |
| 71 | 72 | // 表达式等被处理过的flatten,用于渲染 |
| 72 | - firstMount: true | |
| 73 | + firstMount: true, | |
| 74 | + validatingFields: [] // 在校验状态的表单fields | |
| 75 | + | |
| 73 | 76 | }), |
| 74 | 77 | _useSet2 = _slicedToArray(_useSet, 2), |
| 75 | 78 | state = _useSet2[0], |
| ... | ... | @@ -100,6 +103,8 @@ var useForm = function useForm(props) { |
| 100 | 103 | var _allErrors = useRef([]); // 内部和外部的错误的合并 |
| 101 | 104 | |
| 102 | 105 | |
| 106 | + var _validatingFields = useRef([]); | |
| 107 | + | |
| 103 | 108 | var innerData = state.formData, |
| 104 | 109 | submitData = state.submitData, |
| 105 | 110 | _state$errorFields = state.errorFields, |
| ... | ... | @@ -176,20 +181,7 @@ var useForm = function useForm(props) { |
| 176 | 181 | setState({ |
| 177 | 182 | finalFlatten: newFlatten |
| 178 | 183 | }); |
| 179 | - }, [JSON.stringify(_flatten.current), JSON.stringify(_data.current), firstMount]); | |
| 180 | - useEffect(function () { | |
| 181 | - if (firstMount) return; | |
| 182 | - validateAll({ | |
| 183 | - formData: _data.current, | |
| 184 | - flatten: _finalFlatten.current, | |
| 185 | - isRequired: allTouched, | |
| 186 | - touchedKeys: _touchedKeys.current, | |
| 187 | - locale: localeRef.current, | |
| 188 | - validateMessages: validateMessagesRef.current | |
| 189 | - }).then(function (res) { | |
| 190 | - _setErrors(res); | |
| 191 | - }); | |
| 192 | - }, [JSON.stringify(_data.current)]); // All form methods are down here ---------------------------------------------------------------- | |
| 184 | + }, [JSON.stringify(_flatten.current), JSON.stringify(_data.current), firstMount]); // All form methods are down here ---------------------------------------------------------------- | |
| 193 | 185 | // 两个兼容 0.x 的函数 |
| 194 | 186 | |
| 195 | 187 | var _setData = function _setData(data) { |
| ... | ... | @@ -200,7 +192,8 @@ var useForm = function useForm(props) { |
| 200 | 192 | formData: data |
| 201 | 193 | }); |
| 202 | 194 | } |
| 203 | - }; | |
| 195 | + }; // Allow function to get the old value | |
| 196 | + | |
| 204 | 197 | |
| 205 | 198 | var _setErrors = function _setErrors(errors) { |
| 206 | 199 | if (typeof _onValidate === 'function') { |
| ... | ... | @@ -211,9 +204,18 @@ var useForm = function useForm(props) { |
| 211 | 204 | _onValidate(oldFormatErrors); |
| 212 | 205 | } |
| 213 | 206 | |
| 214 | - setState({ | |
| 215 | - errorFields: errors | |
| 216 | - }); | |
| 207 | + if (typeof errors === 'function') { | |
| 208 | + setState(function (_ref4) { | |
| 209 | + var errorFields = _ref4.errorFields; | |
| 210 | + return { | |
| 211 | + errorFields: errors(errorFields) | |
| 212 | + }; | |
| 213 | + }); | |
| 214 | + } else { | |
| 215 | + setState({ | |
| 216 | + errorFields: errors | |
| 217 | + }); | |
| 218 | + } | |
| 217 | 219 | }; |
| 218 | 220 | |
| 219 | 221 | var setFirstMount = function setFirstMount(value) { |
| ... | ... | @@ -228,6 +230,7 @@ var useForm = function useForm(props) { |
| 228 | 230 | } |
| 229 | 231 | |
| 230 | 232 | var newKeyList = [].concat(_toConsumableArray(_touchedKeys.current), [key]); |
| 233 | + _touchedKeys.current = newKeyList; | |
| 231 | 234 | setState({ |
| 232 | 235 | touchedKeys: newKeyList |
| 233 | 236 | }); |
| ... | ... | @@ -238,6 +241,7 @@ var useForm = function useForm(props) { |
| 238 | 241 | return item.indexOf(key) === -1; |
| 239 | 242 | }); |
| 240 | 243 | |
| 244 | + _touchedKeys.current = newTouch; | |
| 241 | 245 | setState({ |
| 242 | 246 | touchedKeys: newTouch |
| 243 | 247 | }); |
| ... | ... | @@ -272,12 +276,12 @@ var useForm = function useForm(props) { |
| 272 | 276 | // ] |
| 273 | 277 | |
| 274 | 278 | |
| 275 | - var syncStuff = function syncStuff(_ref4) { | |
| 276 | - var schema = _ref4.schema, | |
| 277 | - locale = _ref4.locale, | |
| 278 | - validateMessages = _ref4.validateMessages, | |
| 279 | - beforeFinish = _ref4.beforeFinish, | |
| 280 | - removeHiddenData = _ref4.removeHiddenData; | |
| 279 | + var syncStuff = function syncStuff(_ref5) { | |
| 280 | + var schema = _ref5.schema, | |
| 281 | + locale = _ref5.locale, | |
| 282 | + validateMessages = _ref5.validateMessages, | |
| 283 | + beforeFinish = _ref5.beforeFinish, | |
| 284 | + removeHiddenData = _ref5.removeHiddenData; | |
| 281 | 285 | schemaRef.current = schema; |
| 282 | 286 | localeRef.current = locale; |
| 283 | 287 | validateMessagesRef.current = validateMessages; |
| ... | ... | @@ -357,6 +361,7 @@ var useForm = function useForm(props) { |
| 357 | 361 | newErrorFields = sortedUniqBy(newErrorFields, function (item) { |
| 358 | 362 | return item.name; |
| 359 | 363 | }); |
| 364 | + _outErrorFields.current = newErrorFields; | |
| 360 | 365 | setState({ |
| 361 | 366 | outErrorFields: newErrorFields |
| 362 | 367 | }); |
| ... | ... | @@ -367,13 +372,69 @@ var useForm = function useForm(props) { |
| 367 | 372 | return item.name.indexOf(path) === -1; |
| 368 | 373 | }); |
| 369 | 374 | |
| 375 | + var newOutError = _outErrorFields.current.filter(function (item) { | |
| 376 | + return item.name.indexOf(path) === -1; | |
| 377 | + }); | |
| 378 | + | |
| 370 | 379 | setState({ |
| 371 | - outErrorFields: newError | |
| 380 | + errorFields: newError, | |
| 381 | + outErrorFields: newOutError | |
| 372 | 382 | }); |
| 373 | 383 | }; |
| 384 | + /** | |
| 385 | + * (nameList?: NamePath[], filterFunc?: (meta: { touched: boolean, validating: boolean }) => boolean) => any | |
| 386 | + * 参考rc-field-form中的getFieldsValue | |
| 387 | + * 如果第一个参数为数组类型,则获取nameList数据并且做filterFunc过滤 | |
| 388 | + * 如果第一个参数非数组类型,则获取所有数据并做filterFunc过滤 | |
| 389 | + * | |
| 390 | + * @returns | |
| 391 | + */ | |
| 392 | + | |
| 393 | + | |
| 394 | + var getValues = function getValues(nameList, filterFunc) { | |
| 395 | + var flatten = _finalFlatten.current; | |
| 396 | + var data = _data.current; | |
| 397 | + var currentData = {}; | |
| 398 | + var filterMetaKeys = []; // 当前符合filter条件的key | |
| 399 | + | |
| 400 | + if (Array.isArray(nameList)) { | |
| 401 | + nameList.forEach(function (path) { | |
| 402 | + set(currentData, path, get(data, path)); | |
| 403 | + }); | |
| 404 | + } else { | |
| 405 | + currentData = data; | |
| 406 | + } // 过滤出满足条件的path | |
| 407 | + | |
| 374 | 408 | |
| 375 | - var getValues = function getValues() { | |
| 376 | - return processData(_data.current, _finalFlatten.current, removeHiddenDataRef.current); | |
| 409 | + if (filterFunc && isFunction(filterFunc)) { | |
| 410 | + if (Array.isArray) { | |
| 411 | + flatten = {}; | |
| 412 | + nameList.forEach(function (path) { | |
| 413 | + flatten[path] = get(_finalFlatten.current, path); | |
| 414 | + }); | |
| 415 | + } | |
| 416 | + | |
| 417 | + var metas = {}; | |
| 418 | + Object.keys(flatten).forEach(function (key) { | |
| 419 | + metas[key] = { | |
| 420 | + touched: isFieldTouched(key), | |
| 421 | + validating: isFieldValidating(key) | |
| 422 | + }; | |
| 423 | + }); | |
| 424 | + filterMetaKeys = Object.keys(metas).filter(function (k) { | |
| 425 | + return filterFunc(metas[k]); | |
| 426 | + }); // 没有filter满足条件的就返回{} | |
| 427 | + | |
| 428 | + currentData = {}; | |
| 429 | + | |
| 430 | + if (!isEmpty(filterMetaKeys)) { | |
| 431 | + filterMetaKeys.forEach(function (key) { | |
| 432 | + set(currentData, key, get(data, key)); | |
| 433 | + }); | |
| 434 | + } | |
| 435 | + } | |
| 436 | + | |
| 437 | + return processData(currentData, _finalFlatten.current, removeHiddenDataRef.current); | |
| 377 | 438 | }; |
| 378 | 439 | |
| 379 | 440 | var setValues = function setValues(newFormData) { |
| ... | ... | @@ -392,10 +453,14 @@ var useForm = function useForm(props) { |
| 392 | 453 | return validateAll({ |
| 393 | 454 | formData: _data.current, |
| 394 | 455 | flatten: _finalFlatten.current, |
| 395 | - touchedKeys: [], | |
| 396 | - isRequired: true, | |
| 397 | - locale: localeRef.current, | |
| 398 | - validateMessages: validateMessagesRef.current | |
| 456 | + options: { | |
| 457 | + locale: localeRef.current, | |
| 458 | + validateMessages: validateMessagesRef.current | |
| 459 | + }, | |
| 460 | + formInstance: { | |
| 461 | + setFieldValidating: setFieldValidating, | |
| 462 | + removeFieldValidating: removeFieldValidating | |
| 463 | + } | |
| 399 | 464 | }).then(function (errors) { |
| 400 | 465 | setState({ |
| 401 | 466 | errorFields: errors |
| ... | ... | @@ -438,13 +503,13 @@ var useForm = function useForm(props) { |
| 438 | 503 | }); |
| 439 | 504 | }; |
| 440 | 505 | |
| 441 | - var resetFields = function resetFields() { | |
| 506 | + var resetFields = function resetFields(options) { | |
| 442 | 507 | setState({ |
| 443 | - formData: {}, | |
| 444 | - submitData: {}, | |
| 445 | - errorFields: [], | |
| 446 | - touchedKeys: [], | |
| 447 | - allTouched: false | |
| 508 | + formData: (options === null || options === void 0 ? void 0 : options.formData) || {}, | |
| 509 | + submitData: (options === null || options === void 0 ? void 0 : options.submitData) || {}, | |
| 510 | + errorFields: (options === null || options === void 0 ? void 0 : options.errorFields) || [], | |
| 511 | + touchedKeys: (options === null || options === void 0 ? void 0 : options.touchedKeys) || [], | |
| 512 | + allTouched: (options === null || options === void 0 ? void 0 : options.allTouched) || false | |
| 448 | 513 | }); |
| 449 | 514 | }; |
| 450 | 515 | |
| ... | ... | @@ -464,6 +529,187 @@ var useForm = function useForm(props) { |
| 464 | 529 | }); |
| 465 | 530 | }; |
| 466 | 531 | |
| 532 | + var setFieldValidating = function setFieldValidating(namePath) { | |
| 533 | + if (_validatingFields.current.indexOf(namePath) > -1) { | |
| 534 | + return; | |
| 535 | + } | |
| 536 | + | |
| 537 | + _validatingFields.current = [].concat(_toConsumableArray(_validatingFields.current), [namePath]); | |
| 538 | + }; | |
| 539 | + | |
| 540 | + var removeFieldValidating = function removeFieldValidating(namePath) { | |
| 541 | + _validatingFields.current = _validatingFields.current.filter(function (item) { | |
| 542 | + return item !== namePath; | |
| 543 | + }); | |
| 544 | + }; | |
| 545 | + | |
| 546 | + var isFieldValidating = function isFieldValidating(namePath) { | |
| 547 | + return _validatingFields.current.indexOf(namePath) > -1; | |
| 548 | + }; | |
| 549 | + /** | |
| 550 | + * 参考rc-field-form 校验不包含外部设置的error | |
| 551 | + * @param {*} nameList | |
| 552 | + * @returns | |
| 553 | + */ | |
| 554 | + | |
| 555 | + | |
| 556 | + var validateFields = function validateFields(nameList) { | |
| 557 | + var data = _data.current; | |
| 558 | + | |
| 559 | + if (Array.isArray(nameList)) { | |
| 560 | + set(data, {}); | |
| 561 | + nameList.forEach(function (path) { | |
| 562 | + set(data, path, get(_data.current, path)); | |
| 563 | + }); | |
| 564 | + } | |
| 565 | + | |
| 566 | + setState({ | |
| 567 | + isValidating: true | |
| 568 | + }); | |
| 569 | + return validateAll({ | |
| 570 | + formData: data, | |
| 571 | + flatten: _finalFlatten.current, | |
| 572 | + options: { | |
| 573 | + locale: localeRef.current, | |
| 574 | + validateMessages: validateMessagesRef.current | |
| 575 | + }, | |
| 576 | + formInstance: { | |
| 577 | + setFieldValidating: setFieldValidating, | |
| 578 | + removeFieldValidating: removeFieldValidating | |
| 579 | + } | |
| 580 | + }).then(function (errors) { | |
| 581 | + setState({ | |
| 582 | + isValidating: false, | |
| 583 | + errorFields: errors | |
| 584 | + }); | |
| 585 | + | |
| 586 | + if (!isEmpty(errors)) { | |
| 587 | + return Promise.reject({ | |
| 588 | + errors: errors, | |
| 589 | + data: processData(data, _finalFlatten.current, removeHiddenDataRef.current) | |
| 590 | + }); | |
| 591 | + } else { | |
| 592 | + return Promise.resolve(processData(data, _finalFlatten.current, removeHiddenDataRef.current)); | |
| 593 | + } | |
| 594 | + }); | |
| 595 | + }; | |
| 596 | + /** | |
| 597 | + * (nameList?: NamePath[], allTouched?: boolean) => boolean | |
| 598 | + * 参照antd rc-field-form的处理逻辑 | |
| 599 | + * 如果入参为空,则返回 是否有表单被触碰过 | |
| 600 | + * 如果参数为一个 | |
| 601 | + * 当args0 === Array,则返回当前表单list是否 >= 1个表单被触碰过 | |
| 602 | + * 否则,args0 ? 返回 是否‘所有’表单被触碰过 :是否有表单被触碰过 | |
| 603 | + * 如果参数为两个 | |
| 604 | + * args1 ? args0中的’所有‘表单都被触碰过: args0中的表单 >= 1个被触碰过 | |
| 605 | + * @returns | |
| 606 | + */ | |
| 607 | + | |
| 608 | + | |
| 609 | + function isFieldsTouched() { | |
| 610 | + var argsLen = arguments.length; | |
| 611 | + var namePathList = []; | |
| 612 | + var isAllFieldsTouched = false; | |
| 613 | + var allTouchedKeys = _touchedKeys.current; | |
| 614 | + | |
| 615 | + if (argsLen === 0) { | |
| 616 | + return _touchedKeys.current.length > 0; | |
| 617 | + } else if (argsLen === 1) { | |
| 618 | + if (Array.isArray(arguments[0])) { | |
| 619 | + namePathList = arguments[0]; | |
| 620 | + } else { | |
| 621 | + return arguments[0] ? allTouched : _touchedKeys.current.length > 0; | |
| 622 | + } | |
| 623 | + } else { | |
| 624 | + namePathList = Array.isArray(arguments[0]) ? arguments[0] : []; | |
| 625 | + isAllFieldsTouched = arguments[1]; | |
| 626 | + } | |
| 627 | + | |
| 628 | + try { | |
| 629 | + var touchedFunc = function touchedFunc(key) { | |
| 630 | + return allTouchedKeys.indexOf(key) !== -1; | |
| 631 | + }; | |
| 632 | + | |
| 633 | + return isAllFieldsTouched ? namePathList.every(touchedFunc) : namePathList.some(touchedFunc); | |
| 634 | + } catch (e) { | |
| 635 | + console.error('>>>> isFieldsTouched error, check your input arguments', e); | |
| 636 | + } | |
| 637 | + } | |
| 638 | + | |
| 639 | + var isFieldTouched = function isFieldTouched(namePath) { | |
| 640 | + return _touchedKeys.current.indexOf(namePath) > -1; | |
| 641 | + }; | |
| 642 | + | |
| 643 | + var scrollToPath = function scrollToPath(namePath) { | |
| 644 | + var scroll = new SmoothScroll(); | |
| 645 | + var node = document.querySelector("[datapath=\"".concat(namePath, "\"]")); | |
| 646 | + | |
| 647 | + if (node) { | |
| 648 | + scroll.animateScroll(node); | |
| 649 | + } | |
| 650 | + }; | |
| 651 | + | |
| 652 | + var getFieldError = function getFieldError(namePath) { | |
| 653 | + var _allErrors$current$fi; | |
| 654 | + | |
| 655 | + return ((_allErrors$current$fi = _allErrors.current.find(function (error) { | |
| 656 | + return error.name === namePath; | |
| 657 | + })) === null || _allErrors$current$fi === void 0 ? void 0 : _allErrors$current$fi.error) || []; | |
| 658 | + }; | |
| 659 | + | |
| 660 | + var getFieldsError = function getFieldsError(nameList) { | |
| 661 | + if (!nameList || !Array.isArray(nameList)) { | |
| 662 | + return _allErrors.current; | |
| 663 | + } | |
| 664 | + | |
| 665 | + return _allErrors.current.filter(function (error) { | |
| 666 | + return nameList.indexOf(error.name) > -1; | |
| 667 | + }); | |
| 668 | + }; | |
| 669 | + /** | |
| 670 | + * fields: {error?, name, touched?, validating?, value?} | |
| 671 | + * 参照rc-field-form的实现逻辑 | |
| 672 | + * @param {*} fields | |
| 673 | + * 设置一组字段状态 | |
| 674 | + */ | |
| 675 | + | |
| 676 | + | |
| 677 | + var setFields = function setFields(fields) { | |
| 678 | + // 设置error调用统一的函数,直接设置数组,省去forEach频繁操作 | |
| 679 | + var errors = fields.filter(function (field) { | |
| 680 | + return field.error; | |
| 681 | + }).map(function (field) { | |
| 682 | + return { | |
| 683 | + name: field.name, | |
| 684 | + error: field.error | |
| 685 | + }; | |
| 686 | + }); | |
| 687 | + !isEmpty(errors) && setErrorFields(errors); // 对 value, touched, validating进行设置 | |
| 688 | + | |
| 689 | + fields.forEach(function (field) { | |
| 690 | + var name = field.name, | |
| 691 | + value = field.value, | |
| 692 | + touched = field.touched, | |
| 693 | + validating = field.validating; | |
| 694 | + | |
| 695 | + if ('value' in field) { | |
| 696 | + onItemChange(name, value); | |
| 697 | + } | |
| 698 | + | |
| 699 | + if (typeof touched === 'boolean') { | |
| 700 | + touched ? touchKey(name) : removeTouched(name); | |
| 701 | + } | |
| 702 | + | |
| 703 | + if (typeof validating === 'boolean') { | |
| 704 | + validating ? setFieldValidating(name) : removeFieldValidating(name); | |
| 705 | + } | |
| 706 | + }); | |
| 707 | + }; | |
| 708 | + | |
| 709 | + var getHiddenValues = function getHiddenValues() { | |
| 710 | + return getHiddenData(_data.current, _finalFlatten.current); | |
| 711 | + }; | |
| 712 | + | |
| 467 | 713 | var form = { |
| 468 | 714 | // state |
| 469 | 715 | formData: _data.current, |
| ... | ... | @@ -483,6 +729,7 @@ var useForm = function useForm(props) { |
| 483 | 729 | setSchema: setSchema, |
| 484 | 730 | setValues: setValues, |
| 485 | 731 | getValues: getValues, |
| 732 | + getHiddenValues: getHiddenValues, | |
| 486 | 733 | resetFields: resetFields, |
| 487 | 734 | submit: submit, |
| 488 | 735 | init: submit, |
| ... | ... | @@ -500,11 +747,23 @@ var useForm = function useForm(props) { |
| 500 | 747 | setEditing: setEditing, |
| 501 | 748 | syncStuff: syncStuff, |
| 502 | 749 | showValidate: _showValidate, |
| 750 | + validateFields: validateFields, | |
| 751 | + isFieldTouched: isFieldTouched, | |
| 752 | + isFieldsTouched: isFieldsTouched, | |
| 753 | + setFieldValidating: setFieldValidating, | |
| 754 | + removeFieldValidating: removeFieldValidating, | |
| 755 | + isFieldValidating: isFieldValidating, | |
| 756 | + scrollToPath: scrollToPath, | |
| 757 | + getFieldError: getFieldError, | |
| 758 | + getFieldsError: getFieldsError, | |
| 759 | + setFields: setFields, | |
| 503 | 760 | // firstMount, |
| 504 | 761 | setFirstMount: setFirstMount, |
| 505 | 762 | // logs |
| 506 | 763 | logOnMount: logOnMount, |
| 507 | - logOnSubmit: logOnSubmit | |
| 764 | + logOnSubmit: logOnSubmit, | |
| 765 | + // inner api, DON'T USE | |
| 766 | + _setErrors: _setErrors | |
| 508 | 767 | }; |
| 509 | 768 | return form; |
| 510 | 769 | }; | ... | ... |
es/form-render-core/src/utils.js
0 → 100644
| 1 | +var _excluded = ["propsSchema"], | |
| 2 | + _excluded2 = ["schema"]; | |
| 3 | + | |
| 4 | +function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | |
| 5 | + | |
| 6 | +function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | |
| 7 | + | |
| 8 | +function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | |
| 9 | + | |
| 10 | +function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | |
| 11 | + | |
| 12 | +function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | |
| 13 | + | |
| 14 | +function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | |
| 15 | + | |
| 16 | +function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | |
| 17 | + | |
| 18 | +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | |
| 19 | + | |
| 20 | +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | |
| 21 | + | |
| 22 | +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | |
| 23 | + | |
| 24 | +function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | |
| 25 | + | |
| 26 | +function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | |
| 27 | + | |
| 28 | +function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | |
| 29 | + | |
| 30 | +function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | |
| 31 | + | |
| 32 | +function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | |
| 33 | + | |
| 34 | +function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | |
| 35 | + | |
| 36 | +import { cloneDeep, get, isEmpty, set } from 'lodash-es'; | |
| 37 | +export function getParamByName(name) { | |
| 38 | + var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.href; | |
| 39 | + name = name.replace(/[\[\]]/g, '\\$&'); | |
| 40 | + var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), | |
| 41 | + results = regex.exec(url); | |
| 42 | + if (!results) return null; | |
| 43 | + if (!results[2]) return ''; | |
| 44 | + return decodeURIComponent(results[2].replace(/\+/g, ' ')); | |
| 45 | +} // export function isUrl(string) { | |
| 46 | +// const protocolRE = /^(?:\w+:)?\/\/(\S+)$/; | |
| 47 | +// // const domainRE = /^[^\s\.]+\.\S{2,}$/; | |
| 48 | +// if (typeof string !== 'string') return false; | |
| 49 | +// return protocolRE.test(string); | |
| 50 | +// } | |
| 51 | + | |
| 52 | +export function isCheckBoxType(schema, readOnly) { | |
| 53 | + if (readOnly) return false; | |
| 54 | + if (schema.widget === 'checkbox') return true; | |
| 55 | + | |
| 56 | + if (schema && schema.type === 'boolean') { | |
| 57 | + if (schema.enum) return false; | |
| 58 | + if (schema.widget === undefined) return true; | |
| 59 | + return false; | |
| 60 | + } | |
| 61 | +} // a[].b.c => a.b.c | |
| 62 | + | |
| 63 | +function removeBrackets(string) { | |
| 64 | + if (typeof string === 'string') { | |
| 65 | + return string.replace(/\[\]/g, ''); | |
| 66 | + } else { | |
| 67 | + return string; | |
| 68 | + } | |
| 69 | +} | |
| 70 | + | |
| 71 | +export function getParentPath(path) { | |
| 72 | + if (typeof path === 'string') { | |
| 73 | + var pathArr = path.split('.'); | |
| 74 | + | |
| 75 | + if (pathArr.length === 1) { | |
| 76 | + return '#'; | |
| 77 | + } | |
| 78 | + | |
| 79 | + pathArr.pop(); | |
| 80 | + return pathArr.join('.'); | |
| 81 | + } | |
| 82 | + | |
| 83 | + return '#'; | |
| 84 | +} | |
| 85 | +export function getValueByPath(formData, path) { | |
| 86 | + if (path === '#' || !path) { | |
| 87 | + return formData || {}; | |
| 88 | + } else if (typeof path === 'string') { | |
| 89 | + return get(formData, path); | |
| 90 | + } else { | |
| 91 | + console.error('path has to be a string'); | |
| 92 | + } | |
| 93 | +} // path: 'a.b[1].c[0]' => { id: 'a.b[].c[]' dataIndex: [1,0] } | |
| 94 | + | |
| 95 | +export function destructDataPath(path) { | |
| 96 | + var id; | |
| 97 | + var dataIndex; | |
| 98 | + | |
| 99 | + if (path === '#') { | |
| 100 | + return { | |
| 101 | + id: '#', | |
| 102 | + dataIndex: [] | |
| 103 | + }; | |
| 104 | + } | |
| 105 | + | |
| 106 | + if (typeof path !== 'string') { | |
| 107 | + throw Error("path ".concat(path, " is not a string!!! Something wrong here")); | |
| 108 | + } | |
| 109 | + | |
| 110 | + var pattern = /\[[0-9]+\]/g; | |
| 111 | + var matchList = path.match(pattern); | |
| 112 | + | |
| 113 | + if (!matchList) { | |
| 114 | + id = path; | |
| 115 | + } else { | |
| 116 | + id = path.replace(pattern, '[]'); // 这个是match下来的结果,可安全处理 | |
| 117 | + | |
| 118 | + dataIndex = matchList.map(function (item) { | |
| 119 | + return Number(item.substring(1, item.length - 1)); | |
| 120 | + }); | |
| 121 | + } | |
| 122 | + | |
| 123 | + return { | |
| 124 | + id: id, | |
| 125 | + dataIndex: dataIndex | |
| 126 | + }; | |
| 127 | +} // id: 'a.b[].c[]' dataIndex: [1,0] => 'a.b[1].c[0]' | |
| 128 | + | |
| 129 | +export function getDataPath(id, dataIndex) { | |
| 130 | + if (id === '#') { | |
| 131 | + return id; | |
| 132 | + } | |
| 133 | + | |
| 134 | + if (typeof id !== 'string') { | |
| 135 | + throw Error("id ".concat(id, " is not a string!!! Something wrong here")); | |
| 136 | + } | |
| 137 | + | |
| 138 | + var _id = id; | |
| 139 | + | |
| 140 | + if (Array.isArray(dataIndex)) { | |
| 141 | + // const matches = id.match(/\[\]/g) || []; | |
| 142 | + // const count = matches.length; | |
| 143 | + dataIndex.forEach(function (item) { | |
| 144 | + _id = _id.replace(/\[\]/, "[".concat(item, "]")); | |
| 145 | + }); | |
| 146 | + } | |
| 147 | + | |
| 148 | + return removeBrackets(_id); | |
| 149 | +} | |
| 150 | +export function isObjType(schema) { | |
| 151 | + return schema && schema.type === 'object' && schema.properties && !schema.widget; | |
| 152 | +} | |
| 153 | +export function isBlockType(schema) { | |
| 154 | + return schema && schema.type === 'block' && schema.widget; | |
| 155 | +} // TODO: to support case that item is not an object | |
| 156 | + | |
| 157 | +export function isListType(schema) { | |
| 158 | + return schema && schema.type === 'array' && isObjType(schema.items) && schema.enum === undefined; | |
| 159 | +} | |
| 160 | +export function orderProperties(properties) { | |
| 161 | + var orderKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'order'; | |
| 162 | + var orderHash = new Map(); // order不为数字的数据 | |
| 163 | + | |
| 164 | + var unsortedList = []; | |
| 165 | + | |
| 166 | + var insert = function insert(item) { | |
| 167 | + var _item = _slicedToArray(item, 2), | |
| 168 | + value = _item[1]; | |
| 169 | + | |
| 170 | + if (typeof value[orderKey] !== 'number') { | |
| 171 | + unsortedList.push(item); | |
| 172 | + return; | |
| 173 | + } | |
| 174 | + | |
| 175 | + if (orderHash.has(value[orderKey])) { | |
| 176 | + orderHash.get(value[orderKey]).push(item); | |
| 177 | + } else { | |
| 178 | + orderHash.set(value[orderKey], [item]); | |
| 179 | + } | |
| 180 | + }; | |
| 181 | + | |
| 182 | + properties.forEach(function (item) { | |
| 183 | + return insert(item); | |
| 184 | + }); | |
| 185 | + var sortedList = Array.from(orderHash.entries()).sort(function (_ref, _ref2) { | |
| 186 | + var _ref3 = _slicedToArray(_ref, 1), | |
| 187 | + order1 = _ref3[0]; | |
| 188 | + | |
| 189 | + var _ref4 = _slicedToArray(_ref2, 1), | |
| 190 | + order2 = _ref4[0]; | |
| 191 | + | |
| 192 | + return order1 - order2; | |
| 193 | + }) // order值越小越靠前 | |
| 194 | + .flatMap(function (_ref5) { | |
| 195 | + var _ref6 = _slicedToArray(_ref5, 2), | |
| 196 | + items = _ref6[1]; | |
| 197 | + | |
| 198 | + return items; | |
| 199 | + }); | |
| 200 | + return sortedList.concat(unsortedList); | |
| 201 | +} // TODO: more tests to make sure weird & wrong schema won't crush | |
| 202 | + | |
| 203 | +export function flattenSchema() { | |
| 204 | + var _schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | |
| 205 | + | |
| 206 | + var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '#'; | |
| 207 | + var parent = arguments.length > 2 ? arguments[2] : undefined; | |
| 208 | + var result = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | |
| 209 | + // 排序 | |
| 210 | + // _schema = orderBy(_schema, item => item.order, ['asc']); | |
| 211 | + var schema = clone(_schema); | |
| 212 | + var _name = name; | |
| 213 | + | |
| 214 | + if (!schema.$id) { | |
| 215 | + schema.$id = _name; // path as $id, for easy access to path in schema | |
| 216 | + } | |
| 217 | + | |
| 218 | + var children = []; | |
| 219 | + | |
| 220 | + if (isObjType(schema)) { | |
| 221 | + orderProperties(Object.entries(schema.properties)).forEach(function (_ref7) { | |
| 222 | + var _ref8 = _slicedToArray(_ref7, 2), | |
| 223 | + key = _ref8[0], | |
| 224 | + value = _ref8[1]; | |
| 225 | + | |
| 226 | + var _key = isListType(value) ? key + '[]' : key; | |
| 227 | + | |
| 228 | + var uniqueName = _name === '#' ? _key : _name + '.' + _key; | |
| 229 | + children.push(uniqueName); | |
| 230 | + flattenSchema(value, uniqueName, _name, result); | |
| 231 | + }); | |
| 232 | + schema.properties = {}; | |
| 233 | + } | |
| 234 | + | |
| 235 | + if (isListType(schema)) { | |
| 236 | + orderProperties(Object.entries(schema.items.properties)).forEach(function (_ref9) { | |
| 237 | + var _ref10 = _slicedToArray(_ref9, 2), | |
| 238 | + key = _ref10[0], | |
| 239 | + value = _ref10[1]; | |
| 240 | + | |
| 241 | + var _key = isListType(value) ? key + '[]' : key; | |
| 242 | + | |
| 243 | + var uniqueName = _name === '#' ? _key : _name + '.' + _key; | |
| 244 | + children.push(uniqueName); | |
| 245 | + flattenSchema(value, uniqueName, _name, result); | |
| 246 | + }); | |
| 247 | + schema.items.properties = {}; | |
| 248 | + } | |
| 249 | + | |
| 250 | + if (schema.type) { | |
| 251 | + result[_name] = { | |
| 252 | + parent: parent, | |
| 253 | + schema: schema, | |
| 254 | + children: children | |
| 255 | + }; | |
| 256 | + } | |
| 257 | + | |
| 258 | + return result; | |
| 259 | +} | |
| 260 | +export function getSchemaFromFlatten(flatten) { | |
| 261 | + var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '#'; | |
| 262 | + var schema = {}; | |
| 263 | + var item = clone(flatten[path]); | |
| 264 | + | |
| 265 | + if (item) { | |
| 266 | + schema = item.schema; // schema.$id && delete schema.$id; | |
| 267 | + | |
| 268 | + if (item.children.length > 0) { | |
| 269 | + item.children.forEach(function (child) { | |
| 270 | + if (!flatten[child]) return; | |
| 271 | + var key = getKeyFromPath(child); | |
| 272 | + | |
| 273 | + if (isObjType(schema)) { | |
| 274 | + schema.properties[key] = getSchemaFromFlatten(flatten, child); | |
| 275 | + } | |
| 276 | + | |
| 277 | + if (isListType(schema)) { | |
| 278 | + schema.items.properties[key] = getSchemaFromFlatten(flatten, child); | |
| 279 | + } | |
| 280 | + }); | |
| 281 | + } | |
| 282 | + } | |
| 283 | + | |
| 284 | + return schema; | |
| 285 | +} | |
| 286 | + | |
| 287 | +function stringContains(str, text) { | |
| 288 | + return str.indexOf(text) > -1; | |
| 289 | +} | |
| 290 | + | |
| 291 | +export var isObject = function isObject(a) { | |
| 292 | + return stringContains(Object.prototype.toString.call(a), 'Object'); | |
| 293 | +}; | |
| 294 | +export var clone = cloneDeep; // '3' => true, 3 => true, undefined => false | |
| 295 | + | |
| 296 | +export function isLooselyNumber(num) { | |
| 297 | + if (typeof num === 'number') return true; | |
| 298 | + | |
| 299 | + if (typeof num === 'string') { | |
| 300 | + return !Number.isNaN(Number(num)); | |
| 301 | + } | |
| 302 | + | |
| 303 | + return false; | |
| 304 | +} | |
| 305 | +export function isCssLength(str) { | |
| 306 | + if (typeof str !== 'string') return false; | |
| 307 | + return str.match(/^([0-9])*(%|px|rem|em)$/i); | |
| 308 | +} | |
| 309 | +export function isDeepEqual(param1, param2) { | |
| 310 | + if (param1 === undefined && param2 === undefined) return true;else if (param1 === undefined || param2 === undefined) return false; | |
| 311 | + if (param1 === null && param2 === null) return true;else if (param1 === null || param2 === null) return false;else if (param1.constructor !== param2.constructor) return false; | |
| 312 | + | |
| 313 | + if (param1.constructor === Array) { | |
| 314 | + if (param1.length !== param2.length) return false; | |
| 315 | + | |
| 316 | + for (var i = 0; i < param1.length; i++) { | |
| 317 | + if (param1[i].constructor === Array || param1[i].constructor === Object) { | |
| 318 | + if (!isDeepEqual(param1[i], param2[i])) return false; | |
| 319 | + } else if (param1[i] !== param2[i]) return false; | |
| 320 | + } | |
| 321 | + } else if (param1.constructor === Object) { | |
| 322 | + if (Object.keys(param1).length !== Object.keys(param2).length) return false; | |
| 323 | + | |
| 324 | + for (var _i2 = 0; _i2 < Object.keys(param1).length; _i2++) { | |
| 325 | + var key = Object.keys(param1)[_i2]; | |
| 326 | + | |
| 327 | + if (param1[key] && typeof param1[key] !== 'number' && (param1[key].constructor === Array || param1[key].constructor === Object)) { | |
| 328 | + if (!isDeepEqual(param1[key], param2[key])) return false; | |
| 329 | + } else if (param1[key] !== param2[key]) return false; | |
| 330 | + } | |
| 331 | + } else if (param1.constructor === String || param1.constructor === Number) { | |
| 332 | + return param1 === param2; | |
| 333 | + } | |
| 334 | + | |
| 335 | + return true; | |
| 336 | +} // export function getFormat(format) { | |
| 337 | +// let dateFormat; | |
| 338 | +// switch (format) { | |
| 339 | +// case 'date': | |
| 340 | +// dateFormat = 'YYYY-MM-DD'; | |
| 341 | +// break; | |
| 342 | +// case 'time': | |
| 343 | +// dateFormat = 'HH:mm:ss'; | |
| 344 | +// break; | |
| 345 | +// case 'dateTime': | |
| 346 | +// dateFormat = 'YYYY-MM-DD HH:mm:ss'; | |
| 347 | +// break; | |
| 348 | +// case 'week': | |
| 349 | +// dateFormat = 'YYYY-w'; | |
| 350 | +// break; | |
| 351 | +// case 'year': | |
| 352 | +// dateFormat = 'YYYY'; | |
| 353 | +// break; | |
| 354 | +// case 'quarter': | |
| 355 | +// dateFormat = 'YYYY-Q'; | |
| 356 | +// break; | |
| 357 | +// case 'month': | |
| 358 | +// dateFormat = 'YYYY-MM'; | |
| 359 | +// break; | |
| 360 | +// default: | |
| 361 | +// // dateTime | |
| 362 | +// if (typeof format === 'string') { | |
| 363 | +// dateFormat = format; | |
| 364 | +// } else { | |
| 365 | +// dateFormat = 'YYYY-MM-DD'; | |
| 366 | +// } | |
| 367 | +// } | |
| 368 | +// return dateFormat; | |
| 369 | +// } | |
| 370 | + | |
| 371 | +export function hasRepeat(list) { | |
| 372 | + return list.find(function (x, i, self) { | |
| 373 | + return i !== self.findIndex(function (y) { | |
| 374 | + return JSON.stringify(x) === JSON.stringify(y); | |
| 375 | + }); | |
| 376 | + }); | |
| 377 | +} | |
| 378 | +export function combineSchema() { | |
| 379 | + var propsSchema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | |
| 380 | + var uiSchema = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | |
| 381 | + var propList = getChildren(propsSchema); | |
| 382 | + var newList = propList.map(function (p) { | |
| 383 | + var name = p.name; | |
| 384 | + var _p$schema = p.schema, | |
| 385 | + type = _p$schema.type, | |
| 386 | + options = _p$schema.enum, | |
| 387 | + properties = _p$schema.properties, | |
| 388 | + items = _p$schema.items; | |
| 389 | + var isObj = type === 'object' && properties; | |
| 390 | + var isArr = type === 'array' && items && !options; // enum + array 代表的多选框,没有sub | |
| 391 | + | |
| 392 | + var ui = name && uiSchema[p.name]; | |
| 393 | + | |
| 394 | + if (!ui) { | |
| 395 | + return p; | |
| 396 | + } // 如果是list,递归合并items | |
| 397 | + | |
| 398 | + | |
| 399 | + if (isArr) { | |
| 400 | + var newItems = combineSchema(items, ui.items || {}); | |
| 401 | + return _objectSpread(_objectSpread({}, p), {}, { | |
| 402 | + schema: _objectSpread(_objectSpread(_objectSpread({}, p.schema), ui), {}, { | |
| 403 | + items: newItems | |
| 404 | + }) | |
| 405 | + }); | |
| 406 | + } // object递归合并整个schema | |
| 407 | + | |
| 408 | + | |
| 409 | + if (isObj) { | |
| 410 | + var newSchema = combineSchema(p.schema, ui); | |
| 411 | + return _objectSpread(_objectSpread({}, p), {}, { | |
| 412 | + schema: newSchema | |
| 413 | + }); | |
| 414 | + } | |
| 415 | + | |
| 416 | + return _objectSpread(_objectSpread({}, p), {}, { | |
| 417 | + schema: _objectSpread(_objectSpread({}, p.schema), ui) | |
| 418 | + }); | |
| 419 | + }); | |
| 420 | + var newObj = {}; | |
| 421 | + newList.forEach(function (s) { | |
| 422 | + newObj[s.name] = s.schema; | |
| 423 | + }); | |
| 424 | + var topLevelUi = {}; | |
| 425 | + Object.keys(uiSchema).forEach(function (key) { | |
| 426 | + if (typeof key === 'string' && key.substring(0, 3) === 'ui:') { | |
| 427 | + topLevelUi[key] = uiSchema[key]; | |
| 428 | + } | |
| 429 | + }); | |
| 430 | + | |
| 431 | + if (isEmpty(newObj)) { | |
| 432 | + return _objectSpread(_objectSpread({}, propsSchema), topLevelUi); | |
| 433 | + } | |
| 434 | + | |
| 435 | + return _objectSpread(_objectSpread(_objectSpread({}, propsSchema), topLevelUi), {}, { | |
| 436 | + properties: newObj | |
| 437 | + }); | |
| 438 | +} // export function isEmpty(obj) { | |
| 439 | +// return Object.keys(obj).length === 0; | |
| 440 | +// } | |
| 441 | + | |
| 442 | +function getChildren(schema) { | |
| 443 | + if (!schema) return []; | |
| 444 | + var properties = schema.properties, | |
| 445 | + items = schema.items, | |
| 446 | + type = schema.type; | |
| 447 | + | |
| 448 | + if (!properties && !items) { | |
| 449 | + return []; | |
| 450 | + } | |
| 451 | + | |
| 452 | + var schemaSubs = {}; | |
| 453 | + | |
| 454 | + if (type === 'object') { | |
| 455 | + schemaSubs = properties; | |
| 456 | + } | |
| 457 | + | |
| 458 | + if (type === 'array') { | |
| 459 | + schemaSubs = items; | |
| 460 | + } | |
| 461 | + | |
| 462 | + return Object.keys(schemaSubs).map(function (name) { | |
| 463 | + return { | |
| 464 | + schema: schemaSubs[name], | |
| 465 | + name: name | |
| 466 | + }; | |
| 467 | + }); | |
| 468 | +} | |
| 469 | + | |
| 470 | +export var parseString = function parseString(string) { | |
| 471 | + return Function('"use strict";return (' + string + ')')(); | |
| 472 | +}; | |
| 473 | +export var evaluateString = function evaluateString(string, formData, rootValue) { | |
| 474 | + return Function("\"use strict\";\n const rootValue = ".concat(JSON.stringify(rootValue), ";\n const formData = ").concat(JSON.stringify(formData), ";\n return (").concat(string, ")"))(); | |
| 475 | +}; | |
| 476 | +export function isExpression(func) { | |
| 477 | + // if (typeof func === 'function') { | |
| 478 | + // const funcString = func.toString(); | |
| 479 | + // return ( | |
| 480 | + // funcString.indexOf('formData') > -1 || | |
| 481 | + // funcString.indexOf('rootValue') > -1 | |
| 482 | + // ); | |
| 483 | + // } | |
| 484 | + if (typeof func !== 'string') return false; | |
| 485 | + var pattern = /^{{(.+)}}$/; | |
| 486 | + var reg1 = /^{{function\(.+}}$/; // const reg2 = /^{{(.+=>.+)}}$/; | |
| 487 | + | |
| 488 | + if (typeof func === 'string' && func.match(pattern) && !func.match(reg1)) { | |
| 489 | + return true; | |
| 490 | + } | |
| 491 | + | |
| 492 | + return false; | |
| 493 | +} | |
| 494 | +export var parseRootValueInSchema = function parseRootValueInSchema(schema, rootValue) { | |
| 495 | + var result = clone(schema); | |
| 496 | + | |
| 497 | + if (isObject(schema)) { | |
| 498 | + Object.keys(schema).forEach(function (key) { | |
| 499 | + var item = schema[key]; | |
| 500 | + | |
| 501 | + if (isObject(item)) { | |
| 502 | + result[key] = parseRootValueInSchema(item, rootValue); | |
| 503 | + } else if (typeof item === 'string') { | |
| 504 | + result[key] = parseSingleRootValue(item, rootValue); | |
| 505 | + } | |
| 506 | + }); | |
| 507 | + } else { | |
| 508 | + console.error('schema is not an object:', schema); | |
| 509 | + } | |
| 510 | + | |
| 511 | + return result; | |
| 512 | +}; // handle rootValue inside List | |
| 513 | + | |
| 514 | +export var parseSingleRootValue = function parseSingleRootValue(expression) { | |
| 515 | + var rootValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | |
| 516 | + | |
| 517 | + if (typeof expression === 'string' && expression.indexOf('rootValue') > 0) { | |
| 518 | + var funcBody = expression.substring(2, expression.length - 2); | |
| 519 | + var str = "\n return ".concat(funcBody.replace(/rootValue/g, JSON.stringify(rootValue))); | |
| 520 | + | |
| 521 | + try { | |
| 522 | + return Function(str)(); | |
| 523 | + } catch (error) { | |
| 524 | + console.error(error, 'expression:', expression, 'rootValue:', rootValue); | |
| 525 | + return null; // 如果计算有错误,return null 最合适 | |
| 526 | + } | |
| 527 | + } else { | |
| 528 | + return expression; | |
| 529 | + } | |
| 530 | +}; | |
| 531 | +export function parseSingleExpression(func) { | |
| 532 | + var formData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | |
| 533 | + var dataPath = arguments.length > 2 ? arguments[2] : undefined; | |
| 534 | + var parentPath = getParentPath(dataPath); | |
| 535 | + var parent = getValueByPath(formData, parentPath) || {}; | |
| 536 | + | |
| 537 | + if (typeof func === 'string') { | |
| 538 | + var funcBody = func.substring(2, func.length - 2); | |
| 539 | + var str = "\n return ".concat(funcBody.replace(/formData/g, JSON.stringify(formData)).replace(/rootValue/g, JSON.stringify(parent))); | |
| 540 | + | |
| 541 | + try { | |
| 542 | + return Function(str)(); | |
| 543 | + } catch (error) { | |
| 544 | + console.log(error, func, dataPath); | |
| 545 | + return null; // 如果计算有错误,return null 最合适 | |
| 546 | + } // const funcBody = func.substring(2, func.length - 2); | |
| 547 | + // //TODO: 这样有问题,例如 a.b.indexOf(), 会把 a.b.indexOf 当做值 | |
| 548 | + // const match1 = /formData.([a-zA-Z0-9.$_\[\]]+)/g; | |
| 549 | + // const match2 = /rootValue.([a-zA-Z0-9.$_\[\]]+)/g; | |
| 550 | + // const str = ` | |
| 551 | + // return (${funcBody | |
| 552 | + // .replaceAll(match1, (v, m1) => | |
| 553 | + // JSON.stringify(getValueByPath(formData, m1)) | |
| 554 | + // ) | |
| 555 | + // .replaceAll(match2, (v, m1) => | |
| 556 | + // JSON.stringify(getValueByPath(parent, m1)) | |
| 557 | + // )})`; | |
| 558 | + // try { | |
| 559 | + // return Function(str)(); | |
| 560 | + // } catch (error) { | |
| 561 | + // console.log(error); | |
| 562 | + // return func; | |
| 563 | + // } | |
| 564 | + | |
| 565 | + } else return func; | |
| 566 | +} | |
| 567 | +export var schemaContainsExpression = function schemaContainsExpression(schema) { | |
| 568 | + if (isObject(schema)) { | |
| 569 | + return Object.keys(schema).some(function (key) { | |
| 570 | + var value = schema[key]; | |
| 571 | + | |
| 572 | + if (typeof value === 'string') { | |
| 573 | + return isExpression(value); | |
| 574 | + } else if (isObject(value)) { | |
| 575 | + return schemaContainsExpression(value); | |
| 576 | + } else { | |
| 577 | + return false; | |
| 578 | + } | |
| 579 | + }); | |
| 580 | + } | |
| 581 | + | |
| 582 | + return false; | |
| 583 | +}; | |
| 584 | +export var parseAllExpression = function parseAllExpression(_schema, formData, dataPath) { | |
| 585 | + var schema = clone(_schema); | |
| 586 | + Object.keys(schema).forEach(function (key) { | |
| 587 | + var value = schema[key]; | |
| 588 | + | |
| 589 | + if (isObject(value)) { | |
| 590 | + schema[key] = parseAllExpression(value, formData, dataPath); | |
| 591 | + } else if (isExpression(value)) { | |
| 592 | + schema[key] = parseSingleExpression(value, formData, dataPath); | |
| 593 | + } else if (typeof key === 'string' && key.toLowerCase().indexOf('props') > -1) { | |
| 594 | + // 有可能叫 xxxProps | |
| 595 | + var propsObj = schema[key]; | |
| 596 | + | |
| 597 | + if (isObject(propsObj)) { | |
| 598 | + Object.keys(propsObj).forEach(function (k) { | |
| 599 | + schema[key][k] = parseSingleExpression(propsObj[k], formData, dataPath); | |
| 600 | + }); | |
| 601 | + } | |
| 602 | + } | |
| 603 | + }); | |
| 604 | + return schema; | |
| 605 | +}; | |
| 606 | +export function isFunctionSchema(schema) { | |
| 607 | + return Object.keys(schema).some(function (key) { | |
| 608 | + if (typeof schema[key] === 'function') { | |
| 609 | + return true; | |
| 610 | + } else if (typeof schema[key] === 'string') { | |
| 611 | + return isExpression(schema[key]); | |
| 612 | + } else if (_typeof(schema[key]) === 'object') { | |
| 613 | + return isFunctionSchema(schema[key]); | |
| 614 | + } else { | |
| 615 | + return false; | |
| 616 | + } | |
| 617 | + }); | |
| 618 | +} | |
| 619 | +export var getParentProps = function getParentProps(propName, id, flatten) { | |
| 620 | + try { | |
| 621 | + var item = flatten[id]; | |
| 622 | + if (item.schema[propName] !== undefined) return item.schema[propName]; | |
| 623 | + | |
| 624 | + if (item && item.parent) { | |
| 625 | + var parentSchema = flatten[item.parent].schema; | |
| 626 | + | |
| 627 | + if (parentSchema[propName] !== undefined) { | |
| 628 | + return parentSchema[propName]; | |
| 629 | + } else { | |
| 630 | + return getParentProps(propName, item.parent, flatten); | |
| 631 | + } | |
| 632 | + } | |
| 633 | + } catch (error) { | |
| 634 | + return undefined; | |
| 635 | + } | |
| 636 | +}; | |
| 637 | +export var getSaveNumber = function getSaveNumber() { | |
| 638 | + var searchStr = localStorage.getItem('SAVES'); | |
| 639 | + | |
| 640 | + if (searchStr) { | |
| 641 | + try { | |
| 642 | + var saves = JSON.parse(searchStr); | |
| 643 | + var length = saves.length; | |
| 644 | + if (length) return length + 1; | |
| 645 | + } catch (error) { | |
| 646 | + return 1; | |
| 647 | + } | |
| 648 | + } else { | |
| 649 | + return 1; | |
| 650 | + } | |
| 651 | +}; | |
| 652 | +export function looseJsonParse(obj) { | |
| 653 | + return Function('"use strict";return (' + obj + ')')(); | |
| 654 | +} | |
| 655 | +export var isFunctionString = function isFunctionString(fString) { | |
| 656 | + return typeof fString === 'string' && fString.indexOf('function(') === 0; | |
| 657 | +}; | |
| 658 | +export function parseFunction(fString) { | |
| 659 | + if (isFunctionString(fString)) { | |
| 660 | + return Function('return ' + fString)(); | |
| 661 | + } | |
| 662 | + | |
| 663 | + return fString; | |
| 664 | +} // 获得propsSchema的children | |
| 665 | +// function getChildren2(schema) { | |
| 666 | +// if (!schema) return []; | |
| 667 | +// const { | |
| 668 | +// // object | |
| 669 | +// properties, | |
| 670 | +// // array | |
| 671 | +// items, | |
| 672 | +// type, | |
| 673 | +// } = schema; | |
| 674 | +// if (!properties && !items) { | |
| 675 | +// return []; | |
| 676 | +// } | |
| 677 | +// let schemaSubs = {}; | |
| 678 | +// if (type === 'object') { | |
| 679 | +// schemaSubs = properties; | |
| 680 | +// } | |
| 681 | +// if (type === 'array') { | |
| 682 | +// schemaSubs = items.properties; | |
| 683 | +// } | |
| 684 | +// return Object.keys(schemaSubs).map(name => ({ | |
| 685 | +// schema: schemaSubs[name], | |
| 686 | +// name, | |
| 687 | +// })); | |
| 688 | +// } | |
| 689 | + | |
| 690 | +export var oldSchemaToNew = function oldSchemaToNew(schema) { | |
| 691 | + if (schema && schema.propsSchema) { | |
| 692 | + var propsSchema = schema.propsSchema, | |
| 693 | + rest = _objectWithoutProperties(schema, _excluded); | |
| 694 | + | |
| 695 | + return _objectSpread({ | |
| 696 | + schema: propsSchema | |
| 697 | + }, rest); | |
| 698 | + } | |
| 699 | + | |
| 700 | + return schema; | |
| 701 | +}; | |
| 702 | +export var newSchemaToOld = function newSchemaToOld(setting) { | |
| 703 | + if (setting && setting.schema) { | |
| 704 | + var schema = setting.schema, | |
| 705 | + rest = _objectWithoutProperties(setting, _excluded2); | |
| 706 | + | |
| 707 | + return _objectSpread({ | |
| 708 | + propsSchema: schema | |
| 709 | + }, rest); | |
| 710 | + } | |
| 711 | + | |
| 712 | + return setting; | |
| 713 | +}; // from FR | |
| 714 | + | |
| 715 | +export var getEnum = function getEnum(schema) { | |
| 716 | + if (!schema) return undefined; | |
| 717 | + var itemEnum = schema && schema.items && schema.items.enum; | |
| 718 | + var schemaEnum = schema && schema.enum; | |
| 719 | + return itemEnum ? itemEnum : schemaEnum; | |
| 720 | +}; // export const getArray = (arr, defaultValue = []) => { | |
| 721 | +// if (Array.isArray(arr)) return arr; | |
| 722 | +// return defaultValue; | |
| 723 | +// }; | |
| 724 | + | |
| 725 | +export var isEmail = function isEmail(value) { | |
| 726 | + var regex = '^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$'; | |
| 727 | + | |
| 728 | + if (value && new RegExp(regex).test(value)) { | |
| 729 | + return true; | |
| 730 | + } | |
| 731 | + | |
| 732 | + return false; | |
| 733 | +}; | |
| 734 | +export function defaultGetValueFromEvent(valuePropName) { | |
| 735 | + var event = arguments.length <= 1 ? undefined : arguments[1]; | |
| 736 | + | |
| 737 | + if (event && event.target && valuePropName in event.target) { | |
| 738 | + return event.target[valuePropName]; | |
| 739 | + } | |
| 740 | + | |
| 741 | + return event; | |
| 742 | +} | |
| 743 | +export var getKeyFromPath = function getKeyFromPath() { | |
| 744 | + var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '#'; | |
| 745 | + | |
| 746 | + try { | |
| 747 | + var arr = path.split('.'); | |
| 748 | + var last = arr.slice(-1)[0]; | |
| 749 | + var result = last.replace('[]', ''); | |
| 750 | + return result; | |
| 751 | + } catch (error) { | |
| 752 | + console.error(error, 'getKeyFromPath'); | |
| 753 | + return ''; | |
| 754 | + } | |
| 755 | +}; // 更多的值获取 | |
| 756 | + | |
| 757 | +export var getDisplayValue = function getDisplayValue(value, schema) { | |
| 758 | + if (typeof value === 'boolean') { | |
| 759 | + return value ? 'yes' : 'no'; | |
| 760 | + } | |
| 761 | + | |
| 762 | + if (isObjType(schema) || isListType(schema)) { | |
| 763 | + return '-'; | |
| 764 | + } | |
| 765 | + | |
| 766 | + if (Array.isArray(schema.enum) && Array.isArray(schema.enumNames)) { | |
| 767 | + try { | |
| 768 | + return schema.enumNames[schema.enum.indexOf(value)]; | |
| 769 | + } catch (error) { | |
| 770 | + return value; | |
| 771 | + } | |
| 772 | + } | |
| 773 | + | |
| 774 | + if (_typeof(value) === 'object') { | |
| 775 | + return JSON.stringify(value); | |
| 776 | + } | |
| 777 | + | |
| 778 | + return value; | |
| 779 | +}; // 去掉数组里的空元素 {a: [null, {x:1}]} => {a: [{x:1}]} | |
| 780 | + | |
| 781 | +export var removeEmptyItemFromList = function removeEmptyItemFromList(formData) { | |
| 782 | + var result = {}; | |
| 783 | + | |
| 784 | + if (isObject(formData)) { | |
| 785 | + Object.keys(formData).forEach(function (key) { | |
| 786 | + result[key] = removeEmptyItemFromList(formData[key]); | |
| 787 | + }); | |
| 788 | + } else if (Array.isArray(formData)) { | |
| 789 | + result = formData.filter(function (item) { | |
| 790 | + if ([false, 0, ''].indexOf(item) > -1) return true; | |
| 791 | + | |
| 792 | + if (item && JSON.stringify(item) !== '{}') { | |
| 793 | + return true; | |
| 794 | + } | |
| 795 | + | |
| 796 | + return false; | |
| 797 | + }); | |
| 798 | + } else { | |
| 799 | + result = formData; | |
| 800 | + } | |
| 801 | + | |
| 802 | + return result; | |
| 803 | +}; | |
| 804 | +export var getDescriptorSimple = function getDescriptorSimple() { | |
| 805 | + var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | |
| 806 | + var path = arguments.length > 1 ? arguments[1] : undefined; | |
| 807 | + var result = {}; | |
| 808 | + | |
| 809 | + if (isObject(schema)) { | |
| 810 | + if (schema.type) { | |
| 811 | + switch (schema.type) { | |
| 812 | + case 'range': | |
| 813 | + result.type = 'array'; | |
| 814 | + break; | |
| 815 | + | |
| 816 | + case 'html': | |
| 817 | + result.type = 'string'; | |
| 818 | + break; | |
| 819 | + | |
| 820 | + default: | |
| 821 | + result.type = schema.type; | |
| 822 | + break; | |
| 823 | + } | |
| 824 | + } | |
| 825 | + | |
| 826 | + ['pattern', 'min', 'max', 'len', 'required'].forEach(function (key) { | |
| 827 | + if (Object.keys(schema).indexOf(key) > -1) { | |
| 828 | + result[key] = schema[key]; | |
| 829 | + } | |
| 830 | + }); | |
| 831 | + | |
| 832 | + switch (schema.format) { | |
| 833 | + case 'email': | |
| 834 | + case 'url': | |
| 835 | + result.type = schema.format; | |
| 836 | + break; | |
| 837 | + | |
| 838 | + default: | |
| 839 | + break; | |
| 840 | + } | |
| 841 | + | |
| 842 | + var handleRegx = function handleRegx(desc) { | |
| 843 | + if (desc.pattern && typeof desc.pattern === 'string') { | |
| 844 | + desc.pattern = new RegExp(desc.pattern); | |
| 845 | + } | |
| 846 | + | |
| 847 | + return desc; | |
| 848 | + }; // result be array | |
| 849 | + | |
| 850 | + | |
| 851 | + if (schema.rules) { | |
| 852 | + if (Array.isArray(schema.rules)) { | |
| 853 | + var requiredRule = schema.rules.find(function (rule) { | |
| 854 | + return rule.required === true; | |
| 855 | + }); | |
| 856 | + | |
| 857 | + if (requiredRule) { | |
| 858 | + result = _objectSpread(_objectSpread({}, result), requiredRule); | |
| 859 | + } | |
| 860 | + | |
| 861 | + result = [result].concat(_toConsumableArray(schema.rules)); | |
| 862 | + result = result.map(function (r) { | |
| 863 | + return handleRegx(r); | |
| 864 | + }); | |
| 865 | + } else if (isObject(schema.rules)) { | |
| 866 | + result = [result, schema.rules]; | |
| 867 | + result = result.map(function (r) { | |
| 868 | + return handleRegx(r); | |
| 869 | + }); | |
| 870 | + } | |
| 871 | + } else { | |
| 872 | + result = [result]; | |
| 873 | + } | |
| 874 | + } | |
| 875 | + | |
| 876 | + return _defineProperty({}, path, result); | |
| 877 | +}; // _path 只供内部递归使用 | |
| 878 | + | |
| 879 | +export var generateDataSkeleton = function generateDataSkeleton(schema, formData) { | |
| 880 | + var _formData = clone(formData); | |
| 881 | + | |
| 882 | + var result = _formData; | |
| 883 | + | |
| 884 | + if (isObjType(schema)) { | |
| 885 | + if (_formData === undefined || _typeof(_formData) !== 'object') { | |
| 886 | + _formData = {}; | |
| 887 | + result = {}; | |
| 888 | + } | |
| 889 | + | |
| 890 | + Object.keys(schema.properties).forEach(function (key) { | |
| 891 | + var childSchema = schema.properties[key]; | |
| 892 | + var childData = _formData[key]; | |
| 893 | + var childResult = generateDataSkeleton(childSchema, childData); | |
| 894 | + result[key] = childResult; | |
| 895 | + }); | |
| 896 | + } else if (_formData !== undefined) {// result = _formData; | |
| 897 | + } else if (schema.default !== undefined) { | |
| 898 | + result = clone(schema.default); | |
| 899 | + } else if (isListType(schema)) { | |
| 900 | + result = [generateDataSkeleton(schema.items)]; | |
| 901 | + } else if (schema.type === 'boolean' && !schema.widget) { | |
| 902 | + // result = false; | |
| 903 | + result = undefined; | |
| 904 | + } else { | |
| 905 | + result = undefined; | |
| 906 | + } | |
| 907 | + | |
| 908 | + return result; | |
| 909 | +}; | |
| 910 | +export var translateMessage = function translateMessage(msg, schema) { | |
| 911 | + if (typeof msg !== 'string') { | |
| 912 | + return ''; | |
| 913 | + } | |
| 914 | + | |
| 915 | + if (!schema) return msg; | |
| 916 | + msg = msg.replace('${title}', schema.title); | |
| 917 | + msg = msg.replace('${type}', schema.format || schema.type); // 兼容代码 | |
| 918 | + | |
| 919 | + if (typeof schema.min === 'number') { | |
| 920 | + msg = msg.replace('${min}', schema.min); | |
| 921 | + } | |
| 922 | + | |
| 923 | + if (typeof schema.max === 'number') { | |
| 924 | + msg = msg.replace('${max}', schema.max); | |
| 925 | + } | |
| 926 | + | |
| 927 | + if (schema.rules) { | |
| 928 | + var minRule = schema.rules.find(function (r) { | |
| 929 | + return r.min !== undefined; | |
| 930 | + }); | |
| 931 | + | |
| 932 | + if (minRule) { | |
| 933 | + msg = msg.replace('${min}', minRule.min); | |
| 934 | + } | |
| 935 | + | |
| 936 | + var maxRule = schema.rules.find(function (r) { | |
| 937 | + return r.max !== undefined; | |
| 938 | + }); | |
| 939 | + | |
| 940 | + if (maxRule) { | |
| 941 | + msg = msg.replace('${max}', maxRule.max); | |
| 942 | + } | |
| 943 | + | |
| 944 | + var lenRule = schema.rules.find(function (r) { | |
| 945 | + return r.len !== undefined; | |
| 946 | + }); | |
| 947 | + | |
| 948 | + if (lenRule) { | |
| 949 | + msg = msg.replace('${len}', lenRule.len); | |
| 950 | + } | |
| 951 | + | |
| 952 | + var patternRule = schema.rules.find(function (r) { | |
| 953 | + return r.pattern !== undefined; | |
| 954 | + }); | |
| 955 | + | |
| 956 | + if (patternRule) { | |
| 957 | + msg = msg.replace('${pattern}', patternRule.pattern); | |
| 958 | + } | |
| 959 | + } | |
| 960 | + | |
| 961 | + return msg; | |
| 962 | +}; | |
| 963 | + | |
| 964 | +var changeSchema = function changeSchema(_schema, singleChange) { | |
| 965 | + var schema = clone(_schema); | |
| 966 | + schema = singleChange(schema); | |
| 967 | + | |
| 968 | + if (isObjType(schema)) { | |
| 969 | + var requiredKeys = []; | |
| 970 | + | |
| 971 | + if (Array.isArray(schema.required)) { | |
| 972 | + requiredKeys = schema.required; | |
| 973 | + delete schema.required; | |
| 974 | + } | |
| 975 | + | |
| 976 | + Object.keys(schema.properties).forEach(function (key) { | |
| 977 | + var item = schema.properties[key]; | |
| 978 | + | |
| 979 | + if (requiredKeys.indexOf(key) > -1) { | |
| 980 | + item.required = true; | |
| 981 | + } | |
| 982 | + | |
| 983 | + schema.properties[key] = changeSchema(item, singleChange); | |
| 984 | + }); | |
| 985 | + } else if (isListType(schema)) { | |
| 986 | + Object.keys(schema.items.properties).forEach(function (key) { | |
| 987 | + var item = schema.items.properties[key]; | |
| 988 | + schema.items.properties[key] = changeSchema(item, singleChange); | |
| 989 | + }); | |
| 990 | + } | |
| 991 | + | |
| 992 | + return schema; | |
| 993 | +}; | |
| 994 | + | |
| 995 | +export var updateSchemaToNewVersion = function updateSchemaToNewVersion(schema) { | |
| 996 | + return changeSchema(schema, updateSingleSchema); | |
| 997 | +}; | |
| 998 | + | |
| 999 | +var updateSingleSchema = function updateSingleSchema(schema) { | |
| 1000 | + try { | |
| 1001 | + schema.rules = schema.rules || []; | |
| 1002 | + schema.props = schema.props || {}; | |
| 1003 | + | |
| 1004 | + if (schema['ui:options']) { | |
| 1005 | + schema.props = schema['ui:options']; | |
| 1006 | + delete schema['ui:options']; | |
| 1007 | + } | |
| 1008 | + | |
| 1009 | + if (schema.pattern) { | |
| 1010 | + var validItem = { | |
| 1011 | + pattern: schema.pattern | |
| 1012 | + }; | |
| 1013 | + | |
| 1014 | + if (schema.message && schema.message.pattern) { | |
| 1015 | + validItem.message = schema.message.pattern; | |
| 1016 | + } | |
| 1017 | + | |
| 1018 | + schema.rules.push(validItem); | |
| 1019 | + delete schema.pattern; | |
| 1020 | + delete schema.message; | |
| 1021 | + } // min / max | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + if (schema.minLength) { | |
| 1025 | + schema.min = schema.minLength; | |
| 1026 | + delete schema.minLength; | |
| 1027 | + } | |
| 1028 | + | |
| 1029 | + if (schema.maxLength) { | |
| 1030 | + schema.max = schema.maxLength; | |
| 1031 | + delete schema.maxLength; | |
| 1032 | + } | |
| 1033 | + | |
| 1034 | + if (schema.minItems) { | |
| 1035 | + schema.min = schema.minItems; | |
| 1036 | + delete schema.minItems; | |
| 1037 | + } | |
| 1038 | + | |
| 1039 | + if (schema.maxItems) { | |
| 1040 | + schema.max = schema.maxItems; | |
| 1041 | + delete schema.maxItems; | |
| 1042 | + } | |
| 1043 | + | |
| 1044 | + if (schema.step) { | |
| 1045 | + schema.props.step = schema.step; | |
| 1046 | + delete schema.step; | |
| 1047 | + } // ui:xxx | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + if (schema['ui:className']) { | |
| 1051 | + schema.className = schema['ui:className']; | |
| 1052 | + delete schema['ui:className']; | |
| 1053 | + } | |
| 1054 | + | |
| 1055 | + if (schema['ui:hidden']) { | |
| 1056 | + schema.hidden = schema['ui:hidden']; | |
| 1057 | + delete schema['ui:hidden']; | |
| 1058 | + } | |
| 1059 | + | |
| 1060 | + if (schema['ui:readonly']) { | |
| 1061 | + schema.readOnly = schema['ui:readonly']; // 改成驼峰了 | |
| 1062 | + | |
| 1063 | + delete schema['ui:readonly']; | |
| 1064 | + } | |
| 1065 | + | |
| 1066 | + if (schema['ui:disabled']) { | |
| 1067 | + schema.disabled = schema['ui:disabled']; | |
| 1068 | + delete schema['ui:disabled']; | |
| 1069 | + } | |
| 1070 | + | |
| 1071 | + if (schema['ui:width']) { | |
| 1072 | + schema.width = schema['ui:width']; | |
| 1073 | + delete schema['ui:width']; | |
| 1074 | + } | |
| 1075 | + | |
| 1076 | + if (schema['ui:displayType']) { | |
| 1077 | + schema.displayType = schema['ui:displayType']; | |
| 1078 | + delete schema['ui:displayType']; | |
| 1079 | + } | |
| 1080 | + | |
| 1081 | + if (schema['ui:column']) { | |
| 1082 | + schema.column = schema['ui:column']; | |
| 1083 | + delete schema['ui:column']; | |
| 1084 | + } | |
| 1085 | + | |
| 1086 | + if (schema['ui:widget']) { | |
| 1087 | + schema.widget = schema['ui:widget']; | |
| 1088 | + delete schema['ui:widget']; | |
| 1089 | + } | |
| 1090 | + | |
| 1091 | + if (schema['ui:labelWidth']) { | |
| 1092 | + schema.labelWidth = schema['ui:labelWidth']; | |
| 1093 | + delete schema['ui:labelWidth']; | |
| 1094 | + } | |
| 1095 | + | |
| 1096 | + if (schema.rules && schema.rules.length === 0) { | |
| 1097 | + delete schema.rules; | |
| 1098 | + } | |
| 1099 | + | |
| 1100 | + if (typeof schema.props === 'function' || isObject(schema.props) && Object.keys(schema.props).length > 0) {} else { | |
| 1101 | + delete schema.props; | |
| 1102 | + } | |
| 1103 | + | |
| 1104 | + return schema; | |
| 1105 | + } catch (error) { | |
| 1106 | + console.error('schema转换失败!', error); | |
| 1107 | + return schema; | |
| 1108 | + } | |
| 1109 | +}; // 检验一个string是 function(传统活箭头函数) | |
| 1110 | + | |
| 1111 | + | |
| 1112 | +export var parseFunctionString = function parseFunctionString(string) { | |
| 1113 | + if (typeof string !== 'string') return false; | |
| 1114 | + var reg1 = /^{{(function.+)}}$/; | |
| 1115 | + var reg2 = /^{{(.+=>.+)}}$/; | |
| 1116 | + | |
| 1117 | + if (string.match(reg1)) { | |
| 1118 | + return string.match(reg1)[1]; | |
| 1119 | + } | |
| 1120 | + | |
| 1121 | + if (string.match(reg2)) { | |
| 1122 | + return string.match(reg2)[1]; | |
| 1123 | + } | |
| 1124 | + | |
| 1125 | + return false; | |
| 1126 | +}; | |
| 1127 | +export var completeSchemaWithTheme = function completeSchemaWithTheme() { | |
| 1128 | + var schema = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | |
| 1129 | + var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | |
| 1130 | + var result = {}; | |
| 1131 | + | |
| 1132 | + if (isObject(schema)) { | |
| 1133 | + if (schema.theme && theme[schema.theme]) { | |
| 1134 | + result = _objectSpread(_objectSpread({}, schema), theme[schema.theme]); | |
| 1135 | + } | |
| 1136 | + | |
| 1137 | + Object.keys(schema).forEach(function (key) { | |
| 1138 | + result[key] = completeSchemaWithTheme(schema[key], theme); | |
| 1139 | + }); | |
| 1140 | + } else { | |
| 1141 | + result = schema; | |
| 1142 | + } | |
| 1143 | + | |
| 1144 | + return result; | |
| 1145 | +}; | |
| 1146 | +export var cleanEmpty = function cleanEmpty(obj) { | |
| 1147 | + if (Array.isArray(obj)) { | |
| 1148 | + return obj.map(function (v) { | |
| 1149 | + return v && isObject(v) ? cleanEmpty(v) : v; | |
| 1150 | + }).filter(function (v) { | |
| 1151 | + return !(v == undefined); | |
| 1152 | + }); | |
| 1153 | + } else if (isObject(obj)) { | |
| 1154 | + return Object.entries(obj).map(function (_ref12) { | |
| 1155 | + var _ref13 = _slicedToArray(_ref12, 2), | |
| 1156 | + k = _ref13[0], | |
| 1157 | + v = _ref13[1]; | |
| 1158 | + | |
| 1159 | + return [k, v && isObject(v) ? cleanEmpty(v) : v]; | |
| 1160 | + }).reduce(function (a, _ref14) { | |
| 1161 | + var _ref15 = _slicedToArray(_ref14, 2), | |
| 1162 | + k = _ref15[0], | |
| 1163 | + v = _ref15[1]; | |
| 1164 | + | |
| 1165 | + return v == undefined ? a : (a[k] = v, a); | |
| 1166 | + }, {}); | |
| 1167 | + } else { | |
| 1168 | + return obj; | |
| 1169 | + } | |
| 1170 | +}; // const x = { a: 1, b: { c: 2 }, d: [{ e: 3, f: [{ g: 5 }] }, { e: 4 }] }; | |
| 1171 | +// ['a', 'b.c', 'd[0].e', 'd[0].f[0].g', 'd[1].e'] | |
| 1172 | + | |
| 1173 | +export var dataToKeys = function dataToKeys(data) { | |
| 1174 | + var rootKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | |
| 1175 | + var result = []; | |
| 1176 | + | |
| 1177 | + if (rootKey && rootKey.slice(-1) !== ']') { | |
| 1178 | + result.push(rootKey); | |
| 1179 | + } | |
| 1180 | + | |
| 1181 | + var isComplex = function isComplex(data) { | |
| 1182 | + return isObject(data) || Array.isArray(data); | |
| 1183 | + }; | |
| 1184 | + | |
| 1185 | + if (isObject(data)) { | |
| 1186 | + Object.keys(data).forEach(function (key) { | |
| 1187 | + var item = data[key]; | |
| 1188 | + var itemRootKey = rootKey ? rootKey + '.' + key : key; | |
| 1189 | + | |
| 1190 | + if (isComplex(item)) { | |
| 1191 | + var itemKeys = dataToKeys(item, itemRootKey); | |
| 1192 | + result = [].concat(_toConsumableArray(result), _toConsumableArray(itemKeys)); | |
| 1193 | + } else { | |
| 1194 | + result.push(itemRootKey); | |
| 1195 | + } | |
| 1196 | + }); | |
| 1197 | + } else if (Array.isArray(data)) { | |
| 1198 | + data.forEach(function (item, idx) { | |
| 1199 | + var itemRootKey = rootKey ? "".concat(rootKey, "[").concat(idx, "]") : "[".concat(idx, "]"); | |
| 1200 | + | |
| 1201 | + if (isComplex(item)) { | |
| 1202 | + var itemKeys = dataToKeys(item, itemRootKey); | |
| 1203 | + result = [].concat(_toConsumableArray(result), _toConsumableArray(itemKeys)); | |
| 1204 | + } else { | |
| 1205 | + result.push(itemRootKey); | |
| 1206 | + } | |
| 1207 | + }); | |
| 1208 | + } else {} | |
| 1209 | + | |
| 1210 | + return result; | |
| 1211 | +}; | |
| 1212 | +export var removeHiddenFromResult = function removeHiddenFromResult(data, flatten) { | |
| 1213 | + var result = clone(data); | |
| 1214 | + var keys = dataToKeys(result); | |
| 1215 | + keys.forEach(function (key) { | |
| 1216 | + var _destructDataPath = destructDataPath(key), | |
| 1217 | + id = _destructDataPath.id; | |
| 1218 | + | |
| 1219 | + if (flatten[id]) { | |
| 1220 | + var _ref16 = flatten[id].schema || {}, | |
| 1221 | + hidden = _ref16.hidden; | |
| 1222 | + | |
| 1223 | + if (isExpression(hidden)) { | |
| 1224 | + hidden = parseSingleExpression(hidden, result, key); | |
| 1225 | + } | |
| 1226 | + | |
| 1227 | + if (get(result, key) !== undefined && hidden) { | |
| 1228 | + set(result, key, undefined); | |
| 1229 | + } | |
| 1230 | + } | |
| 1231 | + }); | |
| 1232 | + return result; | |
| 1233 | +}; | |
| 1234 | +export var getHiddenData = function getHiddenData(data, flatten) { | |
| 1235 | + var result = clone(data); | |
| 1236 | + var hiddenData = {}; | |
| 1237 | + var keys = dataToKeys(result); | |
| 1238 | + keys.forEach(function (key) { | |
| 1239 | + var _destructDataPath2 = destructDataPath(key), | |
| 1240 | + id = _destructDataPath2.id; | |
| 1241 | + | |
| 1242 | + if (flatten[id]) { | |
| 1243 | + var _ref17 = flatten[id].schema || {}, | |
| 1244 | + hidden = _ref17.hidden; | |
| 1245 | + | |
| 1246 | + if (isExpression(hidden)) { | |
| 1247 | + hidden = parseSingleExpression(hidden, result, key); | |
| 1248 | + } | |
| 1249 | + | |
| 1250 | + if (hidden) { | |
| 1251 | + debugger; | |
| 1252 | + hiddenData[key] = result[key]; | |
| 1253 | + } | |
| 1254 | + } | |
| 1255 | + }); | |
| 1256 | + return hiddenData; | |
| 1257 | +}; | |
| 1258 | +export function msToTime(duration) { | |
| 1259 | + var seconds = Math.floor(duration / 1000 % 60); | |
| 1260 | + var minutes = Math.floor(duration / (1000 * 60) % 60); | |
| 1261 | + var hours = Math.floor(duration / (1000 * 60 * 60) % 24); | |
| 1262 | + hours = hours < 10 ? '0' + hours : hours; | |
| 1263 | + minutes = minutes < 10 ? '0' + minutes : minutes; | |
| 1264 | + seconds = seconds < 10 ? '0' + seconds : seconds; | |
| 1265 | + return hours + ':' + minutes + ':' + seconds; | |
| 1266 | +} | |
| 1267 | +export function yymmdd(timeStamp) { | |
| 1268 | + var date_ob = new Date(Number(timeStamp)); | |
| 1269 | + | |
| 1270 | + var adjustZero = function adjustZero(num) { | |
| 1271 | + return ('0' + num).slice(-2); | |
| 1272 | + }; | |
| 1273 | + | |
| 1274 | + var day = adjustZero(date_ob.getDate()); | |
| 1275 | + var month = adjustZero(date_ob.getMonth()); | |
| 1276 | + var year = date_ob.getFullYear(); | |
| 1277 | + var hours = adjustZero(date_ob.getHours()); | |
| 1278 | + var minutes = adjustZero(date_ob.getMinutes()); | |
| 1279 | + var seconds = adjustZero(date_ob.getSeconds()); | |
| 1280 | + return "".concat(year, "-").concat(month, "-").concat(day, " ").concat(hours, ":").concat(minutes, ":").concat(seconds); | |
| 1281 | +} | |
| 1282 | +export function allPromiseFinish(promiseList) { | |
| 1283 | + var hasError = false; | |
| 1284 | + var count = promiseList.length; | |
| 1285 | + var results = []; | |
| 1286 | + | |
| 1287 | + if (!promiseList.length) { | |
| 1288 | + return Promise.resolve([]); | |
| 1289 | + } | |
| 1290 | + | |
| 1291 | + return new Promise(function (resolve, reject) { | |
| 1292 | + promiseList.forEach(function (promise, index) { | |
| 1293 | + promise.catch(function (e) { | |
| 1294 | + hasError = true; | |
| 1295 | + return e; | |
| 1296 | + }).then(function (result) { | |
| 1297 | + count -= 1; | |
| 1298 | + results[index] = result; | |
| 1299 | + | |
| 1300 | + if (count > 0) { | |
| 1301 | + return; | |
| 1302 | + } | |
| 1303 | + | |
| 1304 | + if (hasError) { | |
| 1305 | + reject(results); | |
| 1306 | + } | |
| 1307 | + | |
| 1308 | + resolve(results); | |
| 1309 | + }); | |
| 1310 | + }); | |
| 1311 | + }); | |
| 1312 | +} | |
| 1313 | +export var removeDups = function removeDups(arr) { | |
| 1314 | + if (!Array.isArray(arr)) { | |
| 1315 | + console.log('in removeDups: param is not an array'); | |
| 1316 | + return; | |
| 1317 | + } | |
| 1318 | + | |
| 1319 | + var array = []; | |
| 1320 | + | |
| 1321 | + for (var i = 0; i < arr.length; i++) { | |
| 1322 | + if (array.indexOf(arr[i]) === -1) { | |
| 1323 | + array.push(arr[i]); | |
| 1324 | + } | |
| 1325 | + } | |
| 1326 | + | |
| 1327 | + return array; | |
| 1328 | +}; | |
| \ No newline at end of file | ... | ... |
es/form-render-core/src/validateMessage.js
renamed from
es/validateMessage.js
| ... | ... | @@ -2,7 +2,6 @@ var typeTemplate = '${title} is not a valid ${type}'; |
| 2 | 2 | export var defaultValidateMessages = { |
| 3 | 3 | default: 'Validation error on field ${title}', |
| 4 | 4 | required: '${title} is required', |
| 5 | - // enum: '${title} must be one of [${enum}]', | |
| 6 | 5 | whitespace: '${title} cannot be empty', |
| 7 | 6 | date: { |
| 8 | 7 | format: '${title} is invalid for format date', | ... | ... |
es/form-render-core/src/validateMessageCN.js
renamed from
es/validateMessageCN.js
| ... | ... | @@ -27,7 +27,7 @@ export var defaultValidateMessagesCN = { |
| 27 | 27 | len: '${title}长度不是${len}', |
| 28 | 28 | min: '${title}长度不能小于${min}', |
| 29 | 29 | max: '${title}长度不能大于${max}', |
| 30 | - range: '${title}长度需在${min}于${max}之间' | |
| 30 | + range: '${title}长度需在${min}与${max}之间' | |
| 31 | 31 | }, |
| 32 | 32 | number: { |
| 33 | 33 | len: '${title}不等于${len}', |
| ... | ... | @@ -39,7 +39,7 @@ export var defaultValidateMessagesCN = { |
| 39 | 39 | len: '${title}长度不是${len}', |
| 40 | 40 | min: '${title}长度不能小于${min}', |
| 41 | 41 | max: '${title}长度不能大于${max}', |
| 42 | - range: '${title}长度需在${min}于${max}之间' | |
| 42 | + range: '${title}长度需在${min}与${max}之间' | |
| 43 | 43 | }, |
| 44 | 44 | pattern: { |
| 45 | 45 | mismatch: '${title}未通过正则判断${pattern}' | ... | ... |