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"
29a91fbb   Sergio Crisostomo   Correct passing o...
10
11
12
                      :hours="value[0] && date.getHours()"
                      :minutes="value[0] && date.getMinutes()"
                      :seconds="value[0] && 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(),
29a91fbb   Sergio Crisostomo   Correct passing o...
66
                  showDate: false
9d844d53   梁灏   fixed Layout bug
67
68
69
70
              };
          },
          computed: {
              showSeconds () {
22ff9a62   Sergio Crisostomo   fix showSeconds f...
71
                  return !(this.format || '').match(/mm$/);
a8571a5f   梁灏   update DateTimePi...
72
              },
ca8e830c   Sergio Crisostomo   move files to sub...
73
              visibleDate () { // TODO
a8571a5f   梁灏   update DateTimePi...
74
                  const date = this.date;
4ab11811   梁灏   some component su...
75
76
77
78
                  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
79
80
81
              }
          },
          watch: {
ca8e830c   Sergio Crisostomo   move files to sub...
82
83
              value (dates) {
                  let newVal = dates[0] || initTimeDate();
9d844d53   梁灏   fixed Layout bug
84
                  newVal = new Date(newVal);
ca8e830c   Sergio Crisostomo   move files to sub...
85
                  this.date = newVal;
9d844d53   梁灏   fixed Layout bug
86
87
88
              }
          },
          methods: {
603e437b   梁灏   update TimePicker
89
              handleChange (date, emit = true) {
ca8e830c   Sergio Crisostomo   move files to sub...
90
91
92
93
94
95
96
  
                  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...
97
              },
a2a78c38   梁灏   update DateTimePi...
98
          },
531cd165   梁灏   support DatePicke...
99
          mounted () {
a2a78c38   梁灏   update DateTimePi...
100
              if (this.$parent && this.$parent.$options.name === 'DatePicker') this.showDate = true;
9d844d53   梁灏   fixed Layout bug
101
102
          }
      };
9b376832   Sergio Crisostomo   Add feature: allo...
103
  </script>