@alicloud/console-components-search 0.2.20 → 0.2.21

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.
@@ -1,13 +1,13 @@
1
1
  开始构建微应用external依赖...
2
2
  BreezrPluginStyledComponentsIsolation The plugin will trying to use the package's name as isolation id of styled-components. This behavior usually occurred on dev mode. And if you were received this warning on publish mode then you should to set `options.styledComponentStyleSheetId` implicitly.
3
3
  ℹ Compiling Webpack
4
- ✔ Webpack: Compiled successfully in 13.20s
4
+ ✔ Webpack: Compiled successfully in 12.34s
5
5
  WARN asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
6
6
  This can impact web performance.
7
7
  Assets:
8
- main.js (2.5 MiB),entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
8
+ main.js (2.52 MiB),entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
9
9
  Entrypoints:
10
- main (2.5 MiB)
10
+ main (2.52 MiB)
11
11
  main.css
12
12
  main.js
13
13
  ,webpack performance recommendations:
@@ -1,26 +1,33 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["dataSource", "label"];
3
+ var _excluded = ["defaultValue", "dataSource", "label"];
4
4
  import React from 'react';
5
5
  import classNames from 'classnames';
6
6
  import { Icon, Select } from '@alicloud/console-components';
7
7
 
8
8
  var SearchConditionSelectPrefix = function SearchConditionSelectPrefix(props) {
9
- var _props$dataSource = props.dataSource,
9
+ var defaultValue = props.defaultValue,
10
+ _props$dataSource = props.dataSource,
10
11
  dataSource = _props$dataSource === void 0 ? [] : _props$dataSource,
11
12
  label = props.label,
12
13
  reset = _objectWithoutProperties(props, _excluded);
13
14
 
15
+ var noSelect = dataSource.length < 2;
14
16
  return /*#__PURE__*/React.createElement("div", {
15
17
  className: classNames('condition-item')
16
18
  }, /*#__PURE__*/React.createElement("span", {
17
19
  className: classNames('condition-item-txt')
18
- }, label), /*#__PURE__*/React.createElement(Icon, {
20
+ }, label), noSelect ? null : /*#__PURE__*/React.createElement(Icon, {
19
21
  type: "caret-down",
20
22
  size: "xxs"
21
23
  }), /*#__PURE__*/React.createElement(Select, _extends({
22
- className: classNames('condition-select'),
24
+ className: classNames('condition-select', {
25
+ 'rc-search-prefix-no-select': noSelect
26
+ }),
27
+ defaultValue: defaultValue,
23
28
  hasBorder: false,
29
+ disabled: noSelect,
30
+ autoHighlightFirstItem: false,
24
31
  dataSource: dataSource,
25
32
  itemRender: function itemRender(_ref) {
26
33
  var label = _ref.label,
@@ -28,9 +35,11 @@ var SearchConditionSelectPrefix = function SearchConditionSelectPrefix(props) {
28
35
  return /*#__PURE__*/React.createElement("span", {
29
36
  "data-value": value
30
37
  }, label);
31
- },
32
- autoWidth: true
33
- }, reset)));
38
+ }
39
+ }, reset, {
40
+ autoWidth: false,
41
+ popupClassName: "rc-search-prefix"
42
+ })));
34
43
  };
35
44
 
36
45
  export default SearchConditionSelectPrefix;
@@ -17,7 +17,7 @@ import { SearchWarp, MultiBtnWarp } from "../style";
17
17
  import SearchConditionSelectPrefix from "./InputPrefix";
18
18
  import { SEARCH_FILTER_FIELD, SEARCH_FILTER_VALUE_FIELD } from "../constants";
19
19
  import message from "../message";
20
- import { template } from 'lodash';
20
+ import { isPlainObject, template } from 'lodash';
21
21
  var AutoComplete = Select.AutoComplete;
22
22
  /**
23
23
  *
@@ -47,6 +47,20 @@ var normalizeOptions = function normalizeOptions(options) {
47
47
  });
48
48
  };
49
49
 
50
+ var normalizeSuggestion = function normalizeSuggestion(suggestion) {
51
+ var suggestionCopy = cloneDeep(suggestion);
52
+ suggestionCopy.forEach(function (s) {
53
+ if (s.children) {
54
+ s.children.forEach(function (child) {
55
+ if (isPlainObject(child)) {
56
+ child.dataIndex = s.value;
57
+ }
58
+ });
59
+ }
60
+ });
61
+ return suggestionCopy;
62
+ };
63
+
50
64
  var normalizeSelectDataSource = function normalizeSelectDataSource(title, list) {
51
65
  return [{
52
66
  label: title || '',
@@ -99,9 +113,11 @@ var highlightKeyword = function highlightKeyword(value, keywords) {
99
113
  };
100
114
 
101
115
  var ComplexSearch = function ComplexSearch(props) {
102
- var options = props.options,
116
+ var _props$options = props.options,
117
+ options = _props$options === void 0 ? [] : _props$options,
103
118
  fuzzy = props.fuzzy,
104
119
  defaultDataIndex = props.defaultDataIndex,
120
+ defaultSelectedDataIndex = props.defaultSelectedDataIndex,
105
121
  placeholder = props.placeholder,
106
122
  onSearch = props.onSearch,
107
123
  onSuggest = props.onSuggest,
@@ -110,7 +126,9 @@ var ComplexSearch = function ComplexSearch(props) {
110
126
  _props$prefix = props.prefix,
111
127
  prefix = _props$prefix === void 0 ? 'next-' : _props$prefix;
112
128
 
113
- var _useState = useState(null),
129
+ var _useState = useState(options.find(function (o) {
130
+ return o.dataIndex === defaultSelectedDataIndex;
131
+ })),
114
132
  _useState2 = _slicedToArray(_useState, 2),
115
133
  selectedFilterType = _useState2[0],
116
134
  setSelectedFilterType = _useState2[1];
@@ -121,6 +139,7 @@ var ComplexSearch = function ComplexSearch(props) {
121
139
  setFocused = _useState4[1];
122
140
 
123
141
  var autoRef = useRef(null);
142
+ var fuzzyAutoRef = useRef(null);
124
143
  var field = Field.useField();
125
144
  var init = field.init,
126
145
  getValue = field.getValue,
@@ -167,12 +186,12 @@ var ComplexSearch = function ComplexSearch(props) {
167
186
  */
168
187
 
169
188
 
170
- var handlerFilterTypeInput = function handlerFilterTypeInput(value, actionType, isFuzzy) {
189
+ var handlerFilterTypeInput = function handlerFilterTypeInput(value, actionType, isFuzzy, option) {
171
190
  var isFuzzySearch = isFuzzy && getValue(SEARCH_FILTER_FIELD); // 如果是模糊搜索,则直接处理
172
191
 
173
192
  if (isFuzzySearch) {
174
193
  if (actionType !== 'change') {
175
- handleSearch();
194
+ handleSearch(option.dataIndex);
176
195
  } else {
177
196
  onSuggest && onSuggest(value, defaultDataIndex || '');
178
197
  }
@@ -189,12 +208,17 @@ var ComplexSearch = function ComplexSearch(props) {
189
208
  reset();
190
209
  };
191
210
 
192
- var handleSearch = function handleSearch() {
211
+ var handleSearch = function handleSearch(dataIndex) {
193
212
  if (onSearch) {
194
- var value = getValue(SEARCH_FILTER_VALUE_FIELD);
213
+ var value = getValue(SEARCH_FILTER_VALUE_FIELD); // 如果是没有选择下拉
195
214
 
196
215
  if (defaultDataIndex && !selectedFilterType) {
197
216
  onSearch(getValue(SEARCH_FILTER_FIELD), defaultDataIndex, normalizeSearchOptions(defaultDataIndex, getValue(SEARCH_FILTER_FIELD), options));
217
+ } // 如果是用户没有指定 defaultDataIndex 但是设置了 fuzzy
218
+
219
+
220
+ if (fuzzy && !selectedFilterType) {
221
+ onSearch(getValue(SEARCH_FILTER_FIELD), dataIndex || '', normalizeSearchOptions(dataIndex || '', getValue(SEARCH_FILTER_FIELD), options));
198
222
  }
199
223
 
200
224
  if (selectedFilterType) {
@@ -212,6 +236,10 @@ var ComplexSearch = function ComplexSearch(props) {
212
236
  handleSearch();
213
237
  document.body.click();
214
238
  }
239
+
240
+ if (e.keyCode === 8 && !e.currentTarget.value) {
241
+ handlerFilterClear();
242
+ }
215
243
  };
216
244
 
217
245
  var renderMultipleSelectorItem = function renderMultipleSelectorItem(item) {
@@ -225,7 +253,7 @@ var ComplexSearch = function ComplexSearch(props) {
225
253
  };
226
254
 
227
255
  var renderSelectedFilter = function renderSelectedFilter() {
228
- var _selectedFilterType$t, _selectedFilterType$t2;
256
+ var _selectedFilterType$t, _selectedFilterType$t2, _selectedFilterType$t3;
229
257
 
230
258
  var type = selectedFilterType === null || selectedFilterType === void 0 ? void 0 : selectedFilterType.template;
231
259
  var searchValue = getValue(SEARCH_FILTER_VALUE_FIELD);
@@ -249,9 +277,12 @@ var ComplexSearch = function ComplexSearch(props) {
249
277
  switch (type) {
250
278
  case 'input':
251
279
  return /*#__PURE__*/React.createElement(AutoComplete, _extends({}, init(SEARCH_FILTER_VALUE_FIELD, {}), {
252
- className: classNames('main-input', 'multi')
280
+ className: classNames('main-input', 'multi'),
281
+ autoHighlightFirstItem: false
253
282
  }, props, {
254
- onKeyUp: handleKeyUp
283
+ autoWidth: true,
284
+ onKeyUp: handleKeyUp,
285
+ dataSource: selectedFilterType === null || selectedFilterType === void 0 ? void 0 : (_selectedFilterType$t3 = selectedFilterType.templateProps) === null || _selectedFilterType$t3 === void 0 ? void 0 : _selectedFilterType$t3.dataSource
255
286
  }));
256
287
 
257
288
  case 'select':
@@ -261,7 +292,9 @@ var ComplexSearch = function ComplexSearch(props) {
261
292
  props: {
262
293
  onChange: handleSearch
263
294
  }
264
- }), props, selectProps));
295
+ }), {
296
+ autoHighlightFirstItem: false
297
+ }, props, selectProps));
265
298
 
266
299
  case 'multiple':
267
300
  return /*#__PURE__*/React.createElement(Select, _extends({
@@ -270,6 +303,7 @@ var ComplexSearch = function ComplexSearch(props) {
270
303
  itemRender: renderMultipleSelectorItem,
271
304
  popupClassName: "xconsole-rcsearch-multi-pop",
272
305
  mode: "multiple",
306
+ autoHighlightFirstItem: false,
273
307
  maxTagCount: 0,
274
308
  menuProps: {
275
309
  footer: /*#__PURE__*/React.createElement(MultiBtnWarp, {
@@ -336,12 +370,14 @@ var ComplexSearch = function ComplexSearch(props) {
336
370
  }, !selectedFilterType ? /*#__PURE__*/React.createElement(AutoComplete, _extends({}, init(SEARCH_FILTER_FIELD, {
337
371
  props: {
338
372
  // @ts-ignore
339
- onChange: function onChange(value, actionType) {
340
- handlerFilterTypeInput(value, actionType, isFuzzy);
373
+ onChange: function onChange(value, actionType, option) {
374
+ handlerFilterTypeInput(value, actionType, !!isFuzzy, option);
341
375
  }
342
376
  }
343
377
  }), {
344
- // @ts-ignore
378
+ autoFocus: true,
379
+ autoHighlightFirstItem: false // @ts-ignore
380
+ ,
345
381
  itemRender: highlightItem,
346
382
  placeholder: placeholder ? placeholder : defaultFilter !== null && defaultFilter !== void 0 && defaultFilter.label ? template(message.defaultPlaceHolder)({
347
383
  value: defaultFilter === null || defaultFilter === void 0 ? void 0 : defaultFilter.label
@@ -351,10 +387,11 @@ var ComplexSearch = function ComplexSearch(props) {
351
387
  onKeyUp: handleKeyUp,
352
388
  dataSource: // 如果是指定了默认的筛选类型或者是直接指定模糊搜索模式 ,并且用户在这个输入框里面已经输入了值
353
389
  // 则表示需要模糊搜索,调用 handleSuggest
354
- isFuzzy ? suggestions : normalizeOptions(options),
390
+ isFuzzy ? normalizeSuggestion(suggestions) : normalizeOptions(options),
355
391
  popupStyle: {
356
392
  width: 'auto'
357
- }
393
+ },
394
+ popupClassName: 'rc-search-auto-complete'
358
395
  }, focusProps)) : null, renderSelectedFilter(), renderSelectFilterCloseIcon())), /*#__PURE__*/React.createElement("div", {
359
396
  className: classNames('right-wrap'),
360
397
  ref: autoRef
@@ -362,7 +399,9 @@ var ComplexSearch = function ComplexSearch(props) {
362
399
  className: classNames('search-btn', {
363
400
  'focus': focused
364
401
  }),
365
- onClick: handleSearch
402
+ onClick: function onClick() {
403
+ return handleSearch();
404
+ }
366
405
  }, /*#__PURE__*/React.createElement(Icon, {
367
406
  type: "search"
368
407
  }))));
package/es/style.js CHANGED
@@ -6,14 +6,14 @@ var prefix = function prefix(props) {
6
6
 
7
7
  var SearchWarp = styled.div.withConfig({
8
8
  componentId: "sc-1afc1cn-0"
9
- })(["height:100%;width:100%;display:flex;--input-clear-icon-transform:1;--input-hint-icon-color:#808080;.left-wrap{flex:1;border:1px solid var(--btn-pure-normal-border-color,#d1d5d9);display:flex;border-bottom-left-radius:var(--corner-1,2px);border-top-left-radius:var(--corner-1,2px);&.focus{border:1px solid #0064c8;border:1px solid var(--input-focus-border-color,#0064c8);;border-right:1px solid rgba(192,198,204,1);}.condition{height:26px;display:inline-block;margin-top:2px;}.condition-item{height:26px;display:inline-block;line-height:26px;background-color:var(--console-rc-search-label-color,#F7F9FA);:hover{background-color:var(--console-rc-search-label-hover-color,#EFF3F8);}border-radius:var(--corner-1,2px);padding:0 8px;margin:0 2px;font-size:12px;color:#333;position:relative;&-txt{padding-right:4px;}&:hover{background-color:#E0E4E8;}}.condition-select{width:100%;height:100%;opacity:0;position:absolute;top:0;left:0;min-width:auto;", "select-inner{min-width:auto;}}.forms{flex:1;position:relative;.clear-level1{position:absolute;top:var(--console-rc-search-close-btn-top,1px);right:var(--console-rc-search-close-btn-left,1px);height:28px;width:30px;background-color:transparent;z-index:99;color:#333;text-align:center;line-height:28px;font-size:12px;cursor:pointer;padding:6px 0 0 6px;}}.main-input{height:auto;border:none;box-shadow:none;&.single{flex:1;}&.select{width:100%;}&.multi{width:100%;}", "input,", "input{height:auto;box-shadow:none;}}", "input", "medium{height:auto;}}.right-wrap{width:32px;.search-btn{width:32px;padding:0 !important;border-bottom-left-radius:0;border-top-left-radius:0;&.focus{border-color:#0064c8;border-color:var(--input-focus-border-color,#0064c8);}border-left:none;}}& ", "input-control ", "input-clear-icon::before{content:var(--icon-content-close,\"ea22\") !important;}.isWidget & ", "input-control ", "input-clear-icon::before{content:\"\\E697\" !important;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
9
+ })(["height:100%;width:100%;display:flex;--input-clear-icon-transform:1;--input-hint-icon-color:#808080;.left-wrap{flex:1;border:1px solid var(--btn-pure-normal-border-color,#d1d5d9);display:flex;border-bottom-left-radius:var(--corner-1,2px);border-top-left-radius:var(--corner-1,2px);&.focus{border:1px solid #0064c8;border:1px solid var(--input-focus-border-color,#0064c8);;border-right:1px solid rgba(192,198,204,1);}.condition{height:26px;display:inline-block;margin-top:2px;}.condition-item{height:26px;display:inline-block;line-height:26px;background-color:var(--console-rc-search-label-color,#F7F9FA);:hover{background-color:var(--console-rc-search-label-hover-color,#EFF3F8);}border-radius:var(--corner-1,2px);padding:0 8px;margin:0 2px;font-size:12px;color:#333;position:relative;&-txt{padding-right:4px;}&:hover{background-color:#E0E4E8;}}.condition-select{width:100%;height:100%;opacity:0;position:absolute;top:0;left:0;min-width:auto;&.rc-search-prefix-no-select{", "input", "disabled{cursor:auto;}}", "select-inner{min-width:auto;}}.forms{flex:1;position:relative;.clear-level1{position:absolute;top:var(--console-rc-search-close-btn-top,1px);right:var(--console-rc-search-close-btn-left,1px);height:28px;width:30px;background-color:transparent;z-index:99;color:#333;text-align:center;line-height:28px;font-size:12px;cursor:pointer;padding:6px 0 0 6px;}}.main-input{", "select-arrow{display:none !important;}height:auto;border:none;box-shadow:none;&.single{flex:1;}&.select{width:100%;}&.multi{width:100%;}", "input,", "input{height:auto;box-shadow:none;}}", "input", "medium{height:auto;}}.right-wrap{width:32px;.search-btn{width:32px;padding:0 !important;border-bottom-left-radius:0;border-top-left-radius:0;&.focus{border-color:#0064c8;border-color:var(--input-focus-border-color,#0064c8);}border-left:none;}}& ", "input-control ", "input-clear-icon::before{content:var(--icon-content-close,\"ea22\") !important;}.isWidget & ", "input-control ", "input-clear-icon::before{content:\"\\E697\" !important;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
10
10
  var MenuContentWrap = styled.ul.withConfig({
11
11
  componentId: "sc-1afc1cn-1"
12
- })(["", "tag-small", "tag-closable > ", "tag-close-btn{margin-left:8px;padding-right:4px;padding-top:1px;}", "tag-small", "tag-closable > ", "tag-body{max-width:calc(100% - 8px - 8px - var(--tag-size-m-padding-lr,8px));}", "tag-small", "tag-closable > ", "tag-close-btn ", "icon:before,", "tag-small", "tag-closable > ", "tag-close-btn ", "icon ", "icon-remote{font-size:13px;}&& [class*='-icon-close']:hover::before{color:#181818;}&& [class*='-icon-close']::before{color:#808080;content:var(--icon-content-delete-filling);}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
12
+ })(["", "tag-small", "tag-closable > ", "tag-close-btn{margin-left:8px;padding-right:4px;padding-top:1px;}", "tag-small", "tag-closable > ", "tag-body{max-width:calc(100% - 8px - 8px - var(--tag-size-m-padding-lr,8px));}", "tag-small", "tag-closable > ", "tag-close-btn ", "icon:before,", "tag-small", "tag-closable > ", "tag-close-btn ", "icon ", "icon-remote{font-size:13px;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
13
13
  var MultiBtnWarp = styled.div.withConfig({
14
14
  componentId: "sc-1afc1cn-2"
15
15
  })(["padding:\"0 4px\";text-align:\"center\";.pri-btn{margin-right:8px;width:auto;min-width:auto;padding:3px 12px;}.cancel-btn{padding:3px 12px;width:auto;min-width:auto;}", "btn", "small:not(.isOnlyIcon):not(", "btn-text){min-width:auto;}"], prefix, prefix, prefix);
16
16
  var TagListWrap = styled.div.withConfig({
17
17
  componentId: "sc-1afc1cn-3"
18
- })(["", "tag-medium", "tag-closable > ", "tag-close-btn{margin-left:8px;padding-right:6px;}", "tag-medium", "tag-closable > ", "tag-body{max-width:calc(100% - 8px - 8px - var(--tag-size-m-padding-lr,8px));}", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon:before,", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon ", "icon-remote{font-size:16px;}&& [class*='-icon-close']:hover::before{color:#181818;}&& [class*='-icon-close']::before{color:#808080;font-size:12px !important;}.remove-btn{margin-bottom:8px;line-height:24px;display:inline-block;vertical-align:middle;cursor:pointer;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
18
+ })(["", "tag-medium", "tag-closable > ", "tag-close-btn{margin-left:8px;padding-right:6px;}", "tag-medium", "tag-closable > ", "tag-body{max-width:calc(100% - 8px - 8px - var(--tag-size-m-padding-lr,8px));}", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon:before,", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon ", "icon-remote{font-size:16px;}&& [class*='-icon-close']::before{color:#808080;font-size:12px !important;}.remove-btn{margin-bottom:8px;line-height:24px;display:inline-block;vertical-align:middle;cursor:pointer;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
19
19
  export { SearchWarp, MultiBtnWarp, TagListWrap, MenuContentWrap };
@@ -17,23 +17,30 @@ var _classnames = _interopRequireDefault(require("classnames"));
17
17
 
18
18
  var _consoleComponents = require("@alicloud/console-components");
19
19
 
20
- var _excluded = ["dataSource", "label"];
20
+ var _excluded = ["defaultValue", "dataSource", "label"];
21
21
 
22
22
  var SearchConditionSelectPrefix = function SearchConditionSelectPrefix(props) {
23
- var _props$dataSource = props.dataSource,
23
+ var defaultValue = props.defaultValue,
24
+ _props$dataSource = props.dataSource,
24
25
  dataSource = _props$dataSource === void 0 ? [] : _props$dataSource,
25
26
  label = props.label,
26
27
  reset = (0, _objectWithoutProperties2.default)(props, _excluded);
28
+ var noSelect = dataSource.length < 2;
27
29
  return /*#__PURE__*/_react.default.createElement("div", {
28
30
  className: (0, _classnames.default)('condition-item')
29
31
  }, /*#__PURE__*/_react.default.createElement("span", {
30
32
  className: (0, _classnames.default)('condition-item-txt')
31
- }, label), /*#__PURE__*/_react.default.createElement(_consoleComponents.Icon, {
33
+ }, label), noSelect ? null : /*#__PURE__*/_react.default.createElement(_consoleComponents.Icon, {
32
34
  type: "caret-down",
33
35
  size: "xxs"
34
36
  }), /*#__PURE__*/_react.default.createElement(_consoleComponents.Select, (0, _extends2.default)({
35
- className: (0, _classnames.default)('condition-select'),
37
+ className: (0, _classnames.default)('condition-select', {
38
+ 'rc-search-prefix-no-select': noSelect
39
+ }),
40
+ defaultValue: defaultValue,
36
41
  hasBorder: false,
42
+ disabled: noSelect,
43
+ autoHighlightFirstItem: false,
37
44
  dataSource: dataSource,
38
45
  itemRender: function itemRender(_ref) {
39
46
  var label = _ref.label,
@@ -41,9 +48,11 @@ var SearchConditionSelectPrefix = function SearchConditionSelectPrefix(props) {
41
48
  return /*#__PURE__*/_react.default.createElement("span", {
42
49
  "data-value": value
43
50
  }, label);
44
- },
45
- autoWidth: true
46
- }, reset)));
51
+ }
52
+ }, reset, {
53
+ autoWidth: false,
54
+ popupClassName: "rc-search-prefix"
55
+ })));
47
56
  };
48
57
 
49
58
  var _default = SearchConditionSelectPrefix;
@@ -76,6 +76,20 @@ var normalizeOptions = function normalizeOptions(options) {
76
76
  });
77
77
  };
78
78
 
79
+ var normalizeSuggestion = function normalizeSuggestion(suggestion) {
80
+ var suggestionCopy = (0, _cloneDeep.default)(suggestion);
81
+ suggestionCopy.forEach(function (s) {
82
+ if (s.children) {
83
+ s.children.forEach(function (child) {
84
+ if ((0, _lodash.isPlainObject)(child)) {
85
+ child.dataIndex = s.value;
86
+ }
87
+ });
88
+ }
89
+ });
90
+ return suggestionCopy;
91
+ };
92
+
79
93
  var normalizeSelectDataSource = function normalizeSelectDataSource(title, list) {
80
94
  return [{
81
95
  label: title || '',
@@ -128,9 +142,11 @@ var highlightKeyword = function highlightKeyword(value, keywords) {
128
142
  };
129
143
 
130
144
  var ComplexSearch = function ComplexSearch(props) {
131
- var options = props.options,
145
+ var _props$options = props.options,
146
+ options = _props$options === void 0 ? [] : _props$options,
132
147
  fuzzy = props.fuzzy,
133
148
  defaultDataIndex = props.defaultDataIndex,
149
+ defaultSelectedDataIndex = props.defaultSelectedDataIndex,
134
150
  placeholder = props.placeholder,
135
151
  onSearch = props.onSearch,
136
152
  onSuggest = props.onSuggest,
@@ -139,7 +155,9 @@ var ComplexSearch = function ComplexSearch(props) {
139
155
  _props$prefix = props.prefix,
140
156
  prefix = _props$prefix === void 0 ? 'next-' : _props$prefix;
141
157
 
142
- var _useState = (0, _react.useState)(null),
158
+ var _useState = (0, _react.useState)(options.find(function (o) {
159
+ return o.dataIndex === defaultSelectedDataIndex;
160
+ })),
143
161
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
144
162
  selectedFilterType = _useState2[0],
145
163
  setSelectedFilterType = _useState2[1];
@@ -150,6 +168,7 @@ var ComplexSearch = function ComplexSearch(props) {
150
168
  setFocused = _useState4[1];
151
169
 
152
170
  var autoRef = (0, _react.useRef)(null);
171
+ var fuzzyAutoRef = (0, _react.useRef)(null);
153
172
 
154
173
  var field = _consoleComponents.Field.useField();
155
174
 
@@ -198,12 +217,12 @@ var ComplexSearch = function ComplexSearch(props) {
198
217
  */
199
218
 
200
219
 
201
- var handlerFilterTypeInput = function handlerFilterTypeInput(value, actionType, isFuzzy) {
220
+ var handlerFilterTypeInput = function handlerFilterTypeInput(value, actionType, isFuzzy, option) {
202
221
  var isFuzzySearch = isFuzzy && getValue(_constants.SEARCH_FILTER_FIELD); // 如果是模糊搜索,则直接处理
203
222
 
204
223
  if (isFuzzySearch) {
205
224
  if (actionType !== 'change') {
206
- handleSearch();
225
+ handleSearch(option.dataIndex);
207
226
  } else {
208
227
  onSuggest && onSuggest(value, defaultDataIndex || '');
209
228
  }
@@ -220,12 +239,17 @@ var ComplexSearch = function ComplexSearch(props) {
220
239
  reset();
221
240
  };
222
241
 
223
- var handleSearch = function handleSearch() {
242
+ var handleSearch = function handleSearch(dataIndex) {
224
243
  if (onSearch) {
225
- var value = getValue(_constants.SEARCH_FILTER_VALUE_FIELD);
244
+ var value = getValue(_constants.SEARCH_FILTER_VALUE_FIELD); // 如果是没有选择下拉
226
245
 
227
246
  if (defaultDataIndex && !selectedFilterType) {
228
247
  onSearch(getValue(_constants.SEARCH_FILTER_FIELD), defaultDataIndex, normalizeSearchOptions(defaultDataIndex, getValue(_constants.SEARCH_FILTER_FIELD), options));
248
+ } // 如果是用户没有指定 defaultDataIndex 但是设置了 fuzzy
249
+
250
+
251
+ if (fuzzy && !selectedFilterType) {
252
+ onSearch(getValue(_constants.SEARCH_FILTER_FIELD), dataIndex || '', normalizeSearchOptions(dataIndex || '', getValue(_constants.SEARCH_FILTER_FIELD), options));
229
253
  }
230
254
 
231
255
  if (selectedFilterType) {
@@ -243,6 +267,10 @@ var ComplexSearch = function ComplexSearch(props) {
243
267
  handleSearch();
244
268
  document.body.click();
245
269
  }
270
+
271
+ if (e.keyCode === 8 && !e.currentTarget.value) {
272
+ handlerFilterClear();
273
+ }
246
274
  };
247
275
 
248
276
  var renderMultipleSelectorItem = function renderMultipleSelectorItem(item) {
@@ -256,7 +284,7 @@ var ComplexSearch = function ComplexSearch(props) {
256
284
  };
257
285
 
258
286
  var renderSelectedFilter = function renderSelectedFilter() {
259
- var _selectedFilterType$t, _selectedFilterType$t2;
287
+ var _selectedFilterType$t, _selectedFilterType$t2, _selectedFilterType$t3;
260
288
 
261
289
  var type = selectedFilterType === null || selectedFilterType === void 0 ? void 0 : selectedFilterType.template;
262
290
  var searchValue = getValue(_constants.SEARCH_FILTER_VALUE_FIELD);
@@ -280,9 +308,12 @@ var ComplexSearch = function ComplexSearch(props) {
280
308
  switch (type) {
281
309
  case 'input':
282
310
  return /*#__PURE__*/_react.default.createElement(AutoComplete, (0, _extends2.default)({}, init(_constants.SEARCH_FILTER_VALUE_FIELD, {}), {
283
- className: (0, _classnames.default)('main-input', 'multi')
311
+ className: (0, _classnames.default)('main-input', 'multi'),
312
+ autoHighlightFirstItem: false
284
313
  }, props, {
285
- onKeyUp: handleKeyUp
314
+ autoWidth: true,
315
+ onKeyUp: handleKeyUp,
316
+ dataSource: selectedFilterType === null || selectedFilterType === void 0 ? void 0 : (_selectedFilterType$t3 = selectedFilterType.templateProps) === null || _selectedFilterType$t3 === void 0 ? void 0 : _selectedFilterType$t3.dataSource
286
317
  }));
287
318
 
288
319
  case 'select':
@@ -292,7 +323,9 @@ var ComplexSearch = function ComplexSearch(props) {
292
323
  props: {
293
324
  onChange: handleSearch
294
325
  }
295
- }), props, selectProps));
326
+ }), {
327
+ autoHighlightFirstItem: false
328
+ }, props, selectProps));
296
329
 
297
330
  case 'multiple':
298
331
  return /*#__PURE__*/_react.default.createElement(_consoleComponents.Select, (0, _extends2.default)({
@@ -301,6 +334,7 @@ var ComplexSearch = function ComplexSearch(props) {
301
334
  itemRender: renderMultipleSelectorItem,
302
335
  popupClassName: "xconsole-rcsearch-multi-pop",
303
336
  mode: "multiple",
337
+ autoHighlightFirstItem: false,
304
338
  maxTagCount: 0,
305
339
  menuProps: {
306
340
  footer: /*#__PURE__*/_react.default.createElement(_style.MultiBtnWarp, {
@@ -367,12 +401,14 @@ var ComplexSearch = function ComplexSearch(props) {
367
401
  }, !selectedFilterType ? /*#__PURE__*/_react.default.createElement(AutoComplete, (0, _extends2.default)({}, init(_constants.SEARCH_FILTER_FIELD, {
368
402
  props: {
369
403
  // @ts-ignore
370
- onChange: function onChange(value, actionType) {
371
- handlerFilterTypeInput(value, actionType, isFuzzy);
404
+ onChange: function onChange(value, actionType, option) {
405
+ handlerFilterTypeInput(value, actionType, !!isFuzzy, option);
372
406
  }
373
407
  }
374
408
  }), {
375
- // @ts-ignore
409
+ autoFocus: true,
410
+ autoHighlightFirstItem: false // @ts-ignore
411
+ ,
376
412
  itemRender: highlightItem,
377
413
  placeholder: placeholder ? placeholder : defaultFilter !== null && defaultFilter !== void 0 && defaultFilter.label ? (0, _lodash.template)(_message.default.defaultPlaceHolder)({
378
414
  value: defaultFilter === null || defaultFilter === void 0 ? void 0 : defaultFilter.label
@@ -382,10 +418,11 @@ var ComplexSearch = function ComplexSearch(props) {
382
418
  onKeyUp: handleKeyUp,
383
419
  dataSource: // 如果是指定了默认的筛选类型或者是直接指定模糊搜索模式 ,并且用户在这个输入框里面已经输入了值
384
420
  // 则表示需要模糊搜索,调用 handleSuggest
385
- isFuzzy ? suggestions : normalizeOptions(options),
421
+ isFuzzy ? normalizeSuggestion(suggestions) : normalizeOptions(options),
386
422
  popupStyle: {
387
423
  width: 'auto'
388
- }
424
+ },
425
+ popupClassName: 'rc-search-auto-complete'
389
426
  }, focusProps)) : null, renderSelectedFilter(), renderSelectFilterCloseIcon())), /*#__PURE__*/_react.default.createElement("div", {
390
427
  className: (0, _classnames.default)('right-wrap'),
391
428
  ref: autoRef
@@ -393,7 +430,9 @@ var ComplexSearch = function ComplexSearch(props) {
393
430
  className: (0, _classnames.default)('search-btn', {
394
431
  'focus': focused
395
432
  }),
396
- onClick: handleSearch
433
+ onClick: function onClick() {
434
+ return handleSearch();
435
+ }
397
436
  }, /*#__PURE__*/_react.default.createElement(_consoleComponents.Icon, {
398
437
  type: "search"
399
438
  }))));
package/lib/style.js CHANGED
@@ -15,13 +15,13 @@ var prefix = function prefix(props) {
15
15
 
16
16
  var SearchWarp = _styledComponents.default.div.withConfig({
17
17
  componentId: "sc-1afc1cn-0"
18
- })(["height:100%;width:100%;display:flex;--input-clear-icon-transform:1;--input-hint-icon-color:#808080;.left-wrap{flex:1;border:1px solid var(--btn-pure-normal-border-color,#d1d5d9);display:flex;border-bottom-left-radius:var(--corner-1,2px);border-top-left-radius:var(--corner-1,2px);&.focus{border:1px solid #0064c8;border:1px solid var(--input-focus-border-color,#0064c8);;border-right:1px solid rgba(192,198,204,1);}.condition{height:26px;display:inline-block;margin-top:2px;}.condition-item{height:26px;display:inline-block;line-height:26px;background-color:var(--console-rc-search-label-color,#F7F9FA);:hover{background-color:var(--console-rc-search-label-hover-color,#EFF3F8);}border-radius:var(--corner-1,2px);padding:0 8px;margin:0 2px;font-size:12px;color:#333;position:relative;&-txt{padding-right:4px;}&:hover{background-color:#E0E4E8;}}.condition-select{width:100%;height:100%;opacity:0;position:absolute;top:0;left:0;min-width:auto;", "select-inner{min-width:auto;}}.forms{flex:1;position:relative;.clear-level1{position:absolute;top:var(--console-rc-search-close-btn-top,1px);right:var(--console-rc-search-close-btn-left,1px);height:28px;width:30px;background-color:transparent;z-index:99;color:#333;text-align:center;line-height:28px;font-size:12px;cursor:pointer;padding:6px 0 0 6px;}}.main-input{height:auto;border:none;box-shadow:none;&.single{flex:1;}&.select{width:100%;}&.multi{width:100%;}", "input,", "input{height:auto;box-shadow:none;}}", "input", "medium{height:auto;}}.right-wrap{width:32px;.search-btn{width:32px;padding:0 !important;border-bottom-left-radius:0;border-top-left-radius:0;&.focus{border-color:#0064c8;border-color:var(--input-focus-border-color,#0064c8);}border-left:none;}}& ", "input-control ", "input-clear-icon::before{content:var(--icon-content-close,\"ea22\") !important;}.isWidget & ", "input-control ", "input-clear-icon::before{content:\"\\E697\" !important;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
18
+ })(["height:100%;width:100%;display:flex;--input-clear-icon-transform:1;--input-hint-icon-color:#808080;.left-wrap{flex:1;border:1px solid var(--btn-pure-normal-border-color,#d1d5d9);display:flex;border-bottom-left-radius:var(--corner-1,2px);border-top-left-radius:var(--corner-1,2px);&.focus{border:1px solid #0064c8;border:1px solid var(--input-focus-border-color,#0064c8);;border-right:1px solid rgba(192,198,204,1);}.condition{height:26px;display:inline-block;margin-top:2px;}.condition-item{height:26px;display:inline-block;line-height:26px;background-color:var(--console-rc-search-label-color,#F7F9FA);:hover{background-color:var(--console-rc-search-label-hover-color,#EFF3F8);}border-radius:var(--corner-1,2px);padding:0 8px;margin:0 2px;font-size:12px;color:#333;position:relative;&-txt{padding-right:4px;}&:hover{background-color:#E0E4E8;}}.condition-select{width:100%;height:100%;opacity:0;position:absolute;top:0;left:0;min-width:auto;&.rc-search-prefix-no-select{", "input", "disabled{cursor:auto;}}", "select-inner{min-width:auto;}}.forms{flex:1;position:relative;.clear-level1{position:absolute;top:var(--console-rc-search-close-btn-top,1px);right:var(--console-rc-search-close-btn-left,1px);height:28px;width:30px;background-color:transparent;z-index:99;color:#333;text-align:center;line-height:28px;font-size:12px;cursor:pointer;padding:6px 0 0 6px;}}.main-input{", "select-arrow{display:none !important;}height:auto;border:none;box-shadow:none;&.single{flex:1;}&.select{width:100%;}&.multi{width:100%;}", "input,", "input{height:auto;box-shadow:none;}}", "input", "medium{height:auto;}}.right-wrap{width:32px;.search-btn{width:32px;padding:0 !important;border-bottom-left-radius:0;border-top-left-radius:0;&.focus{border-color:#0064c8;border-color:var(--input-focus-border-color,#0064c8);}border-left:none;}}& ", "input-control ", "input-clear-icon::before{content:var(--icon-content-close,\"ea22\") !important;}.isWidget & ", "input-control ", "input-clear-icon::before{content:\"\\E697\" !important;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
19
19
 
20
20
  exports.SearchWarp = SearchWarp;
21
21
 
22
22
  var MenuContentWrap = _styledComponents.default.ul.withConfig({
23
23
  componentId: "sc-1afc1cn-1"
24
- })(["", "tag-small", "tag-closable > ", "tag-close-btn{margin-left:8px;padding-right:4px;padding-top:1px;}", "tag-small", "tag-closable > ", "tag-body{max-width:calc(100% - 8px - 8px - var(--tag-size-m-padding-lr,8px));}", "tag-small", "tag-closable > ", "tag-close-btn ", "icon:before,", "tag-small", "tag-closable > ", "tag-close-btn ", "icon ", "icon-remote{font-size:13px;}&& [class*='-icon-close']:hover::before{color:#181818;}&& [class*='-icon-close']::before{color:#808080;content:var(--icon-content-delete-filling);}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
24
+ })(["", "tag-small", "tag-closable > ", "tag-close-btn{margin-left:8px;padding-right:4px;padding-top:1px;}", "tag-small", "tag-closable > ", "tag-body{max-width:calc(100% - 8px - 8px - var(--tag-size-m-padding-lr,8px));}", "tag-small", "tag-closable > ", "tag-close-btn ", "icon:before,", "tag-small", "tag-closable > ", "tag-close-btn ", "icon ", "icon-remote{font-size:13px;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
25
25
 
26
26
  exports.MenuContentWrap = MenuContentWrap;
27
27
 
@@ -33,6 +33,6 @@ exports.MultiBtnWarp = MultiBtnWarp;
33
33
 
34
34
  var TagListWrap = _styledComponents.default.div.withConfig({
35
35
  componentId: "sc-1afc1cn-3"
36
- })(["", "tag-medium", "tag-closable > ", "tag-close-btn{margin-left:8px;padding-right:6px;}", "tag-medium", "tag-closable > ", "tag-body{max-width:calc(100% - 8px - 8px - var(--tag-size-m-padding-lr,8px));}", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon:before,", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon ", "icon-remote{font-size:16px;}&& [class*='-icon-close']:hover::before{color:#181818;}&& [class*='-icon-close']::before{color:#808080;font-size:12px !important;}.remove-btn{margin-bottom:8px;line-height:24px;display:inline-block;vertical-align:middle;cursor:pointer;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
36
+ })(["", "tag-medium", "tag-closable > ", "tag-close-btn{margin-left:8px;padding-right:6px;}", "tag-medium", "tag-closable > ", "tag-body{max-width:calc(100% - 8px - 8px - var(--tag-size-m-padding-lr,8px));}", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon:before,", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon ", "icon-remote{font-size:16px;}&& [class*='-icon-close']::before{color:#808080;font-size:12px !important;}.remove-btn{margin-bottom:8px;line-height:24px;display:inline-block;vertical-align:middle;cursor:pointer;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
37
37
 
38
38
  exports.TagListWrap = TagListWrap;
@@ -28,9 +28,13 @@ export interface IRcSearchProps {
28
28
  */
29
29
  placeholder?: string;
30
30
  /**
31
- * 默认类别
31
+ * 默认搜索类别
32
32
  */
33
33
  defaultDataIndex?: string;
34
+ /**
35
+ * 默认选中的类别
36
+ */
37
+ defaultSelectedDataIndex?: string;
34
38
  /**
35
39
  * 搜索触发
36
40
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/console-components-search",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "license": "MIT",