Blame view

src/components/date-picker/panel/time-range.vue 8.14 KB
456877a1   梁灏   update TimePicker
1
  <template>
030a522d   Sergio Crisostomo   make picker close...
2
      <div :class="classes" @mousedown.prevent>
456877a1   梁灏   update TimePicker
3
4
          <div :class="[prefixCls + '-body']">
              <div :class="[prefixCls + '-content', prefixCls + '-content-left']">
a2a78c38   梁灏   update DateTimePi...
5
                  <div :class="[timePrefixCls + '-header']">
2537c26d   Sergio Crisostomo   add dateLabel to ...
6
                      <template v-if="showDate">{{ leftDatePanelLabel }}</template>
4ab11811   梁灏   some component su...
7
                      <template v-else>{{ t('i.datepicker.startTime') }}</template>
a2a78c38   梁灏   update DateTimePi...
8
                  </div>
456877a1   梁灏   update TimePicker
9
                  <time-spinner
531cd165   梁灏   support DatePicke...
10
                      ref="timeSpinner"
456877a1   梁灏   update TimePicker
11
12
13
14
15
16
17
18
19
20
21
22
                      :show-seconds="showSeconds"
                      :hours="hours"
                      :minutes="minutes"
                      :seconds="seconds"
                      :disabled-hours="disabledHours"
                      :disabled-minutes="disabledMinutes"
                      :disabled-seconds="disabledSeconds"
                      :hide-disabled-options="hideDisabledOptions"
                      @on-change="handleStartChange"
                      @on-pick-click="handlePickClick"></time-spinner>
              </div>
              <div :class="[prefixCls + '-content', prefixCls + '-content-right']">
a2a78c38   梁灏   update DateTimePi...
23
                  <div :class="[timePrefixCls + '-header']">
2537c26d   Sergio Crisostomo   add dateLabel to ...
24
                      <template v-if="showDate">{{ rightDatePanelLabel }}</template>
4ab11811   梁灏   some component su...
25
                      <template v-else>{{ t('i.datepicker.endTime') }}</template>
a2a78c38   梁灏   update DateTimePi...
26
                  </div>
456877a1   梁灏   update TimePicker
27
                  <time-spinner
531cd165   梁灏   support DatePicke...
28
                      ref="timeSpinnerEnd"
456877a1   梁灏   update TimePicker
29
30
31
32
33
34
35
36
37
38
39
40
                      :show-seconds="showSeconds"
                      :hours="hoursEnd"
                      :minutes="minutesEnd"
                      :seconds="secondsEnd"
                      :disabled-hours="disabledHours"
                      :disabled-minutes="disabledMinutes"
                      :disabled-seconds="disabledSeconds"
                      :hide-disabled-options="hideDisabledOptions"
                      @on-change="handleEndChange"
                      @on-pick-click="handlePickClick"></time-spinner>
              </div>
              <Confirm
d596b9e4   梁灏   update TimePicker
41
                  v-if="confirm"
456877a1   梁灏   update TimePicker
42
43
44
45
46
47
48
49
50
51
                  @on-pick-clear="handlePickClear"
                  @on-pick-success="handlePickSuccess"></Confirm>
          </div>
      </div>
  </template>
  <script>
      import TimeSpinner from '../base/time-spinner.vue';
      import Confirm from '../base/confirm.vue';
  
      import Mixin from './mixin';
4ab11811   梁灏   some component su...
52
      import Locale from '../../../mixins/locale';
456877a1   梁灏   update TimePicker
53
  
2537c26d   Sergio Crisostomo   add dateLabel to ...
54
      import { initTimeDate, toDate, formatDate, formatDateLabels } from '../util';
456877a1   梁灏   update TimePicker
55
56
57
58
59
  
      const prefixCls = 'ivu-picker-panel';
      const timePrefixCls = 'ivu-time-picker';
  
      export default {
21dad188   梁灏   prevent dispatch ...
60
          name: 'TimePicker',
4ab11811   梁灏   some component su...
61
          mixins: [ Mixin, Locale ],
456877a1   梁灏   update TimePicker
62
63
64
65
66
67
          components: { TimeSpinner, Confirm },
          data () {
              return {
                  prefixCls: prefixCls,
                  timePrefixCls: timePrefixCls,
                  format: 'HH:mm:ss',
a2a78c38   梁灏   update DateTimePi...
68
                  showDate: false,
456877a1   梁灏   update TimePicker
69
70
71
72
73
74
75
76
77
78
79
80
                  date: initTimeDate(),
                  dateEnd: initTimeDate(),
                  value: '',
                  hours: '',
                  minutes: '',
                  seconds: '',
                  hoursEnd: '',
                  minutesEnd: '',
                  secondsEnd: '',
                  disabledHours: [],
                  disabledMinutes: [],
                  disabledSeconds: [],
d596b9e4   梁灏   update TimePicker
81
82
                  hideDisabledOptions: false,
                  confirm: false
3a435d65   梁灏   update TimePicker
83
              };
456877a1   梁灏   update TimePicker
84
85
86
87
88
89
90
91
92
93
94
95
96
          },
          computed: {
              classes () {
                  return [
                      `${prefixCls}-body-wrapper`,
                      `${timePrefixCls}-with-range`,
                      {
                          [`${timePrefixCls}-with-seconds`]: this.showSeconds
                      }
                  ];
              },
              showSeconds () {
                  return (this.format || '').indexOf('ss') !== -1;
a2a78c38   梁灏   update DateTimePi...
97
              },
2537c26d   Sergio Crisostomo   add dateLabel to ...
98
99
              leftDatePanelLabel () {
                  return this.panelLabelConfig(this.date);
a2a78c38   梁灏   update DateTimePi...
100
              },
2537c26d   Sergio Crisostomo   add dateLabel to ...
101
102
              rightDatePanelLabel () {
                  return this.panelLabelConfig(this.dateEnd);
456877a1   梁灏   update TimePicker
103
104
105
106
              }
          },
          watch: {
              value (newVal) {
0dd7b94a   梁灏   update TimePicker
107
108
                  if (!newVal) return;
                  if (Array.isArray(newVal)) {
456877a1   梁灏   update TimePicker
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
                      const valStart = newVal[0] ? toDate(newVal[0]) : false;
                      const valEnd = newVal[1] ? toDate(newVal[1]) : false;
  
                      if (valStart && valEnd) {
                          this.handleChange(
                              {
                                  hours: valStart.getHours(),
                                  minutes: valStart.getMinutes(),
                                  seconds: valStart.getSeconds()
                              },
                              {
                                  hours: valEnd.getHours(),
                                  minutes: valEnd.getMinutes(),
                                  seconds: valEnd.getSeconds()
                              },
                              false
3a435d65   梁灏   update TimePicker
125
                          );
456877a1   梁灏   update TimePicker
126
127
128
129
130
                      }
                  }
              }
          },
          methods: {
2537c26d   Sergio Crisostomo   add dateLabel to ...
131
132
133
134
135
136
              panelLabelConfig (date) {
                  const locale = this.t('i.locale');
                  const datePanelLabel = this.t('i.datepicker.datePanelLabel');
                  const { labels, separator } = formatDateLabels(locale, datePanelLabel, date || initTimeDate());
                  return [labels[0].label, separator, labels[1].label].join('');
              },
456877a1   梁灏   update TimePicker
137
138
139
140
141
142
143
144
145
146
147
              handleClear() {
                  this.date = initTimeDate();
                  this.dateEnd = initTimeDate();
                  this.hours = '';
                  this.minutes = '';
                  this.seconds = '';
                  this.hoursEnd = '';
                  this.minutesEnd = '';
                  this.secondsEnd = '';
              },
              handleChange (date, dateEnd, emit = true) {
db9985a9   梁灏   update TimePicker
148
149
                  const oldDateEnd = new Date(this.dateEnd);
  
456877a1   梁灏   update TimePicker
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
                  if (date.hours !== undefined) {
                      this.date.setHours(date.hours);
                      this.hours = this.date.getHours();
                  }
                  if (date.minutes !== undefined) {
                      this.date.setMinutes(date.minutes);
                      this.minutes = this.date.getMinutes();
                  }
                  if (date.seconds !== undefined) {
                      this.date.setSeconds(date.seconds);
                      this.seconds = this.date.getSeconds();
                  }
                  if (dateEnd.hours !== undefined) {
                      this.dateEnd.setHours(dateEnd.hours);
                      this.hoursEnd = this.dateEnd.getHours();
                  }
                  if (dateEnd.minutes !== undefined) {
                      this.dateEnd.setMinutes(dateEnd.minutes);
                      this.minutesEnd = this.dateEnd.getMinutes();
                  }
                  if (dateEnd.seconds !== undefined) {
                      this.dateEnd.setSeconds(dateEnd.seconds);
                      this.secondsEnd = this.dateEnd.getSeconds();
                  }
964582b3   梁灏   update TimePicker
174
175
176
177
178
179
180
                  // judge endTime > startTime?
                  if (this.dateEnd < this.date) {
                      this.$nextTick(() => {
                          this.dateEnd = new Date(this.date);
                          this.hoursEnd = this.dateEnd.getHours();
                          this.minutesEnd = this.dateEnd.getMinutes();
                          this.secondsEnd = this.dateEnd.getSeconds();
db9985a9   梁灏   update TimePicker
181
182
183
184
185
  
                          const format = 'yyyy-MM-dd HH:mm:ss';
                          if (formatDate(oldDateEnd, format) !== formatDate(this.dateEnd, format)) {
                              if (emit) this.$emit('on-pick', [this.date, this.dateEnd], true);
                          }
964582b3   梁灏   update TimePicker
186
187
188
189
                      });
                  } else {
                      if (emit) this.$emit('on-pick', [this.date, this.dateEnd], true);
                  }
456877a1   梁灏   update TimePicker
190
191
192
193
194
195
              },
              handleStartChange (date) {
                  this.handleChange(date, {});
              },
              handleEndChange (date) {
                  this.handleChange({}, date);
2dc27713   梁灏   update DateTimePi...
196
197
198
199
              },
              updateScroll () {
                  this.$refs.timeSpinner.updateScroll();
                  this.$refs.timeSpinnerEnd.updateScroll();
456877a1   梁灏   update TimePicker
200
              }
a2a78c38   梁灏   update DateTimePi...
201
          },
531cd165   梁灏   support DatePicke...
202
          mounted () {
a2a78c38   梁灏   update DateTimePi...
203
              if (this.$parent && this.$parent.$options.name === 'DatePicker') this.showDate = true;
456877a1   梁灏   update TimePicker
204
205
          }
      };
030a522d   Sergio Crisostomo   make picker close...
206
  </script>