time-picker.md 5.7 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

5 6
__Notice:__ Cause this component used create-api, so you should read [create-api](#/en-US/docs/create-api) first.

D
sync  
dolymood 已提交
7
### Example
M
init  
miaodian 已提交
8

D
sync  
dolymood 已提交
9
- Basic usage
M
init  
miaodian 已提交
10

D
dolymood 已提交
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 38 39
  ```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 已提交
40 41
    }
  }
D
dolymood 已提交
42
  ```
M
init  
miaodian 已提交
43

D
dolymood 已提交
44
  `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 已提交
45

D
sync  
dolymood 已提交
46
- Configuration of date options
M
init  
miaodian 已提交
47

D
dolymood 已提交
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 83 84
  ```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 已提交
85
    }
D
sync  
dolymood 已提交
86
  }
D
dolymood 已提交
87
  ```
M
init  
miaodian 已提交
88

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

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

D
dolymood 已提交
93
  `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 已提交
94 95

- Set time manually
M
init  
miaodian 已提交
96

D
dolymood 已提交
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 133 134
  ```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 已提交
135
    }
D
sync  
dolymood 已提交
136
  }
D
dolymood 已提交
137
  ```
M
init  
miaodian 已提交
138

D
dolymood 已提交
139
  `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 已提交
140

M
init  
miaodian 已提交
141

D
sync  
dolymood 已提交
142
### Props configuration
M
init  
miaodian 已提交
143

D
sync  
dolymood 已提交
144 145 146 147 148 149
| Attribute | Description | Type | Default |
| - | - | - | - |
| 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 |
150
| title | title | String | '选择时间' |
A
Amy 已提交
151
| subtitle<sup>1.8.1</sup> | subtitle | String | '' |
152 153 154 155
| cancelTxt<sup>1.8.1</sup> | the text of the cancel button | String | '取消' |
| confirmTxt<sup>1.8.1</sup> | the text of the confirm button | String | '确定' |
| swipeTime | the duration of the momentum animation when user flicks the wheel of the picker, Unit: ms | Number | 2500 |
| visible<sup>1.8.1</sup> | whether visible. Bind to `v-model` | Boolean | false |
M
init  
miaodian 已提交
156

D
sync  
dolymood 已提交
157
* `day` sub configuration
M
init  
miaodian 已提交
158

D
sync  
dolymood 已提交
159 160 161 162 163
| 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 已提交
164

D
sync  
dolymood 已提交
165
### Events
M
init  
miaodian 已提交
166

D
sync  
dolymood 已提交
167 168 169 170 171
| 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 已提交
172

D
sync  
dolymood 已提交
173
### Instance methods
M
init  
miaodian 已提交
174

D
sync  
dolymood 已提交
175 176 177
| Method name | Description | Parameters |
| - | - | - |
| setTime | manually set time displayed in time-picker with with the time stamp as time format | time stamp |
178 179
| show | show | - |
| hide | hide | - |