@hsu-react/ui 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/FormItem/ItemContainer/index.d.ts +2 -0
- package/es/components/FormItem/ItemContainer/index.js +4 -15
- package/es/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.d.ts +3 -3
- package/es/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.js +3 -3
- package/es/components/Search/SearchAdvanced/index.js +26 -148
- package/es/components/Search/SearchCard/index.js +1 -1
- package/es/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.js +2 -2
- package/es/components/Search/SearchCollapsible/index.js +17 -138
- package/es/components/Search/SearchWithFilter/index.js +4 -143
- package/es/components/Search/SearchWithMore/index.js +11 -142
- package/es/components/Search/_components/FilterDropdown/index.js +5 -6
- package/es/components/Search/_components/SearchBase/index.d.ts +32 -0
- package/es/components/Search/_components/SearchBase/index.js +185 -0
- package/es/components/Search/_hooks/useSearchCommon.js +5 -11
- package/es/components/Search/_hooks/useSearchExpand.js +4 -13
- package/es/components/Search/_utils/calculateButtonGroupAndColumnWidth.js +3 -10
- package/es/components/Search/_utils/calculateVisibleItems.js +4 -5
- package/es/components/Search/_utils/index.d.ts +2 -0
- package/es/components/Search/_utils/index.js +3 -1
- package/es/components/Search/_utils/measureButtonGroupWidth.d.ts +6 -0
- package/es/components/Search/_utils/measureButtonGroupWidth.js +18 -0
- package/es/components/Search/_utils/shouldDisplayExtraItem.d.ts +11 -0
- package/es/components/Search/_utils/shouldDisplayExtraItem.js +13 -0
- package/es/components/Search/index.d.ts +4 -0
- package/es/components/Search/index.js +6 -133
- package/es/components/Table/_hooks/useTableColumns.js +11 -0
- package/lib/components/FormItem/ItemContainer/index.d.ts +2 -0
- package/lib/components/FormItem/ItemContainer/index.js +2 -5
- package/lib/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.d.ts +3 -3
- package/lib/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.js +3 -3
- package/lib/components/Search/SearchAdvanced/index.js +19 -134
- package/lib/components/Search/SearchCard/index.js +1 -1
- package/lib/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.js +2 -2
- package/lib/components/Search/SearchCollapsible/index.js +12 -124
- package/lib/components/Search/SearchWithFilter/index.js +5 -129
- package/lib/components/Search/SearchWithMore/index.js +7 -126
- package/lib/components/Search/_components/FilterDropdown/index.js +5 -6
- package/lib/components/Search/_components/SearchBase/index.d.ts +32 -0
- package/lib/components/Search/_components/SearchBase/index.js +169 -0
- package/lib/components/Search/_hooks/useSearchCommon.js +4 -6
- package/lib/components/Search/_hooks/useSearchExpand.js +2 -13
- package/lib/components/Search/_utils/calculateButtonGroupAndColumnWidth.js +2 -10
- package/lib/components/Search/_utils/calculateVisibleItems.js +3 -5
- package/lib/components/Search/_utils/index.d.ts +2 -0
- package/lib/components/Search/_utils/index.js +15 -1
- package/lib/components/Search/_utils/measureButtonGroupWidth.d.ts +6 -0
- package/lib/components/Search/_utils/measureButtonGroupWidth.js +24 -0
- package/lib/components/Search/_utils/shouldDisplayExtraItem.d.ts +11 -0
- package/lib/components/Search/_utils/shouldDisplayExtraItem.js +19 -0
- package/lib/components/Search/index.d.ts +4 -0
- package/lib/components/Search/index.js +8 -119
- package/lib/components/Table/_hooks/useTableColumns.js +11 -0
- package/package.json +1 -1
- package/src/components/FormItem/ItemContainer/index.tsx +4 -7
- package/src/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.tsx +6 -6
- package/src/components/Search/SearchAdvanced/index.tsx +25 -164
- package/src/components/Search/SearchCard/index.tsx +1 -1
- package/src/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.tsx +2 -2
- package/src/components/Search/SearchCollapsible/index.tsx +13 -162
- package/src/components/Search/SearchWithFilter/index.tsx +2 -164
- package/src/components/Search/SearchWithMore/index.tsx +9 -161
- package/src/components/Search/_components/FilterDropdown/index.tsx +5 -6
- package/src/components/Search/_components/SearchBase/index.tsx +224 -0
- package/src/components/Search/_hooks/useSearchCommon.ts +10 -13
- package/src/components/Search/_hooks/useSearchExpand.ts +3 -13
- package/src/components/Search/_utils/calculateButtonGroupAndColumnWidth.ts +2 -10
- package/src/components/Search/_utils/calculateVisibleItems.ts +10 -11
- package/src/components/Search/_utils/index.ts +2 -0
- package/src/components/Search/_utils/measureButtonGroupWidth.ts +23 -0
- package/src/components/Search/_utils/shouldDisplayExtraItem.ts +23 -0
- package/src/components/Search/index.tsx +7 -153
- package/src/components/Table/_hooks/useTableColumns.tsx +17 -0
- /package/es/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.d.ts +0 -0
- /package/lib/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.d.ts +0 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _antd = require("antd");
|
|
9
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
+
var _FormItem = _interopRequireDefault(require("../../../FormItem"));
|
|
11
|
+
var _indexModule = _interopRequireDefault(require("../../index.module.scss"));
|
|
12
|
+
var _hooks = require("../../_hooks");
|
|
13
|
+
var _ButtonGroup = require("../ButtonGroup");
|
|
14
|
+
var _SearchButtons = require("../SearchButtons");
|
|
15
|
+
var _ExpandButton = require("../ExpandButton");
|
|
16
|
+
var _FilterDropdown = require("../FilterDropdown");
|
|
17
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
20
|
+
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 && Object.prototype.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; }
|
|
21
|
+
/** 暴露给变体扩展渲染(如高级筛选抽屉)的上下文 */
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Search 各变体共享的基础实现:
|
|
25
|
+
* 表单渲染、列布局、展开/收起、按钮组、权限控制。
|
|
26
|
+
* 变体只负责自身差异(筛选器、折叠开关、高级筛选抽屉等)。
|
|
27
|
+
*/
|
|
28
|
+
const SearchBase = props => {
|
|
29
|
+
const {
|
|
30
|
+
searchItems = [],
|
|
31
|
+
moreSearchItems = [],
|
|
32
|
+
className,
|
|
33
|
+
onSearch,
|
|
34
|
+
onReset,
|
|
35
|
+
externalForm,
|
|
36
|
+
hasPermi,
|
|
37
|
+
columnNum = 4,
|
|
38
|
+
beforeButtonGroup,
|
|
39
|
+
affterButtonGroup,
|
|
40
|
+
searchData,
|
|
41
|
+
minLabelWidth,
|
|
42
|
+
defaultExpanded = false,
|
|
43
|
+
onExpandChange,
|
|
44
|
+
autoAdaptWidth = true,
|
|
45
|
+
baseWidth,
|
|
46
|
+
onValuesChange,
|
|
47
|
+
searchDisabled = false,
|
|
48
|
+
showAllSearchItems = false,
|
|
49
|
+
searchText,
|
|
50
|
+
resetText,
|
|
51
|
+
onFilterChange,
|
|
52
|
+
columnOffsetWidth = 0,
|
|
53
|
+
advancedFilters = false,
|
|
54
|
+
showFilter = false,
|
|
55
|
+
afterForm,
|
|
56
|
+
renderOutside
|
|
57
|
+
} = props;
|
|
58
|
+
const [form] = _antd.Form.useForm(externalForm);
|
|
59
|
+
const {
|
|
60
|
+
containerRef,
|
|
61
|
+
buttonGroupRef,
|
|
62
|
+
cls,
|
|
63
|
+
getLabelWidth,
|
|
64
|
+
processedSearchItems,
|
|
65
|
+
setSearchItems,
|
|
66
|
+
currentSearchItems,
|
|
67
|
+
totalColumnNum,
|
|
68
|
+
expand,
|
|
69
|
+
setExpand,
|
|
70
|
+
toggleExpand,
|
|
71
|
+
showExpandButton,
|
|
72
|
+
onSearchClick,
|
|
73
|
+
onResetClick,
|
|
74
|
+
shouldRender,
|
|
75
|
+
permitted
|
|
76
|
+
} = (0, _hooks.useSearchCommon)({
|
|
77
|
+
form,
|
|
78
|
+
searchItems,
|
|
79
|
+
moreSearchItems,
|
|
80
|
+
searchData,
|
|
81
|
+
hasPermi,
|
|
82
|
+
beforeButtonGroup,
|
|
83
|
+
affterButtonGroup,
|
|
84
|
+
columnNum,
|
|
85
|
+
autoAdaptWidth,
|
|
86
|
+
defaultExpanded,
|
|
87
|
+
onExpandChange,
|
|
88
|
+
showAllSearchItems,
|
|
89
|
+
minLabelWidth,
|
|
90
|
+
baseWidth,
|
|
91
|
+
onSearch,
|
|
92
|
+
onReset,
|
|
93
|
+
columnOffsetWidth
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// 按列分组预计算(用于对齐同列 label 宽度),避免在 map 中逐项重复 filter
|
|
97
|
+
const columnGroups = (0, _react.useMemo)(() => {
|
|
98
|
+
const groups = Array.from({
|
|
99
|
+
length: totalColumnNum
|
|
100
|
+
}, () => []);
|
|
101
|
+
currentSearchItems.forEach((item, idx) => {
|
|
102
|
+
groups[idx % totalColumnNum].push(item);
|
|
103
|
+
});
|
|
104
|
+
return groups;
|
|
105
|
+
}, [currentSearchItems, totalColumnNum]);
|
|
106
|
+
if (!shouldRender) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
110
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
111
|
+
ref: containerRef,
|
|
112
|
+
className: (0, _classnames.default)(_indexModule.default.Search, className),
|
|
113
|
+
style: {
|
|
114
|
+
"--column-number": totalColumnNum,
|
|
115
|
+
"--column-offset-width": `${columnOffsetWidth}px`
|
|
116
|
+
},
|
|
117
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
118
|
+
className: (0, _classnames.default)(_indexModule.default.searchOption, _indexModule.default[expand.toString()]),
|
|
119
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_antd.Form, {
|
|
120
|
+
form: form,
|
|
121
|
+
className: (0, _classnames.default)(_indexModule.default.option, cls),
|
|
122
|
+
onValuesChange: onValuesChange,
|
|
123
|
+
children: [permitted && currentSearchItems.map((item, idx) => /*#__PURE__*/(0, _react.createElement)(_FormItem.default, {
|
|
124
|
+
...item,
|
|
125
|
+
key: item.name,
|
|
126
|
+
className: (0, _classnames.default)(_indexModule.default.item, item.className, {
|
|
127
|
+
[_indexModule.default.unFill]: item.width !== undefined
|
|
128
|
+
}),
|
|
129
|
+
label: advancedFilters ? undefined : item.label,
|
|
130
|
+
labelWidth: advancedFilters || item.width !== undefined ? undefined : getLabelWidth(columnGroups[idx % totalColumnNum], undefined, minLabelWidth)
|
|
131
|
+
})), (beforeButtonGroup?.length || affterButtonGroup?.length || permitted) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ButtonGroup.ButtonGroup, {
|
|
132
|
+
beforeButtonGroup: beforeButtonGroup,
|
|
133
|
+
affterButtonGroup: affterButtonGroup,
|
|
134
|
+
expandButton: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ExpandButton.ExpandButton, {
|
|
135
|
+
expand: expand,
|
|
136
|
+
toggleExpand: toggleExpand,
|
|
137
|
+
advancedFilters: advancedFilters,
|
|
138
|
+
showExpandButton: showExpandButton,
|
|
139
|
+
showAllSearchItems: showAllSearchItems || !!moreSearchItems?.length
|
|
140
|
+
}),
|
|
141
|
+
permitted: permitted,
|
|
142
|
+
ref: buttonGroupRef,
|
|
143
|
+
children: [currentSearchItems.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_SearchButtons.SearchButtons, {
|
|
144
|
+
onSearch: onSearchClick,
|
|
145
|
+
onReset: onResetClick,
|
|
146
|
+
searchDisabled: searchDisabled,
|
|
147
|
+
searchText: searchText,
|
|
148
|
+
resetText: resetText
|
|
149
|
+
}), showFilter && /*#__PURE__*/(0, _jsxRuntime.jsx)(_FilterDropdown.FilterDropdown, {
|
|
150
|
+
searchItems: processedSearchItems,
|
|
151
|
+
originalSearchItems: searchItems,
|
|
152
|
+
setSearchItems: setSearchItems,
|
|
153
|
+
onFilterChange: onFilterChange
|
|
154
|
+
})]
|
|
155
|
+
})]
|
|
156
|
+
})
|
|
157
|
+
}), permitted && afterForm]
|
|
158
|
+
}), permitted && renderOutside?.({
|
|
159
|
+
form,
|
|
160
|
+
expand,
|
|
161
|
+
setExpand,
|
|
162
|
+
processedSearchItems,
|
|
163
|
+
getLabelWidth,
|
|
164
|
+
onSearchClick,
|
|
165
|
+
onResetClick
|
|
166
|
+
})]
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
var _default = exports.default = SearchBase;
|
|
@@ -61,12 +61,10 @@ const useSearchCommon = params => {
|
|
|
61
61
|
}, [moreSearchItems]);
|
|
62
62
|
|
|
63
63
|
// 计算可见的搜索项数量
|
|
64
|
-
const visibleSearchItemCount =
|
|
65
|
-
return visibleSearchItems.length;
|
|
66
|
-
}, [visibleSearchItems]);
|
|
64
|
+
const visibleSearchItemCount = visibleSearchItems.length;
|
|
67
65
|
|
|
68
66
|
// 计算总列数(包括按钮组)
|
|
69
|
-
const baseTotalColumnNum =
|
|
67
|
+
const baseTotalColumnNum = columnNum + 1;
|
|
70
68
|
|
|
71
69
|
// 根据容器宽度动态调整列数
|
|
72
70
|
const totalColumnNum = (0, _useAdaptiveColumnNum.useAdaptiveColumnNum)(containerRef, baseTotalColumnNum, autoAdaptWidth, 1,
|
|
@@ -78,7 +76,7 @@ const useSearchCommon = params => {
|
|
|
78
76
|
baseWidth);
|
|
79
77
|
|
|
80
78
|
// 计算调整后的搜索项列数(不包括按钮组)
|
|
81
|
-
const adaptiveColumnNum =
|
|
79
|
+
const adaptiveColumnNum = Math.max(1, totalColumnNum - 1);
|
|
82
80
|
|
|
83
81
|
// 使用基于宽度的展开/收起控制
|
|
84
82
|
const {
|
|
@@ -142,7 +140,7 @@ const useSearchCommon = params => {
|
|
|
142
140
|
} = (0, _utils.calculateButtonGroupAndColumnWidth)(containerRef, buttonGroupRef, adaptiveColumnNum, columnOffsetWidth);
|
|
143
141
|
|
|
144
142
|
// 判断按钮组宽度是否大于列宽,如果是,则显示 实际搜索项数量+1
|
|
145
|
-
if (
|
|
143
|
+
if ((0, _utils.shouldDisplayExtraItem)(buttonGroupWidth, columnWidth, adaptiveColumnNum, visibleSearchItemCount)) {
|
|
146
144
|
return adaptiveColumnNum + 1;
|
|
147
145
|
}
|
|
148
146
|
return adaptiveColumnNum;
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useSearchExpand = useSearchExpand;
|
|
7
7
|
var _react = require("react");
|
|
8
|
+
var _utils = require("../_utils");
|
|
8
9
|
/**
|
|
9
10
|
* 基于宽度自适应控制展开/收起的Hook
|
|
10
11
|
* @param containerRef 容器引用
|
|
@@ -34,19 +35,7 @@ function useSearchExpand(containerRef, buttonGroupRef, itemClassName, itemCount,
|
|
|
34
35
|
const availableWidth = containerWidth - 30; // 15px padding on each side
|
|
35
36
|
|
|
36
37
|
// 获取按钮组的实际宽度(计算所有子元素宽度总和)
|
|
37
|
-
|
|
38
|
-
const buttonChildren = Array.from(buttonGroupRef.current.children);
|
|
39
|
-
if (buttonChildren.length > 0) {
|
|
40
|
-
// 计算所有子元素的宽度总和
|
|
41
|
-
let totalWidth = 0;
|
|
42
|
-
buttonChildren?.forEach(child => {
|
|
43
|
-
totalWidth += child.offsetWidth;
|
|
44
|
-
});
|
|
45
|
-
// 加上子元素之间的间距(column-gap: 10px)
|
|
46
|
-
const childGap = 5;
|
|
47
|
-
totalWidth += (buttonChildren.length - 1) * childGap;
|
|
48
|
-
buttonGroupWidth = totalWidth;
|
|
49
|
-
}
|
|
38
|
+
const buttonGroupWidth = (0, _utils.measureButtonGroupWidth)(buttonGroupRef.current) ?? 0;
|
|
50
39
|
|
|
51
40
|
// 获取所有搜索项元素
|
|
52
41
|
const items = container.querySelectorAll(`${itemClassName}`);
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.calculateButtonGroupAndColumnWidth = calculateButtonGroupAndColumnWidth;
|
|
7
|
+
var _measureButtonGroupWidth = require("./measureButtonGroupWidth");
|
|
7
8
|
/**
|
|
8
9
|
* 计算按钮组宽度和列宽
|
|
9
10
|
* @param containerRef 容器引用
|
|
@@ -21,16 +22,7 @@ function calculateButtonGroupAndColumnWidth(containerRef, buttonGroupRef, adapti
|
|
|
21
22
|
const gap = 10; // 项之间的间距
|
|
22
23
|
|
|
23
24
|
// 计算按钮组宽度
|
|
24
|
-
|
|
25
|
-
if (buttonChildren.length > 0) {
|
|
26
|
-
let totalWidth = 0;
|
|
27
|
-
buttonChildren?.forEach(child => {
|
|
28
|
-
totalWidth += child.offsetWidth;
|
|
29
|
-
});
|
|
30
|
-
const childGap = 5;
|
|
31
|
-
totalWidth += (buttonChildren.length - 1) * childGap;
|
|
32
|
-
buttonGroupWidth = totalWidth;
|
|
33
|
-
}
|
|
25
|
+
buttonGroupWidth = (0, _measureButtonGroupWidth.measureButtonGroupWidth)(buttonGroupRef.current);
|
|
34
26
|
|
|
35
27
|
// 计算列宽(单个搜索项的默认宽度)
|
|
36
28
|
if (adaptiveColumnNum > 0) {
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.calculateVisibleItems = calculateVisibleItems;
|
|
7
|
+
var _shouldDisplayExtraItem = require("./shouldDisplayExtraItem");
|
|
7
8
|
/**
|
|
8
9
|
* 计算当前应该显示的搜索项
|
|
9
10
|
* @param searchItems 所有搜索项
|
|
@@ -17,7 +18,7 @@ exports.calculateVisibleItems = calculateVisibleItems;
|
|
|
17
18
|
*/
|
|
18
19
|
function calculateVisibleItems(searchItems, expand, columnNum, visibleItemCount, autoAdaptWidth, buttonGroupWidth, columnWidth) {
|
|
19
20
|
const visibleItems = searchItems.filter(item => item.visible);
|
|
20
|
-
const hasCustomWidth = searchItems.
|
|
21
|
+
const hasCustomWidth = searchItems.some(item => item.width !== undefined);
|
|
21
22
|
if (!expand) {
|
|
22
23
|
// 当有自定义宽度时,使用自适应计算
|
|
23
24
|
if (hasCustomWidth && autoAdaptWidth) {
|
|
@@ -27,10 +28,7 @@ function calculateVisibleItems(searchItems, expand, columnNum, visibleItemCount,
|
|
|
27
28
|
} else if (!hasCustomWidth) {
|
|
28
29
|
// 没有自定义宽度时,使用 columnNum(实际搜索项数量)
|
|
29
30
|
// 判断按钮组宽度是否大于列宽,如果是,则显示 实际搜索项数量+1
|
|
30
|
-
|
|
31
|
-
if (buttonGroupWidth !== undefined && columnWidth !== undefined && (buttonGroupWidth > columnWidth || buttonGroupWidth < columnWidth && columnNum + 1 === visibleItems.length)) {
|
|
32
|
-
displayCount = columnNum + 1;
|
|
33
|
-
}
|
|
31
|
+
const displayCount = (0, _shouldDisplayExtraItem.shouldDisplayExtraItem)(buttonGroupWidth, columnWidth, columnNum, visibleItems.length) ? columnNum + 1 : columnNum;
|
|
34
32
|
if (visibleItems.length >= displayCount) {
|
|
35
33
|
return visibleItems.slice(0, displayCount);
|
|
36
34
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { cleanSearchData } from "./cleanSearchData";
|
|
2
2
|
export { calculateVisibleItems } from "./calculateVisibleItems";
|
|
3
3
|
export { calculateButtonGroupAndColumnWidth } from "./calculateButtonGroupAndColumnWidth";
|
|
4
|
+
export { measureButtonGroupWidth } from "./measureButtonGroupWidth";
|
|
5
|
+
export { shouldDisplayExtraItem } from "./shouldDisplayExtraItem";
|
|
@@ -21,6 +21,20 @@ Object.defineProperty(exports, "cleanSearchData", {
|
|
|
21
21
|
return _cleanSearchData.cleanSearchData;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "measureButtonGroupWidth", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _measureButtonGroupWidth.measureButtonGroupWidth;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "shouldDisplayExtraItem", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _shouldDisplayExtraItem.shouldDisplayExtraItem;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
24
36
|
var _cleanSearchData = require("./cleanSearchData");
|
|
25
37
|
var _calculateVisibleItems = require("./calculateVisibleItems");
|
|
26
|
-
var _calculateButtonGroupAndColumnWidth = require("./calculateButtonGroupAndColumnWidth");
|
|
38
|
+
var _calculateButtonGroupAndColumnWidth = require("./calculateButtonGroupAndColumnWidth");
|
|
39
|
+
var _measureButtonGroupWidth = require("./measureButtonGroupWidth");
|
|
40
|
+
var _shouldDisplayExtraItem = require("./shouldDisplayExtraItem");
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.measureButtonGroupWidth = measureButtonGroupWidth;
|
|
7
|
+
/**
|
|
8
|
+
* 计算按钮组的实际宽度(所有子元素宽度总和 + 子元素间距)
|
|
9
|
+
* @param buttonGroupEl 按钮组元素
|
|
10
|
+
* @returns 按钮组宽度;无子元素时返回 undefined
|
|
11
|
+
*/
|
|
12
|
+
function measureButtonGroupWidth(buttonGroupEl) {
|
|
13
|
+
if (!buttonGroupEl) return undefined;
|
|
14
|
+
const buttonChildren = Array.from(buttonGroupEl.children);
|
|
15
|
+
if (buttonChildren.length === 0) return undefined;
|
|
16
|
+
let totalWidth = 0;
|
|
17
|
+
buttonChildren.forEach(child => {
|
|
18
|
+
totalWidth += child.offsetWidth;
|
|
19
|
+
});
|
|
20
|
+
// 加上子元素之间的间距
|
|
21
|
+
const childGap = 5;
|
|
22
|
+
totalWidth += (buttonChildren.length - 1) * childGap;
|
|
23
|
+
return totalWidth;
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断收起状态下是否应多显示一个搜索项
|
|
3
|
+
*
|
|
4
|
+
* 规则:按钮组宽度大于列宽(按钮组独占更宽空间,首行有富余);
|
|
5
|
+
* 或按钮组宽度小于列宽且可见项刚好比列数多 1(此时收起只会藏起 1 项,不如直接放下)。
|
|
6
|
+
* @param buttonGroupWidth 按钮组宽度
|
|
7
|
+
* @param columnWidth 列宽
|
|
8
|
+
* @param columnNum 搜索项列数(不含按钮组)
|
|
9
|
+
* @param visibleCount 可见搜索项总数
|
|
10
|
+
*/
|
|
11
|
+
export declare function shouldDisplayExtraItem(buttonGroupWidth: number | undefined, columnWidth: number | undefined, columnNum: number, visibleCount: number): boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.shouldDisplayExtraItem = shouldDisplayExtraItem;
|
|
7
|
+
/**
|
|
8
|
+
* 判断收起状态下是否应多显示一个搜索项
|
|
9
|
+
*
|
|
10
|
+
* 规则:按钮组宽度大于列宽(按钮组独占更宽空间,首行有富余);
|
|
11
|
+
* 或按钮组宽度小于列宽且可见项刚好比列数多 1(此时收起只会藏起 1 项,不如直接放下)。
|
|
12
|
+
* @param buttonGroupWidth 按钮组宽度
|
|
13
|
+
* @param columnWidth 列宽
|
|
14
|
+
* @param columnNum 搜索项列数(不含按钮组)
|
|
15
|
+
* @param visibleCount 可见搜索项总数
|
|
16
|
+
*/
|
|
17
|
+
function shouldDisplayExtraItem(buttonGroupWidth, columnWidth, columnNum, visibleCount) {
|
|
18
|
+
return buttonGroupWidth !== undefined && columnWidth !== undefined && (buttonGroupWidth > columnWidth || buttonGroupWidth < columnWidth && columnNum + 1 === visibleCount);
|
|
19
|
+
}
|
|
@@ -26,5 +26,9 @@ export type SearchModePropsMap = {
|
|
|
26
26
|
WithFilter: React.ComponentProps<SearchFC["WithFilter"]>;
|
|
27
27
|
WithMore: React.ComponentProps<SearchFC["WithMore"]>;
|
|
28
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* 基础 Search 组件
|
|
31
|
+
* - 标准的搜索表单布局,自适应列数与展开/收起
|
|
32
|
+
*/
|
|
29
33
|
declare const Search: SearchFC;
|
|
30
34
|
export default Search;
|
|
@@ -4,137 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
8
|
-
var _FormItem = _interopRequireDefault(require("../FormItem"));
|
|
9
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
-
var _indexModule = _interopRequireDefault(require("./index.module.scss"));
|
|
12
|
-
var _hooks = require("./_hooks");
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
8
|
var _SearchCard = _interopRequireDefault(require("./SearchCard"));
|
|
14
9
|
var _SearchAdvanced = _interopRequireDefault(require("./SearchAdvanced"));
|
|
15
10
|
var _SearchCollapsible = _interopRequireDefault(require("./SearchCollapsible"));
|
|
16
11
|
var _SearchWithFilter = _interopRequireDefault(require("./SearchWithFilter"));
|
|
17
12
|
var _SearchWithMore = _interopRequireDefault(require("./SearchWithMore"));
|
|
18
|
-
var
|
|
19
|
-
var _SearchButtons = require("./_components/SearchButtons");
|
|
20
|
-
var _ExpandButton = require("./_components/ExpandButton");
|
|
13
|
+
var _SearchBase = _interopRequireDefault(require("./_components/SearchBase"));
|
|
21
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
23
|
-
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 && Object.prototype.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; }
|
|
24
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
16
|
// 导出所有可用的 Search 模式键名
|
|
26
17
|
|
|
27
18
|
// 导出 Search 模式映射类型
|
|
28
19
|
|
|
20
|
+
/**
|
|
21
|
+
* 基础 Search 组件
|
|
22
|
+
* - 标准的搜索表单布局,自适应列数与展开/收起
|
|
23
|
+
*/
|
|
29
24
|
const Search = props => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
moreSearchItems = [],
|
|
33
|
-
className,
|
|
34
|
-
onSearch,
|
|
35
|
-
onReset,
|
|
36
|
-
externalForm,
|
|
37
|
-
hasPermi,
|
|
38
|
-
columnNum = 4,
|
|
39
|
-
beforeButtonGroup,
|
|
40
|
-
affterButtonGroup,
|
|
41
|
-
searchData,
|
|
42
|
-
minLabelWidth,
|
|
43
|
-
defaultExpanded = false,
|
|
44
|
-
onExpandChange,
|
|
45
|
-
autoAdaptWidth = true,
|
|
46
|
-
baseWidth,
|
|
47
|
-
onValuesChange,
|
|
48
|
-
searchDisabled = false,
|
|
49
|
-
showAllSearchItems = false,
|
|
50
|
-
searchText,
|
|
51
|
-
resetText,
|
|
52
|
-
columnOffsetWidth = 0
|
|
53
|
-
} = props;
|
|
54
|
-
const [form] = _antd.Form.useForm(externalForm);
|
|
55
|
-
const {
|
|
56
|
-
containerRef,
|
|
57
|
-
buttonGroupRef,
|
|
58
|
-
cls,
|
|
59
|
-
getLabelWidth,
|
|
60
|
-
currentSearchItems,
|
|
61
|
-
totalColumnNum,
|
|
62
|
-
expand,
|
|
63
|
-
toggleExpand,
|
|
64
|
-
showExpandButton,
|
|
65
|
-
onSearchClick,
|
|
66
|
-
onResetClick,
|
|
67
|
-
shouldRender,
|
|
68
|
-
permitted
|
|
69
|
-
} = (0, _hooks.useSearchCommon)({
|
|
70
|
-
form,
|
|
71
|
-
searchItems,
|
|
72
|
-
moreSearchItems,
|
|
73
|
-
searchData,
|
|
74
|
-
hasPermi,
|
|
75
|
-
beforeButtonGroup,
|
|
76
|
-
affterButtonGroup,
|
|
77
|
-
columnNum,
|
|
78
|
-
autoAdaptWidth,
|
|
79
|
-
defaultExpanded,
|
|
80
|
-
onExpandChange,
|
|
81
|
-
showAllSearchItems,
|
|
82
|
-
minLabelWidth,
|
|
83
|
-
baseWidth,
|
|
84
|
-
onSearch,
|
|
85
|
-
onReset,
|
|
86
|
-
columnOffsetWidth
|
|
87
|
-
});
|
|
88
|
-
if (!shouldRender) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
92
|
-
ref: containerRef,
|
|
93
|
-
className: (0, _classnames.default)(_indexModule.default.Search, className),
|
|
94
|
-
style: {
|
|
95
|
-
"--column-number": totalColumnNum,
|
|
96
|
-
"--column-offset-width": `${columnOffsetWidth}px`
|
|
97
|
-
},
|
|
98
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
99
|
-
className: (0, _classnames.default)(_indexModule.default.searchOption, _indexModule.default[expand.toString()]),
|
|
100
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_antd.Form, {
|
|
101
|
-
form: form,
|
|
102
|
-
className: (0, _classnames.default)(_indexModule.default.option, cls),
|
|
103
|
-
onValuesChange: onValuesChange,
|
|
104
|
-
children: [permitted && currentSearchItems?.map((item, idx) => {
|
|
105
|
-
const visibleCurrentItems = currentSearchItems.filter(i => i.visible !== false);
|
|
106
|
-
const columnIndex = idx % totalColumnNum;
|
|
107
|
-
const sameColumnItems = visibleCurrentItems.filter((_, _idx) => _idx % totalColumnNum === columnIndex);
|
|
108
|
-
return /*#__PURE__*/(0, _react.createElement)(_FormItem.default, {
|
|
109
|
-
...item,
|
|
110
|
-
key: item.name,
|
|
111
|
-
className: (0, _classnames.default)(_indexModule.default.item, item.className, {
|
|
112
|
-
[_indexModule.default.unFill]: item.width !== undefined
|
|
113
|
-
}),
|
|
114
|
-
labelWidth: item.width !== undefined ? undefined : getLabelWidth(sameColumnItems, undefined, minLabelWidth)
|
|
115
|
-
});
|
|
116
|
-
}), (beforeButtonGroup?.length || affterButtonGroup?.length || permitted) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ButtonGroup.ButtonGroup, {
|
|
117
|
-
beforeButtonGroup: beforeButtonGroup,
|
|
118
|
-
affterButtonGroup: affterButtonGroup,
|
|
119
|
-
expandButton: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ExpandButton.ExpandButton, {
|
|
120
|
-
expand: expand,
|
|
121
|
-
toggleExpand: toggleExpand,
|
|
122
|
-
advancedFilters: false,
|
|
123
|
-
showExpandButton: showExpandButton,
|
|
124
|
-
showAllSearchItems: showAllSearchItems || !!moreSearchItems?.length
|
|
125
|
-
}),
|
|
126
|
-
permitted: permitted,
|
|
127
|
-
ref: buttonGroupRef,
|
|
128
|
-
children: currentSearchItems.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(_SearchButtons.SearchButtons, {
|
|
129
|
-
onSearch: onSearchClick,
|
|
130
|
-
onReset: onResetClick,
|
|
131
|
-
searchDisabled: searchDisabled,
|
|
132
|
-
searchText: searchText,
|
|
133
|
-
resetText: resetText
|
|
134
|
-
})
|
|
135
|
-
})]
|
|
136
|
-
})
|
|
137
|
-
})
|
|
25
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_SearchBase.default, {
|
|
26
|
+
...props
|
|
138
27
|
});
|
|
139
28
|
};
|
|
140
29
|
Search.Card = _SearchCard.default;
|
|
@@ -19,6 +19,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
19
19
|
const MEASURE_ALIGN_FONT_SIZE = 14;
|
|
20
20
|
// Canvas measureText 仅返回 advance width,较 DOM 实际渲染偏窄约 1px,补 2px 缓冲避免最宽行被挤压
|
|
21
21
|
const MEASURE_ALIGN_BUFFER_PX = 2;
|
|
22
|
+
// 单元格左右内边距合计(--td-padding: 4px 8px),用于把列宽抬到能放下定宽内容块
|
|
23
|
+
const MEASURE_ALIGN_CELL_PADDING_PX = 16;
|
|
22
24
|
|
|
23
25
|
// 计算 measureAlign 列的定宽(取本列所有行展示文本的最大像素宽)
|
|
24
26
|
const getMeasureAlignWidth = (column, dataSource) => {
|
|
@@ -109,6 +111,15 @@ const useTableColumns = params => {
|
|
|
109
111
|
}, 0) ?? 0 : 0;
|
|
110
112
|
item.width = Math.max(titleWidth, dataIndexWidth) + 32;
|
|
111
113
|
}
|
|
114
|
+
|
|
115
|
+
// measureAlign 列:列宽须容得下最宽行的定宽内容块 + 单元格左右内边距,
|
|
116
|
+
// 否则出现超长值(如 +3357.52%)时内容会被列宽截断;声明的 width 只作下限。
|
|
117
|
+
if (item.measureAlign && typeof item.width === "number") {
|
|
118
|
+
const measured = getMeasureAlignWidth(item, dataSource);
|
|
119
|
+
if (measured > 0) {
|
|
120
|
+
item.width = Math.max(item.width, measured + MEASURE_ALIGN_CELL_PADDING_PX);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
112
123
|
return item;
|
|
113
124
|
})?.map(item => {
|
|
114
125
|
return {
|
package/package.json
CHANGED
|
@@ -46,6 +46,8 @@ export interface ItemContainerProps extends FormItemProps {
|
|
|
46
46
|
labelBreak?: boolean;
|
|
47
47
|
hideAdditiona?: boolean;
|
|
48
48
|
hideLabel?: boolean;
|
|
49
|
+
/** 显隐开关,由 FormItem 消费;在此解构剥离,避免透传到 DOM */
|
|
50
|
+
visible?: boolean;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
const ItemContainer: React.FC<ItemContainerProps> = (props) => {
|
|
@@ -84,6 +86,7 @@ const ItemContainer: React.FC<ItemContainerProps> = (props) => {
|
|
|
84
86
|
labelBreak = false,
|
|
85
87
|
hideAdditiona = false,
|
|
86
88
|
hideLabel = false,
|
|
89
|
+
visible: _visible,
|
|
87
90
|
...formItemProps
|
|
88
91
|
} = props;
|
|
89
92
|
const { icon = "material-symbols:help", iconClassName, ...tipsConfig } = tips;
|
|
@@ -198,15 +201,9 @@ const ItemContainer: React.FC<ItemContainerProps> = (props) => {
|
|
|
198
201
|
return null;
|
|
199
202
|
}
|
|
200
203
|
|
|
201
|
-
// 页面层 FormItemProps 的展示控制属性(如 visible)不属于 antd Form.Item,
|
|
202
|
-
// 剥离后再透传,避免被 antd 转发到 DOM 触发 React 非法属性警告。
|
|
203
|
-
const restFormItemProps = Object.fromEntries(
|
|
204
|
-
Object.entries(formItemProps).filter(([key]) => key !== "visible")
|
|
205
|
-
);
|
|
206
|
-
|
|
207
204
|
return (
|
|
208
205
|
<Form.Item
|
|
209
|
-
{...
|
|
206
|
+
{...formItemProps}
|
|
210
207
|
name={name}
|
|
211
208
|
rules={[
|
|
212
209
|
{
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { FormInstance } from "antd";
|
|
3
|
-
import Form from "
|
|
3
|
+
import Form from "../../../../Form";
|
|
4
4
|
import { FilterFilled } from "@ant-design/icons";
|
|
5
|
-
import { FormItemProps } from "
|
|
6
|
-
import { DrawerFormProps } from "
|
|
7
|
-
import Icon from "
|
|
8
|
-
import type useLabelWidth from "
|
|
9
|
-
import styles from "
|
|
5
|
+
import { FormItemProps } from "../../../../FormItem";
|
|
6
|
+
import { DrawerFormProps } from "../../../../Form/DrawerForm";
|
|
7
|
+
import Icon from "../../../../Icon";
|
|
8
|
+
import type useLabelWidth from "../../../../../hooks/useLabelWidth";
|
|
9
|
+
import styles from "../../../index.module.scss";
|
|
10
10
|
|
|
11
11
|
interface AdvancedFiltersDrawerProps {
|
|
12
12
|
expand: boolean;
|