@wufengteam/wform
Version:
@wufengteam/wform
132 lines • 7.6 kB
JavaScript
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 */
/* eslint-disable no-shadow */
import { Tabs } from 'antd';
import React, { useState, useImperativeHandle, useMemo, useEffect } from 'react';
import { prefix } from '../../utils';
import "./index.css";
var prefixCls = "".concat(prefix, "-WFTabsPc");
var WFTabsPc = function WFTabsPc(props) {
var children = props.children,
tabStyle = props.tabStyle;
var _useState = useState(''),
_useState2 = _slicedToArray(_useState, 2),
activeKey = _useState2[0],
setActiveKey = _useState2[1];
var _useState3 = useState([]),
_useState4 = _slicedToArray(_useState3, 2),
displayWFTabPaneIds = _useState4[0],
setDisplayWFTabPaneIds = _useState4[1];
useEffect(function () {
if (Array.isArray(children)) {
var ids = [];
children.forEach(function (item) {
var _a, _b, _c, _d, _e;
var compProps = ((_b = (_a = item === null || item === void 0 ? void 0 : item.props) === null || _a === void 0 ? void 0 : _a.schema) === null || _b === void 0 ? void 0 : _b.props) || {};
var itemChildren = (_c = item === null || item === void 0 ? void 0 : item.props) === null || _c === void 0 ? void 0 : _c.children;
if (compProps.basicStatus === 1 && Array.isArray(itemChildren) && itemChildren.length > 0) {
var list = [];
itemChildren.forEach(function (i) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
if (((_c = (_b = (_a = i === null || i === void 0 ? void 0 : i.props) === null || _a === void 0 ? void 0 : _a.schema) === null || _b === void 0 ? void 0 : _b.props) === null || _c === void 0 ? void 0 : _c.basicStatus) === 1) {
list.push(i);
}
if (((_f = (_e = (_d = i === null || i === void 0 ? void 0 : i.props) === null || _d === void 0 ? void 0 : _d.schema) === null || _e === void 0 ? void 0 : _e.props) === null || _f === void 0 ? void 0 : _f.basicStatus) === 3 || ['SerialNumber'].includes((_h = (_g = i === null || i === void 0 ? void 0 : i.props) === null || _g === void 0 ? void 0 : _g.schema) === null || _h === void 0 ? void 0 : _h.compName)) {
list.push(i);
}
if (['BindTable'].includes((_k = (_j = i === null || i === void 0 ? void 0 : i.props) === null || _j === void 0 ? void 0 : _j.schema) === null || _k === void 0 ? void 0 : _k.compName)) {
list.push(i);
}
});
if (list.length > 0) {
ids.push((_e = (_d = item === null || item === void 0 ? void 0 : item.props) === null || _d === void 0 ? void 0 : _d.schema) === null || _e === void 0 ? void 0 : _e.id);
}
}
});
setDisplayWFTabPaneIds(ids);
}
}, [children]);
var childrenF = useMemo(function () {
var _a, _b, _c, _d, _e;
var val = children.filter(function (item) {
var _a, _b;
if (displayWFTabPaneIds.includes((_b = (_a = item === null || item === void 0 ? void 0 : item.props) === null || _a === void 0 ? void 0 : _a.schema) === null || _b === void 0 ? void 0 : _b.id)) {
return true;
}
return false;
});
var activeItem = val.find(function (j) {
if (j.props.schema.props.isActive) {
return true;
}
return false;
});
if (activeItem) {
setActiveKey((_b = (_a = activeItem === null || activeItem === void 0 ? void 0 : activeItem.props) === null || _a === void 0 ? void 0 : _a.schema) === null || _b === void 0 ? void 0 : _b.id);
} else {
setActiveKey((_e = (_d = (_c = val === null || val === void 0 ? void 0 : val[0]) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.schema) === null || _e === void 0 ? void 0 : _e.id);
}
return val;
}, [children, displayWFTabPaneIds]);
useImperativeHandle(props.forwardedRef, function () {
return {
addDisPlayWFTabPaneIds: function addDisPlayWFTabPaneIds(ids) {
setDisplayWFTabPaneIds(function (old) {
var mergedArray = _toConsumableArray(new Set([].concat(_toConsumableArray(old), _toConsumableArray(ids))));
return mergedArray;
});
},
removeDisPlayWFTabPaneIds: function removeDisPlayWFTabPaneIds(ids) {
setDisplayWFTabPaneIds(function (old) {
return old.filter(function (item) {
return !ids.includes(item);
});
});
}
};
});
if (childrenF.length === 0) {
return null;
}
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
style: {
display: 'none'
}
}, children), /*#__PURE__*/React.createElement(Tabs, {
className: "".concat(prefixCls),
activeKey: activeKey,
items: (childrenF || []).map(function (c) {
var _c$props$schema$props = c.props.schema.props,
name = _c$props$schema$props.name,
fieldName = _c$props$schema$props.fieldName;
return {
key: fieldName,
children: /*#__PURE__*/React.cloneElement(c, {
extendProps: {
activeKey: activeKey
}
}),
forceRender: true,
label: name
};
}),
onChange: function onChange(e) {
setActiveKey(e);
},
type: tabStyle === '1' ? 'line' : 'card'
}));
};
export default /*#__PURE__*/React.forwardRef(function (props, ref) {
return /*#__PURE__*/React.createElement(WFTabsPc, Object.assign({}, props, {
forwardedRef: ref
}));
});