tntd 1.3.57 → 1.3.62

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 (110) hide show
  1. package/babel.config.js +2 -2
  2. package/components/Layout/Application.js +1 -1
  3. package/components/QueryForm/Field/index.js +2 -1
  4. package/components/QueryListScene/List.js +17 -13
  5. package/lib/0645cf743e4e44ca9da321d689897f07.png +0 -0
  6. package/lib/09db77de0c24fa0f45f8a5cf299a3d11.png +0 -0
  7. package/lib/1d0b52448de217857b270af807e9360d.png +0 -0
  8. package/lib/25d78d77c9c2f0d403e5d899ceb5b1ef.png +0 -0
  9. package/lib/27fa44ff0c98e1594d79b73045aabedf.png +0 -0
  10. package/lib/2c95075adb68d6131b59cae9fa554ec2.png +0 -0
  11. package/lib/377c871d922a25c773a9e7c2f42ed7c0.png +0 -0
  12. package/lib/3d901589b40bd56ff1fde2bbb700bfe1.png +0 -0
  13. package/lib/4abe481e130d7be0574e45573de8beb7.png +0 -0
  14. package/lib/95ee2260a509cd630d89c5367ed1973b.png +0 -0
  15. package/lib/ArrayInput/icon.js +31 -27
  16. package/lib/ArrayInput/index.js +298 -211
  17. package/lib/AuthContext.js +13 -2
  18. package/lib/BlockHeader/README.md +83 -0
  19. package/lib/BlockHeader/fonts/OswaldLight.ttf +0 -0
  20. package/lib/BlockHeader/index.js +42 -0
  21. package/lib/BlockHeader/index.less +141 -0
  22. package/lib/Columns/index.js +100 -71
  23. package/lib/DevelopmentLogin/LoginModal.js +141 -79
  24. package/lib/DevelopmentLogin/index.js +55 -28
  25. package/lib/Ellipsis/Svg/CopySVG.js +71 -23
  26. package/lib/Ellipsis/Svg/TickSVG.js +49 -17
  27. package/lib/Ellipsis/index.js +155 -149
  28. package/lib/Handle/index.js +109 -72
  29. package/lib/Icon/fonts/iconfont.js +43 -1
  30. package/lib/Icon/iconList.js +8 -119
  31. package/lib/Icon/index.js +45 -13
  32. package/lib/Img/Contain.js +81 -49
  33. package/lib/Img/Cover.js +136 -88
  34. package/lib/Img/index.js +89 -36
  35. package/lib/Layout/ActionsContext.js +11 -2
  36. package/lib/Layout/AppList.js +256 -262
  37. package/lib/Layout/Application.js +135 -119
  38. package/lib/Layout/Avatar.js +137 -137
  39. package/lib/Layout/CompatibleLanguage.js +195 -214
  40. package/lib/Layout/EnterpriseLayout/Avatar.js +168 -156
  41. package/lib/Layout/EnterpriseLayout/Language.js +100 -75
  42. package/lib/Layout/EnterpriseLayout/Theme.js +94 -96
  43. package/lib/Layout/EnterpriseLayout/index.js +45 -32
  44. package/lib/Layout/GlobalNavigation/NavigationPopup.js +407 -335
  45. package/lib/Layout/GlobalNavigation/index.js +158 -110
  46. package/lib/Layout/Header.js +116 -165
  47. package/lib/Layout/HeaderActions.js +129 -170
  48. package/lib/Layout/HeaderNavs.js +113 -90
  49. package/lib/Layout/HeaderTabs.js +278 -312
  50. package/lib/Layout/Iconfont.js +15 -2
  51. package/lib/Layout/Language.js +102 -63
  52. package/lib/Layout/Layout.js +261 -272
  53. package/lib/Layout/Logo.js +87 -132
  54. package/lib/Layout/OrgAppList.js +319 -440
  55. package/lib/Layout/SideMenu.js +343 -429
  56. package/lib/Layout/Theme.js +124 -95
  57. package/lib/Layout/checkAuth.js +35 -21
  58. package/lib/Layout/createActions.js +51 -38
  59. package/lib/Layout/images/index.js +41 -33
  60. package/lib/Layout/index.js +161 -110
  61. package/lib/Layout/locale.js +53 -0
  62. package/lib/Layout/paaslayout/CompactSideMenu.js +178 -200
  63. package/lib/Layout/paaslayout/Header.js +90 -84
  64. package/lib/Layout/paaslayout/Logo.js +32 -27
  65. package/lib/Layout/paaslayout/SideMenu.js +174 -161
  66. package/lib/Layout/paaslayout/index.js +261 -240
  67. package/lib/Layout/paaslayout/index.less +75 -0
  68. package/lib/Layout/storage.js +78 -20
  69. package/lib/Layout/utils.js +143 -93
  70. package/lib/LoadingButton/index.js +57 -29
  71. package/lib/Modal/index.js +108 -83
  72. package/lib/Page/Box.js +81 -56
  73. package/lib/Page/index.js +173 -151
  74. package/lib/Page/utils.js +30 -12
  75. package/lib/QueryForm/Field/Checkbox.js +33 -11
  76. package/lib/QueryForm/Field/Select.js +99 -63
  77. package/lib/QueryForm/Field/SelectInput.js +114 -69
  78. package/lib/QueryForm/Field/fieldsMap.js +52 -30
  79. package/lib/QueryForm/Field/index.js +158 -75
  80. package/lib/QueryForm/createActions.js +65 -50
  81. package/lib/QueryForm/index.js +382 -303
  82. package/lib/QueryForm/useForm.js +17 -6
  83. package/lib/QueryListScene/Field/SelectInput.js +115 -0
  84. package/lib/QueryListScene/Field/fieldsMap.js +52 -0
  85. package/lib/QueryListScene/Field/index.js +159 -0
  86. package/lib/QueryListScene/Field/select.js +100 -0
  87. package/lib/QueryListScene/List.js +362 -285
  88. package/lib/QueryListScene/QueryForm/index.js +423 -0
  89. package/lib/QueryListScene/QueryForm/index.less +141 -0
  90. package/lib/QueryListScene/QueryForm.js +159 -91
  91. package/lib/QueryListScene/QueryListScene.js +87 -33
  92. package/lib/QueryListScene/Title.js +20 -10
  93. package/lib/QueryListScene/Toolbar.js +31 -8
  94. package/lib/QueryListScene/createActions.js +79 -64
  95. package/lib/QueryListScene/index.js +40 -23
  96. package/lib/QueryListScene/useActions.js +17 -6
  97. package/lib/Select/DropDownWrap.js +124 -60
  98. package/lib/Select/index.js +563 -426
  99. package/lib/Table/ResizableTable/index.js +121 -77
  100. package/lib/Table/index.js +51 -19
  101. package/lib/Title/index.js +52 -34
  102. package/lib/b9dd5ff3622296fbee51ed68f4bca1bf.png +0 -0
  103. package/lib/bd2921989f9296089ba58efb7a76f3ef.png +0 -0
  104. package/lib/index.html +6 -0
  105. package/lib/index.js +159 -19
  106. package/lib/locale.js +63 -48
  107. package/lib/main.css +16420 -0
  108. package/lib/tntd.js +2 -0
  109. package/lib/tntd.js.LICENSE.txt +36 -0
  110. package/package.json +1 -1
@@ -1,504 +1,641 @@
1
- import React, { PureComponent } from 'react';
2
- import { Select, Empty } from 'antd';
3
- import DropDownWrap from './DropDownWrap';
1
+ "use strict";
4
2
 
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
- };
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
13
7
 
14
- const ARROW_CODE = {
15
- 40: 'down',
16
- 38: 'up'
17
- };
8
+ require("antd/es/empty/style");
18
9
 
19
- const DROPDOWN_HEIGHT = 224;
10
+ var _empty = _interopRequireDefault(require("antd/es/empty"));
20
11
 
21
- const Option = Select.Option;
12
+ require("antd/es/select/style");
22
13
 
23
- class SuperSelect extends PureComponent {
24
- constructor(props) {
25
- super(props);
14
+ var _select = _interopRequireDefault(require("antd/es/select"));
26
15
 
27
- const { mode, defaultValue, value, optionHeight, children: arr } = props;
28
- this.isMultiple = ['tags', 'multiple'].includes(mode);
29
- const children = this.turnChildren(arr);
16
+ var _react = _interopRequireWildcard(require("react"));
30
17
 
31
- // 设置默认 value
32
- let defaultV = this.isMultiple ? [] : '';
33
- defaultV = value || defaultValue || defaultV;
18
+ var _DropDownWrap = _interopRequireDefault(require("./DropDownWrap"));
34
19
 
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()}`;
20
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
61
21
 
62
- }
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; }
63
23
 
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
- }
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
75
25
 
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
- }
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); }
94
27
 
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));
111
- }
112
- if (arr.length > 0) {
113
- formulaMaxWidth = Math.max(...arr);
114
- }
115
- }
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; }
116
29
 
117
- this.setState({
118
- selectWidth,
119
- maxWidth: formulaMaxWidth
120
- });
121
- }
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; }
122
31
 
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
- }
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; }
37
+
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); }
39
+
40
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
41
+
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); } }
43
+
44
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
45
+
46
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
47
+
48
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
49
+
50
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
51
+
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); }
53
+
54
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
55
+
56
+ // 页面实际渲染的下拉菜单数量,实际为 2 * ITEM_ELEMENT_NUMBER
57
+ var ITEM_ELEMENT_NUMBER = 30; // Select size 配置
131
58
 
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();
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);
144
96
  }
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);
122
+
123
+ for (var i = 0; i < children.length; i++) {
124
+ var val = children[i].props.children;
125
+
126
+ var textWidth = _this.getTextPixelWith(val);
127
+
128
+ arr.push(textWidth.toFixed(2));
145
129
  }
146
- if (prevProps.value !== value) {
147
- // 更新时设置默认 value
148
- let defaultV = this.isMultiple ? [] : '';
149
- defaultV = value || defaultValue || defaultV;
150
- this.setState({ value: defaultV });
130
+
131
+ if (arr.length > 0) {
132
+ formulaMaxWidth = Math.max.apply(Math, arr);
151
133
  }
152
- }
134
+ }
153
135
 
154
- componentWillUnmount() {
155
- this.removeEvent();
156
- }
136
+ _this.setState({
137
+ selectWidth: selectWidth,
138
+ maxWidth: formulaMaxWidth
139
+ });
140
+ };
157
141
 
158
- getItemStyle = i => ({
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); // 测量文字
151
+
152
+ return dimension.width;
153
+ };
154
+
155
+ _this.getItemStyle = function (i) {
156
+ return {
159
157
  position: 'absolute',
160
- top: this.ITEM_HEIGHT * i,
158
+ top: _this.ITEM_HEIGHT * i,
161
159
  width: '100%',
162
- height: this.ITEM_HEIGHT
163
- });
160
+ height: _this.ITEM_HEIGHT
161
+ };
162
+ };
163
+
164
+ _this.addEvent = function () {
165
+ _this.scrollEle = document.querySelector(".".concat(_this.dropdownClassName)); // 下拉菜单未展开时元素不存在
164
166
 
165
- addEvent = () => {
166
- this.scrollEle = document.querySelector(`.${this.dropdownClassName}`);
167
- // 下拉菜单未展开时元素不存在
168
- if (!this.scrollEle) return;
167
+ if (!_this.scrollEle) return;
169
168
 
170
- this.scrollEle.addEventListener('scroll', this.onScroll, false);
171
- this.inputEle = document.querySelector(`#${this.id}`);
169
+ _this.scrollEle.addEventListener('scroll', _this.onScroll, false);
172
170
 
173
- if (!this.inputEle) return;
174
- this.inputEle.addEventListener('keydown', this.onKeyDown, false);
171
+ _this.inputEle = document.querySelector("#".concat(_this.id));
172
+ if (!_this.inputEle) return;
173
+
174
+ _this.inputEle.addEventListener('keydown', _this.onKeyDown, false);
175
175
  };
176
176
 
177
- // 模拟 antd select 按下 上下箭头 键时滚动列表
178
- onKeyDown = e => {
179
- const { keyCode } = e || {};
177
+ _this.onKeyDown = function (e) {
178
+ var _ref = e || {},
179
+ keyCode = _ref.keyCode;
180
180
 
181
- setTimeout(() => {
182
- const activeItem = document.querySelector(
183
- `.${this.dropdownClassName} .ant-select-dropdown-menu-item-active`
184
- );
185
- if (!activeItem) return;
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'; // 在所有列表第一行按上键
186
187
 
187
- const { offsetTop } = activeItem;
188
- const isUp = ARROW_CODE[keyCode] === 'up';
189
- const isDown = ARROW_CODE[keyCode] === 'down';
188
+ if (offsetTop - _this.prevTop > DROPDOWN_HEIGHT && isUp) {
189
+ _this.scrollEle.scrollTo(0, _this.allHeight - DROPDOWN_HEIGHT);
190
190
 
191
- // 在所有列表第一行按上键
192
- if (offsetTop - this.prevTop > DROPDOWN_HEIGHT && isUp) {
193
- this.scrollEle.scrollTo(0, this.allHeight - DROPDOWN_HEIGHT);
194
- this.prevTop = this.allHeight;
191
+ _this.prevTop = _this.allHeight;
192
+ return;
193
+ } // 在所有列表中最后一行按下键
195
194
 
196
- return;
197
- }
198
195
 
199
- // 在所有列表中最后一行按下键
200
- if (this.prevTop > offsetTop + DROPDOWN_HEIGHT && isDown) {
201
- this.scrollEle.scrollTo(0, 0);
202
- this.prevTop = 0;
196
+ if (_this.prevTop > offsetTop + DROPDOWN_HEIGHT && isDown) {
197
+ _this.scrollEle.scrollTo(0, 0);
203
198
 
204
- return;
205
- }
199
+ _this.prevTop = 0;
200
+ return;
201
+ }
206
202
 
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);
222
- };
203
+ _this.prevTop = offsetTop; // 向下滚动到下拉框最后一行时,向下滚动一行的高度
223
204
 
224
- onScroll = () => this.throttleByHeight(this.onScrollReal);
205
+ if (offsetTop > _this.scrollEle.scrollTop + DROPDOWN_HEIGHT - _this.ITEM_HEIGHT + 10 && isDown) {
206
+ _this.scrollEle.scrollTo(0, _this.scrollTop + _this.ITEM_HEIGHT);
225
207
 
226
- onScrollReal = () => {
227
- this.allList = this.getUseChildrenList();
228
- const { startIndex, endIndex } = this.getStartAndEndIndex();
208
+ return;
209
+ } // 向上滚动到下拉框第一一行时,向上滚动一行的高度
229
210
 
230
- this.prevScrollTop = this.scrollTop;
231
- // 重新渲染列表组件 Wrap
232
- const allHeight = this.allList.length * this.ITEM_HEIGHT || 100;
233
- this.wrap.reactList(allHeight, startIndex, endIndex);
211
+
212
+ if (offsetTop < _this.scrollEle.scrollTop && isUp) {
213
+ _this.scrollEle.scrollTo(0, _this.scrollTop - _this.ITEM_HEIGHT);
214
+ }
215
+ }, 100);
216
+ };
217
+
218
+ _this.onScroll = function () {
219
+ return _this.throttleByHeight(_this.onScrollReal);
234
220
  };
235
221
 
236
- throttleByHeight = () => {
237
- this.scrollTop = this.scrollEle.scrollTop;
238
- // 滚动的高度
239
- let delta = this.prevScrollTop - this.scrollTop;
240
- delta = delta < 0 ? 0 - delta : delta;
222
+ _this.onScrollReal = function () {
223
+ _this.allList = _this.getUseChildrenList();
241
224
 
242
- delta > this.reactDelta && this.onScrollReal();
225
+ var _this$getStartAndEndI = _this.getStartAndEndIndex(),
226
+ startIndex = _this$getStartAndEndI.startIndex,
227
+ endIndex = _this$getStartAndEndI.endIndex;
228
+
229
+ _this.prevScrollTop = _this.scrollTop; // 重新渲染列表组件 Wrap
230
+
231
+ var allHeight = _this.allList.length * _this.ITEM_HEIGHT || 100;
232
+
233
+ _this.wrap.reactList(allHeight, startIndex, endIndex);
243
234
  };
244
235
 
245
- // 列表可展示所有 children
246
- getUseChildrenList = () => this.state.filterChildren || this.state.children;
236
+ _this.throttleByHeight = function () {
237
+ _this.scrollTop = _this.scrollEle.scrollTop; // 滚动的高度
238
+
239
+ var delta = _this.prevScrollTop - _this.scrollTop;
240
+ delta = delta < 0 ? 0 - delta : delta;
241
+ delta > _this.reactDelta && _this.onScrollReal();
242
+ };
247
243
 
248
- getStartAndEndIndex = () => {
249
- // 滚动后显示在列表可视区中的第一个 item 的 index
250
- const showIndex = Number((this.scrollTop / this.ITEM_HEIGHT).toFixed(0));
244
+ _this.getUseChildrenList = function () {
245
+ return _this.state.filterChildren || _this.state.children;
246
+ };
251
247
 
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 };
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
+ };
258
257
  };
259
258
 
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
- }
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
+ }
276
278
  };
277
279
 
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
- }
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);
302
309
  }
310
+ }
303
311
  };
304
312
 
305
- onDeselect = value => {
306
- const { onDeselect } = this.props;
307
- onDeselect && onDeselect(value);
313
+ _this.onDeselect = function (value) {
314
+ var onDeselect = _this.props.onDeselect;
315
+ onDeselect && onDeselect(value);
308
316
  };
309
317
 
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
- }
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
+ });
321
335
  }
336
+ }
322
337
 
323
- if (mode === 'multiple') {
324
- if (value.length <= maxCount) {
325
- this.setState({ value });
326
- }
327
- } else {
328
- this.setState({ value });
338
+ if (mode === 'multiple') {
339
+ if (value.length <= maxCount) {
340
+ _this.setState({
341
+ value: value
342
+ });
329
343
  }
330
- onChange && onChange(value, opt);
344
+ } else {
345
+ _this.setState({
346
+ value: value
347
+ });
348
+ }
331
349
 
332
- if (mode !== 'multiple') {
333
- this.select &&
334
- this.select.blur();
335
- }
350
+ onChange && onChange(value, opt);
351
+
352
+ if (mode !== 'multiple') {
353
+ _this.select && _this.select.blur();
354
+ }
336
355
  };
337
356
 
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
- }
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; // 设置下拉列表显示数据
349
388
 
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);
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
+ }
405
+
406
+ onSearch && onSearch(v);
377
407
  };
378
408
 
379
- filterOption = (v, option) => {
380
- // 自定义过滤对应的 option 属性配置
381
- const filterProps = this.props.optionFilterProp || 'value';
382
- return `${option.props[filterProps]}`.indexOf(v) >= 0;
409
+ _this.filterOption = function (v, option) {
410
+ // 自定义过滤对应的 option 属性配置
411
+ var filterProps = _this.props.optionFilterProp || 'value';
412
+ return "".concat(option.props[filterProps]).indexOf(v) >= 0;
383
413
  };
384
414
 
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
- }
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;
410
443
  }
444
+ }
411
445
  };
412
446
 
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);
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);
418
455
  };
419
456
 
420
- render() {
421
- const { maxWidth, selectWidth } = this.state;
422
- let {
423
- dropdownStyle,
424
- optionLabelProp,
425
- dropdownClassName,
426
- ...props
427
- } = this.props;
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);
428
463
 
429
- this.allList = this.getUseChildrenList();
464
+ var _children = _this.turnChildren(_arr); // 设置默认 value
430
465
 
431
- this.allHeight = this.allList.length * this.ITEM_HEIGHT || 100;
432
- const { startIndex, endIndex } = this.getStartAndEndIndex();
433
466
 
434
- let dynamicWidth = maxWidth;
435
- if (this.allList.length === 0 || maxWidth < selectWidth) {
436
- dynamicWidth = selectWidth;
437
- }
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
490
+
491
+ _this.dropdownClassName = "dc".concat(+new Date());
492
+ _this.id = "sid".concat(+new Date());
493
+ return _this;
494
+ }
495
+
496
+ _createClass(SuperSelect, [{
497
+ key: "componentDidMount",
498
+ value: function componentDidMount() {
499
+ var _this2 = this;
438
500
 
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;
501
+ // defaultOpens=true 时添加滚动事件
502
+ setTimeout(function () {
503
+ _this2.addEvent();
504
+ }, 500);
505
+ var arr = this.props.children;
506
+ var children = this.turnChildren(arr);
507
+
508
+ if (children && children.length > 0) {
509
+ this.formulaWidth();
510
+ }
511
+ }
512
+ }, {
513
+ key: "componentDidUpdate",
514
+ value: function componentDidUpdate(prevProps) {
515
+ var _this$props4 = this.props,
516
+ mode = _this$props4.mode,
517
+ defaultValue = _this$props4.defaultValue,
518
+ value = _this$props4.value,
519
+ children = _this$props4.children;
520
+ var arr = this.turnChildren(children);
521
+
522
+ if (prevProps.children !== children) {
523
+ this.isMultiple = ['tags', 'multiple'].includes(mode);
524
+ this.setState({
525
+ children: arr || [],
526
+ filterChildren: null
527
+ });
528
+
529
+ if (arr && arr.length > 0) {
530
+ this.formulaWidth();
458
531
  }
532
+ }
459
533
 
460
- optionLabelProp = optionLabelProp || 'children';
461
-
462
- return (
463
- <Select
464
- {..._props}
465
- id={this.id}
466
- onSearch={this.onSearch}
467
- onChange={this.onChange}
468
- dropdownClassName={`${this.dropdownClassName} ${dropdownClassName ||
469
- ''}`}
470
- optionLabelProp={optionLabelProp}
471
- dropdownStyle={dropdownStyle}
472
- onDropdownVisibleChange={this.onDropdownVisibleChange}
473
- onDeselect={this.onDeselect}
474
- ref={ele => (this.select = ele)}
475
- dropdownRender={(menu, props) => {
476
- if (this.allList.length === 0) {
477
- return <div style={{ padding: '5px 12px' }}><Empty image={Empty.PRESENTED_IMAGE_SIMPLE} /></div>;
478
- }
479
-
480
- return (
481
- <DropDownWrap
482
- {...{
483
- startIndex,
484
- endIndex,
485
- allHeight: this.allHeight,
486
- menu,
487
- itemHeight: this.ITEM_HEIGHT
488
- }}
489
- ref={ele => {
490
- this.wrap = ele;
491
- }}
492
- />
493
- );
494
- }}
495
- >
496
- {this.allList}
497
- </Select>
498
- );
534
+ if (prevProps.value !== value) {
535
+ // 更新时设置默认 value
536
+ var defaultV = this.isMultiple ? [] : '';
537
+ defaultV = value || defaultValue || defaultV;
538
+ this.setState({
539
+ value: defaultV
540
+ });
541
+ }
542
+ }
543
+ }, {
544
+ key: "componentWillUnmount",
545
+ value: function componentWillUnmount() {
546
+ this.removeEvent();
499
547
  }
500
- }
548
+ }, {
549
+ key: "render",
550
+ value: function render() {
551
+ var _this3 = this;
552
+
553
+ var _this$state2 = this.state,
554
+ maxWidth = _this$state2.maxWidth,
555
+ selectWidth = _this$state2.selectWidth;
556
+
557
+ var _this$props5 = this.props,
558
+ dropdownStyle = _this$props5.dropdownStyle,
559
+ optionLabelProp = _this$props5.optionLabelProp,
560
+ dropdownClassName = _this$props5.dropdownClassName,
561
+ props = _objectWithoutProperties(_this$props5, ["dropdownStyle", "optionLabelProp", "dropdownClassName"]);
562
+
563
+ this.allList = this.getUseChildrenList();
564
+ this.allHeight = this.allList.length * this.ITEM_HEIGHT || 100;
565
+
566
+ var _this$getStartAndEndI3 = this.getStartAndEndIndex(),
567
+ startIndex = _this$getStartAndEndI3.startIndex,
568
+ endIndex = _this$getStartAndEndI3.endIndex;
569
+
570
+ var dynamicWidth = maxWidth;
571
+
572
+ if (this.allList.length === 0 || maxWidth < selectWidth) {
573
+ dynamicWidth = selectWidth;
574
+ }
575
+
576
+ dropdownStyle = _objectSpread({
577
+ maxHeight: "".concat(DROPDOWN_HEIGHT, "px")
578
+ }, dropdownStyle, {
579
+ overflow: 'auto',
580
+ position: 'relative',
581
+ maxWidth: dynamicWidth
582
+ });
583
+ var value = this.state.value; // 判断处于 antd Form 中时不自动设置 value
584
+
585
+ var _props = _objectSpread({}, props); // 先删除 value,再手动赋值,防止空 value 影响 placeholder
586
+
587
+
588
+ delete _props.value; // value 为空字符会隐藏 placeholder,改为 undefined
589
+
590
+ if (typeof value === 'string' && !value) {
591
+ _props.value = undefined;
592
+ } else {
593
+ _props.value = value;
594
+ }
595
+
596
+ optionLabelProp = optionLabelProp || 'children';
597
+ return _react["default"].createElement(_select["default"], _extends({}, _props, {
598
+ id: this.id,
599
+ onSearch: this.onSearch,
600
+ onChange: this.onChange,
601
+ dropdownClassName: "".concat(this.dropdownClassName, " ").concat(dropdownClassName || ''),
602
+ optionLabelProp: optionLabelProp,
603
+ dropdownStyle: dropdownStyle,
604
+ onDropdownVisibleChange: this.onDropdownVisibleChange,
605
+ onDeselect: this.onDeselect,
606
+ ref: function ref(ele) {
607
+ return _this3.select = ele;
608
+ },
609
+ dropdownRender: function dropdownRender(menu, props) {
610
+ if (_this3.allList.length === 0) {
611
+ return _react["default"].createElement("div", {
612
+ style: {
613
+ padding: '5px 12px'
614
+ }
615
+ }, _react["default"].createElement(_empty["default"], {
616
+ image: _empty["default"].PRESENTED_IMAGE_SIMPLE
617
+ }));
618
+ }
619
+
620
+ return _react["default"].createElement(_DropDownWrap["default"], _extends({
621
+ startIndex: startIndex,
622
+ endIndex: endIndex,
623
+ allHeight: _this3.allHeight,
624
+ menu: menu,
625
+ itemHeight: _this3.ITEM_HEIGHT
626
+ }, {
627
+ ref: function ref(ele) {
628
+ _this3.wrap = ele;
629
+ }
630
+ }));
631
+ }
632
+ }), this.allList);
633
+ }
634
+ }]);
501
635
 
502
- SuperSelect.Option = Option;
636
+ return SuperSelect;
637
+ }(_react.PureComponent);
503
638
 
504
- export default SuperSelect;
639
+ SuperSelect.Option = Option;
640
+ var _default = SuperSelect;
641
+ exports["default"] = _default;