@wufengteam/wform
Version:
@wufengteam/wform
141 lines (140 loc) • 7.67 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");
require("./index.css");
var _core = require("@wufengteam/core");
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 */ /* eslint-disable no-shadow */
var prefixCls = "".concat(_utils.prefix, "-WFTabsEdPc");
// function changeAlpha(color, newAlpha) {
// // 解析颜色值为 RGBA 分量
// const rgbaValues = color.match(/\d+/g);
// const red = rgbaValues[0];
// const green = rgbaValues[1];
// const blue = rgbaValues[2];
// // 替换 alpha 值为传入的参数
// const newColor = `rgba(${red}, ${green}, ${blue}, ${newAlpha})`;
// return newColor;
// }
// tabBgColor, tabFontColor, tabFontSize, tabFontWeight
var WFTabsEdPc = function WFTabsEdPc(props) {
var ContainerDropBox = props.ContainerDropBox,
children = props.children,
style = props.style,
_component = props._component,
_props$canDrag = props.canDrag,
propsCanDrag = _props$canDrag === void 0 ? true : _props$canDrag,
tabsItems = props.tabsItems,
tabStyle = props.tabStyle;
var _useState = (0, _react.useState)(''),
_useState2 = _slicedToArray(_useState, 2),
activeKey = _useState2[0],
setActiveKey = _useState2[1];
(0, _react.useEffect)(function () {
var activeItem = tabsItems === null || tabsItems === void 0 ? void 0 : tabsItems.find(function (item) {
var isActive = item.props.isActive;
if (isActive) {
return true;
}
return false;
});
if (activeItem) {
var fieldName = activeItem.props.fieldName;
setActiveKey(fieldName);
}
}, [tabsItems]);
// const LabelComp = ({ name, activeKey, index, tabStyle, tabBgColor, tabFontColor, tabFontSize, tabFontWeight }) => {
// console.log('tabStyle', tabStyle, tabBgColor, tabFontColor, tabFontSize, tabFontWeight);
// if (tabStyle === '3') {
// return (
// <div
// className={`${prefixCls}-tabs-tab`}
// style={{
// background: activeKey === index ? tabBgColor : `${changeAlpha(tabBgColor, 0.06)}`,
// color: activeKey === index ? tabFontColor : '#414352',
// fontSize: `${tabFontSize}px`,
// fontWeight: tabFontWeight,
// }}
// >{name}</div>
// )
// }
// if (tabStyle === '2') {
// return (
// <div
// className={`${prefixCls}-tabs-tab`}
// style={{
// background: activeKey === index ? tabBgColor : '#F2F3F5',
// color: activeKey === index ? tabFontColor : '#414352',
// fontSize: `${tabFontSize}px`,
// fontWeight: tabFontWeight,
// }}
// >{name}</div>
// )
// }
// return (
// <div
// className={`${prefixCls}-tabs-tab1`}
// style={{
// color: activeKey === index ? tabFontColor : '#414352',
// fontSize: `${tabFontSize}px`,
// fontWeight: tabFontWeight,
// borderColor: activeKey === index ? `${tabBgColor}` : '#fff',
// }}
// >{name}</div>
// )
// };
return /*#__PURE__*/_react.default.createElement(ContainerDropBox, {
style: Object.assign({}, style),
_component: _component,
canDrag: propsCanDrag
}, /*#__PURE__*/_react.default.createElement(_antd.Tabs, {
className: "".concat(prefixCls),
activeKey: activeKey,
items: (children || []).map(function (c) {
var _c$props$_component$p = c.props._component.props,
name = _c$props$_component$p.name,
fieldName = _c$props$_component$p.fieldName;
return {
key: fieldName,
children: c,
label: name
// label: (
// <LabelComp
// tabStyle={tabStyle}
// activeKey={activeKey}
// index={fieldName}
// name={name}
// tabBgColor={tabBgColor}
// tabFontColor={tabFontColor}
// tabFontSize={tabFontSize}
// tabFontWeight={tabFontWeight}
// />),
};
}),
onChange: function onChange(activeKey) {
setActiveKey(activeKey);
_core.wufengController.emit('activeKeyChange', {
activeKey: activeKey
});
},
// tabBarStyle={{
// background: tabStyle === '3' ? `${changeAlpha(tabBgColor, 0.06)}` : '#ffffff',
// border: tabStyle === '3' ? `2px solid ${tabBgColor}` : 'none',
// paddingLeft: tabStyle === '1' ? '16px' : 0,
// }}
type: tabStyle === '1' ? 'line' : 'card'
}));
};
var _default = exports.default = WFTabsEdPc;