Blame view

src/components/date-picker/panel/time.vue 4.21 KB
9d844d53   梁灏   fixed Layout bug
1
  <template>
030a522d   Sergio Crisostomo   make picker close...
2
      <div :class="[prefixCls + '-body-wrapper']" @mousedown.prevent>
9d844d53   梁灏   fixed Layout bug
3
          <div :class="[prefixCls + '-body']">
a8571a5f   梁灏   update DateTimePi...
4
              <div :class="[timePrefixCls + '-header']" v-if="showDate">{{ visibleDate }}</div>
9d844d53   梁灏   fixed Layout bug
5
6
              <div :class="[prefixCls + '-content']">
                  <time-spinner
531cd165   梁灏   support DatePicke...
7
                      ref="timeSpinner"
9d844d53   梁灏   fixed Layout bug
8
                      :show-seconds="showSeconds"
9b376832   Sergio Crisostomo   Add feature: allo...
9
                      :steps="steps"
9d844d53   梁灏   fixed Layout bug
10
11
12
                      :hours="hours"
                      :minutes="minutes"
                      :seconds="seconds"
36628aca   梁灏   update TimePicker
13
14
15
16
                      :disabled-hours="disabledHours"
                      :disabled-minutes="disabledMinutes"
                      :disabled-seconds="disabledSeconds"
                      :hide-disabled-options="hideDisabledOptions"
9d844d53   梁灏   fixed Layout bug
17
18
19
20
                      @on-change="handleChange"
                      @on-pick-click="handlePickClick"></time-spinner>
              </div>
              <Confirm
d596b9e4   梁灏   update TimePicker
21
                  v-if="confirm"
9d844d53   梁灏   fixed Layout bug
22
23
24
25
26
27
28
29
30
31
                  @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...
32
      import Locale from '../../../mixins/locale';
9d844d53   梁灏   fixed Layout bug
33
  
2dbbd7de   梁灏   update TimePicker
34
35
      import { initTimeDate } from '../util';
  
9d844d53   梁灏   fixed Layout bug
36
37
38
39
      const prefixCls = 'ivu-picker-panel';
      const timePrefixCls = 'ivu-time-picker';
  
      export default {
21dad188   梁灏   prevent dispatch ...
40
          name: 'TimePicker',
4ab11811   梁灏   some component su...
41
          mixins: [ Mixin, Locale ],
9d844d53   梁灏   fixed Layout bug
42
          components: { TimeSpinner, Confirm },
9b376832   Sergio Crisostomo   Add feature: allo...
43
44
45
46
47
48
          props: {
              steps: {
                  type: Array,
                  default: () => []
              }
          },
9d844d53   梁灏   fixed Layout bug
49
50
51
52
          data () {
              return {
                  prefixCls: prefixCls,
                  timePrefixCls: timePrefixCls,
36931442   梁灏   update DateTimePi...
53
54
                  date: initTimeDate(),
                  value: '',
a2a78c38   梁灏   update DateTimePi...
55
                  showDate: false,
36931442   梁灏   update DateTimePi...
56
                  format: 'HH:mm:ss',
2dbbd7de   梁灏   update TimePicker
57
58
59
                  hours: '',
                  minutes: '',
                  seconds: '',
c1abaed9   梁灏   update TimePicker
60
61
62
                  disabledHours: [],
                  disabledMinutes: [],
                  disabledSeconds: [],
d596b9e4   梁灏   update TimePicker
63
64
                  hideDisabledOptions: false,
                  confirm: false
9d844d53   梁灏   fixed Layout bug
65
66
67
68
69
              };
          },
          computed: {
              showSeconds () {
                  return (this.format || '').indexOf('ss') !== -1;
a8571a5f   梁灏   update DateTimePi...
70
71
72
              },
              visibleDate () {
                  const date = this.date;
4ab11811   梁灏   some component su...
73
74
75
76
                  const month = date.getMonth() + 1;
                  const tYear = this.t('i.datepicker.year');
                  const tMonth = this.t(`i.datepicker.month${month}`);
                  return `${date.getFullYear()}${tYear} ${tMonth}`;
9d844d53   梁灏   fixed Layout bug
77
78
79
80
81
82
83
              }
          },
          watch: {
              value (newVal) {
                  if (!newVal) return;
                  newVal = new Date(newVal);
                  if (!isNaN(newVal)) {
603e437b   梁灏   update TimePicker
84
                      this.date = newVal;
9d844d53   梁灏   fixed Layout bug
85
                      this.handleChange({
c1abaed9   梁灏   update TimePicker
86
87
88
                          hours: newVal.getHours(),
                          minutes: newVal.getMinutes(),
                          seconds: newVal.getSeconds()
603e437b   梁灏   update TimePicker
89
                      }, false);
9d844d53   梁灏   fixed Layout bug
90
91
92
93
                  }
              }
          },
          methods: {
2dbbd7de   梁灏   update TimePicker
94
95
96
97
98
              handleClear() {
                  this.date = initTimeDate();
                  this.hours = '';
                  this.minutes = '';
                  this.seconds = '';
2dbbd7de   梁灏   update TimePicker
99
              },
603e437b   梁灏   update TimePicker
100
              handleChange (date, emit = true) {
9d844d53   梁灏   fixed Layout bug
101
102
103
104
105
106
107
108
109
110
111
112
                  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();
                  }
603e437b   梁灏   update TimePicker
113
                  if (emit) this.$emit('on-pick', this.date, true);
5cc9b892   梁灏   update DateTimePi...
114
115
116
              },
              updateScroll () {
                  this.$refs.timeSpinner.updateScroll();
9d844d53   梁灏   fixed Layout bug
117
              }
a2a78c38   梁灏   update DateTimePi...
118
          },
531cd165   梁灏   support DatePicke...
119
          mounted () {
a2a78c38   梁灏   update DateTimePi...
120
              if (this.$parent && this.$parent.$options.name === 'DatePicker') this.showDate = true;
9d844d53   梁灏   fixed Layout bug
121
122
          }
      };
9b376832   Sergio Crisostomo   Add feature: allo...
123
  </script>