Blame view

src/components/date-picker/panel/Time/time.vue 3.42 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"
ca8e830c   Sergio Crisostomo   move files to sub...
10
11
12
                      :hours="date.getHours()"
                      :minutes="date.getMinutes()"
                      :seconds="date.getSeconds()"
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
                  @on-pick-clear="handlePickClear"
                  @on-pick-success="handlePickSuccess"></Confirm>
          </div>
      </div>
  </template>
  <script>
ca8e830c   Sergio Crisostomo   move files to sub...
28
29
30
      import TimeSpinner from '../../base/time-spinner.vue';
      import Confirm from '../../base/confirm.vue';
      import Options from '../../time-mixins';
9d844d53   梁灏   fixed Layout bug
31
  
9d844d53   梁灏   fixed Layout bug
32
  
ca8e830c   Sergio Crisostomo   move files to sub...
33
34
35
36
      import Mixin from '../panel-mixin';
      import Locale from '../../../../mixins/locale';
  
      import { initTimeDate } from '../../util';
2dbbd7de   梁灏   update TimePicker
37
  
9d844d53   梁灏   fixed Layout bug
38
39
40
      const prefixCls = 'ivu-picker-panel';
      const timePrefixCls = 'ivu-time-picker';
  
ca8e830c   Sergio Crisostomo   move files to sub...
41
42
      const capitalize = (str) => str[0].toUpperCase() + str.slice(1);
  
9d844d53   梁灏   fixed Layout bug
43
      export default {
ca8e830c   Sergio Crisostomo   move files to sub...
44
45
          name: 'TimePickerPanel',
          mixins: [ Mixin, Locale, Options ],
9d844d53   梁灏   fixed Layout bug
46
          components: { TimeSpinner, Confirm },
9b376832   Sergio Crisostomo   Add feature: allo...
47
48
49
50
          props: {
              steps: {
                  type: Array,
                  default: () => []
ca8e830c   Sergio Crisostomo   move files to sub...
51
52
53
54
55
56
57
58
59
              },
              format: {
                  type: String,
                  default: 'HH:mm:ss'
              },
              value: {
                  type: Array,
                  required: true
              },
9b376832   Sergio Crisostomo   Add feature: allo...
60
          },
9d844d53   梁灏   fixed Layout bug
61
62
63
64
          data () {
              return {
                  prefixCls: prefixCls,
                  timePrefixCls: timePrefixCls,
ca8e830c   Sergio Crisostomo   move files to sub...
65
                  date: this.value[0] || initTimeDate(),
a2a78c38   梁灏   update DateTimePi...
66
                  showDate: false,
d596b9e4   梁灏   update TimePicker
67
                  confirm: false
9d844d53   梁灏   fixed Layout bug
68
69
70
71
              };
          },
          computed: {
              showSeconds () {
22ff9a62   Sergio Crisostomo   fix showSeconds f...
72
                  return !(this.format || '').match(/mm$/);
a8571a5f   梁灏   update DateTimePi...
73
              },
ca8e830c   Sergio Crisostomo   move files to sub...
74
              visibleDate () { // TODO
a8571a5f   梁灏   update DateTimePi...
75
                  const date = this.date;
4ab11811   梁灏   some component su...
76
77
78
79
                  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
80
81
82
              }
          },
          watch: {
ca8e830c   Sergio Crisostomo   move files to sub...
83
84
              value (dates) {
                  let newVal = dates[0] || initTimeDate();
9d844d53   梁灏   fixed Layout bug
85
                  newVal = new Date(newVal);
ca8e830c   Sergio Crisostomo   move files to sub...
86
                  this.date = newVal;
9d844d53   梁灏   fixed Layout bug
87
88
89
              }
          },
          methods: {
603e437b   梁灏   update TimePicker
90
              handleChange (date, emit = true) {
ca8e830c   Sergio Crisostomo   move files to sub...
91
92
93
94
95
96
97
  
                  const newDate = new Date(this.date);
                  Object.keys(date).forEach(
                      type => newDate[`set${capitalize(type)}`](date[type])
                  );
  
                  if (emit) this.$emit('on-pick', newDate, true);
5cc9b892   梁灏   update DateTimePi...
98
              },
a2a78c38   梁灏   update DateTimePi...
99
          },
531cd165   梁灏   support DatePicke...
100
          mounted () {
a2a78c38   梁灏   update DateTimePi...
101
              if (this.$parent && this.$parent.$options.name === 'DatePicker') this.showDate = true;
9d844d53   梁灏   fixed Layout bug
102
103
          }
      };
9b376832   Sergio Crisostomo   Add feature: allo...
104
  </script>