UNPKG

10.7 kBJavaScriptView Raw
1import "core-js/modules/es7.object.get-own-property-descriptors";
2import "core-js/modules/es6.symbol";
3import "core-js/modules/web.dom.iterable";
4import "core-js/modules/es6.array.iterator";
5import "core-js/modules/es6.object.to-string";
6import "core-js/modules/es6.object.keys";
7import _extends from "@babel/runtime/helpers/extends";
8import _defineProperty from "@babel/runtime/helpers/defineProperty";
9import "core-js/modules/es6.regexp.split";
10
11function 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
13function _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
15import React from 'react';
16import MonthCalendar from './rc-calendar/lib/MonthCalendar';
17import RcDatePicker from './rc-calendar/lib/Picker';
18import GregorianCalendar from 'gregorian-calendar';
19import classNames from 'classnames';
20import { findDOMNode } from 'react-dom';
21import ToolTip from "@beisen-platform/tool-tip";
22import DateIcon from '@beisen-platform/react-icons/lib/icons/FormRiqi.js';
23import createReactClass from '@beisen/create-react-class';
24import uuid from 'uuid/v4';
25export 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); //如果未改值直接点击确定按钮,将时分秒修改为传入值timeValue
65 }
66
67 props.onChange(timeValue, dateValue, isToday);
68 },
69 calendarOnKeyDown: function calendarOnKeyDown(e) {},
70 clearShowInput: function clearShowInput() {},
71 changeInput: function changeInput(val) {
72 //同步input值
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 // Click clear button
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)); // default width for showTime
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 } // if(props.showStatus=='searchBtn'){
188 // icon = <span className='icon-label' />;
189 // showClassName = 'date-time-search-status ';
190 // }
191 // var showStatus = this.props.showStatus;
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 // //TODO : showStatus这个状态是否可以移除了,不知道使用场景
233 // if(showStatus=='searchBtn'){
234 // return (
235 // <span className='search-btn icon-gongzuorili'> <CalendarIcon /> </span>
236 // )
237 // }else{
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