1 | import "core-js/modules/es7.object.get-own-property-descriptors";
|
2 | import "core-js/modules/es6.symbol";
|
3 | import "core-js/modules/web.dom.iterable";
|
4 | import "core-js/modules/es6.array.iterator";
|
5 | import "core-js/modules/es6.object.to-string";
|
6 | import "core-js/modules/es6.object.keys";
|
7 | import _extends from "@babel/runtime/helpers/extends";
|
8 | import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
9 | import "core-js/modules/es6.regexp.split";
|
10 |
|
11 | 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; }
|
12 |
|
13 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
14 |
|
15 | import React from 'react';
|
16 | import MonthCalendar from './rc-calendar/lib/MonthCalendar';
|
17 | import RcDatePicker from './rc-calendar/lib/Picker';
|
18 | import GregorianCalendar from 'gregorian-calendar';
|
19 | import classNames from 'classnames';
|
20 | import { findDOMNode } from 'react-dom';
|
21 | import ToolTip from "@beisen-platform/tool-tip";
|
22 | import DateIcon from '@beisen-platform/react-icons/lib/icons/FormRiqi.js';
|
23 | import createReactClass from '@beisen/create-react-class';
|
24 | import uuid from 'uuid/v4';
|
25 | export default function createPicker(TheCalendar) {
|
26 | return createReactClass({
|
27 | getInitialState: function getInitialState() {
|
28 | this.domId = uuid();
|
29 | return {
|
30 | value: this.props.parseDateFromValue(this.props.value || this.props.defaultValue),
|
31 | tabId: Math.random()
|
32 | };
|
33 | },
|
34 | componentDidMount: function componentDidMount() {
|
35 | this.setState({
|
36 | inputTarget: findDOMNode(this.refs.picker)
|
37 | });
|
38 | },
|
39 | componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
|
40 | if (nextProps.value) {
|
41 | this.setState({
|
42 | value: nextProps.parseDateFromValue(nextProps.value)
|
43 | });
|
44 | } else {
|
45 | this.setState({
|
46 | value: ''
|
47 | });
|
48 | }
|
49 | },
|
50 | handleChange: function handleChange(value, isToday) {
|
51 | var props = this.props;
|
52 |
|
53 | if (!('value' in props)) {
|
54 | this.setState({
|
55 | value: value
|
56 | });
|
57 | }
|
58 |
|
59 | var dateValue = value ? props.getFormatter().format(value) : '';
|
60 | var timeValue = value && new Date(dateValue);
|
61 |
|
62 | if (!isToday && dateValue && this.props.timeValue && !window.timeChange && this.props.value.length == 0) {
|
63 | dateValue = dateValue.split(" ")[0] + ' ' + this.props.timeValue;
|
64 | timeValue = new Date(dateValue);
|
65 | }
|
66 |
|
67 | props.onChange(timeValue, dateValue, isToday);
|
68 | },
|
69 | calendarOnKeyDown: function calendarOnKeyDown(e) {},
|
70 | clearShowInput: function clearShowInput() {},
|
71 | changeInput: function changeInput(val) {
|
72 |
|
73 | this.setState({
|
74 | value: val
|
75 | });
|
76 | },
|
77 | DateInputBlur: function DateInputBlur(e) {
|
78 | var self = this;
|
79 |
|
80 | if (e.target.className.indexOf("icon-close") >= 0) {
|
81 | return;
|
82 | }
|
83 |
|
84 | var dom = document.getElementsByClassName("ant-calendar-picker-container")[0];
|
85 |
|
86 | if (!dom) {
|
87 | document.removeEventListener('mouseup', self.DateInputBlur);
|
88 | self.props.hiddenClose();
|
89 | self.setState({
|
90 | InputActive: false
|
91 | });
|
92 | }
|
93 |
|
94 | var btn = e.target.className.indexOf("-btn") >= 0 && e.target.className.indexOf('-footer-btn') == -1;
|
95 | var month = e.target.className.indexOf("-panel-month") >= 0;
|
96 | var year = e.target.className.indexOf("-panel-year") >= 0;
|
97 | var date = e.target.className.indexOf("-date") >= 0;
|
98 |
|
99 | if (dom && dom.contains && (!dom.contains(e.target) || btn || year && this.props.type == "YearPicker" || month && this.props.type == "MonthPicker" || date && !this.props.showTime)) {
|
100 | self.setState({
|
101 | InputActive: false
|
102 | });
|
103 | self.props.hiddenClose();
|
104 | document.removeEventListener('mouseup', self.DateInputBlur);
|
105 | }
|
106 | },
|
107 | onClear: function onClear() {
|
108 | this.props.onChange('');
|
109 | },
|
110 | DateInputClick: function DateInputClick() {
|
111 | var self = this;
|
112 | this.setState({
|
113 | InputActive: true
|
114 | });
|
115 | document.removeEventListener('mouseup', self.DateInputBlur);
|
116 | document.addEventListener('mouseup', self.DateInputBlur);
|
117 | },
|
118 | handleFocus: function handleFocus() {
|
119 | this.setState({
|
120 | InputActive: true
|
121 | });
|
122 | },
|
123 | render: function render() {
|
124 | var _classNames,
|
125 | _this = this;
|
126 |
|
127 | var props = this.props;
|
128 | var locale = props.locale;
|
129 |
|
130 |
|
131 |
|
132 | var defaultCalendarValue = new GregorianCalendar(locale);
|
133 | defaultCalendarValue.setTime(Date.now());
|
134 | var placeholder = 'placeholder' in props ? props.placeholder : locale.lang.placeholder;
|
135 | var disabledTime = props.showTime ? props.disabledTime : null;
|
136 | var calendarClassName = classNames((_classNames = {}, _defineProperty(_classNames, 'ant-calendar-time', props.showTime), _defineProperty(_classNames, 'ant-calendar-month', MonthCalendar === TheCalendar), _classNames));
|
137 | var pickerChangeHandler = {
|
138 | onChange: this.handleChange
|
139 | };
|
140 | var calendarHandler = {
|
141 | onOk: this.handleChange
|
142 | };
|
143 |
|
144 | if (props.showTime) {
|
145 | pickerChangeHandler.onChange = function (value) {
|
146 |
|
147 | if (value === null) {
|
148 | _this.handleChange(value);
|
149 | }
|
150 | };
|
151 | } else {
|
152 | calendarHandler = {};
|
153 | }
|
154 |
|
155 | var calendar = React.createElement(TheCalendar, _extends({
|
156 | disabledDate: props.disabledDate,
|
157 | disabledTime: disabledTime,
|
158 | locale: locale.lang,
|
159 | lablePos: props.lablePos,
|
160 | timeValue: props.timeValue,
|
161 | type: props.type,
|
162 | onClear: this.onClear,
|
163 | yearPicker: props.yearPicker,
|
164 | timePicker: props.timePicker,
|
165 | changeInput: this.changeInput,
|
166 | defaultValue: defaultCalendarValue,
|
167 | dateInputPlaceholder: placeholder,
|
168 | onKeyDown: this.calendarOnKeyDown,
|
169 | clearShowInput: this.clearShowInput,
|
170 | clickDataTable: props.clickDataTable,
|
171 | prefixCls: "ant-calendar",
|
172 | className: calendarClassName
|
173 | }, calendarHandler));
|
174 |
|
175 | var pickerStyle = {};
|
176 | var showClassName = '',
|
177 | icon = React.createElement("span", {
|
178 | onMouseUp: this.DateInputClick,
|
179 | className: "ant-calendar-picker-icon icon-form-riqi"
|
180 | }, React.createElement(DateIcon, null));
|
181 |
|
182 | if (props.showStatus == 'search') {
|
183 | icon = React.createElement("span", {
|
184 | className: "icon-label"
|
185 | });
|
186 | showClassName = 'date-time-search-status ';
|
187 | }
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | var testClass = classNames({
|
195 | 'ant-calendar-picker': true,
|
196 | 'ant-calendar-picker_has-error': !props.disabled && this.props.errorStatus,
|
197 | 'ant-calendar-picker-open': !props.disabled && (this.state.InputActive || this.props.errorStatus)
|
198 | });
|
199 | return React.createElement("span", {
|
200 | ref: "picker",
|
201 | id: this.domId,
|
202 | className: showClassName + testClass,
|
203 | style: _objectSpread({}, pickerStyle, {}, props.style)
|
204 | }, React.createElement(RcDatePicker, _extends({}, this.props, {
|
205 | logicContainerId: props.logicContainerId,
|
206 | showTime: props.showTime
|
207 | ,
|
208 | dateStyle: props.dateStyle
|
209 | ,
|
210 | cmp_id: props.cmp_id
|
211 | ,
|
212 | transitionName: props.transitionName,
|
213 | disabled: props.disabled,
|
214 | calendar: calendar,
|
215 | value: this.state.value,
|
216 | timeValue: props.timeValue,
|
217 | lablePos: props.lablePos,
|
218 | open: props.IsActive,
|
219 | inputTarget: this.state.inputTarget,
|
220 | inputTargetId: this.domId,
|
221 | popClose: this.popClose,
|
222 | prefixCls: "ant-calendar-picker-container",
|
223 | style: props.popupStyle,
|
224 | align: props.align,
|
225 | showStatus: this.props.showStatus,
|
226 | getCalendarContainer: props.getCalendarContainer,
|
227 | onOpen: props.toggleOpen,
|
228 | changeInput: this.changeInput,
|
229 | onClose: props.toggleOpen
|
230 | }, pickerChangeHandler), function (_ref) {
|
231 | var value = _ref.value;
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 | return React.createElement("span", {
|
239 | style: {
|
240 | "width": "100%"
|
241 | }
|
242 | }, React.createElement(ToolTip, {
|
243 | title: value ? props.getFormatter().format(value) : ''
|
244 | }, React.createElement("div", {
|
245 | className: "date-time_is-hidden-tips"
|
246 | }, value ? props.getFormatter().format(value) : '')), React.createElement("input", {
|
247 | id: _this.state.tabId,
|
248 | readOnly: props.disabled,
|
249 | onMouseUp: _this.DateInputClick,
|
250 | value: value ? props.getFormatter().format(value) : '',
|
251 | placeholder: value ? '' : placeholder,
|
252 | className: props.pickerInputClass + ' input-create-picker ' + (props.IsActive ? 'date-time__input_is-active' : ''),
|
253 | style: props.removeSuffixIcon ? {
|
254 | maxWidth: '100%',
|
255 | width: '100%'
|
256 | } : null,
|
257 | "data-logtype": props.dateStyle == 'DatePicker' && !props.showTime ? 'click' : '',
|
258 | "data-loglabel": "DateTime-Show",
|
259 | "data-logcmpid": props.cmp_id
|
260 |
|
261 | }), props.readonly || props.removeSuffixIcon ? null : icon);
|
262 | }));
|
263 | }
|
264 | });
|
265 | } |
\ | No newline at end of file |