@wufengteam/inputs
Version:
平台提供的右侧属性编辑器,需要在主工程中注册
132 lines (131 loc) • 7.65 kB
JavaScript
;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _antd = require("antd");
var _lodash = _interopRequireDefault(require("lodash.uniq"));
var _utils = require("../utils");
var _menu = require("./menu");
require("./index.css");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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; }
var prefix = "".concat(_utils.cssPrefixCls, "-map");
var Item = _antd.Form.Item,
useForm = _antd.Form.useForm;
var Option = _antd.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 = (0, _react.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]') || [];
(0, _react.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)]);
(0, _react.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 ((0, _lodash.default)(list).length !== list.length) {
_antd.message.error('表单字段不可重复选择,请修改');
return;
}
onOk(values);
};
var onFinishFailed = function onFinishFailed(_ref4) {
var errorFields = _ref4.errorFields;
var _a;
_antd.message.error((_a = errorFields[0]) === null || _a === void 0 ? void 0 : _a.errors[0], 1);
};
(0, _react.useEffect)(function () {
form.setFieldsValue(value);
}, [JSON.stringify(value)]);
return /*#__PURE__*/_react.default.createElement(_antd.Modal, {
title: "\u5EFA\u7ACB\u5B57\u6BB5\u6620\u5C04",
className: "".concat(prefix, "-modal"),
visible: visible,
onCancel: onClose,
onOk: function onOk() {
return form.submit();
}
}, /*#__PURE__*/_react.default.createElement("div", {
className: "".concat(prefix, "-modal-content")
}, /*#__PURE__*/_react.default.createElement(_antd.Form, {
name: "basic",
initialValues: value,
labelCol: {
span: 7
},
wrapperCol: {
span: 16
},
onFinish: onFinish,
onFinishFailed: onFinishFailed,
autoComplete: "off",
form: form
}, _menu.MAP_TYPE[idenTemplate].map(function (item) {
return /*#__PURE__*/_react.default.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.default.createElement(_antd.Select, {
placeholder: "\u8BF7\u9009\u62E9",
allowClear: true
}, options.map(function (val) {
var attrName = val.attrName,
attrCode = val.attrCode;
return /*#__PURE__*/_react.default.createElement(Option, {
key: attrCode,
value: attrCode
}, attrName);
})));
}))));
};
var _default = exports.default = FieldMappingGroup;