@wufengteam/inputs
Version:
平台提供的右侧属性编辑器,需要在主工程中注册
188 lines (187 loc) • 10.3 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 _core = require("@wufengteam/core");
var _icons = require("@ant-design/icons");
var _RuleSetModal = _interopRequireDefault(require("./components/RuleSetModal"));
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; } /* eslint-disable no-console */
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 = (0, _react.useState)(false),
_useState2 = _slicedToArray(_useState, 2),
visible = _useState2[0],
setVisible = _useState2[1];
var _useState3 = (0, _react.useState)(false),
_useState4 = _slicedToArray(_useState3, 2),
loading = _useState4[0],
setLoading = _useState4[1];
var onCancel = function onCancel() {
setVisible(false);
};
// 关联表单的字段列表
var _useState5 = (0, _react.useState)(),
_useState6 = _slicedToArray(_useState5, 2),
fieldList = _useState6[0],
setFieldList = _useState6[1];
(0, _react.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);
_core.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 = (0, _react.useState)([]),
_useState8 = _slicedToArray(_useState7, 2),
localFieldList = _useState8[0],
setLocalFieldList = _useState8[1];
(0, _react.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.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_antd.Spin, {
spinning: loading
}, /*#__PURE__*/_react.default.createElement("div", {
onClick: function onClick(e) {
e.stopPropagation();
if (catalogItemId) {
setVisible(!visible);
} else {
_antd.message.warn('请先关联表单');
}
},
style: {
display: 'flex',
alignItems: 'center'
}
}, /*#__PURE__*/_react.default.createElement(_antd.Select, {
value: "\u5173\u8054\u6570\u636E\u8BBE\u7F6E",
dropdownStyle: {
display: 'none'
},
style: {
width: '100%'
}
}), /*#__PURE__*/_react.default.createElement(_antd.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.default.createElement(_icons.QuestionCircleOutlined, {
style: {
marginLeft: '5px'
}
})))), /*#__PURE__*/_react.default.createElement(_RuleSetModal.default, {
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.default.createElement(_antd.Form.Item, {
label: label,
name: name,
rules: rules
}, /*#__PURE__*/_react.default.createElement(InnerDataLinkageRule, {
DSLCore: DSLCore,
initialValue: initialValue
}));
};
var _default = exports.default = DataLinkageRule;