Commit f6a50bedd590b6493d6250b84708ed5b3b224215

Authored by 乔启韬
1 parent ea4c3d0d

按钮行宽度优化

... ... @@ -173,6 +173,7 @@ var VirtualList = function VirtualList(_ref) {
173 173 searchName = _useState12[0],
174 174 setSearchName = _useState12[1];
175 175
  176 + var btnMap = useRef({});
176 177 var padding = useMemo(function () {
177 178 return size === 'default' ? 32 : 16;
178 179 }, [size]);
... ... @@ -547,13 +548,15 @@ var VirtualList = function VirtualList(_ref) {
547 548 needConfirm = item.needConfirm,
548 549 confirmContent = item.confirmContent,
549 550 icon = item.icon;
  551 + var display = handleState(record, code, props.originWidget);
  552 + btnMap.current[code] = display;
550 553 return /*#__PURE__*/React.createElement(_Tooltip, {
551 554 title: name
552 555 }, /*#__PURE__*/React.createElement(_Button, _extends({
553 556 key: code,
554 557 style: {
555 558 marginLeft: 8,
556   - display: "".concat(handleState(record, code, props.originWidget))
  559 + display: display
557 560 }
558 561 }, item, {
559 562 icon: icon && style !== 'TEXT' ? BUTTON_ICONS_MAP[icon] : null,
... ... @@ -606,7 +609,13 @@ var VirtualList = function VirtualList(_ref) {
606 609 };
607 610
608 611 if (style === "ICON" || props.originWidget === 'subform') {
609   - action.width = len * 32 + padding - 8;
  612 + var effectiveLength = 0;
  613 + Object.keys(btnMap.current || {}).forEach(function (code) {
  614 + if (btnMap.current[code] !== 'none') {
  615 + effectiveLength += 1;
  616 + }
  617 + });
  618 + action.width = effectiveLength * 32 + padding - 8;
610 619 } else {
611 620 var div = document.createElement('div');
612 621 div.style.position = 'absolute';
... ... @@ -615,8 +624,10 @@ var VirtualList = function VirtualList(_ref) {
615 624 window.document.body.appendChild(div);
616 625 var leng = 0;
617 626 line.buttons.map(function (item) {
  627 + var _btnMap$current;
  628 +
618 629 div.innerHTML = item.name;
619   - leng += div.clientWidth + padding + (style !== 'TEXT' && item.icon ? 22 : 0);
  630 + leng += ((_btnMap$current = btnMap.current) === null || _btnMap$current === void 0 ? void 0 : _btnMap$current[item.code]) === 'none' ? 0 : div.clientWidth + padding + (style !== 'TEXT' && item.icon ? 22 : 0);
620 631 });
621 632 action.width = leng + padding - 8;
622 633 div.remove();
... ...
... ... @@ -222,6 +222,7 @@ var VirtualList = function VirtualList(_ref) {
222 222 searchName = _useState12[0],
223 223 setSearchName = _useState12[1];
224 224
  225 + var btnMap = (0, _react.useRef)({});
225 226 var padding = (0, _react.useMemo)(function () {
226 227 return size === 'default' ? 32 : 16;
227 228 }, [size]);
... ... @@ -598,13 +599,15 @@ var VirtualList = function VirtualList(_ref) {
598 599 needConfirm = item.needConfirm,
599 600 confirmContent = item.confirmContent,
600 601 icon = item.icon;
  602 + var display = handleState(record, code, props.originWidget);
  603 + btnMap.current[code] = display;
601 604 return /*#__PURE__*/_react.default.createElement(_tooltip.default, {
602 605 title: name
603 606 }, /*#__PURE__*/_react.default.createElement(_button.default, _extends({
604 607 key: code,
605 608 style: {
606 609 marginLeft: 8,
607   - display: "".concat(handleState(record, code, props.originWidget))
  610 + display: display
608 611 }
609 612 }, item, {
610 613 icon: icon && style !== 'TEXT' ? BUTTON_ICONS_MAP[icon] : null,
... ... @@ -657,7 +660,13 @@ var VirtualList = function VirtualList(_ref) {
657 660 };
658 661
659 662 if (style === "ICON" || props.originWidget === 'subform') {
660   - action.width = len * 32 + padding - 8;
  663 + var effectiveLength = 0;
  664 + Object.keys(btnMap.current || {}).forEach(function (code) {
  665 + if (btnMap.current[code] !== 'none') {
  666 + effectiveLength += 1;
  667 + }
  668 + });
  669 + action.width = effectiveLength * 32 + padding - 8;
661 670 } else {
662 671 var div = document.createElement('div');
663 672 div.style.position = 'absolute';
... ... @@ -666,8 +675,10 @@ var VirtualList = function VirtualList(_ref) {
666 675 window.document.body.appendChild(div);
667 676 var leng = 0;
668 677 line.buttons.map(function (item) {
  678 + var _btnMap$current;
  679 +
669 680 div.innerHTML = item.name;
670   - leng += div.clientWidth + padding + (style !== 'TEXT' && item.icon ? 22 : 0);
  681 + leng += ((_btnMap$current = btnMap.current) === null || _btnMap$current === void 0 ? void 0 : _btnMap$current[item.code]) === 'none' ? 0 : div.clientWidth + padding + (style !== 'TEXT' && item.icon ? 22 : 0);
671 682 });
672 683 action.width = leng + padding - 8;
673 684 div.remove();
... ...