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.
- package/components/Layout/HeaderActions.js +90 -128
- package/components/LoadingButton/index.js +11 -15
- package/components/QueryListScene/QueryForm.js +7 -4
- package/dist/stats.json +4990 -4990
- package/dist/tntd.js +1 -1
- package/es/Layout/HeaderActions.js +10 -10
- package/es/LoadingButton/index.js +20 -10
- package/es/QueryListScene/QueryForm.js +6 -3
- package/lib/ArrayInput/icon.js +27 -31
- package/lib/ArrayInput/index.js +211 -298
- package/lib/AuthContext.js +2 -13
- package/lib/Columns/index.js +71 -100
- package/lib/DevelopmentLogin/LoginModal.js +79 -141
- package/lib/DevelopmentLogin/index.js +28 -55
- package/lib/Ellipsis/Svg/CopySVG.js +23 -71
- package/lib/Ellipsis/Svg/TickSVG.js +17 -49
- package/lib/Ellipsis/index.js +148 -154
- package/lib/Handle/index.js +72 -109
- package/lib/Icon/fonts/iconfont.js +1 -43
- package/lib/Icon/iconList.js +119 -8
- package/lib/Icon/index.js +13 -45
- package/lib/Img/Contain.js +49 -81
- package/lib/Img/Cover.js +88 -136
- package/lib/Img/index.js +36 -89
- package/lib/Layout/ActionsContext.js +2 -11
- package/lib/Layout/AppList.js +262 -256
- package/lib/Layout/Application.js +119 -135
- package/lib/Layout/Avatar.js +137 -137
- package/lib/Layout/CompatibleLanguage.js +214 -195
- package/lib/Layout/EnterpriseLayout/Avatar.js +156 -168
- package/lib/Layout/EnterpriseLayout/Language.js +75 -100
- package/lib/Layout/EnterpriseLayout/Theme.js +96 -94
- package/lib/Layout/EnterpriseLayout/index.js +32 -45
- package/lib/Layout/GlobalNavigation/NavigationPopup.js +335 -407
- package/lib/Layout/GlobalNavigation/index.js +110 -158
- package/lib/Layout/Header.js +165 -116
- package/lib/Layout/HeaderActions.js +132 -129
- package/lib/Layout/HeaderNavs.js +90 -113
- package/lib/Layout/HeaderTabs.js +312 -278
- package/lib/Layout/Iconfont.js +2 -15
- package/lib/Layout/Language.js +63 -102
- package/lib/Layout/Layout.js +272 -261
- package/lib/Layout/Logo.js +132 -87
- package/lib/Layout/OrgAppList.js +440 -319
- package/lib/Layout/SideMenu.js +429 -343
- package/lib/Layout/Theme.js +95 -124
- package/lib/Layout/checkAuth.js +21 -35
- package/lib/Layout/createActions.js +38 -51
- package/lib/Layout/images/index.js +33 -41
- package/lib/Layout/index.js +110 -161
- package/lib/Layout/paaslayout/CompactSideMenu.js +200 -178
- package/lib/Layout/paaslayout/Header.js +84 -90
- package/lib/Layout/paaslayout/Logo.js +27 -32
- package/lib/Layout/paaslayout/SideMenu.js +161 -174
- package/lib/Layout/paaslayout/index.js +240 -261
- package/lib/Layout/storage.js +20 -78
- package/lib/Layout/utils.js +93 -143
- package/lib/LoadingButton/index.js +25 -57
- package/lib/Modal/index.js +83 -108
- package/lib/Page/Box.js +56 -81
- package/lib/Page/index.js +151 -173
- package/lib/Page/utils.js +12 -30
- package/lib/QueryForm/Field/Checkbox.js +11 -33
- package/lib/QueryForm/Field/Select.js +63 -99
- package/lib/QueryForm/Field/SelectInput.js +69 -114
- package/lib/QueryForm/Field/fieldsMap.js +30 -52
- package/lib/QueryForm/Field/index.js +76 -158
- package/lib/QueryForm/createActions.js +50 -65
- package/lib/QueryForm/index.js +304 -383
- package/lib/QueryForm/useForm.js +6 -17
- package/lib/QueryListScene/List.js +290 -366
- package/lib/QueryListScene/QueryForm.js +93 -158
- package/lib/QueryListScene/QueryListScene.js +33 -87
- package/lib/QueryListScene/Title.js +10 -20
- package/lib/QueryListScene/Toolbar.js +8 -31
- package/lib/QueryListScene/createActions.js +64 -79
- package/lib/QueryListScene/index.js +23 -40
- package/lib/QueryListScene/useActions.js +6 -17
- package/lib/Select/DropDownWrap.js +60 -124
- package/lib/Select/index.js +425 -561
- package/lib/Table/ResizableTable/index.js +77 -121
- package/lib/Table/index.js +19 -51
- package/lib/Title/index.js +34 -52
- package/lib/index.js +19 -159
- package/lib/locale.js +48 -63
- package/package.json +1 -1
- package/lib/Layout/EnterpriseLayout/Header.js +0 -113
- package/lib/Layout/EnterpriseLayout/HeaderActions.js +0 -104
package/lib/Select/index.js
CHANGED
|
@@ -1,639 +1,503 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
import { Select, Empty } from 'antd';
|
|
3
|
+
import DropDownWrap from './DropDownWrap';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
+
const ARROW_CODE = {
|
|
15
|
+
40: 'down',
|
|
16
|
+
38: 'up'
|
|
17
|
+
};
|
|
39
18
|
|
|
40
|
-
|
|
19
|
+
const DROPDOWN_HEIGHT = 224;
|
|
41
20
|
|
|
42
|
-
|
|
21
|
+
const Option = Select.Option;
|
|
43
22
|
|
|
44
|
-
|
|
23
|
+
class SuperSelect extends PureComponent {
|
|
24
|
+
constructor(props) {
|
|
25
|
+
super(props);
|
|
45
26
|
|
|
46
|
-
|
|
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
|
-
|
|
31
|
+
// 设置默认 value
|
|
32
|
+
let defaultV = this.isMultiple ? [] : '';
|
|
33
|
+
defaultV = value || defaultValue || defaultV;
|
|
49
34
|
|
|
50
|
-
|
|
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
|
-
|
|
62
|
+
}
|
|
53
63
|
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
124
|
-
|
|
117
|
+
this.setState({
|
|
118
|
+
selectWidth,
|
|
119
|
+
maxWidth: formulaMaxWidth
|
|
120
|
+
});
|
|
121
|
+
}
|
|
125
122
|
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
|
|
132
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
+
componentWillUnmount() {
|
|
155
|
+
this.removeEvent();
|
|
156
|
+
}
|
|
154
157
|
|
|
155
|
-
|
|
156
|
-
return {
|
|
158
|
+
getItemStyle = i => ({
|
|
157
159
|
position: 'absolute',
|
|
158
|
-
top:
|
|
160
|
+
top: this.ITEM_HEIGHT * i,
|
|
159
161
|
width: '100%',
|
|
160
|
-
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
|
-
|
|
165
|
+
addEvent = () => {
|
|
166
|
+
this.scrollEle = document.querySelector(`.${this.dropdownClassName}`);
|
|
167
|
+
// 下拉菜单未展开时元素不存在
|
|
168
|
+
if (!this.scrollEle) return;
|
|
170
169
|
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
this.scrollEle.addEventListener('scroll', this.onScroll, false);
|
|
171
|
+
this.inputEle = document.querySelector(`#${this.id}`);
|
|
173
172
|
|
|
174
|
-
|
|
173
|
+
if (!this.inputEle) return;
|
|
174
|
+
this.inputEle.addEventListener('keydown', this.onKeyDown, false);
|
|
175
175
|
};
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
177
|
+
// 模拟 antd select 按下 上下箭头 键时滚动列表
|
|
178
|
+
onKeyDown = e => {
|
|
179
|
+
const { keyCode } = e || {};
|
|
180
180
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
189
|
-
|
|
187
|
+
const { offsetTop } = activeItem;
|
|
188
|
+
const isUp = ARROW_CODE[keyCode] === 'up';
|
|
189
|
+
const isDown = ARROW_CODE[keyCode] === 'down';
|
|
190
190
|
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
}, 100);
|
|
216
|
-
};
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
217
206
|
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
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
|
-
|
|
226
|
+
onScrollReal = () => {
|
|
227
|
+
this.allList = this.getUseChildrenList();
|
|
228
|
+
const { startIndex, endIndex } = this.getStartAndEndIndex();
|
|
230
229
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
237
|
-
|
|
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
|
-
|
|
240
|
-
delta = delta < 0 ? 0 - delta : delta;
|
|
241
|
-
delta > _this.reactDelta && _this.onScrollReal();
|
|
242
|
+
delta > this.reactDelta && this.onScrollReal();
|
|
242
243
|
};
|
|
243
244
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
};
|
|
245
|
+
// 列表可展示所有 children
|
|
246
|
+
getUseChildrenList = () => this.state.filterChildren || this.state.children;
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
314
|
-
|
|
315
|
-
|
|
305
|
+
onDeselect = value => {
|
|
306
|
+
const { onDeselect } = this.props;
|
|
307
|
+
onDeselect && onDeselect(value);
|
|
316
308
|
};
|
|
317
309
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
323
|
+
if (mode === 'multiple') {
|
|
324
|
+
if (value.length <= maxCount) {
|
|
325
|
+
this.setState({ value });
|
|
326
|
+
}
|
|
327
|
+
} else {
|
|
328
|
+
this.setState({ value });
|
|
343
329
|
}
|
|
344
|
-
|
|
345
|
-
_this.setState({
|
|
346
|
-
value: value
|
|
347
|
-
});
|
|
348
|
-
}
|
|
330
|
+
onChange && onChange(value, opt);
|
|
349
331
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
332
|
+
if (mode !== 'multiple') {
|
|
333
|
+
this.select &&
|
|
334
|
+
this.select.blur();
|
|
335
|
+
}
|
|
355
336
|
};
|
|
356
337
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
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
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
-
|
|
492
|
-
_this.id = "sid".concat(+new Date());
|
|
493
|
-
return _this;
|
|
494
|
-
}
|
|
429
|
+
this.allList = this.getUseChildrenList();
|
|
495
430
|
|
|
496
|
-
|
|
497
|
-
|
|
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
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
635
|
-
|
|
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
|
-
|
|
639
|
-
|
|
502
|
+
|
|
503
|
+
export default SuperSelect;
|