UNPKG

@wufengteam/inputs

Version:

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

148 lines 7.37 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; } var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; /* eslint-disable no-console */ import React, { useEffect, useState } from 'react'; import { Select, Form, Tooltip } from 'antd'; import { wufengController } from '@wufengteam/core'; import { QuestionCircleOutlined } from '@ant-design/icons'; import { cssPrefixCls } from '../utils'; import "./index.css"; var Option = Select.Option; var prefix = "".concat(cssPrefixCls, "-select-attr"); var AttrSelect = function AttrSelect(props) { var _a; var value = props.value, onChange = props.onChange, _props$placeholder = props.placeholder, placeholder = _props$placeholder === void 0 ? '请选择' : _props$placeholder, DSLCore = props.DSLCore, _props$tooltipText = props.tooltipText, tooltipText = _props$tooltipText === void 0 ? '' : _props$tooltipText, ignoreFieldByCode = props.ignoreFieldByCode, ignoreFieldByCompType = props.ignoreFieldByCompType; var _useState = useState(value), _useState2 = _slicedToArray(_useState, 2), options = _useState2[0], setOptions = _useState2[1]; var _useState3 = useState(value), _useState4 = _slicedToArray(_useState3, 2), selfValue = _useState4[0], setSelfValue = _useState4[1]; var _useState5 = useState({}), _useState6 = _slicedToArray(_useState5, 2), selfBindForm = _useState6[0], setSelfBindForm = _useState6[1]; var _ref = ((_a = DSLCore === null || DSLCore === void 0 ? void 0 : DSLCore.current) === null || _a === void 0 ? void 0 : _a.props) || {}, bindForm = _ref.bindForm; // 在关联数据组件中根据组件类型忽略字段, // const dataLinkageIgnoreCompList = [ // 'Switch', // 开关 // 'Rate', // 评分 // 'Api', // Api查询 // 'QuillEditor', // 富文本 // 'Attachments', // 附件下载 // 'BindTable', // 关联表单 // 'TextRecognition', // 文本识别 // 'DataLinkage', // 数据关联 // 'SubForm', // 子表单 // ]; /** * 查询表单的字段 */ var queryFormFiledById = function queryFormFiledById(id, appId) { if (!id || !appId) return; wufengController.getAction('queryFormFiledById', { catalogItemId: id, appId: appId }).then(function (res) { var _ref2 = res || {}, resultObject = _ref2.resultObject, resultCode = _ref2.resultCode; if (res && resultCode === '0') { if (Array.isArray(resultObject)) { var optionVal = resultObject; if (Array.isArray(ignoreFieldByCode)) { optionVal = resultObject.filter(function (item) { return !ignoreFieldByCode.includes(item === null || item === void 0 ? void 0 : item.attrCode) && (item === null || item === void 0 ? void 0 : item.customizedAttribute) !== 'flow'; }); } if (Array.isArray(ignoreFieldByCompType)) { optionVal = optionVal.filter(function (item) { return !ignoreFieldByCompType.includes(item === null || item === void 0 ? void 0 : item.compType); }); } setOptions(optionVal); } } }); }; useEffect(function () { if ((selfBindForm === null || selfBindForm === void 0 ? void 0 : selfBindForm.catalogItemId) && (selfBindForm === null || selfBindForm === void 0 ? void 0 : selfBindForm.catalogItemId) !== (bindForm === null || bindForm === void 0 ? void 0 : bindForm.catalogItemId)) { setSelfValue(undefined); onChange === null || onChange === void 0 ? void 0 : onChange([]); setOptions([]); } setSelfBindForm(bindForm); queryFormFiledById(bindForm === null || bindForm === void 0 ? void 0 : bindForm.catalogItemId, bindForm === null || bindForm === void 0 ? void 0 : bindForm.appId); }, [JSON.stringify(bindForm)]); useEffect(function () { setSelfValue(value); }, [JSON.stringify(value)]); var handleChange = function handleChange(_, option) { setSelfValue(option); onChange === null || onChange === void 0 ? void 0 : onChange(option); }; return /*#__PURE__*/React.createElement("div", { className: prefix }, /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "-select") }, /*#__PURE__*/React.createElement(Select, { onChange: handleChange, value: selfValue, labelInValue: true, placeholder: placeholder, mode: "multiple", allowClear: true }, options && options.map(function (i) { return /*#__PURE__*/React.createElement(Option, { key: i.attrCode, label: i.attrName, value: i.attrCode, attrName: i.attrName, attrCode: i.attrCode, staticCode: i.staticCode, busiObjectId: i.busiObjectId, attrId: i.busiObjectAttrId, compType: i.compType, attribute: i.attribute }, i.attrName); }))), tooltipText && ( /*#__PURE__*/React.createElement("div", { className: "".concat(prefix, "-ques") }, /*#__PURE__*/React.createElement(Tooltip, { title: tooltipText }, /*#__PURE__*/React.createElement(QuestionCircleOutlined, null))))); }; var SelectAttr = function SelectAttr(props) { var label = props.label, name = props.name, rules = props.rules, other = __rest(props, ["label", "name", "rules"]); return /*#__PURE__*/React.createElement(Form.Item, { label: label, name: name, rules: rules }, /*#__PURE__*/React.createElement(AttrSelect, Object.assign({}, other))); }; export default SelectAttr;