@creekjs/web-components 1.0.2 → 1.0.3
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/.fatherrc.ts +1 -5
- package/.turbo/turbo-father$colon$build.log +5 -0
- package/.turbo/turbo-father$colon$dev.log +33 -0
- package/dist/creek-config-provider/CreekConfigContext.js +31 -2
- package/dist/creek-config-provider/CreekConfigContext.js.map +7 -0
- package/dist/creek-config-provider/index.js +35 -13
- package/dist/creek-config-provider/index.js.map +7 -0
- package/dist/creek-hooks/index.d.ts +1 -0
- package/dist/creek-hooks/index.js +26 -1
- package/dist/creek-hooks/index.js.map +7 -0
- package/dist/creek-hooks/useApp/DrawerHelper.d.ts +9 -0
- package/dist/creek-hooks/useApp/DrawerHelper.js +62 -0
- package/dist/creek-hooks/useApp/DrawerHelper.js.map +7 -0
- package/dist/creek-hooks/useApp/ModalHelper.d.ts +9 -0
- package/dist/creek-hooks/useApp/ModalHelper.js +62 -0
- package/dist/creek-hooks/useApp/ModalHelper.js.map +7 -0
- package/dist/creek-hooks/useApp/index.d.ts +25 -0
- package/dist/creek-hooks/useApp/index.js +118 -0
- package/dist/creek-hooks/useApp/index.js.map +7 -0
- package/dist/creek-hooks/useApp/types.d.ts +26 -0
- package/dist/creek-hooks/useApp/types.js +18 -0
- package/dist/creek-hooks/useApp/types.js.map +7 -0
- package/dist/creek-hooks/useViewportHeight.js +99 -97
- package/dist/creek-hooks/useViewportHeight.js.map +7 -0
- package/dist/creek-icon/index.js +53 -31
- package/dist/creek-icon/index.js.map +7 -0
- package/dist/creek-keep-alive/index.js +36 -18
- package/dist/creek-keep-alive/index.js.map +7 -0
- package/dist/creek-layout/CollapseButton.js +69 -47
- package/dist/creek-layout/CollapseButton.js.map +7 -0
- package/dist/creek-layout/Exception/NotFound.js +42 -13
- package/dist/creek-layout/Exception/NotFound.js.map +7 -0
- package/dist/creek-layout/Exception/NotFoundPage.js +30 -5
- package/dist/creek-layout/Exception/NotFoundPage.js.map +7 -0
- package/dist/creek-layout/Exception/index.js +37 -8
- package/dist/creek-layout/Exception/index.js.map +7 -0
- package/dist/creek-layout/HeaderContent/FullScreen.js +45 -39
- package/dist/creek-layout/HeaderContent/FullScreen.js.map +7 -0
- package/dist/creek-layout/HeaderContent/UserInfo.js +75 -53
- package/dist/creek-layout/HeaderContent/UserInfo.js.map +7 -0
- package/dist/creek-layout/HeaderContent/index.js +48 -28
- package/dist/creek-layout/HeaderContent/index.js.map +7 -0
- package/dist/creek-layout/index.js +117 -81
- package/dist/creek-layout/index.js.map +7 -0
- package/dist/creek-loading/index.js +55 -48
- package/dist/creek-loading/index.js.map +7 -0
- package/dist/creek-table/SearchTable.js +107 -116
- package/dist/creek-table/SearchTable.js.map +7 -0
- package/dist/creek-table/TableOptionRender.js +69 -60
- package/dist/creek-table/TableOptionRender.js.map +7 -0
- package/dist/creek-table/TableViewContent.js +59 -40
- package/dist/creek-table/TableViewContent.js.map +7 -0
- package/dist/creek-table/hooks/index.d.ts +1 -1
- package/dist/creek-table/hooks/index.js +28 -3
- package/dist/creek-table/hooks/index.js.map +7 -0
- package/dist/creek-table/hooks/useAdaptiveToolBar.js +48 -36
- package/dist/creek-table/hooks/useAdaptiveToolBar.js.map +7 -0
- package/dist/creek-table/hooks/useAutoWidthColumns.d.ts +6 -0
- package/dist/creek-table/hooks/useAutoWidthColumns.js +187 -0
- package/dist/creek-table/hooks/useAutoWidthColumns.js.map +7 -0
- package/dist/creek-table/hooks/useElementDistance.js +51 -39
- package/dist/creek-table/hooks/useElementDistance.js.map +7 -0
- package/dist/creek-table/index.js +35 -25
- package/dist/creek-table/index.js.map +7 -0
- package/dist/creek-table/toolBarRender.js +55 -33
- package/dist/creek-table/toolBarRender.js.map +7 -0
- package/dist/creek-table/type.d.ts +1 -1
- package/dist/creek-table/type.js +18 -1
- package/dist/creek-table/type.js.map +7 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +34 -7
- package/dist/index.js.map +7 -0
- package/package.json +2 -2
- package/src/creek-hooks/index.ts +2 -0
- package/src/creek-hooks/useApp/DrawerHelper.tsx +43 -0
- package/src/creek-hooks/useApp/ModalHelper.tsx +43 -0
- package/src/creek-hooks/useApp/index.tsx +119 -0
- package/src/creek-hooks/useApp/types.ts +25 -0
- package/src/creek-hooks/useViewportHeight.tsx +34 -5
- package/src/creek-table/SearchTable.tsx +16 -37
- package/src/creek-table/TableViewContent.tsx +21 -14
- package/src/creek-table/hooks/index.ts +1 -1
- package/src/creek-table/hooks/useAutoWidthColumns.tsx +212 -0
- package/src/creek-table/index.tsx +1 -5
- package/src/creek-table/type.ts +1 -1
- package/src/index.tsx +2 -2
- package/dist/bg-center/index.d.ts +0 -5
- package/dist/bg-center/index.d.ts.map +0 -1
- package/dist/bg-center/index.js +0 -28
- package/dist/creek-config-provider/CreekConfigContext.d.ts.map +0 -1
- package/dist/creek-config-provider/index.d.ts.map +0 -1
- package/dist/creek-hooks/index.d.ts.map +0 -1
- package/dist/creek-hooks/useViewportHeight.d.ts.map +0 -1
- package/dist/creek-icon/index.d.ts.map +0 -1
- package/dist/creek-keep-alive/index.d.ts.map +0 -1
- package/dist/creek-layout/CollapseButton.d.ts.map +0 -1
- package/dist/creek-layout/Exception/NotFound.d.ts.map +0 -1
- package/dist/creek-layout/Exception/NotFoundPage.d.ts.map +0 -1
- package/dist/creek-layout/Exception/index.d.ts.map +0 -1
- package/dist/creek-layout/HeaderContent/FullScreen.d.ts.map +0 -1
- package/dist/creek-layout/HeaderContent/UserInfo.d.ts.map +0 -1
- package/dist/creek-layout/HeaderContent/index.d.ts.map +0 -1
- package/dist/creek-layout/index.d.ts.map +0 -1
- package/dist/creek-loading/index.d.ts.map +0 -1
- package/dist/creek-search/CreekSearch.d.ts +0 -7
- package/dist/creek-search/CreekSearch.d.ts.map +0 -1
- package/dist/creek-search/CreekSearch.js +0 -51
- package/dist/creek-search/CreekSearchContext.d.ts +0 -54
- package/dist/creek-search/CreekSearchContext.d.ts.map +0 -1
- package/dist/creek-search/CreekSearchContext.js +0 -546
- package/dist/creek-search/CreekSearchFilterDisplay.d.ts +0 -5
- package/dist/creek-search/CreekSearchFilterDisplay.d.ts.map +0 -1
- package/dist/creek-search/CreekSearchFilterDisplay.js +0 -97
- package/dist/creek-search/CreekSearchInput.d.ts +0 -4
- package/dist/creek-search/CreekSearchInput.d.ts.map +0 -1
- package/dist/creek-search/CreekSearchInput.js +0 -96
- package/dist/creek-search/CreekSearchValueSelector.d.ts +0 -5
- package/dist/creek-search/CreekSearchValueSelector.d.ts.map +0 -1
- package/dist/creek-search/CreekSearchValueSelector.js +0 -422
- package/dist/creek-search/index.d.ts +0 -5
- package/dist/creek-search/index.d.ts.map +0 -1
- package/dist/creek-search/index.js +0 -5
- package/dist/creek-search/type.d.ts +0 -8
- package/dist/creek-search/type.d.ts.map +0 -1
- package/dist/creek-search/type.js +0 -1
- package/dist/creek-table/SearchTable.d.ts.map +0 -1
- package/dist/creek-table/TableOptionRender.d.ts.map +0 -1
- package/dist/creek-table/TableViewContent.d.ts.map +0 -1
- package/dist/creek-table/hooks/index.d.ts.map +0 -1
- package/dist/creek-table/hooks/useAdaptiveToolBar.d.ts.map +0 -1
- package/dist/creek-table/hooks/useAutoAddFilterToColumns.d.ts +0 -12
- package/dist/creek-table/hooks/useAutoAddFilterToColumns.d.ts.map +0 -1
- package/dist/creek-table/hooks/useAutoAddFilterToColumns.js +0 -96
- package/dist/creek-table/hooks/useElementDistance.d.ts.map +0 -1
- package/dist/creek-table/index.d.ts.map +0 -1
- package/dist/creek-table/toolBarRender.d.ts.map +0 -1
- package/dist/creek-table/type.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/src/bg-center/index.tsx +0 -26
- package/src/creek-search/CreekSearch.tsx +0 -60
- package/src/creek-search/CreekSearchContext.tsx +0 -593
- package/src/creek-search/CreekSearchFilterDisplay.tsx +0 -84
- package/src/creek-search/CreekSearchInput.tsx +0 -75
- package/src/creek-search/CreekSearchValueSelector.tsx +0 -324
- package/src/creek-search/index.tsx +0 -5
- package/src/creek-search/type.ts +0 -9
- package/src/creek-table/hooks/useAutoAddFilterToColumns.tsx +0 -90
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { SearchOutlined } from '@ant-design/icons';
|
|
2
|
-
import { AutoComplete, Input, Popover } from 'antd';
|
|
3
|
-
import { createStyles } from 'antd-style';
|
|
4
|
-
import classNames from 'classnames';
|
|
5
|
-
|
|
6
|
-
import { useSearchContext } from './CreekSearchContext';
|
|
7
|
-
import { CreekSearchValueSelector } from './CreekSearchValueSelector';
|
|
8
|
-
|
|
9
|
-
const useStyles = createStyles(({ token, prefixCls }) => {
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
searchWrapper: {
|
|
13
|
-
width: 350,
|
|
14
|
-
position: 'relative',
|
|
15
|
-
},
|
|
16
|
-
autoCompleteContainer: {
|
|
17
|
-
width: '100%',
|
|
18
|
-
},
|
|
19
|
-
searchInput: {
|
|
20
|
-
[`& .${prefixCls}-input`]: { fontSize: token.fontSize },
|
|
21
|
-
[`& .${prefixCls}-input-prefix`]: { color: token.colorTextTertiary },
|
|
22
|
-
},
|
|
23
|
-
popoverContent: {
|
|
24
|
-
[`& .${prefixCls}-popover-inner`]: { padding: 0 },
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// 搜索输入框组件
|
|
30
|
-
const SearchInput = () => {
|
|
31
|
-
const { styles } = useStyles();
|
|
32
|
-
const { searchValue, filterOptions, inputRef, setSearchValue, handleSearch, handleSelectColumn } = useSearchContext();
|
|
33
|
-
|
|
34
|
-
// AutoComplete 选项
|
|
35
|
-
const autoCompleteOptions = filterOptions?.map((option) => ({
|
|
36
|
-
value: option.dataIndex,
|
|
37
|
-
label: option.title,
|
|
38
|
-
}));
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<AutoComplete ref={inputRef} className={styles.autoCompleteContainer} options={autoCompleteOptions} onSearch={setSearchValue} onSelect={handleSelectColumn} value={searchValue} allowClear>
|
|
42
|
-
<Input placeholder="添加筛选条件" prefix={<SearchOutlined />} onPressEnter={(e) => handleSearch((e.target as HTMLInputElement).value)} className={styles.searchInput} />
|
|
43
|
-
</AutoComplete>
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export type CreekSearchInputProps = {
|
|
48
|
-
className?: string;
|
|
49
|
-
};
|
|
50
|
-
// 主搜索输入组件
|
|
51
|
-
export const CreekSearchInput = (props: CreekSearchInputProps) => {
|
|
52
|
-
const { className } = props;
|
|
53
|
-
const { styles } = useStyles();
|
|
54
|
-
const { showValueSelector, cancelValueSelector } = useSearchContext();
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<div className={classNames(styles.searchWrapper, className)}>
|
|
58
|
-
<Popover
|
|
59
|
-
content={<CreekSearchValueSelector />}
|
|
60
|
-
trigger="click"
|
|
61
|
-
arrow={false}
|
|
62
|
-
open={showValueSelector}
|
|
63
|
-
onOpenChange={(visible) => {
|
|
64
|
-
if (!visible) {
|
|
65
|
-
cancelValueSelector();
|
|
66
|
-
}
|
|
67
|
-
}}
|
|
68
|
-
overlayClassName={styles.popoverContent}
|
|
69
|
-
placement="bottomLeft"
|
|
70
|
-
>
|
|
71
|
-
<SearchInput />
|
|
72
|
-
</Popover>
|
|
73
|
-
</div>
|
|
74
|
-
);
|
|
75
|
-
};
|
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
import { ParamsType } from '@ant-design/pro-components';
|
|
2
|
-
import { Button, Checkbox, DatePicker, Input, InputNumber, Radio, Select, Space, Switch, TimePicker } from 'antd';
|
|
3
|
-
import { createStyles } from 'antd-style';
|
|
4
|
-
import _ from 'lodash';
|
|
5
|
-
import { useEffect, useMemo } from 'react';
|
|
6
|
-
|
|
7
|
-
import { useSearchContext } from './CreekSearchContext';
|
|
8
|
-
|
|
9
|
-
const { RangePicker } = DatePicker;
|
|
10
|
-
const { RangePicker: TimeRangePicker } = TimePicker;
|
|
11
|
-
|
|
12
|
-
// 组件渲染器接口
|
|
13
|
-
interface ComponentRendererProps {
|
|
14
|
-
column: any;
|
|
15
|
-
value: any;
|
|
16
|
-
onChange: (value: any) => void;
|
|
17
|
-
className?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// 各类型组件渲染器
|
|
21
|
-
const ComponentRenderer = ({ column, value, onChange, className }: ComponentRendererProps) => {
|
|
22
|
-
const { getValueTypeConfig, getColumnOptions, hasOptions } = useSearchContext();
|
|
23
|
-
|
|
24
|
-
const { valueType, fieldProps = {} } = column;
|
|
25
|
-
|
|
26
|
-
const config = getValueTypeConfig(valueType);
|
|
27
|
-
const baseStyle = { width: '100%' };
|
|
28
|
-
const mergedProps = { ...fieldProps, style: { ...baseStyle, ...fieldProps.style } };
|
|
29
|
-
|
|
30
|
-
// 如果有选项配置,优先使用选项组件
|
|
31
|
-
if (hasOptions(column)) {
|
|
32
|
-
const options = getColumnOptions(column);
|
|
33
|
-
|
|
34
|
-
switch (config.componentType) {
|
|
35
|
-
case 'radio':
|
|
36
|
-
const radioOptions = options.map((option) => ({
|
|
37
|
-
...option,
|
|
38
|
-
}));
|
|
39
|
-
|
|
40
|
-
return <Radio.Group {...mergedProps} className={className} value={value} onChange={(e) => onChange(e.target.value)} options={radioOptions} />;
|
|
41
|
-
|
|
42
|
-
case 'checkbox':
|
|
43
|
-
const currentValue = value || [];
|
|
44
|
-
const allValues = options.map((opt) => opt.value);
|
|
45
|
-
const checkAll = allValues.length === currentValue.length && allValues.length > 0;
|
|
46
|
-
const indeterminate = currentValue.length > 0 && currentValue.length < allValues.length;
|
|
47
|
-
|
|
48
|
-
const handleCheckboxChange = (checkedValues: any[]) => {
|
|
49
|
-
onChange(checkedValues);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const onCheckAllChange = (e: any) => {
|
|
53
|
-
onChange(e.target.checked ? allValues : []);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<div className={className}>
|
|
58
|
-
<Checkbox indeterminate={indeterminate} onChange={onCheckAllChange} checked={checkAll} style={{ marginBottom: 4 }}>
|
|
59
|
-
全部
|
|
60
|
-
</Checkbox>
|
|
61
|
-
<Checkbox.Group {...mergedProps} value={currentValue} onChange={handleCheckboxChange} options={options} />
|
|
62
|
-
</div>
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
case 'select':
|
|
66
|
-
default:
|
|
67
|
-
return <Select {...mergedProps} placeholder="请选择" value={value} onChange={onChange} options={options} showSearch allowClear />;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 根据组件类型渲染对应组件
|
|
72
|
-
switch (config.componentType) {
|
|
73
|
-
case 'input':
|
|
74
|
-
return <Input {...mergedProps} placeholder={fieldProps.placeholder || '请输入值'} value={value} onChange={(e) => onChange(e.target.value)} />;
|
|
75
|
-
|
|
76
|
-
case 'number':
|
|
77
|
-
return <InputNumber {...mergedProps} placeholder={fieldProps.placeholder || '请输入数字'} value={value} onChange={onChange} />;
|
|
78
|
-
|
|
79
|
-
case 'select':
|
|
80
|
-
// 处理switch类型的特殊情况
|
|
81
|
-
if (valueType === 'switch') {
|
|
82
|
-
return <Select {...mergedProps} placeholder="请选择" value={value} onChange={onChange} allowClear />;
|
|
83
|
-
}
|
|
84
|
-
return <Select {...mergedProps} placeholder="请选择" value={value} onChange={onChange} allowClear />;
|
|
85
|
-
|
|
86
|
-
case 'switch':
|
|
87
|
-
return <Switch {...mergedProps} checked={value} onChange={onChange} />;
|
|
88
|
-
|
|
89
|
-
case 'date':
|
|
90
|
-
const dateProps = {
|
|
91
|
-
...mergedProps,
|
|
92
|
-
placeholder: fieldProps.placeholder || '请选择日期',
|
|
93
|
-
value: value,
|
|
94
|
-
onChange: onChange,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// 根据具体的日期类型渲染不同的组件
|
|
98
|
-
switch (valueType) {
|
|
99
|
-
case 'dateTime':
|
|
100
|
-
return <DatePicker {...dateProps} showTime />;
|
|
101
|
-
case 'dateMonth':
|
|
102
|
-
return <DatePicker {...dateProps} picker="month" />;
|
|
103
|
-
case 'dateWeek':
|
|
104
|
-
return <DatePicker {...dateProps} picker="week" />;
|
|
105
|
-
case 'dateQuarter':
|
|
106
|
-
return <DatePicker {...dateProps} picker="quarter" />;
|
|
107
|
-
case 'dateYear':
|
|
108
|
-
return <DatePicker {...dateProps} picker="year" />;
|
|
109
|
-
case 'date':
|
|
110
|
-
default:
|
|
111
|
-
return <DatePicker {...dateProps} />;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
case 'dateRange':
|
|
115
|
-
const rangeProps = {
|
|
116
|
-
...mergedProps,
|
|
117
|
-
placeholder: fieldProps.placeholder || ['开始日期', '结束日期'],
|
|
118
|
-
value: value,
|
|
119
|
-
onChange: onChange,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// 根据具体的日期范围类型渲染不同的组件
|
|
123
|
-
switch (valueType) {
|
|
124
|
-
case 'dateTimeRange':
|
|
125
|
-
return <RangePicker {...rangeProps} showTime />;
|
|
126
|
-
case 'dateMonthRange':
|
|
127
|
-
return <RangePicker {...rangeProps} picker="month" />;
|
|
128
|
-
case 'dateWeekRange':
|
|
129
|
-
return <RangePicker {...rangeProps} picker="week" />;
|
|
130
|
-
case 'dateQuarterRange':
|
|
131
|
-
return <RangePicker {...rangeProps} picker="quarter" />;
|
|
132
|
-
case 'dateYearRange':
|
|
133
|
-
return <RangePicker {...rangeProps} picker="year" />;
|
|
134
|
-
case 'dateRange':
|
|
135
|
-
default:
|
|
136
|
-
return <RangePicker {...rangeProps} />;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
case 'time':
|
|
140
|
-
return <TimePicker {...mergedProps} placeholder={fieldProps.placeholder || '请选择时间'} value={value} onChange={onChange} />;
|
|
141
|
-
|
|
142
|
-
case 'timeRange':
|
|
143
|
-
return <TimeRangePicker {...mergedProps} placeholder={fieldProps.placeholder || ['开始时间', '结束时间']} value={value} onChange={onChange} />;
|
|
144
|
-
|
|
145
|
-
case 'radio':
|
|
146
|
-
const iswitch = valueType === 'switch';
|
|
147
|
-
const radioOptions = [
|
|
148
|
-
{ label: '开', value: true },
|
|
149
|
-
{ label: '关', value: false },
|
|
150
|
-
];
|
|
151
|
-
const _radioOptions = iswitch ? radioOptions : mergedProps.options;
|
|
152
|
-
|
|
153
|
-
// 如果valueType是switch,使用RadioButton样式
|
|
154
|
-
return <Radio.Group {...mergedProps} options={_radioOptions} className={className} value={value} onChange={(e) => onChange(e.target.value)} />;
|
|
155
|
-
|
|
156
|
-
case 'checkbox':
|
|
157
|
-
return <Checkbox.Group {...mergedProps} className={className} value={value} onChange={onChange} />;
|
|
158
|
-
|
|
159
|
-
default:
|
|
160
|
-
return <Input {...mergedProps} placeholder="请输入值" value={value} onChange={(e) => onChange(e.target.value)} />;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// 样式定义
|
|
165
|
-
const useStyles = createStyles(({ token, prefixCls }) => {
|
|
166
|
-
const selectedBgColor = '#F5F7F9';
|
|
167
|
-
|
|
168
|
-
// 公共选项样式
|
|
169
|
-
const optionBase = {
|
|
170
|
-
width: '100%',
|
|
171
|
-
padding: 8,
|
|
172
|
-
borderRadius: 2,
|
|
173
|
-
marginBottom: 4,
|
|
174
|
-
marginInlineEnd: 0,
|
|
175
|
-
'&:hover': { backgroundColor: selectedBgColor },
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
return {
|
|
179
|
-
valueSelectorContent: {
|
|
180
|
-
padding: 8,
|
|
181
|
-
borderBottom: `1px solid ${token.colorBorderSecondary}`,
|
|
182
|
-
|
|
183
|
-
// 复用公共样式
|
|
184
|
-
[`& .${prefixCls}-checkbox-wrapper, & .${prefixCls}-radio-wrapper`]: optionBase,
|
|
185
|
-
|
|
186
|
-
// checked 状态
|
|
187
|
-
[`& .${prefixCls}-checkbox-wrapper-checked, & .${prefixCls}-radio-wrapper-checked`]: {
|
|
188
|
-
backgroundColor: selectedBgColor,
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
valueSelectorActions: {
|
|
193
|
-
display: 'flex',
|
|
194
|
-
justifyContent: 'flex-end',
|
|
195
|
-
gap: token.marginXS,
|
|
196
|
-
padding: 8,
|
|
197
|
-
},
|
|
198
|
-
verticalStyle: {
|
|
199
|
-
display: 'flex',
|
|
200
|
-
flexDirection: 'column',
|
|
201
|
-
},
|
|
202
|
-
|
|
203
|
-
// 不同宽度样式
|
|
204
|
-
smallSelector: { width: 80 },
|
|
205
|
-
narrowSelector: { width: 150 },
|
|
206
|
-
mediumSelector: { width: 280 },
|
|
207
|
-
wideSelector: { width: 350 },
|
|
208
|
-
};
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
export type CreekSearchValueSelectorProps<T extends ParamsType, U extends ParamsType> = {
|
|
212
|
-
onConfirm?: () => void;
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
// 根据不同类型获取初始值
|
|
216
|
-
const getInitialValue = (componentType: string) => {
|
|
217
|
-
switch (componentType) {
|
|
218
|
-
case 'checkbox':
|
|
219
|
-
return [];
|
|
220
|
-
case 'switch':
|
|
221
|
-
return false;
|
|
222
|
-
case 'number':
|
|
223
|
-
return undefined; // InputNumber 使用 undefined 而不是 null
|
|
224
|
-
default:
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
// 值选择器组件
|
|
230
|
-
export const CreekSearchValueSelector = <T extends ParamsType, U extends ParamsType>(props: CreekSearchValueSelectorProps<T, U>) => {
|
|
231
|
-
const { styles } = useStyles();
|
|
232
|
-
const searchContext = useSearchContext();
|
|
233
|
-
|
|
234
|
-
const { selectedColumn, tempValue, setTempValue, confirmAddFilter, getValueTypeConfig, filters } = searchContext;
|
|
235
|
-
const { onConfirm } = props;
|
|
236
|
-
|
|
237
|
-
const config = getValueTypeConfig(selectedColumn?.valueType);
|
|
238
|
-
|
|
239
|
-
// 获取当前过滤器的值
|
|
240
|
-
const currentFilterValue = useMemo(() => {
|
|
241
|
-
const currentFilter = filters.find((item) => item.dataIndex === selectedColumn?.dataIndex);
|
|
242
|
-
return currentFilter?.value;
|
|
243
|
-
}, [filters, selectedColumn]);
|
|
244
|
-
|
|
245
|
-
// 计算实际显示的值
|
|
246
|
-
const actualValue = useMemo(() => {
|
|
247
|
-
// 如果 tempValue 已设置(不是 null 和 undefined),优先使用 tempValue
|
|
248
|
-
if (tempValue !== null && tempValue !== undefined) {
|
|
249
|
-
return tempValue;
|
|
250
|
-
}
|
|
251
|
-
// 否则使用当前过滤器的值,如果也没有则使用初始值
|
|
252
|
-
return currentFilterValue ?? getInitialValue(config.componentType);
|
|
253
|
-
}, [tempValue, currentFilterValue, selectedColumn?.valueType, config.componentType]);
|
|
254
|
-
|
|
255
|
-
// 当选择的列发生变化时,重置 tempValue 为当前过滤器的值
|
|
256
|
-
useEffect(() => {
|
|
257
|
-
if (selectedColumn) {
|
|
258
|
-
const currentFilter = filters.find((item) => item.dataIndex === selectedColumn.dataIndex);
|
|
259
|
-
if (currentFilter?.value !== undefined) {
|
|
260
|
-
setTempValue(currentFilter.value);
|
|
261
|
-
} else {
|
|
262
|
-
// 如果没有现有的过滤器值,设置为初始值
|
|
263
|
-
setTempValue(getInitialValue(config.componentType));
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}, [selectedColumn?.dataIndex]); // 只在 selectedColumn.dataIndex 变化时触发
|
|
267
|
-
|
|
268
|
-
// 根据组件类型获取合适的宽度
|
|
269
|
-
const getPopoverWidth = () => {
|
|
270
|
-
switch (config.componentType) {
|
|
271
|
-
case 'select':
|
|
272
|
-
case 'radio':
|
|
273
|
-
case 'checkbox':
|
|
274
|
-
case 'switch':
|
|
275
|
-
return styles.narrowSelector;
|
|
276
|
-
case 'number':
|
|
277
|
-
return styles.mediumSelector;
|
|
278
|
-
case 'date':
|
|
279
|
-
case 'dateRange':
|
|
280
|
-
case 'time':
|
|
281
|
-
case 'timeRange':
|
|
282
|
-
default:
|
|
283
|
-
return styles.wideSelector;
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
// 重置值的处理
|
|
288
|
-
const handleReset = () => {
|
|
289
|
-
const initialValue = getInitialValue(config.componentType);
|
|
290
|
-
setTempValue(initialValue);
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
// 处理值的变化
|
|
294
|
-
const handleValueChange = (value: any) => {
|
|
295
|
-
setTempValue(value);
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
return selectedColumn ? (
|
|
299
|
-
<div className={getPopoverWidth()}>
|
|
300
|
-
<div className={styles.valueSelectorContent}>
|
|
301
|
-
<ComponentRenderer column={selectedColumn} value={actualValue} onChange={handleValueChange} className={['radio', 'checkbox'].includes(config.componentType) ? styles.verticalStyle : ''} />
|
|
302
|
-
</div>
|
|
303
|
-
<div className={styles.valueSelectorActions}>
|
|
304
|
-
<Space size="small">
|
|
305
|
-
<Button size="small" onClick={handleReset}>
|
|
306
|
-
重置
|
|
307
|
-
</Button>
|
|
308
|
-
<Button
|
|
309
|
-
type="primary"
|
|
310
|
-
size="small"
|
|
311
|
-
onClick={() => {
|
|
312
|
-
confirmAddFilter();
|
|
313
|
-
if (_.isFunction(onConfirm)) {
|
|
314
|
-
onConfirm();
|
|
315
|
-
}
|
|
316
|
-
}}
|
|
317
|
-
>
|
|
318
|
-
确定
|
|
319
|
-
</Button>
|
|
320
|
-
</Space>
|
|
321
|
-
</div>
|
|
322
|
-
</div>
|
|
323
|
-
) : null;
|
|
324
|
-
};
|
package/src/creek-search/type.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { ParamsType, ProColumnType } from '@ant-design/pro-components';
|
|
2
|
-
import { useMemoizedFn, useSafeState } from 'ahooks';
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
import { CreekSearchValueSelector, useSearchContext } from '../../creek-search';
|
|
6
|
-
import { CreekTableProps } from '../type';
|
|
7
|
-
|
|
8
|
-
interface UseAutoAddFilterToColumnsProps<T extends ParamsType, U extends ParamsType, ValueType = 'text'> {
|
|
9
|
-
columns: CreekTableProps<T, U, ValueType>['columns'];
|
|
10
|
-
autoAddFilterForColumn?: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface UseAutoAddFilterToColumnsReturn<T extends ParamsType, U extends ParamsType, ValueType> {
|
|
14
|
-
columnsWithFilter: CreekTableProps<T, U, ValueType>['columns'];
|
|
15
|
-
getColumnKey: (column: ProColumnType<T, U>) => string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const useAutoAddFilterToColumns = <T extends ParamsType, U extends ParamsType, ValueType = 'text'>({
|
|
19
|
-
columns,
|
|
20
|
-
autoAddFilterForColumn,
|
|
21
|
-
}: UseAutoAddFilterToColumnsProps<T, U, ValueType>): UseAutoAddFilterToColumnsReturn<T, U, ValueType> => {
|
|
22
|
-
const { hasOptions, setSelectedColumn, filters, filterOptions } = useSearchContext();
|
|
23
|
-
|
|
24
|
-
// 管理每列的下拉框状态
|
|
25
|
-
const [filterOpenMap, setFilterOpenMap] = useSafeState<Record<string, boolean>>({});
|
|
26
|
-
|
|
27
|
-
// 获取列的唯一标识
|
|
28
|
-
const getColumnKey = useMemoizedFn((column: ProColumnType<T, U>) => {
|
|
29
|
-
return column.dataIndex as string;
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// 控制特定列的下拉框开关
|
|
33
|
-
const setColumnFilterOpen = useMemoizedFn((columnKey: string, open: boolean) => {
|
|
34
|
-
setFilterOpenMap((prev) => ({
|
|
35
|
-
...prev,
|
|
36
|
-
[columnKey]: open,
|
|
37
|
-
}));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// 关闭特定列的下拉框
|
|
41
|
-
const closeColumnFilter = useMemoizedFn((columnKey: string) => {
|
|
42
|
-
setFilterOpenMap((prev) => ({
|
|
43
|
-
...prev,
|
|
44
|
-
[columnKey]: false,
|
|
45
|
-
}));
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// 自动为列添加筛选功能
|
|
49
|
-
const autoAddFilterToColumns = useMemoizedFn((columns: CreekTableProps<T, U, ValueType>['columns'] = []) => {
|
|
50
|
-
return columns.map((column) => {
|
|
51
|
-
if (hasOptions(column) && filterOptions?.map(item => item.dataIndex).includes(column.dataIndex as string)) {
|
|
52
|
-
const newColumn = { ...column };
|
|
53
|
-
const columnKey = getColumnKey(newColumn as ProColumnType<T, U>);
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
...newColumn,
|
|
57
|
-
filters: newColumn?.filters || true,
|
|
58
|
-
onFilter: newColumn?.onFilter || false,
|
|
59
|
-
filtered: filters.map((item) => item.dataIndex).includes(columnKey),
|
|
60
|
-
filterDropdown: (
|
|
61
|
-
<CreekSearchValueSelector
|
|
62
|
-
onConfirm={() => {
|
|
63
|
-
// 点击确认时关闭当前列的下拉框
|
|
64
|
-
closeColumnFilter(columnKey);
|
|
65
|
-
}}
|
|
66
|
-
/>
|
|
67
|
-
),
|
|
68
|
-
filterDropdownProps: {
|
|
69
|
-
open: filterOpenMap[columnKey] || false,
|
|
70
|
-
onOpenChange: (open: boolean) => {
|
|
71
|
-
if (open) {
|
|
72
|
-
const selectedColumn = columns.find((item) => item.dataIndex === columnKey);
|
|
73
|
-
setSelectedColumn(selectedColumn);
|
|
74
|
-
}
|
|
75
|
-
setColumnFilterOpen(columnKey, open);
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return column;
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const columnsWithFilter = useMemo(() => (autoAddFilterForColumn ? autoAddFilterToColumns(columns) : columns), [columns, filters, autoAddFilterToColumns, filterOpenMap]);
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
columnsWithFilter,
|
|
88
|
-
getColumnKey,
|
|
89
|
-
};
|
|
90
|
-
};
|