1 | import "core-js/modules/es6.function.name";
|
2 | import _extends from "@babel/runtime/helpers/extends";
|
3 | import "core-js/modules/es6.object.assign";
|
4 | import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
5 | import _createClass from "@babel/runtime/helpers/createClass";
|
6 | import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
7 | import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
8 | import _inherits from "@babel/runtime/helpers/inherits";
|
9 | import React, { Component } from 'react';
|
10 | import omit from 'lodash/omit';
|
11 | import ToolTip from '@beisen-platform/tool-tip';
|
12 | import { decode } from '@beisen-platform/common-func';
|
13 | import CommonInput from '@beisen-platform/common-input';
|
14 | import CloseIcon from '@beisen-platform/react-icons/lib/icons/Close.js';
|
15 | import ArrowDownIcon from '@beisen-platform/react-icons/lib/icons/ArrowdownNomal.js';
|
16 |
|
17 | function empty() {}
|
18 |
|
19 | var Input =
|
20 |
|
21 | function (_Component) {
|
22 | _inherits(Input, _Component);
|
23 |
|
24 | function Input(props) {
|
25 | var _this;
|
26 |
|
27 | _classCallCheck(this, Input);
|
28 |
|
29 | _this = _possibleConstructorReturn(this, _getPrototypeOf(Input).call(this, props));
|
30 |
|
31 | _this.fixControlledValue = function (value, tempValue) {
|
32 | if (!value) {
|
33 | return tempValue ? " " : "";
|
34 | } else {
|
35 | return value;
|
36 | }
|
37 | };
|
38 |
|
39 | _this.handlerKeyDown = function (event) {
|
40 | if (_this.props.readOnly || !_this.props.isShowFindAll) return;
|
41 |
|
42 | if (event.keyCode == 13) {
|
43 | _this.props.onKeyDown(event);
|
44 |
|
45 | _this.props.setComState('isShowDoropList', false);
|
46 |
|
47 | if (Array.isArray(_this.props.listValue) && !_this.props.listValue.length) {
|
48 | _this.refs.input.blur();
|
49 |
|
50 | _this.setState({
|
51 | isFocus: false
|
52 | });
|
53 |
|
54 | _this.props.handlerFindAll(event);
|
55 | }
|
56 | }
|
57 | };
|
58 |
|
59 | _this.handlerBlur = function (event) {
|
60 | if (_this.props.readOnly) return;
|
61 |
|
62 | if (_this.isActiveClear) {
|
63 | _this.isActiveClear = false;
|
64 |
|
65 | _this.refs.input.focus();
|
66 |
|
67 | return;
|
68 | }
|
69 |
|
70 | _this.setState({
|
71 | isFocus: false,
|
72 | pointerEvent: 'auto'
|
73 | });
|
74 |
|
75 | _this.props.onBlur(event);
|
76 | };
|
77 |
|
78 | _this.handlerFocus = function (event) {
|
79 | if (_this.props.readOnly) return;
|
80 |
|
81 | if (_this.props.onlyShowAdvanced) {
|
82 | _this.props.handlerFindAll();
|
83 |
|
84 | _this.refs.input.blur();
|
85 |
|
86 | return;
|
87 | }
|
88 |
|
89 | _this.refs.input.focus();
|
90 |
|
91 | _this.setState({
|
92 | isFocus: true
|
93 | });
|
94 |
|
95 | _this.props.setComState('isShowDoropList', true);
|
96 |
|
97 | _this.props.onFocus(event);
|
98 | };
|
99 |
|
100 | _this.handlerChange = function (event) {
|
101 | _this.props.onChange(event);
|
102 | };
|
103 |
|
104 | _this.handlerMouseOver = function (event) {
|
105 | if (_this.props.readOnly || _this.props.disabled) return;
|
106 |
|
107 | _this.setState({
|
108 | isHover: true
|
109 | });
|
110 | };
|
111 |
|
112 | _this.handlerMouseOut = function (event) {
|
113 | if (_this.props.readOnly || _this.props.disabled) return;
|
114 | var node = event.target;
|
115 |
|
116 | if (node.nodeName.toLowerCase() == 'i') {
|
117 | return;
|
118 | } else {
|
119 | _this.setState({
|
120 | isHover: false
|
121 | });
|
122 | }
|
123 | };
|
124 |
|
125 | _this.clearValue = function (event) {
|
126 | if (_this.state.isFocus) _this.isActiveClear = true;
|
127 |
|
128 | _this.props.onChange('', true);
|
129 | };
|
130 |
|
131 | _this.clearMultiValue = function (event) {
|
132 | if (_this.props.readOnly || _this.props.disabled) return;
|
133 | var node = event.target;
|
134 | var index;
|
135 |
|
136 | if (node.nodeName.toLowerCase() == 'i') {
|
137 | index = node.getAttribute('data-index');
|
138 |
|
139 | _this.props.multipleClear(parseInt(index));
|
140 | }
|
141 | };
|
142 |
|
143 | _this.tipsClick = function () {
|
144 | _this.setState({
|
145 | pointerEvent: "none"
|
146 | });
|
147 |
|
148 | _this.refs.input.focus();
|
149 | };
|
150 |
|
151 | _this.state = {
|
152 | isFocus: false,
|
153 | isHover: false,
|
154 | defaultValue: '',
|
155 | pointerEvent: "auto"
|
156 | };
|
157 |
|
158 | if (props.status == 'search') {
|
159 | _this.state.isFocus = true;
|
160 | }
|
161 |
|
162 | _this.isShowClose = false;
|
163 | return _this;
|
164 | }
|
165 |
|
166 | _createClass(Input, [{
|
167 | key: "componentDidMount",
|
168 | value: function componentDidMount() {
|
169 | if (this.props.status == 'search') {
|
170 | this.refs.input.focus();
|
171 | }
|
172 | }
|
173 | }, {
|
174 | key: "componentDidUpdate",
|
175 | value: function componentDidUpdate(prevProps, prevState) {
|
176 | if (this.props.status == 'edit' && !this.props.readOnly && !this.props.disabled) {
|
177 | var wrapperDom = this.refs.wrapper;
|
178 |
|
179 | var _expectHeight = this.props.promptMsg || this.props.errorMsg ? 46 : 26;
|
180 |
|
181 | if (wrapperDom.offsetHeight > _expectHeight) {} else {
|
182 | if (this.refs && this.refs.topIcon) this.refs.topIcon.style.display = 'block';
|
183 | }
|
184 | }
|
185 | }
|
186 | }, {
|
187 | key: "render",
|
188 | value: function render() {
|
189 | var self = this;
|
190 | var props = Object.assign({}, this.props);
|
191 | var otherProps = omit(props, ['title', 'required', 'multiple']);
|
192 |
|
193 | if ('value' in props) {
|
194 | otherProps.value = decode(this.fixControlledValue(props.value, props.tempValue));
|
195 | delete otherProps.defaultValue;
|
196 | }
|
197 |
|
198 | var _className1 = this.state.isFocus ? " form-item__control_is-active " : "";
|
199 |
|
200 | if (otherProps.value && otherProps.value.length && (this.state.isFocus || this.state.isHover)) {
|
201 | this.isShowClose = true;
|
202 | } else {
|
203 | this.isShowClose = false;
|
204 | }
|
205 |
|
206 | var isHaveMsg;
|
207 |
|
208 | if (props.promptMsg || props.errorMsg) {
|
209 | isHaveMsg = true;
|
210 | } else {
|
211 | isHaveMsg = false;
|
212 | }
|
213 |
|
214 | var _className2 = props.readOnly ? " form-item__control_is-readonly " : "";
|
215 |
|
216 | var _className3 = props.disabled ? " form-item__control_is-disabled " : "";
|
217 |
|
218 | var _className4 = isHaveMsg ? props.promptMsg ? " form-item__control_has-info" : " form-item__control_is-active form-item__control_has-info form-item__control_has-error" : "";
|
219 |
|
220 | var _className5 = props.multiple && props.multiValue && props.multiValue.length > 5 ? ' lookupv2__is-multiple ' : '';
|
221 |
|
222 | var _iconCloseHeight = isHaveMsg ? 25 : 5;
|
223 |
|
224 | if (props.readOnly) otherProps.placeholder = '';
|
225 |
|
226 | if ((props.readOnly || props.disabled) && !props.multiple) {
|
227 | return React.createElement(CommonInput, {
|
228 | readonly: true,
|
229 | errorStatus: isHaveMsg,
|
230 | errorMsg: props.errorMsg,
|
231 | defaultValue: decode(otherProps.value)
|
232 | });
|
233 | } else {
|
234 | return React.createElement("div", {
|
235 | className: "form-item__control" + _className1 + _className2 + _className3 + _className4 + _className5,
|
236 | ref: "wrapper",
|
237 | onMouseOut: this.handlerMouseOut,
|
238 | onMouseOver: this.handlerMouseOver
|
239 | }, React.createElement("ul", {
|
240 | className: "list_horizontal list_wrap form-item__multi-list lookupv2__select-list",
|
241 | onClick: this.clearMultiValue
|
242 | }, props.multiple && props.multiValue.map(function (item, index) {
|
243 | return React.createElement(MultiItem, _extends({
|
244 | key: index
|
245 | }, item, {
|
246 | index: index,
|
247 | readOnly: props.readOnly,
|
248 | disabled: props.disabled
|
249 | }));
|
250 | }), !props.multiple ? React.createElement(ToolTip, {
|
251 | title: decode(otherProps.value),
|
252 | hidden: otherProps.value == ' ' ? true : false
|
253 | }, React.createElement("div", {
|
254 | className: "form-item_is-hidden-tips",
|
255 | style: {
|
256 | pointerEvents: this.state.pointerEvent
|
257 | },
|
258 | onClick: this.tipsClick
|
259 | }, decode(otherProps.value))) : "", !props.multiple ? React.createElement("input", _extends({}, otherProps, {
|
260 | defaultValue: decode(otherProps.value),
|
261 | type: "text",
|
262 | className: "u-input",
|
263 | ref: "input",
|
264 | onKeyDown: this.handlerKeyDown,
|
265 | onFocus: this.handlerFocus,
|
266 | onBlur: this.handlerBlur
|
267 | })) : props.readOnly || props.disabled ? "" : React.createElement("input", _extends({}, otherProps, {
|
268 | type: "text",
|
269 | className: "u-input",
|
270 | ref: "input",
|
271 | onKeyDown: this.handlerKeyDown,
|
272 | onFocus: this.handlerFocus,
|
273 | onBlur: this.handlerBlur
|
274 | }))), React.createElement("span", {
|
275 | className: "form-item__right-icon"
|
276 | }, props.multiple ? "" : React.createElement("i", {
|
277 | className: "u-icon icon-close",
|
278 | ref: "topIcon",
|
279 | onMouseDown: this.clearValue,
|
280 | style: this.isShowClose ? {
|
281 | visibility: 'visible'
|
282 | } : {
|
283 | visibility: 'hidden'
|
284 | }
|
285 | }, React.createElement(CloseIcon, null)), props.status == 'edit' ? React.createElement("i", {
|
286 | className: "u-icon icon-arrowdown",
|
287 | onClick: this.handlerFocus,
|
288 | onBlur: this.handlerBlur
|
289 | }, React.createElement(ArrowDownIcon, {
|
290 | width: 11,
|
291 | height: 6
|
292 | })) : null), isHaveMsg ? React.createElement("span", {
|
293 | className: "form-item__explain"
|
294 | }, props.promptMsg || props.errorMsg) : null);
|
295 | }
|
296 | }
|
297 | }]);
|
298 |
|
299 | return Input;
|
300 | }(Component);
|
301 |
|
302 | Input.defaultProps = {
|
303 | value: '',
|
304 | className: '',
|
305 | placeholder: '',
|
306 | promptMsg: '',
|
307 | errorMsg: '',
|
308 | multiple: false,
|
309 | multiValue: [],
|
310 | onKeyDown: empty,
|
311 | readOnly: false,
|
312 | disabled: false,
|
313 | onBlur: empty,
|
314 | onFocus: empty,
|
315 | onChange: empty,
|
316 | unmountBox: empty,
|
317 | multipleClear: empty
|
318 | };
|
319 | export { Input as default };
|
320 |
|
321 | var MultiItem =
|
322 |
|
323 | function (_Component2) {
|
324 | _inherits(MultiItem, _Component2);
|
325 |
|
326 | function MultiItem() {
|
327 | _classCallCheck(this, MultiItem);
|
328 |
|
329 | return _possibleConstructorReturn(this, _getPrototypeOf(MultiItem).apply(this, arguments));
|
330 | }
|
331 |
|
332 | _createClass(MultiItem, [{
|
333 | key: "render",
|
334 | value: function render() {
|
335 | var props = Object.assign({}, this.props);
|
336 | return React.createElement("li", {
|
337 | className: "form-item__multi-item"
|
338 | }, React.createElement(ToolTip, _extends({}, props, {
|
339 | title: decode(props.name)
|
340 | }), React.createElement("span", {
|
341 | className: "form-item__text"
|
342 | }, decode(props.name))), !props.readOnly && !props.disabled ? React.createElement("i", {
|
343 | className: "u-icon icon-close",
|
344 | "data-index": props.index
|
345 | }, React.createElement(CloseIcon, null)) : '');
|
346 | }
|
347 | }]);
|
348 |
|
349 | return MultiItem;
|
350 | }(Component); |
\ | No newline at end of file |