UNPKG

@wufengteam/inputs

Version:

平台提供的右侧属性编辑器,需要在主工程中注册

122 lines 6.12 kB
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } 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."); } 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); } 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; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } import React, { useState, useEffect } from 'react'; import { Modal, Form, Select, message } from 'antd'; import uniq from 'lodash.uniq'; import { cssPrefixCls } from '../utils'; import { MAP_TYPE } from './menu'; import "./index.css"; var prefix = "".concat(cssPrefixCls, "-map"); var Item = Form.Item, useForm = Form.useForm; var Option = Select.Option; var ignoreComponent = ['ImgUpload', 'VideoUpload', 'StdUpload', 'Attachments', 'TreeSelect', 'Cascader', 'DataLinkage', 'BindTable', 'QuillEditor', 'RichTextEditor', 'Location', 'Autograph', 'AddMember', 'AddDepartment', 'EditableTable', 'CheckUpload', 'TextRecognition', 'Address', 'Input']; var FieldMappingGroup = function FieldMappingGroup(props) { var _a; var visible = props.visible, onClose = props.onClose, DSLCore = props.DSLCore, onOk = props.onOk, value = props.value; var _useForm = useForm(), _useForm2 = _slicedToArray(_useForm, 1), form = _useForm2[0]; var _useState = useState([]), _useState2 = _slicedToArray(_useState, 2), options = _useState2[0], setOptions = _useState2[1]; var _ref = (_a = DSLCore === null || DSLCore === void 0 ? void 0 : DSLCore.current) === null || _a === void 0 ? void 0 : _a.props, _ref$idenTemplate = _ref.idenTemplate, idenTemplate = _ref$idenTemplate === void 0 ? '1' : _ref$idenTemplate; var components = DSLCore.querySelectAll('[compType=2]') || []; useEffect(function () { var filterList = components.filter(function (item) { var _a; return !ignoreComponent.includes((_a = item === null || item === void 0 ? void 0 : item.attribute) === null || _a === void 0 ? void 0 : _a.compName); }); var list = filterList.map(function (item) { var _a, _b, _c, _d, _e; var compType = (_a = item === null || item === void 0 ? void 0 : item.attribute) === null || _a === void 0 ? void 0 : _a.compName; var attrCode = (_c = (_b = item === null || item === void 0 ? void 0 : item.attribute) === null || _b === void 0 ? void 0 : _b.props) === null || _c === void 0 ? void 0 : _c.fieldName; var attrName = (_e = (_d = item === null || item === void 0 ? void 0 : item.attribute) === null || _d === void 0 ? void 0 : _d.props) === null || _e === void 0 ? void 0 : _e.name; return { compType: compType, attrCode: attrCode, attrName: attrName }; }); setOptions(list); }, [JSON.stringify(components)]); useEffect(function () { onOk({}); form.setFieldsValue({}); }, [idenTemplate]); var onFinish = function onFinish(values) { var list = []; Object.entries(values).forEach(function (_ref2) { var _ref3 = _slicedToArray(_ref2, 2), _key = _ref3[0], val = _ref3[1]; if (val) list.push(val); }); if (uniq(list).length !== list.length) { message.error('表单字段不可重复选择,请修改'); return; } onOk(values); }; var onFinishFailed = function onFinishFailed(_ref4) { var errorFields = _ref4.errorFields; var _a; message.error((_a = errorFields[0]) === null || _a === void 0 ? void 0 : _a.errors[0], 1); }; useEffect(function () { form.setFieldsValue(value); }, [JSON.stringify(value)]); return /*#__PURE__*/React.createElement(Modal, { title: "\u5EFA\u7ACB\u5B57\u6BB5\u6620\u5C04", className: "".concat(prefix, "-modal"), visible: visible, onCancel: onClose, onOk: function onOk() { return form.submit(); } }, /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "-modal-content") }, /*#__PURE__*/React.createElement(Form, { name: "basic", initialValues: value, labelCol: { span: 7 }, wrapperCol: { span: 16 }, onFinish: onFinish, onFinishFailed: onFinishFailed, autoComplete: "off", form: form }, MAP_TYPE[idenTemplate].map(function (item) { return /*#__PURE__*/React.createElement(Item, { key: item === null || item === void 0 ? void 0 : item.value, name: item === null || item === void 0 ? void 0 : item.value, label: item === null || item === void 0 ? void 0 : item.label, colon: false }, /*#__PURE__*/React.createElement(Select, { placeholder: "\u8BF7\u9009\u62E9", allowClear: true }, options.map(function (val) { var attrName = val.attrName, attrCode = val.attrCode; return /*#__PURE__*/React.createElement(Option, { key: attrCode, value: attrCode }, attrName); }))); })))); }; export default FieldMappingGroup;