UNPKG

@wufengteam/inputs

Version:

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

179 lines 8.79 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; } /* eslint-disable no-console */ import React, { useEffect, useState } from 'react'; import { Form, message, Select, Spin, Tooltip } from 'antd'; import { wufengController } from '@wufengteam/core'; import { QuestionCircleOutlined } from '@ant-design/icons'; import RuleSetModal from './components/RuleSetModal'; import "./index.css"; var InnerDataLinkageRule = function InnerDataLinkageRule(props) { var _a; var onChange = props.onChange, DSLCore = props.DSLCore, initialValue = props.initialValue; var _ref = ((_a = DSLCore === null || DSLCore === void 0 ? void 0 : DSLCore.current) === null || _a === void 0 ? void 0 : _a.props) || {}, bindForm = _ref.bindForm; var _ref2 = bindForm || {}, catalogItemId = _ref2.catalogItemId, appId = _ref2.appId; // 关联表单字段类型 var dataLinkShowCompType = ['Input', 'TextArea', 'Password', 'InputNumber', 'InputPhone', 'InputMail', 'Select', 'MultipleSelect', 'Radio', 'CheckboxGroup', 'TreeSelect', 'Cascader', 'TimePicker', 'DatePicker', 'RangePicker', 'Location', 'AddMember', 'AddDepartment', 'SerialNumber']; var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), visible = _useState2[0], setVisible = _useState2[1]; var _useState3 = useState(false), _useState4 = _slicedToArray(_useState3, 2), loading = _useState4[0], setLoading = _useState4[1]; var onCancel = function onCancel() { setVisible(false); }; // 关联表单的字段列表 var _useState5 = useState(), _useState6 = _slicedToArray(_useState5, 2), fieldList = _useState6[0], setFieldList = _useState6[1]; useEffect(function () { var catalogItemIdCopy = ''; initialValue === null || initialValue === void 0 ? void 0 : initialValue.forEach(function (item) { var _a; catalogItemIdCopy = (_a = item === null || item === void 0 ? void 0 : item.fieldInfo) === null || _a === void 0 ? void 0 : _a.catalogItemId; }); if (!catalogItemId) return; setLoading(true); wufengController.getAction('queryFormFiledById', { catalogItemId: catalogItemId, appId: appId }).then(function (res) { setLoading(false); var resultCode = res.resultCode, resultObject = res.resultObject; if (resultCode === '0') { // 2023.2.16 后端统一接口,防止代码重复,适配出参,故修改 if (catalogItemIdCopy === catalogItemId || !catalogItemIdCopy) { if (Array.isArray(resultObject)) { var attrsFiltered = resultObject.filter(function (item) { return dataLinkShowCompType.includes(item.compType) && (item === null || item === void 0 ? void 0 : item.customizedAttribute) !== 'flow'; }); setFieldList(function () { var list = attrsFiltered.map(function (item) { return { compType: item.compType, attrCode: item.attrCode, attrName: item.attrName, attrId: item.busiObjectAttrId, busiObjectId: item.busiObjectId }; }); // console.log('关联表单字段', list); return list; }); } } else { onChange === null || onChange === void 0 ? void 0 : onChange([]); } } }).catch(function () { setLoading(false); }); }, [bindForm]); // 本地表单的字段列表 var _useState7 = useState([]), _useState8 = _slicedToArray(_useState7, 2), localFieldList = _useState8[0], setLocalFieldList = _useState8[1]; useEffect(function () { if (visible) { setLocalFieldList(function () { // const parentId = DSLCore?.query(fieldName)?.parentId; // const components = DSLCore.querySelectAll(`#${parentId} [compType=2]`) || []; // } else { // components = DSLCore.querySelectAll('[compType=2]') || []; // } console.log('components', DSLCore.querySelectAll('[compType=2]') || []); // const components = DSLCore.current?.parent().children(); var components = DSLCore.querySelectAll('[compType=2]') || []; var filterList = components.filter(function (item) { var _a; return ((_a = item === null || item === void 0 ? void 0 : item.attribute) === null || _a === void 0 ? void 0 : _a.compName) !== 'DataLinkage'; }); 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 }; }); // console.log('本表单字段', list); return list; }); } }, [visible]); return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Spin, { spinning: loading }, /*#__PURE__*/React.createElement("div", { onClick: function onClick(e) { e.stopPropagation(); if (catalogItemId) { setVisible(!visible); } else { message.warn('请先关联表单'); } }, style: { display: 'flex', alignItems: 'center' } }, /*#__PURE__*/React.createElement(Select, { value: "\u5173\u8054\u6570\u636E\u8BBE\u7F6E", dropdownStyle: { display: 'none' }, style: { width: '100%' } }), /*#__PURE__*/React.createElement(Tooltip, { title: "\u6570\u636E\u586B\u5145\uFF1A\u652F\u6301\u5C06\u5173\u8054\u8868\u5355\u4E2D\u9009\u62E9\u7684\u67D0\u6761\u6570\u636E\u7684\u5B57\u6BB5\u503C\u586B\u5145\u5230\u5F53\u524D\u8868\u5355\u4E2D\u7684\u5176\u5B83\u5B57\u6BB5\u3002", placement: "topRight" }, /*#__PURE__*/React.createElement(QuestionCircleOutlined, { style: { marginLeft: '5px' } })))), /*#__PURE__*/React.createElement(RuleSetModal, { fieldList: fieldList, localFieldList: localFieldList, catalogItemId: catalogItemId, initialValue: initialValue, visible: visible, onCancel: onCancel, onChange: onChange })); }; var DataLinkageRule = function DataLinkageRule(props) { var _a; var name = props.name, rules = props.rules, label = props.label, DSLCore = props.DSLCore, selectedComp = props.selectedComp; var initialValue = ((_a = selectedComp === null || selectedComp === void 0 ? void 0 : selectedComp.props) === null || _a === void 0 ? void 0 : _a.dataLinkageRuleInfo) || []; return /*#__PURE__*/React.createElement(Form.Item, { label: label, name: name, rules: rules }, /*#__PURE__*/React.createElement(InnerDataLinkageRule, { DSLCore: DSLCore, initialValue: initialValue })); }; export default DataLinkageRule;