tntd 1.4.4 → 1.4.7

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.
Files changed (88) hide show
  1. package/components/Layout/HeaderActions.js +90 -128
  2. package/components/LoadingButton/index.js +11 -15
  3. package/components/QueryListScene/QueryForm.js +7 -4
  4. package/dist/stats.json +4990 -4990
  5. package/dist/tntd.js +1 -1
  6. package/es/Layout/HeaderActions.js +10 -10
  7. package/es/LoadingButton/index.js +20 -10
  8. package/es/QueryListScene/QueryForm.js +6 -3
  9. package/lib/ArrayInput/icon.js +27 -31
  10. package/lib/ArrayInput/index.js +211 -298
  11. package/lib/AuthContext.js +2 -13
  12. package/lib/Columns/index.js +71 -100
  13. package/lib/DevelopmentLogin/LoginModal.js +79 -141
  14. package/lib/DevelopmentLogin/index.js +28 -55
  15. package/lib/Ellipsis/Svg/CopySVG.js +23 -71
  16. package/lib/Ellipsis/Svg/TickSVG.js +17 -49
  17. package/lib/Ellipsis/index.js +148 -154
  18. package/lib/Handle/index.js +72 -109
  19. package/lib/Icon/fonts/iconfont.js +1 -43
  20. package/lib/Icon/iconList.js +119 -8
  21. package/lib/Icon/index.js +13 -45
  22. package/lib/Img/Contain.js +49 -81
  23. package/lib/Img/Cover.js +88 -136
  24. package/lib/Img/index.js +36 -89
  25. package/lib/Layout/ActionsContext.js +2 -11
  26. package/lib/Layout/AppList.js +262 -256
  27. package/lib/Layout/Application.js +119 -135
  28. package/lib/Layout/Avatar.js +137 -137
  29. package/lib/Layout/CompatibleLanguage.js +214 -195
  30. package/lib/Layout/EnterpriseLayout/Avatar.js +156 -168
  31. package/lib/Layout/EnterpriseLayout/Language.js +75 -100
  32. package/lib/Layout/EnterpriseLayout/Theme.js +96 -94
  33. package/lib/Layout/EnterpriseLayout/index.js +32 -45
  34. package/lib/Layout/GlobalNavigation/NavigationPopup.js +335 -407
  35. package/lib/Layout/GlobalNavigation/index.js +110 -158
  36. package/lib/Layout/Header.js +165 -116
  37. package/lib/Layout/HeaderActions.js +132 -129
  38. package/lib/Layout/HeaderNavs.js +90 -113
  39. package/lib/Layout/HeaderTabs.js +312 -278
  40. package/lib/Layout/Iconfont.js +2 -15
  41. package/lib/Layout/Language.js +63 -102
  42. package/lib/Layout/Layout.js +272 -261
  43. package/lib/Layout/Logo.js +132 -87
  44. package/lib/Layout/OrgAppList.js +440 -319
  45. package/lib/Layout/SideMenu.js +429 -343
  46. package/lib/Layout/Theme.js +95 -124
  47. package/lib/Layout/checkAuth.js +21 -35
  48. package/lib/Layout/createActions.js +38 -51
  49. package/lib/Layout/images/index.js +33 -41
  50. package/lib/Layout/index.js +110 -161
  51. package/lib/Layout/paaslayout/CompactSideMenu.js +200 -178
  52. package/lib/Layout/paaslayout/Header.js +84 -90
  53. package/lib/Layout/paaslayout/Logo.js +27 -32
  54. package/lib/Layout/paaslayout/SideMenu.js +161 -174
  55. package/lib/Layout/paaslayout/index.js +240 -261
  56. package/lib/Layout/storage.js +20 -78
  57. package/lib/Layout/utils.js +93 -143
  58. package/lib/LoadingButton/index.js +25 -57
  59. package/lib/Modal/index.js +83 -108
  60. package/lib/Page/Box.js +56 -81
  61. package/lib/Page/index.js +151 -173
  62. package/lib/Page/utils.js +12 -30
  63. package/lib/QueryForm/Field/Checkbox.js +11 -33
  64. package/lib/QueryForm/Field/Select.js +63 -99
  65. package/lib/QueryForm/Field/SelectInput.js +69 -114
  66. package/lib/QueryForm/Field/fieldsMap.js +30 -52
  67. package/lib/QueryForm/Field/index.js +76 -158
  68. package/lib/QueryForm/createActions.js +50 -65
  69. package/lib/QueryForm/index.js +304 -383
  70. package/lib/QueryForm/useForm.js +6 -17
  71. package/lib/QueryListScene/List.js +290 -366
  72. package/lib/QueryListScene/QueryForm.js +93 -158
  73. package/lib/QueryListScene/QueryListScene.js +33 -87
  74. package/lib/QueryListScene/Title.js +10 -20
  75. package/lib/QueryListScene/Toolbar.js +8 -31
  76. package/lib/QueryListScene/createActions.js +64 -79
  77. package/lib/QueryListScene/index.js +23 -40
  78. package/lib/QueryListScene/useActions.js +6 -17
  79. package/lib/Select/DropDownWrap.js +60 -124
  80. package/lib/Select/index.js +425 -561
  81. package/lib/Table/ResizableTable/index.js +77 -121
  82. package/lib/Table/index.js +19 -51
  83. package/lib/Title/index.js +34 -52
  84. package/lib/index.js +19 -159
  85. package/lib/locale.js +48 -63
  86. package/package.json +1 -1
  87. package/lib/Layout/EnterpriseLayout/Header.js +0 -113
  88. package/lib/Layout/EnterpriseLayout/HeaderActions.js +0 -104
@@ -1,639 +1,503 @@
1
- "use strict";
1
+ import React, { PureComponent } from 'react';
2
+ import { Select, Empty } from 'antd';
3
+ import DropDownWrap from './DropDownWrap';
2
4
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
-
8
- require("antd/lib/empty/style");
9
-
10
- var _empty = _interopRequireDefault(require("antd/lib/empty"));
11
-
12
- require("antd/lib/select/style");
13
-
14
- var _select = _interopRequireDefault(require("antd/lib/select"));
15
-
16
- var _react = _interopRequireWildcard(require("react"));
17
-
18
- var _DropDownWrap = _interopRequireDefault(require("./DropDownWrap"));
19
-
20
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
21
-
22
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
-
26
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
27
-
28
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
29
-
30
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
31
-
32
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
33
-
34
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
35
-
36
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5
+ // 页面实际渲染的下拉菜单数量,实际为 2 * ITEM_ELEMENT_NUMBER
6
+ const ITEM_ELEMENT_NUMBER = 30;
7
+ // Select size 配置
8
+ const ITEM_HEIGHT_CFG = {
9
+ small: 24,
10
+ large: 40,
11
+ default: 32
12
+ };
37
13
 
38
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
14
+ const ARROW_CODE = {
15
+ 40: 'down',
16
+ 38: 'up'
17
+ };
39
18
 
40
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
+ const DROPDOWN_HEIGHT = 224;
41
20
 
42
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
21
+ const Option = Select.Option;
43
22
 
44
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
23
+ class SuperSelect extends PureComponent {
24
+ constructor(props) {
25
+ super(props);
45
26
 
46
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
27
+ const { mode, defaultValue, value, optionHeight, children: arr } = props;
28
+ this.isMultiple = ['tags', 'multiple'].includes(mode);
29
+ const children = this.turnChildren(arr);
47
30
 
48
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
31
+ // 设置默认 value
32
+ let defaultV = this.isMultiple ? [] : '';
33
+ defaultV = value || defaultValue || defaultV;
49
34
 
50
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
35
+ this.state = {
36
+ children: children || [],
37
+ filterChildren: null, // 筛选后的 options,优先显示,所以清除筛选后手动设为 null
38
+ value: defaultV,
39
+ maxWidth: null,
40
+ selectWidth: null
41
+ };
42
+ // 下拉菜单项行高
43
+ this.ITEM_HEIGHT = optionHeight || ITEM_HEIGHT_CFG[props.size || 'default'];
44
+ // 可视区 dom 高度
45
+ this.visibleDomHeight = this.ITEM_HEIGHT * ITEM_ELEMENT_NUMBER;
46
+ // 滚动时重新渲染的 scrollTop 判断值,大于 reactDelta 则刷新下拉列表
47
+ this.reactDelta = this.visibleDomHeight / 3;
48
+ // 是否拖动滚动条快速滚动状态
49
+ this.isStopReact = false;
50
+ // 上一次滚动的 scrollTop 值
51
+ this.prevScrollTop = 0;
52
+ // 上一次按下方向键时 scrollTop 值
53
+ this.prevTop = 0;
54
+
55
+ this.scrollTop = 0;
56
+
57
+ // className
58
+ this.dropdownClassName = `dc${+new Date()}`;
59
+
60
+ this.id = `sid${+new Date()}`;
51
61
 
52
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
62
+ }
53
63
 
54
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
64
+ componentDidMount() {
65
+ // defaultOpens=true 时添加滚动事件
66
+ setTimeout(() => {
67
+ this.addEvent();
68
+ }, 500);
69
+ const { children: arr } = this.props;
70
+ const children = this.turnChildren(arr);
71
+ // if (children && children.length > 0) {
72
+ this.formulaWidth();
73
+ // }
74
+ }
55
75
 
56
- // 页面实际渲染的下拉菜单数量,实际为 2 * ITEM_ELEMENT_NUMBER
57
- var ITEM_ELEMENT_NUMBER = 30; // Select size 配置
76
+ turnChildren = (children) => {
77
+ if (!children) return [];
78
+ let arr = [];
79
+ if (children && children.props) {
80
+ arr.push(children);
81
+ } else {
82
+ children.forEach(item => {
83
+ if (item) {
84
+ if (item instanceof Array) {
85
+ arr = arr.concat(item);
86
+ } else {
87
+ arr.push(item);
88
+ }
89
+ }
90
+ });
91
+ }
92
+ return arr;
93
+ }
58
94
 
59
- var ITEM_HEIGHT_CFG = {
60
- small: 24,
61
- large: 40,
62
- "default": 32
63
- };
64
- var ARROW_CODE = {
65
- 40: 'down',
66
- 38: 'up'
67
- };
68
- var DROPDOWN_HEIGHT = 224;
69
- var Option = _select["default"].Option;
70
-
71
- var SuperSelect =
72
- /*#__PURE__*/
73
- function (_PureComponent) {
74
- _inherits(SuperSelect, _PureComponent);
75
-
76
- function SuperSelect(props) {
77
- var _this;
78
-
79
- _classCallCheck(this, SuperSelect);
80
-
81
- _this = _possibleConstructorReturn(this, _getPrototypeOf(SuperSelect).call(this, props));
82
-
83
- _this.turnChildren = function (children) {
84
- if (!children) return [];
85
- var arr = [];
86
-
87
- if (children && children.props) {
88
- arr.push(children);
89
- } else {
90
- children.forEach(function (item) {
91
- if (item) {
92
- if (item instanceof Array) {
93
- arr = arr.concat(item);
94
- } else {
95
- arr.push(item);
95
+ formulaWidth = () => {
96
+ // 获取dom设置宽度
97
+ const { children: arr2, dropdownMatchSelectWidth = true, maxWidth } = this.props;
98
+ const selectDom = document.getElementById(this.id);
99
+ const selectWidth = selectDom.clientWidth || selectDom.offsetWidth;
100
+ let arr = [];
101
+ let formulaMaxWidth = 10;
102
+ if (!dropdownMatchSelectWidth) {
103
+ formulaMaxWidth = maxWidth || 10;
104
+ }
105
+ if (!dropdownMatchSelectWidth && !maxWidth) {
106
+ const children = this.turnChildren(arr2);
107
+ for (let i = 0; i < children.length; i++) {
108
+ const val = children[i].props.children;
109
+ const textWidth = this.getTextPixelWith(val);
110
+ arr.push(textWidth.toFixed(2));
96
111
  }
97
- }
98
- });
99
- }
100
-
101
- return arr;
102
- };
103
-
104
- _this.formulaWidth = function () {
105
- // 获取dom设置宽度
106
- var _this$props = _this.props,
107
- arr2 = _this$props.children,
108
- _this$props$dropdownM = _this$props.dropdownMatchSelectWidth,
109
- dropdownMatchSelectWidth = _this$props$dropdownM === void 0 ? true : _this$props$dropdownM,
110
- maxWidth = _this$props.maxWidth;
111
- var selectDom = document.getElementById(_this.id);
112
- var selectWidth = selectDom.clientWidth || selectDom.offsetWidth;
113
- var arr = [];
114
- var formulaMaxWidth = 10;
115
-
116
- if (!dropdownMatchSelectWidth) {
117
- formulaMaxWidth = maxWidth || 10;
118
- }
119
-
120
- if (!dropdownMatchSelectWidth && !maxWidth) {
121
- var children = _this.turnChildren(arr2);
112
+ if (arr.length > 0) {
113
+ formulaMaxWidth = Math.max(...arr);
114
+ }
115
+ }
122
116
 
123
- for (var i = 0; i < children.length; i++) {
124
- var val = children[i].props.children;
117
+ this.setState({
118
+ selectWidth,
119
+ maxWidth: formulaMaxWidth
120
+ });
121
+ }
125
122
 
126
- var textWidth = _this.getTextPixelWith(val);
123
+ // 获取单行文本的像素宽度
124
+ getTextPixelWith = (text, fontStyle = '14px') => {
125
+ let canvas = document.createElement('canvas'); // 创建 canvas 画布
126
+ let context = canvas.getContext('2d'); // 获取 canvas 绘图上下文环境
127
+ context.font = fontStyle; // 设置字体样式,使用前设置好对应的 font 样式才能准确获取文字的像素长度
128
+ let dimension = context.measureText(text); // 测量文字
129
+ return dimension.width;
130
+ }
127
131
 
128
- arr.push(textWidth.toFixed(2));
132
+ componentDidUpdate(prevProps) {
133
+ const { mode, defaultValue, value, children } = this.props;
134
+ let arr = this.turnChildren(children);
135
+ if (prevProps.children !== children) {
136
+ this.isMultiple = ['tags', 'multiple'].includes(mode);
137
+
138
+ this.setState({
139
+ children: arr || [],
140
+ filterChildren: null
141
+ });
142
+ if (arr && arr.length > 0) {
143
+ this.formulaWidth();
144
+ }
129
145
  }
130
-
131
- if (arr.length > 0) {
132
- formulaMaxWidth = Math.max.apply(Math, arr);
146
+ if (prevProps.value !== value) {
147
+ // 更新时设置默认 value
148
+ let defaultV = this.isMultiple ? [] : '';
149
+ defaultV = value || defaultValue || defaultV;
150
+ this.setState({ value: defaultV });
133
151
  }
134
- }
135
-
136
- _this.setState({
137
- selectWidth: selectWidth,
138
- maxWidth: formulaMaxWidth
139
- });
140
- };
141
-
142
- _this.getTextPixelWith = function (text) {
143
- var fontStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '14px';
144
- var canvas = document.createElement('canvas'); // 创建 canvas 画布
145
-
146
- var context = canvas.getContext('2d'); // 获取 canvas 绘图上下文环境
147
-
148
- context.font = fontStyle; // 设置字体样式,使用前设置好对应的 font 样式才能准确获取文字的像素长度
149
-
150
- var dimension = context.measureText(text); // 测量文字
152
+ }
151
153
 
152
- return dimension.width;
153
- };
154
+ componentWillUnmount() {
155
+ this.removeEvent();
156
+ }
154
157
 
155
- _this.getItemStyle = function (i) {
156
- return {
158
+ getItemStyle = i => ({
157
159
  position: 'absolute',
158
- top: _this.ITEM_HEIGHT * i,
160
+ top: this.ITEM_HEIGHT * i,
159
161
  width: '100%',
160
- height: _this.ITEM_HEIGHT
161
- };
162
- };
163
-
164
- _this.addEvent = function () {
165
- _this.scrollEle = document.querySelector(".".concat(_this.dropdownClassName)); // 下拉菜单未展开时元素不存在
166
-
167
- if (!_this.scrollEle) return;
162
+ height: this.ITEM_HEIGHT
163
+ });
168
164
 
169
- _this.scrollEle.addEventListener('scroll', _this.onScroll, false);
165
+ addEvent = () => {
166
+ this.scrollEle = document.querySelector(`.${this.dropdownClassName}`);
167
+ // 下拉菜单未展开时元素不存在
168
+ if (!this.scrollEle) return;
170
169
 
171
- _this.inputEle = document.querySelector("#".concat(_this.id));
172
- if (!_this.inputEle) return;
170
+ this.scrollEle.addEventListener('scroll', this.onScroll, false);
171
+ this.inputEle = document.querySelector(`#${this.id}`);
173
172
 
174
- _this.inputEle.addEventListener('keydown', _this.onKeyDown, false);
173
+ if (!this.inputEle) return;
174
+ this.inputEle.addEventListener('keydown', this.onKeyDown, false);
175
175
  };
176
176
 
177
- _this.onKeyDown = function (e) {
178
- var _ref = e || {},
179
- keyCode = _ref.keyCode;
177
+ // 模拟 antd select 按下 上下箭头 键时滚动列表
178
+ onKeyDown = e => {
179
+ const { keyCode } = e || {};
180
180
 
181
- setTimeout(function () {
182
- var activeItem = document.querySelector(".".concat(_this.dropdownClassName, " .ant-select-dropdown-menu-item-active"));
183
- if (!activeItem) return;
184
- var offsetTop = activeItem.offsetTop;
185
- var isUp = ARROW_CODE[keyCode] === 'up';
186
- var isDown = ARROW_CODE[keyCode] === 'down'; // 在所有列表第一行按上键
181
+ setTimeout(() => {
182
+ const activeItem = document.querySelector(
183
+ `.${this.dropdownClassName} .ant-select-dropdown-menu-item-active`
184
+ );
185
+ if (!activeItem) return;
187
186
 
188
- if (offsetTop - _this.prevTop > DROPDOWN_HEIGHT && isUp) {
189
- _this.scrollEle.scrollTo(0, _this.allHeight - DROPDOWN_HEIGHT);
187
+ const { offsetTop } = activeItem;
188
+ const isUp = ARROW_CODE[keyCode] === 'up';
189
+ const isDown = ARROW_CODE[keyCode] === 'down';
190
190
 
191
- _this.prevTop = _this.allHeight;
192
- return;
193
- } // 在所有列表中最后一行按下键
191
+ // 在所有列表第一行按上键
192
+ if (offsetTop - this.prevTop > DROPDOWN_HEIGHT && isUp) {
193
+ this.scrollEle.scrollTo(0, this.allHeight - DROPDOWN_HEIGHT);
194
+ this.prevTop = this.allHeight;
194
195
 
196
+ return;
197
+ }
195
198
 
196
- if (_this.prevTop > offsetTop + DROPDOWN_HEIGHT && isDown) {
197
- _this.scrollEle.scrollTo(0, 0);
198
-
199
- _this.prevTop = 0;
200
- return;
201
- }
202
-
203
- _this.prevTop = offsetTop; // 向下滚动到下拉框最后一行时,向下滚动一行的高度
204
-
205
- if (offsetTop > _this.scrollEle.scrollTop + DROPDOWN_HEIGHT - _this.ITEM_HEIGHT + 10 && isDown) {
206
- _this.scrollEle.scrollTo(0, _this.scrollTop + _this.ITEM_HEIGHT);
207
-
208
- return;
209
- } // 向上滚动到下拉框第一一行时,向上滚动一行的高度
210
-
199
+ // 在所有列表中最后一行按下键
200
+ if (this.prevTop > offsetTop + DROPDOWN_HEIGHT && isDown) {
201
+ this.scrollEle.scrollTo(0, 0);
202
+ this.prevTop = 0;
211
203
 
212
- if (offsetTop < _this.scrollEle.scrollTop && isUp) {
213
- _this.scrollEle.scrollTo(0, _this.scrollTop - _this.ITEM_HEIGHT);
214
- }
215
- }, 100);
216
- };
204
+ return;
205
+ }
217
206
 
218
- _this.onScroll = function () {
219
- return _this.throttleByHeight(_this.onScrollReal);
207
+ this.prevTop = offsetTop;
208
+ // 向下滚动到下拉框最后一行时,向下滚动一行的高度
209
+ if (
210
+ offsetTop >
211
+ this.scrollEle.scrollTop + DROPDOWN_HEIGHT - this.ITEM_HEIGHT + 10 &&
212
+ isDown
213
+ ) {
214
+ this.scrollEle.scrollTo(0, this.scrollTop + this.ITEM_HEIGHT);
215
+ return;
216
+ }
217
+ // 向上滚动到下拉框第一一行时,向上滚动一行的高度
218
+ if (offsetTop < this.scrollEle.scrollTop && isUp) {
219
+ this.scrollEle.scrollTo(0, this.scrollTop - this.ITEM_HEIGHT);
220
+ }
221
+ }, 100);
220
222
  };
221
223
 
222
- _this.onScrollReal = function () {
223
- _this.allList = _this.getUseChildrenList();
224
-
225
- var _this$getStartAndEndI = _this.getStartAndEndIndex(),
226
- startIndex = _this$getStartAndEndI.startIndex,
227
- endIndex = _this$getStartAndEndI.endIndex;
224
+ onScroll = () => this.throttleByHeight(this.onScrollReal);
228
225
 
229
- _this.prevScrollTop = _this.scrollTop; // 重新渲染列表组件 Wrap
226
+ onScrollReal = () => {
227
+ this.allList = this.getUseChildrenList();
228
+ const { startIndex, endIndex } = this.getStartAndEndIndex();
230
229
 
231
- var allHeight = _this.allList.length * _this.ITEM_HEIGHT || 100;
232
-
233
- _this.wrap.reactList(allHeight, startIndex, endIndex);
230
+ this.prevScrollTop = this.scrollTop;
231
+ // 重新渲染列表组件 Wrap
232
+ const allHeight = this.allList.length * this.ITEM_HEIGHT || 100;
233
+ this.wrap.reactList(allHeight, startIndex, endIndex);
234
234
  };
235
235
 
236
- _this.throttleByHeight = function () {
237
- _this.scrollTop = _this.scrollEle.scrollTop; // 滚动的高度
236
+ throttleByHeight = () => {
237
+ this.scrollTop = this.scrollEle.scrollTop;
238
+ // 滚动的高度
239
+ let delta = this.prevScrollTop - this.scrollTop;
240
+ delta = delta < 0 ? 0 - delta : delta;
238
241
 
239
- var delta = _this.prevScrollTop - _this.scrollTop;
240
- delta = delta < 0 ? 0 - delta : delta;
241
- delta > _this.reactDelta && _this.onScrollReal();
242
+ delta > this.reactDelta && this.onScrollReal();
242
243
  };
243
244
 
244
- _this.getUseChildrenList = function () {
245
- return _this.state.filterChildren || _this.state.children;
246
- };
245
+ // 列表可展示所有 children
246
+ getUseChildrenList = () => this.state.filterChildren || this.state.children;
247
247
 
248
- _this.getStartAndEndIndex = function () {
249
- // 滚动后显示在列表可视区中的第一个 item 的 index
250
- var showIndex = Number((_this.scrollTop / _this.ITEM_HEIGHT).toFixed(0));
251
- var startIndex = showIndex - ITEM_ELEMENT_NUMBER < 0 ? 0 : showIndex - ITEM_ELEMENT_NUMBER / 2;
252
- var endIndex = showIndex + ITEM_ELEMENT_NUMBER;
253
- return {
254
- startIndex: startIndex,
255
- endIndex: endIndex
256
- };
248
+ getStartAndEndIndex = () => {
249
+ // 滚动后显示在列表可视区中的第一个 item 的 index
250
+ const showIndex = Number((this.scrollTop / this.ITEM_HEIGHT).toFixed(0));
251
+
252
+ const startIndex =
253
+ showIndex - ITEM_ELEMENT_NUMBER < 0
254
+ ? 0
255
+ : showIndex - ITEM_ELEMENT_NUMBER / 2;
256
+ const endIndex = showIndex + ITEM_ELEMENT_NUMBER;
257
+ return { startIndex, endIndex };
257
258
  };
258
259
 
259
- _this.setSuperDrowDownMenu = function (visible) {
260
- if (!visible) return;
261
- _this.allList = _this.getUseChildrenList();
262
-
263
- if (!_this.eventTimer || !_this.scrollEle) {
264
- _this.eventTimer = setTimeout(function () {
265
- return _this.addEvent();
266
- }, 0);
267
- } else {
268
- var allHeight = _this.allList.length * _this.ITEM_HEIGHT || 100; // 下拉列表单独重新渲染
269
-
270
- var _this$getStartAndEndI2 = _this.getStartAndEndIndex(),
271
- startIndex = _this$getStartAndEndI2.startIndex,
272
- endIndex = _this$getStartAndEndI2.endIndex;
273
-
274
- setTimeout(function () {
275
- _this.wrap && _this.wrap.reactList(allHeight, startIndex, endIndex);
276
- }, 0);
277
- }
260
+ // 须使用 setTimeout 确保在 dom 加载完成之后添加事件
261
+ setSuperDrowDownMenu = visible => {
262
+ if (!visible) return;
263
+
264
+ this.allList = this.getUseChildrenList();
265
+
266
+ if (!this.eventTimer || !this.scrollEle) {
267
+ this.eventTimer = setTimeout(() => this.addEvent(), 0);
268
+ } else {
269
+ const allHeight = this.allList.length * this.ITEM_HEIGHT || 100;
270
+ // 下拉列表单独重新渲染
271
+ const { startIndex, endIndex } = this.getStartAndEndIndex();
272
+ setTimeout(() => {
273
+ this.wrap && this.wrap.reactList(allHeight, startIndex, endIndex);
274
+ }, 0);
275
+ }
278
276
  };
279
277
 
280
- _this.onDropdownVisibleChange = function (visible) {
281
- var onDropdownVisibleChange = _this.props.onDropdownVisibleChange;
282
- onDropdownVisibleChange && onDropdownVisibleChange(visible);
283
- var _this$state = _this.state,
284
- value = _this$state.value,
285
- children = _this$state.children; // 关闭下拉框前清空筛选条件,防止下次打开任然显示筛选后的 options
286
-
287
- if (!visible) {
288
- // 定时器确保关闭后再设置 filterChildren,防止列表刷新闪烁
289
- setTimeout(function () {
290
- _this.setState({
291
- filterChildren: null
292
- });
293
-
294
- _this.setDefaultScrollTop(value);
295
- }, 100); // this.removeEvent();
296
- } else {
297
- // this.addEvent();
298
- if (value) {
299
- // 如果已有 value, 设置默认滚动位置
300
- _this.setDefaultScrollTop(); // 设置下拉列表显示数据
301
-
302
-
303
- _this.setSuperDrowDownMenu(visible);
304
- } else if (!value && value !== 0 && children && children.length > 0) {
305
- // 无数据时,下拉回归至第一个
306
- var val = children[0].props.value;
307
-
308
- _this.setDefaultScrollTop(val);
278
+ onDropdownVisibleChange = visible => {
279
+ const { onDropdownVisibleChange } = this.props;
280
+ onDropdownVisibleChange && onDropdownVisibleChange(visible);
281
+
282
+ const { value, children } = this.state;
283
+ // 关闭下拉框前清空筛选条件,防止下次打开任然显示筛选后的 options
284
+ if (!visible) {
285
+ // 定时器确保关闭后再设置 filterChildren,防止列表刷新闪烁
286
+ setTimeout(() => {
287
+ this.setState({ filterChildren: null });
288
+ this.setDefaultScrollTop(value);
289
+ }, 100);
290
+ // this.removeEvent();
291
+ } else {
292
+ // this.addEvent();
293
+ if (value) {
294
+ // 如果已有 value, 设置默认滚动位置
295
+ this.setDefaultScrollTop();
296
+ // 设置下拉列表显示数据
297
+ this.setSuperDrowDownMenu(visible);
298
+ } else if (!value && value !== 0 && children && children.length > 0) { // 无数据时,下拉回归至第一个
299
+ const val = children[0].props.value;
300
+ this.setDefaultScrollTop(val);
301
+ }
309
302
  }
310
- }
311
303
  };
312
304
 
313
- _this.onDeselect = function (value) {
314
- var onDeselect = _this.props.onDeselect;
315
- onDeselect && onDeselect(value);
305
+ onDeselect = value => {
306
+ const { onDeselect } = this.props;
307
+ onDeselect && onDeselect(value);
316
308
  };
317
309
 
318
- _this.onChange = function (value, opt) {
319
- var _this$props2 = _this.props,
320
- showSearch = _this$props2.showSearch,
321
- onChange = _this$props2.onChange,
322
- autoClearSearchValue = _this$props2.autoClearSearchValue,
323
- maxCount = _this$props2.maxCount,
324
- mode = _this$props2.mode;
325
-
326
- if (showSearch || _this.isMultiple) {
327
- // 搜索模式下选择后是否需要重置搜索状态
328
- if (autoClearSearchValue !== false) {
329
- _this.setState({
330
- filterChildren: null
331
- }, function () {
332
- // 搜索成功后重新设置列表的总高度
333
- _this.setSuperDrowDownMenu(true);
334
- });
310
+ // 在搜索重新计算下拉滚动条高度
311
+ onChange = (value, opt) => {
312
+ const { showSearch, onChange, autoClearSearchValue, maxCount, mode } = this.props;
313
+ if (showSearch || this.isMultiple) {
314
+ // 搜索模式下选择后是否需要重置搜索状态
315
+ if (autoClearSearchValue !== false) {
316
+ this.setState({ filterChildren: null }, () => {
317
+ // 搜索成功后重新设置列表的总高度
318
+ this.setSuperDrowDownMenu(true);
319
+ });
320
+ }
335
321
  }
336
- }
337
322
 
338
- if (mode === 'multiple') {
339
- if (value.length <= maxCount) {
340
- _this.setState({
341
- value: value
342
- });
323
+ if (mode === 'multiple') {
324
+ if (value.length <= maxCount) {
325
+ this.setState({ value });
326
+ }
327
+ } else {
328
+ this.setState({ value });
343
329
  }
344
- } else {
345
- _this.setState({
346
- value: value
347
- });
348
- }
330
+ onChange && onChange(value, opt);
349
331
 
350
- onChange && onChange(value, opt);
351
-
352
- if (mode !== 'multiple') {
353
- _this.select && _this.select.blur();
354
- }
332
+ if (mode !== 'multiple') {
333
+ this.select &&
334
+ this.select.blur();
335
+ }
355
336
  };
356
337
 
357
- _this.onSearch = function (v) {
358
- var _this$props3 = _this.props,
359
- showSearch = _this$props3.showSearch,
360
- onSearch = _this$props3.onSearch,
361
- filterOption = _this$props3.filterOption,
362
- arr = _this$props3.children;
363
-
364
- var children = _this.turnChildren(arr);
365
-
366
- if (showSearch && filterOption !== false) {
367
- // 须根据 filterOption(如有该自定义函数)手动 filter 搜索匹配的列表
368
- var filterChildren = null;
369
-
370
- if (typeof filterOption === 'function') {
371
- filterChildren = children.filter(function (item) {
372
- return filterOption(v, item);
373
- });
374
- } else if (filterOption === undefined) {
375
- filterChildren = children.filter(function (item) {
376
- return _this.filterOption(v, item);
377
- });
378
- } // 搜索框有值,去除disabled=true的children
379
-
380
-
381
- var newFilterChild = [];
382
- filterChildren && filterChildren.forEach(function (item, index) {
383
- if (!item.props.disabled) {
384
- newFilterChild.push(item);
385
- }
386
- });
387
- filterChildren = newFilterChild; // 设置下拉列表显示数据
388
-
389
- _this.setState({
390
- filterChildren: v === '' ? null : filterChildren
391
- }, function () {
392
- setTimeout(function () {
393
- // 搜索后需要重置滚动位置到0,防止上次 scrollTop 位置无数据
394
- if (filterChildren) {
395
- _this.scrollTop = 0;
396
-
397
- _this.scrollEle.scrollTo(0, 0);
398
- } // 搜索成功后需要重新设置列表的总高度
399
-
400
-
401
- _this.setSuperDrowDownMenu(true);
402
- }, 0);
403
- });
404
- }
338
+ onSearch = v => {
339
+ const { showSearch, onSearch, filterOption, children: arr } = this.props;
340
+ let children = this.turnChildren(arr);
341
+ if (showSearch && filterOption !== false) {
342
+ // 须根据 filterOption(如有该自定义函数)手动 filter 搜索匹配的列表
343
+ let filterChildren = null;
344
+ if (typeof filterOption === 'function') {
345
+ filterChildren = children.filter(item => filterOption(v, item));
346
+ } else if (filterOption === undefined) {
347
+ filterChildren = children.filter(item => this.filterOption(v, item));
348
+ }
405
349
 
406
- onSearch && onSearch(v);
350
+ // 搜索框有值,去除disabled=true的children
351
+ let newFilterChild = [];
352
+ filterChildren &&
353
+ filterChildren.forEach((item, index) => {
354
+ if (!item.props.disabled) {
355
+ newFilterChild.push(item);
356
+ }
357
+ });
358
+ filterChildren = newFilterChild;
359
+
360
+ // 设置下拉列表显示数据
361
+ this.setState(
362
+ { filterChildren: v === '' ? null : filterChildren },
363
+ () => {
364
+ setTimeout(() => {
365
+ // 搜索后需要重置滚动位置到0,防止上次 scrollTop 位置无数据
366
+ if (filterChildren) {
367
+ this.scrollTop = 0;
368
+ this.scrollEle.scrollTo(0, 0);
369
+ }
370
+ // 搜索成功后需要重新设置列表的总高度
371
+ this.setSuperDrowDownMenu(true);
372
+ }, 0);
373
+ }
374
+ );
375
+ }
376
+ onSearch && onSearch(v);
407
377
  };
408
378
 
409
- _this.filterOption = function (v, option) {
410
- // 自定义过滤对应的 option 属性配置
411
- var filterProps = _this.props.optionFilterProp || 'value';
412
- return "".concat(option.props[filterProps]).indexOf(v) >= 0;
379
+ filterOption = (v, option) => {
380
+ // 自定义过滤对应的 option 属性配置
381
+ const filterProps = this.props.optionFilterProp || 'value';
382
+ return `${option.props[filterProps]}`.indexOf(v) >= 0;
413
383
  };
414
384
 
415
- _this.setDefaultScrollTop = function (data) {
416
- var value = _this.state.value;
417
- var arr = _this.props.children;
418
-
419
- var children = _this.turnChildren(arr);
420
-
421
- var val = data || data === 0 ? data : value;
422
-
423
- for (var i = 0; i < children.length; i++) {
424
- var item = children[i];
425
- var itemValue = item.props.value;
426
-
427
- if (itemValue === val || Array.isArray(val) && val.includes(itemValue)) {
428
- var _ret = function () {
429
- var targetScrollTop = i * _this.ITEM_HEIGHT;
430
- setTimeout(function () {
431
- if (!_this.scrollEle) {
432
- _this.addEvent();
433
- }
434
-
435
- _this.scrollEle && _this.scrollEle.scrollTo(0, targetScrollTop);
436
- }, 100);
437
- return {
438
- v: void 0
439
- };
440
- }();
441
-
442
- if (_typeof(_ret) === "object") return _ret.v;
385
+ setDefaultScrollTop = (data) => {
386
+ const { value } = this.state;
387
+ const { children: arr } = this.props;
388
+ const children = this.turnChildren(arr);
389
+
390
+ let val = (data || data === 0) ? data : value;
391
+
392
+ for (let i = 0; i < children.length; i++) {
393
+ const item = children[i];
394
+ const itemValue = item.props.value;
395
+ if (
396
+ itemValue === val ||
397
+ (Array.isArray(val) && val.includes(itemValue))
398
+ ) {
399
+ const targetScrollTop = i * this.ITEM_HEIGHT;
400
+
401
+ setTimeout(() => {
402
+ if (!this.scrollEle) {
403
+ this.addEvent();
404
+ }
405
+ this.scrollEle &&
406
+ this.scrollEle.scrollTo(0, targetScrollTop);
407
+ }, 100);
408
+ return;
409
+ }
443
410
  }
444
- }
445
411
  };
446
412
 
447
- _this.removeEvent = function () {
448
- if (!_this.scrollEle) return;
449
-
450
- _this.scrollEle.removeEventListener('scroll', _this.onScroll, false);
451
-
452
- if (!_this.inputEle) return;
453
-
454
- _this.inputEle.removeEventListener('keydown', _this.onKeyDown, false);
413
+ removeEvent = () => {
414
+ if (!this.scrollEle) return;
415
+ this.scrollEle.removeEventListener('scroll', this.onScroll, false);
416
+ if (!this.inputEle) return;
417
+ this.inputEle.removeEventListener('keydown', this.onKeyDown, false);
455
418
  };
456
419
 
457
- var _mode = props.mode,
458
- defaultValue = props.defaultValue,
459
- _value = props.value,
460
- optionHeight = props.optionHeight,
461
- _arr = props.children;
462
- _this.isMultiple = ['tags', 'multiple'].includes(_mode);
463
-
464
- var _children = _this.turnChildren(_arr); // 设置默认 value
465
-
466
-
467
- var defaultV = _this.isMultiple ? [] : '';
468
- defaultV = _value || defaultValue || defaultV;
469
- _this.state = {
470
- children: _children || [],
471
- filterChildren: null,
472
- // 筛选后的 options,优先显示,所以清除筛选后手动设为 null
473
- value: defaultV,
474
- maxWidth: null,
475
- selectWidth: null
476
- }; // 下拉菜单项行高
477
-
478
- _this.ITEM_HEIGHT = optionHeight || ITEM_HEIGHT_CFG[props.size || 'default']; // 可视区 dom 高度
479
-
480
- _this.visibleDomHeight = _this.ITEM_HEIGHT * ITEM_ELEMENT_NUMBER; // 滚动时重新渲染的 scrollTop 判断值,大于 reactDelta 则刷新下拉列表
481
-
482
- _this.reactDelta = _this.visibleDomHeight / 3; // 是否拖动滚动条快速滚动状态
483
-
484
- _this.isStopReact = false; // 上一次滚动的 scrollTop 值
485
-
486
- _this.prevScrollTop = 0; // 上一次按下方向键时 scrollTop 值
487
-
488
- _this.prevTop = 0;
489
- _this.scrollTop = 0; // className
420
+ render() {
421
+ const { maxWidth, selectWidth } = this.state;
422
+ let {
423
+ dropdownStyle,
424
+ optionLabelProp,
425
+ dropdownClassName,
426
+ ...props
427
+ } = this.props;
490
428
 
491
- _this.dropdownClassName = "dc".concat(+new Date());
492
- _this.id = "sid".concat(+new Date());
493
- return _this;
494
- }
429
+ this.allList = this.getUseChildrenList();
495
430
 
496
- _createClass(SuperSelect, [{
497
- key: "componentDidMount",
498
- value: function componentDidMount() {
499
- var _this2 = this;
431
+ this.allHeight = this.allList.length * this.ITEM_HEIGHT || 100;
432
+ const { startIndex, endIndex } = this.getStartAndEndIndex();
500
433
 
501
- // defaultOpens=true 时添加滚动事件
502
- setTimeout(function () {
503
- _this2.addEvent();
504
- }, 500);
505
- var arr = this.props.children;
506
- var children = this.turnChildren(arr); // if (children && children.length > 0) {
507
-
508
- this.formulaWidth(); // }
509
- }
510
- }, {
511
- key: "componentDidUpdate",
512
- value: function componentDidUpdate(prevProps) {
513
- var _this$props4 = this.props,
514
- mode = _this$props4.mode,
515
- defaultValue = _this$props4.defaultValue,
516
- value = _this$props4.value,
517
- children = _this$props4.children;
518
- var arr = this.turnChildren(children);
519
-
520
- if (prevProps.children !== children) {
521
- this.isMultiple = ['tags', 'multiple'].includes(mode);
522
- this.setState({
523
- children: arr || [],
524
- filterChildren: null
525
- });
526
-
527
- if (arr && arr.length > 0) {
528
- this.formulaWidth();
434
+ let dynamicWidth = maxWidth;
435
+ if (this.allList.length === 0 || maxWidth < selectWidth) {
436
+ dynamicWidth = selectWidth;
529
437
  }
530
- }
531
438
 
532
- if (prevProps.value !== value) {
533
- // 更新时设置默认 value
534
- var defaultV = this.isMultiple ? [] : '';
535
- defaultV = value || defaultValue || defaultV;
536
- this.setState({
537
- value: defaultV
538
- });
539
- }
540
- }
541
- }, {
542
- key: "componentWillUnmount",
543
- value: function componentWillUnmount() {
544
- this.removeEvent();
545
- }
546
- }, {
547
- key: "render",
548
- value: function render() {
549
- var _this3 = this;
550
-
551
- var _this$state2 = this.state,
552
- maxWidth = _this$state2.maxWidth,
553
- selectWidth = _this$state2.selectWidth;
554
-
555
- var _this$props5 = this.props,
556
- dropdownStyle = _this$props5.dropdownStyle,
557
- optionLabelProp = _this$props5.optionLabelProp,
558
- dropdownClassName = _this$props5.dropdownClassName,
559
- props = _objectWithoutProperties(_this$props5, ["dropdownStyle", "optionLabelProp", "dropdownClassName"]);
560
-
561
- this.allList = this.getUseChildrenList();
562
- this.allHeight = this.allList.length * this.ITEM_HEIGHT || 100;
563
-
564
- var _this$getStartAndEndI3 = this.getStartAndEndIndex(),
565
- startIndex = _this$getStartAndEndI3.startIndex,
566
- endIndex = _this$getStartAndEndI3.endIndex;
567
-
568
- var dynamicWidth = maxWidth;
569
-
570
- if (this.allList.length === 0 || maxWidth < selectWidth) {
571
- dynamicWidth = selectWidth;
572
- }
573
-
574
- dropdownStyle = _objectSpread({
575
- maxHeight: "".concat(DROPDOWN_HEIGHT, "px")
576
- }, dropdownStyle, {
577
- overflow: 'auto',
578
- position: 'relative',
579
- maxWidth: dynamicWidth
580
- });
581
- var value = this.state.value; // 判断处于 antd Form 中时不自动设置 value
582
-
583
- var _props = _objectSpread({}, props); // 先删除 value,再手动赋值,防止空 value 影响 placeholder
584
-
585
-
586
- delete _props.value; // value 为空字符会隐藏 placeholder,改为 undefined
587
-
588
- if (typeof value === 'string' && !value) {
589
- _props.value = undefined;
590
- } else {
591
- _props.value = value;
592
- }
593
-
594
- optionLabelProp = optionLabelProp || 'children';
595
- return _react["default"].createElement(_select["default"], _extends({}, _props, {
596
- id: this.id,
597
- onSearch: this.onSearch,
598
- onChange: this.onChange,
599
- dropdownClassName: "".concat(this.dropdownClassName, " ").concat(dropdownClassName || ''),
600
- optionLabelProp: optionLabelProp,
601
- dropdownStyle: dropdownStyle,
602
- onDropdownVisibleChange: this.onDropdownVisibleChange,
603
- onDeselect: this.onDeselect,
604
- ref: function ref(ele) {
605
- return _this3.select = ele;
606
- },
607
- dropdownRender: function dropdownRender(menu, props) {
608
- if (_this3.allList.length === 0) {
609
- return _react["default"].createElement("div", {
610
- style: {
611
- padding: '5px 12px'
612
- }
613
- }, _react["default"].createElement(_empty["default"], {
614
- image: _empty["default"].PRESENTED_IMAGE_SIMPLE
615
- }));
616
- }
617
-
618
- return _react["default"].createElement(_DropDownWrap["default"], _extends({
619
- startIndex: startIndex,
620
- endIndex: endIndex,
621
- allHeight: _this3.allHeight,
622
- menu: menu,
623
- itemHeight: _this3.ITEM_HEIGHT
624
- }, {
625
- ref: function ref(ele) {
626
- _this3.wrap = ele;
627
- }
628
- }));
439
+ dropdownStyle = {
440
+ maxHeight: `${DROPDOWN_HEIGHT}px`,
441
+ ...dropdownStyle,
442
+ overflow: 'auto',
443
+ position: 'relative',
444
+ maxWidth: dynamicWidth
445
+ };
446
+
447
+ const { value } = this.state;
448
+ // 判断处于 antd Form 中时不自动设置 value
449
+ const _props = { ...props };
450
+ // 先删除 value,再手动赋值,防止空 value 影响 placeholder
451
+ delete _props.value;
452
+
453
+ // value 为空字符会隐藏 placeholder,改为 undefined
454
+ if (typeof value === 'string' && !value) {
455
+ _props.value = undefined;
456
+ } else {
457
+ _props.value = value;
629
458
  }
630
- }), this.allList);
631
- }
632
- }]);
633
459
 
634
- return SuperSelect;
635
- }(_react.PureComponent);
460
+ optionLabelProp = optionLabelProp || 'children';
461
+ return (
462
+ <Select
463
+ {..._props}
464
+ id={this.id}
465
+ onSearch={this.onSearch}
466
+ onChange={this.onChange}
467
+ dropdownClassName={`${this.dropdownClassName} ${dropdownClassName ||
468
+ ''}`}
469
+ optionLabelProp={optionLabelProp}
470
+ dropdownStyle={dropdownStyle}
471
+ onDropdownVisibleChange={this.onDropdownVisibleChange}
472
+ onDeselect={this.onDeselect}
473
+ ref={ele => (this.select = ele)}
474
+ dropdownRender={(menu, props) => {
475
+ if (this.allList.length === 0) {
476
+ return <div style={{ padding: '5px 12px' }}><Empty image={Empty.PRESENTED_IMAGE_SIMPLE} /></div>;
477
+ }
478
+
479
+ return (
480
+ <DropDownWrap
481
+ {...{
482
+ startIndex,
483
+ endIndex,
484
+ allHeight: this.allHeight,
485
+ menu,
486
+ itemHeight: this.ITEM_HEIGHT
487
+ }}
488
+ ref={ele => {
489
+ this.wrap = ele;
490
+ }}
491
+ />
492
+ );
493
+ }}
494
+ >
495
+ {this.allList}
496
+ </Select>
497
+ );
498
+ }
499
+ }
636
500
 
637
501
  SuperSelect.Option = Option;
638
- var _default = SuperSelect;
639
- exports["default"] = _default;
502
+
503
+ export default SuperSelect;