amis 1.5.8-beta.2 → 1.6.0

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 (187) hide show
  1. package/lib/components/CalendarMobile.js +5 -5
  2. package/lib/components/CalendarMobile.js.map +2 -2
  3. package/lib/components/Card.d.ts +20 -20
  4. package/lib/components/Cascader.d.ts +123 -0
  5. package/lib/components/Cascader.js +487 -0
  6. package/lib/components/Cascader.js.map +13 -0
  7. package/lib/components/CityArea.d.ts +527 -0
  8. package/lib/components/CityArea.js +177 -0
  9. package/lib/components/CityArea.js.map +13 -0
  10. package/lib/components/ColorPicker.js +4 -3
  11. package/lib/components/ColorPicker.js.map +2 -2
  12. package/lib/components/DatePicker.d.ts +85 -84
  13. package/lib/components/DatePicker.js +7 -6
  14. package/lib/components/DatePicker.js.map +2 -2
  15. package/lib/components/DateRangePicker.js +8 -11
  16. package/lib/components/DateRangePicker.js.map +2 -2
  17. package/lib/components/MonthRangePicker.js +5 -8
  18. package/lib/components/MonthRangePicker.js.map +2 -2
  19. package/lib/components/Picker.d.ts +1 -0
  20. package/lib/components/Picker.js +10 -6
  21. package/lib/components/Picker.js.map +2 -2
  22. package/lib/components/PickerColumn.d.ts +1 -0
  23. package/lib/components/PickerColumn.js +21 -17
  24. package/lib/components/PickerColumn.js.map +2 -2
  25. package/lib/components/PopOverContainer.d.ts +1 -0
  26. package/lib/components/PopOverContainer.js +5 -3
  27. package/lib/components/PopOverContainer.js.map +2 -2
  28. package/lib/components/PopUp.d.ts +1040 -28
  29. package/lib/components/PopUp.js +32 -8
  30. package/lib/components/PopUp.js.map +2 -2
  31. package/lib/components/ResultBox.d.ts +85 -84
  32. package/lib/components/ResultBox.js +7 -3
  33. package/lib/components/ResultBox.js.map +2 -2
  34. package/lib/components/Select.js +9 -6
  35. package/lib/components/Select.js.map +2 -2
  36. package/lib/components/TransferDropDown.d.ts +85 -84
  37. package/lib/components/TransferDropDown.js +9 -6
  38. package/lib/components/TransferDropDown.js.map +2 -2
  39. package/lib/components/calendar/Calendar.d.ts +14 -0
  40. package/lib/components/calendar/Calendar.js +62 -5
  41. package/lib/components/calendar/Calendar.js.map +2 -2
  42. package/lib/components/calendar/DaysView.d.ts +20 -0
  43. package/lib/components/calendar/DaysView.js +51 -4
  44. package/lib/components/calendar/DaysView.js.map +2 -2
  45. package/lib/components/calendar/MonthsView.d.ts +7 -1
  46. package/lib/components/calendar/MonthsView.js +41 -52
  47. package/lib/components/calendar/MonthsView.js.map +2 -2
  48. package/lib/components/calendar/TimeView.d.ts +27 -20
  49. package/lib/components/calendar/TimeView.js +40 -4
  50. package/lib/components/calendar/TimeView.js.map +2 -2
  51. package/lib/components/calendar/YearsView.d.ts +6 -0
  52. package/lib/components/calendar/YearsView.js +15 -6
  53. package/lib/components/calendar/YearsView.js.map +2 -2
  54. package/lib/index.js +1 -1
  55. package/lib/locale/de-DE.js +4 -0
  56. package/lib/locale/de-DE.js.map +2 -2
  57. package/lib/locale/en-US.js +4 -0
  58. package/lib/locale/en-US.js.map +2 -2
  59. package/lib/locale/zh-CN.js +4 -0
  60. package/lib/locale/zh-CN.js.map +2 -2
  61. package/lib/renderers/DropDownButton.d.ts +11 -2
  62. package/lib/renderers/DropDownButton.js +30 -12
  63. package/lib/renderers/DropDownButton.js.map +2 -2
  64. package/lib/renderers/Form/CityDB.js +526 -2
  65. package/lib/renderers/Form/CityDB.js.map +2 -2
  66. package/lib/renderers/Form/InputCity.d.ts +85 -84
  67. package/lib/renderers/Form/InputCity.js +4 -2
  68. package/lib/renderers/Form/InputCity.js.map +2 -2
  69. package/lib/renderers/Form/InputColor.js +6 -2
  70. package/lib/renderers/Form/InputColor.js.map +2 -2
  71. package/lib/renderers/Form/InputDate.js +5 -2
  72. package/lib/renderers/Form/InputDate.js.map +2 -2
  73. package/lib/renderers/Form/InputDateRange.js +6 -2
  74. package/lib/renderers/Form/InputDateRange.js.map +2 -2
  75. package/lib/renderers/Form/Item.d.ts +10 -14
  76. package/lib/renderers/Form/Item.js +7 -5
  77. package/lib/renderers/Form/Item.js.map +2 -2
  78. package/lib/renderers/Form/NestedSelect.d.ts +1 -0
  79. package/lib/renderers/Form/NestedSelect.js +7 -3
  80. package/lib/renderers/Form/NestedSelect.js.map +2 -2
  81. package/lib/renderers/Form/Select.d.ts +2 -0
  82. package/lib/renderers/Form/Select.js +7 -4
  83. package/lib/renderers/Form/Select.js.map +2 -2
  84. package/lib/renderers/Form/TreeSelect.js +4 -4
  85. package/lib/renderers/Form/TreeSelect.js.map +2 -2
  86. package/lib/renderers/Remark.js +2 -1
  87. package/lib/renderers/Remark.js.map +2 -2
  88. package/lib/schemaExtend.js +23 -9
  89. package/lib/schemaExtend.js.map +2 -2
  90. package/lib/themes/ang-ie11.css +312 -29
  91. package/lib/themes/ang.css +312 -29
  92. package/lib/themes/ang.css.map +1 -1
  93. package/lib/themes/antd-ie11.css +312 -29
  94. package/lib/themes/antd.css +312 -29
  95. package/lib/themes/antd.css.map +1 -1
  96. package/lib/themes/cxd-ie11.css +315 -41
  97. package/lib/themes/cxd.css +315 -41
  98. package/lib/themes/cxd.css.map +1 -1
  99. package/lib/themes/dark-ie11.css +312 -29
  100. package/lib/themes/dark.css +312 -29
  101. package/lib/themes/dark.css.map +1 -1
  102. package/lib/themes/default.css +315 -41
  103. package/lib/themes/default.css.map +1 -1
  104. package/lib/utils/helper.d.ts +1 -6
  105. package/lib/utils/helper.js +6 -17
  106. package/lib/utils/helper.js.map +2 -2
  107. package/package.json +1 -2
  108. package/schema.json +2192 -20
  109. package/scss/_properties.scss +10 -6
  110. package/scss/components/_calendar.scss +9 -2
  111. package/scss/components/_cascader.scss +102 -0
  112. package/scss/components/_city-area.scss +27 -0
  113. package/scss/components/_dropdown.scss +39 -9
  114. package/scss/components/_picker-columns.scss +15 -5
  115. package/scss/components/_popup.scss +35 -12
  116. package/scss/components/_result-box.scss +31 -0
  117. package/scss/components/form/_checks.scss +2 -0
  118. package/scss/components/form/_color.scss +2 -2
  119. package/scss/components/form/_date-range.scss +1 -1
  120. package/scss/components/form/_date.scss +46 -1
  121. package/scss/components/form/_nested-select.scss +3 -0
  122. package/scss/components/form/_select.scss +32 -3
  123. package/scss/components/form/_transfer.scss +3 -0
  124. package/scss/components/form/_tree-select.scss +1 -1
  125. package/scss/themes/_common.scss +2 -0
  126. package/scss/themes/_cxd-variables.scss +3 -3
  127. package/scss/themes/cxd.scss +0 -12
  128. package/sdk/ang-ie11.css +368 -29
  129. package/sdk/ang.css +367 -30
  130. package/sdk/antd-ie11.css +368 -29
  131. package/sdk/antd.css +367 -30
  132. package/sdk/charts.js +18 -18
  133. package/sdk/codemirror.js +7 -7
  134. package/sdk/color-picker.js +65 -65
  135. package/sdk/cropperjs.js +3 -3
  136. package/sdk/cxd-ie11.css +370 -42
  137. package/sdk/cxd.css +370 -44
  138. package/sdk/dark-ie11.css +368 -29
  139. package/sdk/dark.css +367 -30
  140. package/sdk/exceljs.js +1 -1
  141. package/sdk/locale/de-DE.js +4 -0
  142. package/sdk/markdown.js +69 -69
  143. package/sdk/papaparse.js +1 -1
  144. package/sdk/renderers/Form/CityDB.js +1 -1
  145. package/sdk/rest.js +18 -18
  146. package/sdk/rich-text.js +62 -62
  147. package/sdk/sdk-ie11.css +370 -42
  148. package/sdk/sdk.css +370 -44
  149. package/sdk/sdk.js +1309 -1227
  150. package/sdk/thirds/hls.js/hls.js +18 -18
  151. package/sdk/thirds/mpegts.js/mpegts.js +2 -2
  152. package/sdk/tinymce.js +57 -57
  153. package/src/components/CalendarMobile.tsx +5 -5
  154. package/src/components/Cascader.tsx +564 -0
  155. package/src/components/CityArea.tsx +315 -0
  156. package/src/components/ColorPicker.tsx +5 -2
  157. package/src/components/DatePicker.tsx +15 -5
  158. package/src/components/DateRangePicker.tsx +52 -43
  159. package/src/components/MonthRangePicker.tsx +44 -38
  160. package/src/components/Picker.tsx +27 -12
  161. package/src/components/PickerColumn.tsx +28 -18
  162. package/src/components/PopOverContainer.tsx +31 -17
  163. package/src/components/PopUp.tsx +55 -13
  164. package/src/components/ResultBox.tsx +10 -1
  165. package/src/components/Select.tsx +20 -23
  166. package/src/components/TransferDropDown.tsx +19 -5
  167. package/src/components/calendar/Calendar.tsx +86 -9
  168. package/src/components/calendar/DaysView.tsx +86 -2
  169. package/src/components/calendar/MonthsView.tsx +56 -63
  170. package/src/components/calendar/TimeView.tsx +82 -29
  171. package/src/components/calendar/YearsView.tsx +25 -6
  172. package/src/locale/de-DE.ts +4 -0
  173. package/src/locale/en-US.ts +4 -0
  174. package/src/locale/zh-CN.ts +4 -0
  175. package/src/renderers/DropDownButton.tsx +69 -35
  176. package/src/renderers/Form/CityDB.ts +526 -2
  177. package/src/renderers/Form/InputCity.tsx +23 -3
  178. package/src/renderers/Form/InputColor.tsx +21 -2
  179. package/src/renderers/Form/InputDate.tsx +10 -1
  180. package/src/renderers/Form/InputDateRange.tsx +9 -1
  181. package/src/renderers/Form/Item.tsx +14 -4
  182. package/src/renderers/Form/NestedSelect.tsx +31 -3
  183. package/src/renderers/Form/Select.tsx +15 -2
  184. package/src/renderers/Form/TreeSelect.tsx +10 -6
  185. package/src/renderers/Remark.tsx +2 -1
  186. package/src/schemaExtend.ts +22 -10
  187. package/src/utils/helper.ts +6 -16
@@ -7,7 +7,23 @@ import CustomCalendarContainer from './CalendarContainer';
7
7
  import cx from 'classnames';
8
8
  import moment from 'moment';
9
9
  import {themeable, ThemeOutterProps, ThemeProps} from '../../theme';
10
- import {convertDateArrayToDate} from '../../utils/helper';
10
+ import {convertArrayValueToMoment, getRange} from "../../utils/helper";
11
+ import {PickerOption} from '../PickerColumn';
12
+
13
+ export type DateType = 'year' | 'month' | 'date' | 'hours' | 'minutes' | 'seconds';
14
+ export interface BoundaryObject {
15
+ max: number;
16
+ min: number;
17
+ }
18
+
19
+ export interface DateBoundary {
20
+ year: BoundaryObject;
21
+ month: BoundaryObject;
22
+ date: BoundaryObject;
23
+ hours: BoundaryObject;
24
+ minutes: BoundaryObject;
25
+ seconds: BoundaryObject;
26
+ }
11
27
 
12
28
  interface BaseDatePickerProps
13
29
  extends Omit<ReactDatePicker.DatetimepickerProps, 'viewMode'> {
@@ -41,6 +57,7 @@ interface BaseDatePickerProps
41
57
  hideHeader?: boolean;
42
58
  updateOn?: string;
43
59
  useMobileUI?: boolean;
60
+ embed?: boolean;
44
61
  showToolbar?: boolean;
45
62
  }
46
63
 
@@ -50,6 +67,16 @@ class BaseDatePicker extends ReactDatePicker {
50
67
  setState: (state: any) => void;
51
68
  getStateFromProps: any;
52
69
 
70
+ timeCellLength = {
71
+ year: 4,
72
+ month: 2,
73
+ date: 2,
74
+ hours: 2,
75
+ minutes: 2,
76
+ seconds: 2,
77
+ milliseconds: 3
78
+ };
79
+
53
80
  constructor(props: any) {
54
81
  super(props);
55
82
  const state = this.getStateFromProps(this.props);
@@ -104,7 +131,9 @@ class BaseDatePicker extends ReactDatePicker {
104
131
  'hideHeader',
105
132
  'updateOn',
106
133
  'useMobileUI',
107
- 'showToolbar'
134
+ 'showToolbar',
135
+ 'embed',
136
+ 'onScheduleClick'
108
137
  ].forEach(key => (props[key] = (this.props as any)[key]));
109
138
 
110
139
  return props;
@@ -202,14 +231,58 @@ class BaseDatePicker extends ReactDatePicker {
202
231
  that.props.onChange(date);
203
232
  };
204
233
 
205
- onConfirm = (value: number[], types: string[]) => {
206
- const currentDate = (
207
- this.state.selectedDate ||
208
- this.state.viewDate ||
209
- moment()
210
- ).clone();
234
+ getDateBoundary = (currentDate: moment.Moment) => {
235
+ const {years, months} = currentDate.toObject();
236
+ const maxDateObject = this.props.maxDate?.toObject();
237
+ const minDateObject = this.props.minDate?.toObject();
211
238
 
212
- const date = convertDateArrayToDate(value, types, currentDate);
239
+ const yearBoundary = {
240
+ max: maxDateObject ? maxDateObject.years : years + 100,
241
+ min: minDateObject ? minDateObject.years : years - 100,
242
+ };
243
+ const monthBoundary = {
244
+ max: years === maxDateObject?.years ? maxDateObject.months : 11,
245
+ min: years === minDateObject?.years ? minDateObject.months : 0
246
+ };
247
+ const dateBoundary = {
248
+ max: years === maxDateObject?.years && months === maxDateObject?.months ? maxDateObject.date : currentDate.daysInMonth(),
249
+ min: years === minDateObject?.years && months === minDateObject?.months ? minDateObject.date : 1
250
+ }
251
+ return {
252
+ year: yearBoundary,
253
+ month: monthBoundary,
254
+ date: dateBoundary,
255
+ hours: {max: 23, min: 0},
256
+ minutes: {max: 59, min: 0},
257
+ seconds: {max: 59, min: 0}
258
+ };
259
+ };
260
+
261
+ timeCell = (value: number, type: DateType) => {
262
+ let str = value + '';
263
+ while (str.length < this.timeCellLength[type])
264
+ str = '0' + str;
265
+ return str;
266
+ };
267
+
268
+ getColumns = (types: DateType[], dateBoundary: DateBoundary) => {
269
+ const columns: { options: PickerOption[] }[] = [];
270
+ types.map((type: DateType) => {
271
+ const options = getRange(dateBoundary[type].min, dateBoundary[type].max, 1).map(item => {
272
+
273
+ return {
274
+ text: type === 'month' ? this.timeCell(item+1, type) : this.timeCell(item, type),
275
+ value: item
276
+ };
277
+ });
278
+ columns.push({options})
279
+ });
280
+ return columns;
281
+ };
282
+
283
+ onConfirm = (value: number[], types: string[]) => {
284
+ const currentDate = (this.state.selectedDate || this.state.viewDate || moment()).clone();
285
+ const date = convertArrayValueToMoment(value, types, currentDate);
213
286
 
214
287
  if (!this.props.value) {
215
288
  this.setState({
@@ -221,6 +294,7 @@ class BaseDatePicker extends ReactDatePicker {
221
294
  this.props.onClose && this.props.onClose();
222
295
  };
223
296
 
297
+
224
298
  render() {
225
299
  const Component = CustomCalendarContainer as any;
226
300
  const viewProps = this.getComponentProps();
@@ -239,6 +313,9 @@ class BaseDatePicker extends ReactDatePicker {
239
313
  }
240
314
 
241
315
  viewProps.onConfirm = this.onConfirm;
316
+ viewProps.getDateBoundary = this.getDateBoundary;
317
+ viewProps.getColumns = this.getColumns;
318
+ viewProps.timeCell = this.timeCell;
242
319
 
243
320
  return (
244
321
  <div className={cx('rdt rdtStatic rdtOpen', this.props.className)}>
@@ -3,9 +3,13 @@ import moment from 'moment';
3
3
  import DaysView from 'react-datetime/src/DaysView';
4
4
  import React from 'react';
5
5
  import Downshift from 'downshift';
6
+ import find from 'lodash/find';
6
7
  import {LocaleProps, localeable} from '../../locale';
7
8
  import {ClassNamesFn} from '../../theme';
8
- import find from 'lodash/find';
9
+ import {isMobile, convertArrayValueToMoment} from "../../utils/helper";
10
+ import Picker from '../Picker';
11
+ import {PickerOption} from '../PickerColumn';
12
+ import {DateType} from './Calendar';
9
13
 
10
14
  interface CustomDaysViewProps extends LocaleProps {
11
15
  classPrefix?: string;
@@ -14,12 +18,16 @@ interface CustomDaysViewProps extends LocaleProps {
14
18
  viewDate: moment.Moment;
15
19
  selectedDate: moment.Moment;
16
20
  minDate: moment.Moment;
21
+ maxDate: moment.Moment;
22
+ useMobileUI: boolean;
23
+ embed: boolean;
17
24
  timeFormat: string;
18
25
  requiredConfirm?: boolean;
19
26
  isEndDate?: boolean;
20
27
  renderDay?: Function;
21
28
  onClose?: () => void;
22
29
  onChange: (value: moment.Moment) => void;
30
+ onConfirm?: (value: number[], types: DateType[]) => void;
23
31
  setDateTimeState: (state: any) => void;
24
32
  setTime: (type: string, amount: number) => void;
25
33
  subtractTime: (
@@ -49,13 +57,44 @@ interface CustomDaysViewProps extends LocaleProps {
49
57
  largeMode?: boolean;
50
58
  onScheduleClick?: (scheduleData: any) => void;
51
59
  hideHeader?: boolean;
60
+ getColumns: (types: DateType[], dateBoundary: void) => any;
61
+ getDateBoundary: (currentDate: moment.Moment) => any;
52
62
  }
53
63
 
54
64
  export class CustomDaysView extends DaysView {
55
65
  props: CustomDaysViewProps;
66
+ state: { columns: { options: PickerOption[] }[]; types: DateType[]; pickerValue: number[]};
67
+ setState: (arg0: any) => () => any;
56
68
  getDaysOfWeek: (locale: any) => any;
57
69
  renderDays: () => JSX.Element;
58
70
 
71
+ constructor(props: any) {
72
+ super(props);
73
+
74
+ const {selectedDate, viewDate, timeFormat} = props;
75
+ const currentDate = (selectedDate || viewDate || moment());
76
+
77
+ const types: DateType[] = ['year', 'month', 'date'];
78
+ timeFormat.split(':').forEach((format: string) => {
79
+ const type: DateType | '' = /h/i.test(format)
80
+ ? 'hours'
81
+ : /m/.test(format)
82
+ ? 'minutes'
83
+ : /s/.test(format)
84
+ ? 'seconds'
85
+ : '';
86
+ type && types.push(type)
87
+ });
88
+
89
+ const dateBoundary = this.props.getDateBoundary(currentDate);
90
+ const columns = this.props.getColumns(types, dateBoundary);
91
+ this.state = {
92
+ columns,
93
+ types,
94
+ pickerValue: currentDate.toArray()
95
+ }
96
+ }
97
+
59
98
  updateSelectedDate = (event: React.MouseEvent<any>) => {
60
99
  // need confirm
61
100
  if (this.props.requiredConfirm) {
@@ -405,11 +444,56 @@ export class CustomDaysView extends DaysView {
405
444
  );
406
445
  };
407
446
 
447
+ onPickerConfirm = (value: number[]) => {
448
+ this.props.onConfirm && this.props.onConfirm(value, this.state.types);
449
+ }
450
+
451
+ onPickerChange = (value: number[], index: number) => {
452
+ const {selectedDate, viewDate} = this.props;
453
+
454
+ // 变更年份、月份的时候,需要更新columns
455
+ if (index === 1 || index === 0) {
456
+ const currentDate = (selectedDate || viewDate || moment()).clone();
457
+
458
+ // 只需计算year 、month
459
+ const selectDate = convertArrayValueToMoment(value, ['year', 'month'], currentDate);
460
+ const dateBoundary = this.props.getDateBoundary(selectDate);
461
+ this.setState({
462
+ columns: this.props.getColumns(this.state.types, dateBoundary),
463
+ pickerValue: value
464
+ });
465
+ }
466
+ }
467
+
468
+ renderPicker = () => {
469
+ const {translate: __} = this.props;
470
+ const title = this.state.types.length > 3 ? __('Date.titleTime') : __('Date.titleDate');
471
+ return (
472
+ <Picker
473
+ translate={this.props.translate}
474
+ locale={this.props.locale}
475
+ title={title}
476
+ columns={this.state.columns}
477
+ value={this.state.pickerValue}
478
+ onChange={this.onPickerChange}
479
+ onConfirm={this.onPickerConfirm}
480
+ onClose={this.cancel}
481
+ />
482
+ );
483
+ };
484
+
408
485
  render() {
486
+ const {viewDate: date, useMobileUI, embed} = this.props;
409
487
  const footer = this.renderFooter();
410
- const date = this.props.viewDate;
411
488
  const locale = date.localeData();
412
489
  const __ = this.props.translate;
490
+ if (isMobile() && useMobileUI && !embed) {
491
+ return (
492
+ <div className="rdtYears">
493
+ {this.renderPicker()}
494
+ </div>
495
+ );
496
+ }
413
497
 
414
498
  const tableChildren = [
415
499
  this.props.hideHeader ? null : <thead key="th">
@@ -4,7 +4,9 @@ import moment from 'moment';
4
4
  import React from 'react';
5
5
  import {LocaleProps, localeable, TranslateFn} from '../../locale';
6
6
  import Picker from '../Picker';
7
- import {convertDateToObject, getRange, isMobile} from '../../utils/helper';
7
+ import {PickerOption} from '../PickerColumn';
8
+ import {getRange, isMobile} from '../../utils/helper';
9
+ import {DateType} from './Calendar';
8
10
 
9
11
  export interface OtherProps {
10
12
  inputFormat?: string;
@@ -31,52 +33,31 @@ export class CustomMonthsView extends MonthsView {
31
33
  onChange?: () => void;
32
34
  onClose?: () => void;
33
35
  onConfirm?: (value: number[], types: string[]) => void;
36
+ getColumns: (types: DateType[], dateBoundary: void) => any;
37
+ timeCell: (value: number, type: DateType) => string;
38
+ getDateBoundary: (currentDate: moment.Moment) => any;
34
39
  useMobileUI: boolean;
35
40
  } & LocaleProps &
36
41
  OtherProps;
37
42
  maxDateObject: {year: number; month: number; day?: number};
38
43
  minDateObject: {year: number; month: number; day?: number};
39
- state: {columns: {options: number[]}[]};
44
+ state: { columns: { options: PickerOption[] }[]; pickerValue: number[]};
40
45
  setState: (arg0: any) => () => any;
41
46
  renderMonths: () => JSX.Element;
42
47
 
48
+
43
49
  constructor(props: any) {
44
50
  super(props);
45
51
 
46
- const {minDate, maxDate, selectedDate, viewDate} = props;
47
- const currentDate = selectedDate || viewDate || moment();
48
- const year = currentDate.year();
49
- this.maxDateObject = maxDate
50
- ? convertDateToObject(maxDate)
51
- : {
52
- year: year + 100,
53
- month: 12
54
- };
55
- this.minDateObject = minDate
56
- ? convertDateToObject(minDate)
57
- : {
58
- year: year - 100,
59
- month: 1
60
- };
61
-
62
- const columns = ['year', 'month'].map((type: 'year' | 'month') => {
63
- if (type === 'month') {
64
- const minMonth =
65
- year === this.minDateObject.year ? this.minDateObject.month : 1;
66
- const maxMonth =
67
- year === this.maxDateObject.year ? this.maxDateObject.month : 12;
68
- return {
69
- options: getRange(minMonth, maxMonth, 1)
70
- };
71
- }
72
- return {
73
- options: getRange(this.minDateObject[type], this.maxDateObject[type], 1)
74
- };
75
- });
52
+ const {selectedDate, viewDate} = props;
53
+ const currentDate = (selectedDate || viewDate || moment());
76
54
 
55
+ const dateBoundary = this.props.getDateBoundary(currentDate);
56
+ const columns = this.props.getColumns(['year', 'month'], dateBoundary);
77
57
  this.state = {
78
- columns
79
- };
58
+ columns,
59
+ pickerValue: currentDate.toArray()
60
+ }
80
61
  }
81
62
 
82
63
  renderMonth = (props: any, month: number) => {
@@ -96,55 +77,66 @@ export class CustomMonthsView extends MonthsView {
96
77
  };
97
78
 
98
79
  onConfirm = (value: number[]) => {
99
- // 将月份的值减1 ,月份是0-11
100
- value[1] && --value[1];
101
80
  this.props.onConfirm && this.props.onConfirm(value, ['year', 'month']);
102
81
  };
103
82
 
104
83
  onPickerChange = (value: number[], index: number) => {
84
+ const {maxDate, minDate} = this.props;
85
+ const year = moment().year();
105
86
  const columns = [...this.state.columns];
87
+ const maxDateObject = maxDate
88
+ ? maxDate.toObject()
89
+ : {
90
+ years: year + 100,
91
+ months: 11
92
+ };
93
+ const minDateObject = minDate
94
+ ? minDate.toObject()
95
+ : {
96
+ years: year - 100,
97
+ months: 0
98
+ };
99
+ let range = [];
106
100
  // 选择年份是最大值的年或者最小值的月时,需要重新计算月分选择的cloumn
107
101
  if (index === 0) {
108
102
  if (
109
- value[0] === this.minDateObject.year &&
110
- value[0] === this.maxDateObject.year
103
+ value[0] === minDateObject.years &&
104
+ value[0] === maxDateObject.years
111
105
  ) {
112
- columns[1] = {
113
- options: getRange(
114
- this.minDateObject.month,
115
- this.maxDateObject.month,
116
- 1
117
- )
118
- };
119
- } else if (value[0] === this.minDateObject.year) {
120
- columns[1] = {
121
- options: getRange(this.minDateObject.month, 12, 1)
122
- };
123
- } else if (value[0] === this.maxDateObject.year) {
124
- columns[1] = {
125
- options: getRange(1, this.maxDateObject.month, 1)
126
- };
127
- } else {
128
- columns[1] = {
129
- options: getRange(1, 12, 1)
130
- };
106
+ range = getRange(minDateObject.months, maxDateObject.months, 1);
131
107
  }
132
- this.setState({columns});
108
+ else if (value[0] === minDateObject.years) {
109
+ range = getRange(minDateObject.months, 11, 1);
110
+ }
111
+ else if (value[0] === maxDateObject.years) {
112
+ range = getRange(0, maxDateObject.months, 1);
113
+ }
114
+ else {
115
+ range = getRange(0, 11, 1);
116
+ }
117
+ columns[1] = {
118
+ options: range.map(i => {
119
+ return {
120
+ text: this.props.timeCell(i+1, 'month'),
121
+ value: i
122
+ };
123
+ })
124
+ };
125
+ this.setState({columns, pickerValue: value});
133
126
  }
134
127
  };
135
128
 
136
129
  renderPicker = () => {
137
- const {selectedDate, viewDate} = this.props;
138
- const currentDate = selectedDate || viewDate || moment();
139
- const year = currentDate.year();
140
- const month = parseInt(currentDate.format('MM'), 10);
130
+ const {translate: __} = this.props;
131
+ const title = __('Date.titleMonth');
141
132
 
142
133
  return (
143
134
  <Picker
144
135
  translate={this.props.translate}
145
136
  locale={this.props.locale}
137
+ title={title}
146
138
  columns={this.state.columns}
147
- value={[year, month]}
139
+ value={this.state.pickerValue}
148
140
  onChange={this.onPickerChange}
149
141
  onConfirm={this.onConfirm}
150
142
  onClose={this.props.onClose}
@@ -156,6 +148,7 @@ export class CustomMonthsView extends MonthsView {
156
148
  const __ = this.props.translate;
157
149
  const showYearHead = !/^mm$/i.test(this.props.inputFormat || '') && !this.props.hideHeader;
158
150
  const canClick = /yy/i.test(this.props.inputFormat || '');
151
+
159
152
  if (isMobile() && this.props.useMobileUI) {
160
153
  return <div className="rdtYears">{this.renderPicker()}</div>;
161
154
  }
@@ -9,35 +9,44 @@ import Picker from '../Picker';
9
9
  import {PickerColumnItem} from '../PickerColumn';
10
10
  import {getRange, isMobile} from '../../utils/helper';
11
11
 
12
+ interface State {
13
+ daypart: any;
14
+ counters: Array<string>;
15
+ [propName: string]: any;
16
+ }
17
+
18
+ interface CustomTimeViewProps {
19
+ viewDate: moment.Moment;
20
+ selectedDate: moment.Moment;
21
+ subtractTime: (
22
+ amount: number,
23
+ type: string,
24
+ toSelected?: moment.Moment
25
+ ) => () => void;
26
+ addTime: (
27
+ amount: number,
28
+ type: string,
29
+ toSelected?: moment.Moment
30
+ ) => () => void;
31
+ showView: (view: string) => () => void;
32
+ timeFormat: string;
33
+ classnames: ClassNamesFn;
34
+ setTime: (type: string, value: any) => void;
35
+ onClose?: () => void;
36
+ onConfirm?: (value: number[], types: string[]) => void;
37
+ useMobileUI: boolean;
38
+ showToolbar?: boolean;
39
+ onChange?: (value: any) => void;
40
+ };
41
+
12
42
  export class CustomTimeView extends TimeView {
13
- props: {
14
- viewDate: moment.Moment;
15
- subtractTime: (
16
- amount: number,
17
- type: string,
18
- toSelected?: moment.Moment
19
- ) => () => void;
20
- addTime: (
21
- amount: number,
22
- type: string,
23
- toSelected?: moment.Moment
24
- ) => () => void;
25
- showView: (view: string) => () => void;
26
- timeFormat: string;
27
- classnames: ClassNamesFn;
28
- setTime: (type: string, value: any) => void;
29
- onClose?: () => void;
30
- onConfirm?: (value: number[], types: string[]) => void;
31
- useMobileUI: boolean;
32
- showToolbar?: boolean;
33
- onChange?: (value: any) => void;
34
- } & LocaleProps;
43
+ props: CustomTimeViewProps & LocaleProps;
35
44
  onStartClicking: any;
36
45
  disableContextMenu: any;
37
46
  updateMilli: any;
38
47
  renderHeader: any;
39
48
  pad: any;
40
- state: {daypart: any; counters: Array<string>; [propName: string]: any};
49
+ state: State;
41
50
  timeConstraints: any;
42
51
  padValues = {
43
52
  hours: 2,
@@ -45,11 +54,22 @@ export class CustomTimeView extends TimeView {
45
54
  seconds: 2,
46
55
  milliseconds: 3
47
56
  };
57
+ setState: (arg0: any) => () => any;
58
+ calculateState: (props: CustomTimeViewProps) => () => any;
48
59
 
49
60
  static defaultProps = {
50
61
  showToolbar: true
51
62
  };
52
63
 
64
+
65
+ componentWillReceiveProps(nextProps: CustomTimeViewProps) {
66
+ if (nextProps.viewDate !== this.props.viewDate
67
+ || nextProps.selectedDate !== this.props.selectedDate
68
+ || nextProps.timeFormat !== this.props.timeFormat) {
69
+ this.setState(this.calculateState(nextProps));
70
+ }
71
+ }
72
+
53
73
  renderDayPart = () => {
54
74
  const {translate: __, classnames: cx} = this.props;
55
75
  return (
@@ -154,8 +174,22 @@ export class CustomTimeView extends TimeView {
154
174
  return null;
155
175
  };
156
176
 
157
- onConfirm = (value: number[]) => {
158
- this.props.onConfirm && this.props.onConfirm(value, this.state.counters);
177
+ onConfirm = (value: (number | string)[]) => {
178
+ // 修正am、pm
179
+ const hourIndex = this.state.counters.indexOf('hours');
180
+ if (
181
+ hourIndex !== -1 &&
182
+ this.state.daypart !== false &&
183
+ this.props.timeFormat.toLowerCase().indexOf(' a') !== -1
184
+ ) {
185
+ const amMode: string = value.splice(-1, 1)[0] as string;
186
+ let hour = (value[hourIndex] as number) % 12;
187
+ // 修正pm
188
+ amMode.toLowerCase().indexOf('p') !== -1 && (hour = hour + 12);
189
+ value[hourIndex] = hour;
190
+ }
191
+
192
+ this.props.onConfirm && this.props.onConfirm(value as number[], this.state.counters);
159
193
  };
160
194
 
161
195
  getDayPartOptions = () => {
@@ -171,13 +205,26 @@ export class CustomTimeView extends TimeView {
171
205
  }));
172
206
  };
173
207
 
208
+ onPickerChange = (value: (number | string)[], index: number) => {
209
+ const time: {[prop:string]: any} = {};
210
+ this.state.counters.forEach((type, i) => time[type] = value[i]);
211
+ if (this.state.daypart !== false && index > this.state.counters.length -1) {
212
+ time.daypart = value[value.length -1];
213
+ }
214
+ this.setState((prevState: State) => {
215
+ return {...prevState, ...time}
216
+ });
217
+ this.props.onChange && this.props.onChange(value);
218
+ }
219
+
174
220
  renderTimeViewPicker = () => {
221
+ const {translate: __} = this.props;
222
+ const title = __('Date.titleTime');
175
223
  const columns: PickerColumnItem[] = [];
176
224
  const values = [];
177
225
 
178
226
  this.state.counters.forEach(type => {
179
227
  if (type !== 'daypart') {
180
- const counterValue: number = this.getCounterValue(type);
181
228
  let {min, max, step} = this.timeConstraints[type];
182
229
  // 修正am pm时hours可选最大值
183
230
  if (
@@ -188,9 +235,14 @@ export class CustomTimeView extends TimeView {
188
235
  max = max > 12 ? 12 : max;
189
236
  }
190
237
  columns.push({
191
- options: getRange(min, max, step)
238
+ options: getRange(min, max, step).map(item => {
239
+ return {
240
+ text: this.pad(type, item),
241
+ value: item
242
+ }
243
+ })
192
244
  });
193
- values.push(counterValue);
245
+ values.push(parseInt(this.state[type], 10));
194
246
  }
195
247
  });
196
248
  if (this.state.daypart !== false) {
@@ -204,12 +256,13 @@ export class CustomTimeView extends TimeView {
204
256
  <Picker
205
257
  translate={this.props.translate}
206
258
  locale={this.props.locale}
259
+ title={title}
207
260
  columns={columns}
208
261
  value={values}
209
262
  onConfirm={this.onConfirm}
210
263
  onClose={this.props.onClose}
211
264
  showToolbar={this.props.showToolbar}
212
- onChange={this.props.onChange}
265
+ onChange={this.onPickerChange}
213
266
  />
214
267
  );
215
268
  };
@@ -4,7 +4,7 @@ import moment from 'moment';
4
4
  import React from 'react';
5
5
  import {LocaleProps, localeable} from '../../locale';
6
6
  import Picker from '../Picker';
7
- import {convertDateToObject, getRange, isMobile} from '../../utils/helper';
7
+ import {getRange, isMobile} from '../../utils/helper';
8
8
 
9
9
  export class CustomYearsView extends YearsView {
10
10
  props: {
@@ -28,6 +28,8 @@ export class CustomYearsView extends YearsView {
28
28
  onConfirm?: (value: number[], types: string[]) => void;
29
29
  useMobileUI: boolean;
30
30
  } & LocaleProps;
31
+ state: {pickerValue: number[]};
32
+ setState: (arg0: any) => () => any;
31
33
  renderYears: (year: number) => JSX.Element;
32
34
  renderYear = (props: any, year: number) => {
33
35
  return (
@@ -37,15 +39,31 @@ export class CustomYearsView extends YearsView {
37
39
  );
38
40
  };
39
41
 
42
+ constructor(props: any) {
43
+ super(props);
44
+
45
+ const {selectedDate, viewDate} = props;
46
+ const currentDate = (selectedDate || viewDate || moment());
47
+
48
+ this.state = {
49
+ pickerValue: currentDate.toObject().years
50
+ }
51
+ }
52
+
40
53
  onConfirm = (value: number[]) => {
41
54
  this.props.onConfirm && this.props.onConfirm(value, ['year']);
42
55
  };
43
56
 
57
+ onPickerChange = (value: number[]) => {
58
+ this.setState({pickerValue: value[0]});
59
+ }
60
+
44
61
  renderYearPicker = () => {
45
- const {minDate, maxDate, selectedDate, viewDate} = this.props;
62
+ const {translate: __, minDate, maxDate, selectedDate, viewDate} = this.props;
46
63
  const year = (selectedDate || viewDate || moment()).year();
47
- const maxYear = maxDate ? convertDateToObject(maxDate)!.year : year + 100;
48
- const minYear = minDate ? convertDateToObject(minDate)!.year : year - 100;
64
+ const maxYear = maxDate ? maxDate.toObject().years : year + 100;
65
+ const minYear = minDate ? minDate.toObject().years : year - 100;
66
+ const title = __('Date.titleYear');
49
67
 
50
68
  const columns = [
51
69
  {
@@ -57,9 +75,11 @@ export class CustomYearsView extends YearsView {
57
75
  <Picker
58
76
  translate={this.props.translate}
59
77
  locale={this.props.locale}
78
+ title={title}
60
79
  columns={columns}
61
- value={[year]}
80
+ value={this.state.pickerValue}
62
81
  onConfirm={this.onConfirm}
82
+ onChange={this.onPickerChange}
63
83
  onClose={this.props.onClose}
64
84
  />
65
85
  );
@@ -69,7 +89,6 @@ export class CustomYearsView extends YearsView {
69
89
  let year = this.props.viewDate.year();
70
90
  year = year - (year % 10);
71
91
  const __ = this.props.translate;
72
-
73
92
  if (isMobile() && this.props.useMobileUI) {
74
93
  return <div className="rdtYears">{this.renderYearPicker()}</div>;
75
94
  }