@wufengteam/inputs
Version:
平台提供的右侧属性编辑器,需要在主工程中注册
196 lines (195 loc) • 11.7 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 _utils = require("../../../utils");
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 Option = _antd.Select.Option;
// 被填充字段所使用控件规则限制
var linkageRules = {
Input: ['Input', 'TextArea', 'Password', 'InputNumber', 'InputPhone', 'InputMail'],
SerialNumber: ['Input', 'TextArea', 'Password', 'InputNumber', 'InputPhone', 'InputMail'],
TextArea: ['Input', 'TextArea', 'Password', 'InputNumber', 'InputPhone', 'InputMail'],
Password: ['Input', 'TextArea', 'Password'],
InputNumber: ['Input', 'TextArea', 'InputNumber'],
InputPhone: ['Input', 'TextArea', 'InputPhone'],
InputMail: ['Input', 'TextArea', 'InputMail'],
Select: ['Select', 'MultipleSelect', 'Radio', 'CheckboxGroup', 'TreeSelect'],
MultipleSelect: ['MultipleSelect', 'CheckboxGroup', 'Cascader'],
Radio: ['Select', 'MultipleSelect', 'Radio', 'CheckboxGroup'],
CheckboxGroup: ['MultipleSelect', 'CheckboxGroup', 'Cascader'],
TreeSelect: ['Select', 'MultipleSelect', 'Radio', 'CheckboxGroup', 'TreeSelect'],
Cascader: ['Cascader', 'MultipleSelect', 'CheckboxGroup'],
TimePicker: ['TimePicker', 'DatePicker'],
DatePicker: ['TimePicker', 'DatePicker'],
RangePicker: ['RangePicker', 'Input', 'TextArea'],
Location: ['Input', 'TextArea', 'Location'],
AddMember: ['Input', 'TextArea', 'AddMember'],
AddDepartment: ['Input', 'TextArea', 'AddDepartment']
};
var RuleSet = function RuleSet(props) {
var _a, _b;
var _props$fieldList = props.fieldList,
fieldList = _props$fieldList === void 0 ? [] : _props$fieldList,
_props$localFieldList = props.localFieldList,
localFieldList = _props$localFieldList === void 0 ? [] : _props$localFieldList,
onChange = props.onChange,
value = props.value,
catalogItemId = props.catalogItemId;
// 可被填充字段列表
var _useState = (0, _react.useState)([]),
_useState2 = _slicedToArray(_useState, 2),
fillFieldList = _useState2[0],
setFillFieldList = _useState2[1];
// 填充字段信息
var fieldInfo = (0, _react.useRef)({
name: '',
compType: '',
attrName: '',
attrId: '',
busiObjectId: '',
catalogItemId: catalogItemId
});
// 关联表单字段根据attrCode为key转成map结构
var fieldListMap = (0, _react.useRef)({});
// 本地表单字段根据attrCode为key转成map结构
var localFieldListMap = (0, _react.useRef)({});
// 设置可被填充的字段列表
(0, _react.useEffect)(function () {
var _a;
var mapData = {};
fieldList.forEach(function (item) {
mapData[item.attrCode] = item;
});
fieldListMap.current = mapData;
if (!((_a = value === null || value === void 0 ? void 0 : value.fieldInfo) === null || _a === void 0 ? void 0 : _a.name)) return;
fieldInfo.current = value === null || value === void 0 ? void 0 : value.fieldInfo;
setFillFieldList(function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
var compType = (_b = mapData === null || mapData === void 0 ? void 0 : mapData[(_a = value === null || value === void 0 ? void 0 : value.fieldInfo) === null || _a === void 0 ? void 0 : _a.name]) === null || _b === void 0 ? void 0 : _b.compType;
var attrName = (_d = mapData === null || mapData === void 0 ? void 0 : mapData[(_c = value === null || value === void 0 ? void 0 : value.fieldInfo) === null || _c === void 0 ? void 0 : _c.name]) === null || _d === void 0 ? void 0 : _d.attrName;
var attrId = (_f = mapData === null || mapData === void 0 ? void 0 : mapData[(_e = value === null || value === void 0 ? void 0 : value.fieldInfo) === null || _e === void 0 ? void 0 : _e.name]) === null || _f === void 0 ? void 0 : _f.attrId;
var busiObjectId = (_h = mapData === null || mapData === void 0 ? void 0 : mapData[(_g = value === null || value === void 0 ? void 0 : value.fieldInfo) === null || _g === void 0 ? void 0 : _g.name]) === null || _h === void 0 ? void 0 : _h.busiObjectId;
var linkageRule = (linkageRules === null || linkageRules === void 0 ? void 0 : linkageRules[compType]) || [];
var list = localFieldList.filter(function (item) {
return linkageRule === null || linkageRule === void 0 ? void 0 : linkageRule.includes(item.compType);
});
if ((list === null || list === void 0 ? void 0 : list.length) === 0) {
onChange === null || onChange === void 0 ? void 0 : onChange({
fieldInfo: {
name: (_j = value === null || value === void 0 ? void 0 : value.fieldInfo) === null || _j === void 0 ? void 0 : _j.name,
compType: compType,
attrName: attrName,
attrId: attrId,
busiObjectId: busiObjectId,
catalogItemId: catalogItemId
},
fillFieldInfo: {
name: '',
compType: ''
}
});
}
return list || [];
});
}, [fieldList, localFieldList]);
(0, _react.useEffect)(function () {
var mapData = {};
localFieldList.forEach(function (item) {
mapData[item.attrCode] = item;
});
localFieldListMap.current = mapData;
}, [localFieldList]);
var onFiledChange = function onFiledChange(val) {
var _a, _b, _c, _d, _e, _f, _g, _h;
var compType = (_b = (_a = fieldListMap === null || fieldListMap === void 0 ? void 0 : fieldListMap.current) === null || _a === void 0 ? void 0 : _a[val]) === null || _b === void 0 ? void 0 : _b.compType;
var attrName = (_d = (_c = fieldListMap === null || fieldListMap === void 0 ? void 0 : fieldListMap.current) === null || _c === void 0 ? void 0 : _c[val]) === null || _d === void 0 ? void 0 : _d.attrName;
var attrId = (_f = (_e = fieldListMap === null || fieldListMap === void 0 ? void 0 : fieldListMap.current) === null || _e === void 0 ? void 0 : _e[val]) === null || _f === void 0 ? void 0 : _f.attrId;
var busiObjectId = (_h = (_g = fieldListMap === null || fieldListMap === void 0 ? void 0 : fieldListMap.current) === null || _g === void 0 ? void 0 : _g[val]) === null || _h === void 0 ? void 0 : _h.busiObjectId;
var linkageRule = (linkageRules === null || linkageRules === void 0 ? void 0 : linkageRules[compType]) || [];
setFillFieldList(function () {
var list = localFieldList.filter(function (item) {
return linkageRule === null || linkageRule === void 0 ? void 0 : linkageRule.includes(item.compType);
});
return list;
});
fieldInfo.current = {
name: val,
compType: compType,
attrName: attrName,
attrId: attrId,
busiObjectId: busiObjectId,
catalogItemId: catalogItemId
};
onChange === null || onChange === void 0 ? void 0 : onChange({
fieldInfo: {
name: val,
compType: compType,
attrName: attrName,
attrId: attrId,
busiObjectId: busiObjectId,
catalogItemId: catalogItemId
},
fillFieldInfo: {
name: '',
compType: ''
}
});
};
var onFillFiledChange = function onFillFiledChange(val) {
var _a, _b;
var compType = (_b = (_a = localFieldListMap === null || localFieldListMap === void 0 ? void 0 : localFieldListMap.current) === null || _a === void 0 ? void 0 : _a[val]) === null || _b === void 0 ? void 0 : _b.compType;
onChange === null || onChange === void 0 ? void 0 : onChange({
fieldInfo: (fieldInfo === null || fieldInfo === void 0 ? void 0 : fieldInfo.current) || {},
fillFieldInfo: {
name: val,
compType: compType
}
});
};
return /*#__PURE__*/_react.default.createElement("div", {
className: "".concat(_utils.cssPrefixCls, "-dataLinkageRuleSet-item")
}, /*#__PURE__*/_react.default.createElement(_antd.Select, {
style: {
width: 145
},
allowClear: true,
onChange: onFiledChange,
value: (_a = value === null || value === void 0 ? void 0 : value.fieldInfo) === null || _a === void 0 ? void 0 : _a.name
}, fieldList.map(function (item) {
var attrCode = item.attrCode,
attrName = item.attrName;
return /*#__PURE__*/_react.default.createElement(Option, {
value: attrCode,
key: attrCode
}, attrName);
})), /*#__PURE__*/_react.default.createElement("span", {
className: "".concat(_utils.cssPrefixCls, "-dataLinkageRuleSet-item-space")
}, "\u7684\u503C\u586B\u5145\u5230"), /*#__PURE__*/_react.default.createElement(_antd.Select, {
style: {
width: 145
},
allowClear: true,
onChange: onFillFiledChange,
value: (_b = value === null || value === void 0 ? void 0 : value.fillFieldInfo) === null || _b === void 0 ? void 0 : _b.name
}, fillFieldList.map(function (item) {
var attrCode = item.attrCode,
attrName = item.attrName;
return /*#__PURE__*/_react.default.createElement(Option, {
value: attrCode,
key: attrCode
}, attrName);
})));
};
var _default = exports.default = RuleSet;