Blame view

src/components/date-picker/panel/Time/time-range.vue 6.03 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"
e6029f1d   Graham Fairweather   Fix: Missing step...
11
                      :steps="steps"
456877a1   梁灏   update TimePicker
12
                      :show-seconds="showSeconds"
ca8e830c   Sergio Crisostomo   move files to sub...
13
14
15
                      :hours="dateStart.getHours()"
                      :minutes="dateStart.getMinutes()"
                      :seconds="dateStart.getSeconds()"
456877a1   梁灏   update TimePicker
16
17
18
19
20
21
22
23
                      :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...
24
                  <div :class="[timePrefixCls + '-header']">
2537c26d   Sergio Crisostomo   add dateLabel to ...
25
                      <template v-if="showDate">{{ rightDatePanelLabel }}</template>
4ab11811   梁灏   some component su...
26
                      <template v-else>{{ t('i.datepicker.endTime') }}</template>
a2a78c38   梁灏   update DateTimePi...
27
                  </div>
456877a1   梁灏   update TimePicker
28
                  <time-spinner
531cd165   梁灏   support DatePicke...
29
                      ref="timeSpinnerEnd"
e6029f1d   Graham Fairweather   Fix: Missing step...
30
                      :steps="steps"
456877a1   梁灏   update TimePicker
31
                      :show-seconds="showSeconds"
ca8e830c   Sergio Crisostomo   move files to sub...
32
33
34
                      :hours="dateEnd.getHours()"
                      :minutes="dateEnd.getMinutes()"
                      :seconds="dateEnd.getSeconds()"
456877a1   梁灏   update TimePicker
35
36
37
38
39
40
41
42
                      :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
43
                  v-if="confirm"
456877a1   梁灏   update TimePicker
44
45
46
47
48
49
                  @on-pick-clear="handlePickClear"
                  @on-pick-success="handlePickSuccess"></Confirm>
          </div>
      </div>
  </template>
  <script>
ca8e830c   Sergio Crisostomo   move files to sub...
50
51
52
      import TimeSpinner from '../../base/time-spinner.vue';
      import Confirm from '../../base/confirm.vue';
      import Options from '../../time-mixins';
456877a1   梁灏   update TimePicker
53
  
456877a1   梁灏   update TimePicker
54
  
ca8e830c   Sergio Crisostomo   move files to sub...
55
56
57
58
      import Mixin from '../panel-mixin';
      import Locale from '../../../../mixins/locale';
  
      import { initTimeDate, formatDateLabels } from '../../util';
456877a1   梁灏   update TimePicker
59
60
61
62
  
      const prefixCls = 'ivu-picker-panel';
      const timePrefixCls = 'ivu-time-picker';
  
ca8e830c   Sergio Crisostomo   move files to sub...
63
64
      const capitalize = (str) => str[0].toUpperCase() + str.slice(1);
  
456877a1   梁灏   update TimePicker
65
      export default {
ca8e830c   Sergio Crisostomo   move files to sub...
66
67
          name: 'RangeTimePickerPanel',
          mixins: [ Mixin, Locale, Options ],
456877a1   梁灏   update TimePicker
68
          components: { TimeSpinner, Confirm },
e6029f1d   Graham Fairweather   Fix: Missing step...
69
70
71
72
          props: {
              steps: {
                  type: Array,
                  default: () => []
ca8e830c   Sergio Crisostomo   move files to sub...
73
74
75
76
77
78
79
80
81
              },
              format: {
                  type: String,
                  default: 'HH:mm:ss'
              },
              value: {
                  type: Array,
                  required: true
              },
e6029f1d   Graham Fairweather   Fix: Missing step...
82
          },
456877a1   梁灏   update TimePicker
83
          data () {
ca8e830c   Sergio Crisostomo   move files to sub...
84
              const [dateStart, dateEnd] = this.value.slice();
456877a1   梁灏   update TimePicker
85
86
87
              return {
                  prefixCls: prefixCls,
                  timePrefixCls: timePrefixCls,
a2a78c38   梁灏   update DateTimePi...
88
                  showDate: false,
ca8e830c   Sergio Crisostomo   move files to sub...
89
90
                  dateStart: dateStart || initTimeDate(),
                  dateEnd: dateEnd || initTimeDate(),
d596b9e4   梁灏   update TimePicker
91
                  confirm: false
3a435d65   梁灏   update TimePicker
92
              };
456877a1   梁灏   update TimePicker
93
94
95
96
97
98
99
100
101
102
103
104
          },
          computed: {
              classes () {
                  return [
                      `${prefixCls}-body-wrapper`,
                      `${timePrefixCls}-with-range`,
                      {
                          [`${timePrefixCls}-with-seconds`]: this.showSeconds
                      }
                  ];
              },
              showSeconds () {
22ff9a62   Sergio Crisostomo   fix showSeconds f...
105
                  return !(this.format || '').match(/mm$/);
a2a78c38   梁灏   update DateTimePi...
106
              },
2537c26d   Sergio Crisostomo   add dateLabel to ...
107
108
              leftDatePanelLabel () {
                  return this.panelLabelConfig(this.date);
a2a78c38   梁灏   update DateTimePi...
109
              },
2537c26d   Sergio Crisostomo   add dateLabel to ...
110
111
              rightDatePanelLabel () {
                  return this.panelLabelConfig(this.dateEnd);
456877a1   梁灏   update TimePicker
112
113
114
              }
          },
          watch: {
ca8e830c   Sergio Crisostomo   move files to sub...
115
116
117
118
              value (dates) {
                  const [dateStart, dateEnd] = dates.slice();
                  this.dateStart = dateStart || initTimeDate();
                  this.dateEnd = dateEnd || initTimeDate();
456877a1   梁灏   update TimePicker
119
120
121
              }
          },
          methods: {
2537c26d   Sergio Crisostomo   add dateLabel to ...
122
123
124
125
126
127
              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('');
              },
ca8e830c   Sergio Crisostomo   move files to sub...
128
129
130
131
132
133
134
              handleChange (start, end, emit = true) {
  
                  const dateStart = new Date(this.dateStart);
                  let dateEnd = new Date(this.dateEnd);
  
                  // set dateStart
                  Object.keys(start).forEach(type => {
5426dcf9   Sergio Crisostomo   fix specs, fix me...
135
                      dateStart[`set${capitalize(type)}`](start[type]);
ca8e830c   Sergio Crisostomo   move files to sub...
136
137
138
139
140
141
                  });
  
                  // set dateEnd
                  Object.keys(end).forEach(type => {
                      dateEnd[`set${capitalize(type)}`](end[type]);
                  });
db9985a9   梁灏   update TimePicker
142
  
964582b3   梁灏   update TimePicker
143
                  // judge endTime > startTime?
ca8e830c   Sergio Crisostomo   move files to sub...
144
                  if (dateEnd < dateStart) dateEnd = dateStart;
db9985a9   梁灏   update TimePicker
145
  
ca8e830c   Sergio Crisostomo   move files to sub...
146
                  if (emit) this.$emit('on-pick', [dateStart, dateEnd], true);
456877a1   梁灏   update TimePicker
147
148
149
150
151
152
              },
              handleStartChange (date) {
                  this.handleChange(date, {});
              },
              handleEndChange (date) {
                  this.handleChange({}, date);
2dc27713   梁灏   update DateTimePi...
153
154
155
156
              },
              updateScroll () {
                  this.$refs.timeSpinner.updateScroll();
                  this.$refs.timeSpinnerEnd.updateScroll();
456877a1   梁灏   update TimePicker
157
              }
a2a78c38   梁灏   update DateTimePi...
158
          },
531cd165   梁灏   support DatePicke...
159
          mounted () {
a2a78c38   梁灏   update DateTimePi...
160
              if (this.$parent && this.$parent.$options.name === 'DatePicker') this.showDate = true;
456877a1   梁灏   update TimePicker
161
162
          }
      };
030a522d   Sergio Crisostomo   make picker close...
163
  </script>