time-picker.md 5.2 KB
Newer Older
D
sync  
dolymood 已提交
1
## TimePicker
M
init  
miaodian 已提交
2

D
sync  
dolymood 已提交
3
`TimePicker` component provides commonly used functions of date selection.
M
init  
miaodian 已提交
4

D
sync  
dolymood 已提交
5
### Example
M
init  
miaodian 已提交
6

D
sync  
dolymood 已提交
7
- Basic usage
M
init  
miaodian 已提交
8

D
dolymood 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  ```html
  <cube-button @click="showTimePicker">TimePicker</cube-button>
  ```

  ```js
  export default {
    methods: {
      showTimePicker () {
        this.$createTimePicker({
          showNow: true,
          minuteStep: 5,
          delay: 15,
          onSelect: (selectedTime, selectedText) => {
            this.$createDialog({
              type: 'warn',
              title: `selected timestamp ${selectedTime}`,
              content: `selected content ${selectedText}`,
              icon: 'cubeic-alert'
            }).show()
          },
          onCancel: () => {
            this.$createToast({
              type: 'correct',
              txt: 'Clicked cancel button',
              time: 1000
            }).show()
          }
        }).show()
      }
M
init  
miaodian 已提交
38 39
    }
  }
D
dolymood 已提交
40
  ```
M
init  
miaodian 已提交
41

D
dolymood 已提交
42
  `showNow` is uesed to control whether the time "now" is displayed. `minuteStep` is used to control the step of the minute. `delay` represents the time that postponed backwards from now, which determines the minimal optional time.
M
init  
miaodian 已提交
43

D
sync  
dolymood 已提交
44
- Configuration of date options
M
init  
miaodian 已提交
45

D
dolymood 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  ```html
  <cube-button @click="showTimePicker">TimePicker - day options</cube-button>
  ```

  ```js
  export default {
    methods: {
      showTimePicker () {
        this.$createTimePicker({
          showNow: true,
          minuteStep: 10,
          delay: 10,
          day: {
            len: 5,
            filter: ['Today', 'Tomorrow'],
            format: 'M year d day'
          },
          onSelect(selectedTime, selectedText) {
            console.log(selectedTime, selectedText)
          },
          onSelect: (selectedTime, selectedText) => {
            this.$createDialog({
              type: 'warn',
              title: `selected timestamp ${selectedTime}`,
              content: `selected content ${selectedText}`,
              icon: 'cubeic-alert'
            }).show()
          },
          onCancel: () => {
            this.$createToast({
              type: 'correct',
              txt: 'Clicked cancel button',
              time: 1000
            }).show()
          }
        }).show()
      }
M
init  
miaodian 已提交
83
    }
D
sync  
dolymood 已提交
84
  }
D
dolymood 已提交
85
  ```
M
init  
miaodian 已提交
86

D
dolymood 已提交
87
  `len` attribute in `day` can set the length of date displayed in the first column.
D
sync  
dolymood 已提交
88

D
dolymood 已提交
89
  `filter` attribute can set the text of the date displayed in the first column.
D
sync  
dolymood 已提交
90

D
dolymood 已提交
91
  `format` attribute can set the text in `M year d day` format when the `len` is greater than the length of `filter` array.
D
sync  
dolymood 已提交
92 93

- Set time manually
M
init  
miaodian 已提交
94

D
dolymood 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
  ```html
  <cube-button @click="showTimePicker">TimePicker - setTime(next hour)</cube-button>
  ```

  ```js
  export default {
    methods: {
      const time = new Date().valueOf() + 1 * 60 * 60 * 1000
      showTimePicker () {
        const timePicker = this.$createTimePicker({
          showNow: true,
          minuteStep: 10,
          delay: 15,
          day: {
            len: 5,
            filter: ['Today', 'Tomorrow', 'The day after tomorrow'],
            format: 'M year d day'
          },
          onSelect: (selectedTime, selectedText) => {
            this.$createDialog({
              type: 'warn',
              title: `selected timestamp: ${selectedTime}`,
              content: `selected content ${selectedText}`,
              icon: 'cubeic-alert'
            }).show()
          },
          onCancel: () => {
            this.$createToast({
              type: 'correct',
              txt: 'Clicked cancel button',
              time: 1000
            }).show()
          }
        })

        timePicker.setTime(time)
        timePicker.show()
      }
M
init  
miaodian 已提交
133
    }
D
sync  
dolymood 已提交
134
  }
D
dolymood 已提交
135
  ```
M
init  
miaodian 已提交
136

D
dolymood 已提交
137
  `timePicker` instance exports `setTime` methos to set time manually with the time stamp as time format. When the time stamp is lower than current time stamp, `timePicker` displays current time by default.
D
sync  
dolymood 已提交
138

M
init  
miaodian 已提交
139

D
sync  
dolymood 已提交
140
### Props configuration
M
init  
miaodian 已提交
141

D
sync  
dolymood 已提交
142 143 144
| Attribute | Description | Type | Default |
| - | - | - | - |
| title | title | String | '选择时间' |
A
Amy 已提交
145
| swipeTime | the duration of the momentum animation when user flicks the wheel of the picker, Unit: ms | Number | 2500 |
D
sync  
dolymood 已提交
146 147 148 149
| delay | minutes that postponed backwards from now, which determines the minimal optional time| Number | 15 |
| day | date configuration | Object | { len: 3, filter: ['今日'], format: 'M月d日' } |
| showNow | whether to display current time | Boolean | true |
| minuteStep | step of the minute | Number | 10 |
M
init  
miaodian 已提交
150

D
sync  
dolymood 已提交
151
* `day` sub configuration
M
init  
miaodian 已提交
152

D
sync  
dolymood 已提交
153 154 155 156 157
| Attribute | Description | Type | Default |
| - | - | - | - |
| len | date column, postpone `len` days backwards from now | Number | 3 |
| filter | date column, map time to the text in filter | Array | ['今日'] |
| format | format time | String | 'M月d日' |
M
init  
miaodian 已提交
158

D
sync  
dolymood 已提交
159
### Events
M
init  
miaodian 已提交
160

D
sync  
dolymood 已提交
161 162 163 164 165
| Event Name | Description | Parameters 1 | Parameters 2 |
| - | - | - | - |
| select | triggers when clicking the confirm button | selectedTime: currently selected timestamp | selectText: text of currently selected time |
| change | triggers when sliding to change time-picker roller | selectedTime: currently selected timestamp | selectText: text of currently selected time |
| cancel | triggers when clicking the cancel button | - | - |
M
init  
miaodian 已提交
166

D
sync  
dolymood 已提交
167
### Instance methods
M
init  
miaodian 已提交
168

D
sync  
dolymood 已提交
169 170 171
| Method name | Description | Parameters |
| - | - | - |
| setTime | manually set time displayed in time-picker with with the time stamp as time format | time stamp |