@wufengteam/inputs
Version:
平台提供的右侧属性编辑器,需要在主工程中注册
173 lines • 8.24 kB
JavaScript
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 } from 'antd';
import { wufengController } from '@wufengteam/core';
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,
selectedComp = props.selectedComp;
var _ref = ((_a = DSLCore === null || DSLCore === void 0 ? void 0 : DSLCore.current) === null || _a === void 0 ? void 0 : _a.props) || {},
otherForm = _ref.otherForm;
var _ref2 = otherForm || {},
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);
});
}, [otherForm]);
// 本地表单的字段列表
var _useState7 = useState([]),
_useState8 = _slicedToArray(_useState7, 2),
localFieldList = _useState8[0],
setLocalFieldList = _useState8[1];
useEffect(function () {
if (visible) {
setLocalFieldList(function () {
var _a;
// 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 = (_a = selectedComp === null || selectedComp === void 0 ? void 0 : selectedComp.props) === null || _a === void 0 ? void 0 : _a.subFormFields;
var filterList = components.filter(function (item) {
return (item === null || item === void 0 ? void 0 : item.compName) !== 'DataLinkage';
});
var list = filterList.map(function (item) {
var _a, _b;
var compType = item === null || item === void 0 ? void 0 : item.compName;
var attrCode = (_a = item === null || item === void 0 ? void 0 : item.props) === null || _a === void 0 ? void 0 : _a.fieldName;
var attrName = (_b = item === null || item === void 0 ? void 0 : item.props) === null || _b === void 0 ? void 0 : _b.name;
return {
compType: compType,
attrCode: attrCode,
attrName: attrName
};
});
// console.log('本表单字段', list);
return list;
});
}
}, [visible, selectedComp]);
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(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.subFormFillOtherFormRule) || [];
return /*#__PURE__*/React.createElement(Form.Item, {
label: label,
name: name,
rules: rules
}, /*#__PURE__*/React.createElement(InnerDataLinkageRule, {
DSLCore: DSLCore,
initialValue: initialValue,
selectedComp: selectedComp
}));
};
export default DataLinkageRule;