@wufengteam/wform
Version:
@wufengteam/wform
134 lines • 6.36 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 */
/* eslint-disable no-shadow */
import React, { useEffect, useState } from 'react';
import { Tabs } from 'antd';
import { prefix } from '../../utils';
import "./index.css";
import { wufengController } from '@wufengteam/core';
var prefixCls = "".concat(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 = useState(''),
_useState2 = _slicedToArray(_useState, 2),
activeKey = _useState2[0],
setActiveKey = _useState2[1];
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.createElement(ContainerDropBox, {
style: Object.assign({}, style),
_component: _component,
canDrag: propsCanDrag
}, /*#__PURE__*/React.createElement(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);
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'
}));
};
export default WFTabsEdPc;