ant-design-vue/components/vc-time-picker/demo/all.vue

161 lines
3.9 KiB
Vue
Raw Normal View History

2018-03-08 15:02:04 +00:00
<script>
2019-01-12 03:33:27 +00:00
import '../assets/index.less';
2018-03-08 15:02:04 +00:00
2019-01-12 03:33:27 +00:00
import moment from 'moment';
2018-03-08 15:02:04 +00:00
2019-01-12 03:33:27 +00:00
import TimePicker from '../index';
2018-03-08 15:02:04 +00:00
2019-01-12 03:33:27 +00:00
const format = 'h:mm a';
2018-03-08 15:02:04 +00:00
2019-01-12 03:33:27 +00:00
const now = moment().hour(0).minute(0);
2018-03-08 15:02:04 +00:00
function onChange (value) {
2019-01-12 03:33:27 +00:00
console.log(value && value.format(format));
2018-03-08 15:02:04 +00:00
}
2019-01-12 03:33:27 +00:00
const showSecond = true;
const str = showSecond ? 'HH:mm:ss' : 'HH:mm';
2018-03-08 15:02:04 +00:00
2019-01-12 03:33:27 +00:00
const now1 = moment().hour(14).minute(30);
2018-03-08 15:02:04 +00:00
function generateOptions (length, excludedOptions) {
2019-01-12 03:33:27 +00:00
const arr = [];
2018-03-08 15:02:04 +00:00
for (let value = 0; value < length; value++) {
if (excludedOptions.indexOf(value) < 0) {
2019-01-12 03:33:27 +00:00
arr.push(value);
2018-03-08 15:02:04 +00:00
}
}
2019-01-12 03:33:27 +00:00
return arr;
2018-03-08 15:02:04 +00:00
}
function onChange1 (value) {
2019-01-12 03:33:27 +00:00
console.log(value && value.format(str));
2018-03-08 15:02:04 +00:00
}
function disabledHours () {
2019-01-12 03:33:27 +00:00
return [0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23];
2018-03-08 15:02:04 +00:00
}
function disabledMinutes (h) {
switch (h) {
case 9:
2019-01-12 03:33:27 +00:00
return generateOptions(60, [30]);
2018-03-08 15:02:04 +00:00
case 21:
2019-01-12 03:33:27 +00:00
return generateOptions(60, [0]);
2018-03-08 15:02:04 +00:00
default:
2019-01-12 03:33:27 +00:00
return generateOptions(60, [0, 30]);
2018-03-08 15:02:04 +00:00
}
}
function disabledSeconds (h, m) {
2019-01-12 03:33:27 +00:00
return [h + m % 60];
2018-03-08 15:02:04 +00:00
}
export default{
data () {
return {
open: false,
value: moment(),
2019-01-12 03:33:27 +00:00
};
2018-03-08 15:02:04 +00:00
},
methods: {
setOpen ({ open }) {
2019-01-12 03:33:27 +00:00
this.open = open;
2018-03-08 15:02:04 +00:00
},
toggleOpen () {
2019-01-12 03:33:27 +00:00
this.open = !this.open;
2018-03-08 15:02:04 +00:00
},
handleValueChange (value) {
2019-01-12 03:33:27 +00:00
console.log(value && value.format('HH:mm:ss'));
this.value = value;
2018-03-08 15:02:04 +00:00
},
clear () {
2019-01-12 03:33:27 +00:00
this.value = undefined;
2018-03-08 15:02:04 +00:00
},
},
render () {
return (
<div>
<TimePicker
showSecond={false}
defaultValue={now}
class='xxx'
onChange={onChange}
format={format}
use12Hours
inputReadOnly
/>
<br/>
<br/>
<div>
<h3>Disabled picker</h3>
<TimePicker
defaultValue={now1}
disabled
onChange={onChange1}
/>
<h3>Disabled options</h3>
<TimePicker
showSecond={showSecond}
defaultValue={now1}
class='xxx'
onChange={onChange1}
disabledHours={disabledHours}
disabledMinutes={disabledMinutes}
disabledSeconds={disabledSeconds}
/>
</div>
<div>
<TimePicker defaultValue={moment()} showHour={false} />
<TimePicker defaultValue={moment()} showMinute={false} />
<TimePicker defaultValue={moment()} showSecond={false} />
<TimePicker defaultValue={moment()} showMinute={false} showSecond={false} />
<TimePicker defaultValue={moment()} showHour={false} showSecond={false}/>
<TimePicker defaultValue={moment()} showHour={false} showMinute={false} />
</div>
<TimePicker
format={str}
showSecond={showSecond}
// use to control utfOffset, locale, default open value
defaultOpenValue={moment()}
class='xxx'
onChange={onChange1}
disabledHours={() => [0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]}
disabledMinutes={() => [0, 2, 4, 6, 8]}
hideDisabledOptions
/>
<div>
<button onClick={this.toggleOpen}>Toggle open</button>
<TimePicker
open={this.open}
onOpen={this.setOpen}
onClose={this.setOpen}
focusOnOpen
/>
</div>
<TimePicker
style={{ width: '100px' }}
showSecond={showSecond}
defaultValue={moment()}
class='xxx'
onChange={onChange}
/>
<TimePicker defaultValue={moment()} showSecond={false} minuteStep={15} />
<div>
<TimePicker
defaultValue={this.value}
onChange={this.handleValueChange}
/>
<TimePicker
value={this.value}
onChange={this.handleValueChange}
/>
<button onClick={this.clear}>clear</button>
</div>
</div>
2019-01-12 03:33:27 +00:00
);
2018-03-08 15:02:04 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-03-08 15:02:04 +00:00
</script>