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

150 lines
3.7 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-09-28 12:45:07 +00:00
const now = moment()
.hour(0)
.minute(0);
2018-03-08 15:02:04 +00:00
2019-09-28 12:45:07 +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-09-28 12:45:07 +00:00
const now1 = moment()
.hour(14)
.minute(30);
2018-03-08 15:02:04 +00:00
2019-09-28 12:45:07 +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
}
2019-09-28 12:45:07 +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
}
2019-09-28 12:45:07 +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
}
2019-09-28 12:45:07 +00:00
function disabledMinutes(h) {
2018-03-08 15:02:04 +00:00
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
}
}
2019-09-28 12:45:07 +00:00
function disabledSeconds(h, m) {
return [h + (m % 60)];
2018-03-08 15:02:04 +00:00
}
2019-09-28 12:45:07 +00:00
export default {
data() {
2018-03-08 15:02:04 +00:00
return {
open: false,
value: moment(),
2019-01-12 03:33:27 +00:00
};
2018-03-08 15:02:04 +00:00
},
methods: {
2019-09-28 12:45:07 +00:00
setOpen({ open }) {
2019-01-12 03:33:27 +00:00
this.open = open;
2018-03-08 15:02:04 +00:00
},
2019-09-28 12:45:07 +00:00
toggleOpen() {
2019-01-12 03:33:27 +00:00
this.open = !this.open;
2018-03-08 15:02:04 +00:00
},
2019-09-28 12:45:07 +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
},
2019-09-28 12:45:07 +00:00
clear() {
2019-01-12 03:33:27 +00:00
this.value = undefined;
2018-03-08 15:02:04 +00:00
},
},
2019-09-28 12:45:07 +00:00
render() {
2018-03-08 15:02:04 +00:00
return (
<div>
<TimePicker
showSecond={false}
defaultValue={now}
2019-09-28 12:45:07 +00:00
class="xxx"
2018-03-08 15:02:04 +00:00
onChange={onChange}
format={format}
use12Hours
inputReadOnly
/>
2019-09-28 12:45:07 +00:00
<br />
<br />
2018-03-08 15:02:04 +00:00
<div>
<h3>Disabled picker</h3>
2019-09-28 12:45:07 +00:00
<TimePicker defaultValue={now1} disabled onChange={onChange1} />
2018-03-08 15:02:04 +00:00
<h3>Disabled options</h3>
<TimePicker
showSecond={showSecond}
defaultValue={now1}
2019-09-28 12:45:07 +00:00
class="xxx"
2018-03-08 15:02:04 +00:00
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} />
2019-09-28 12:45:07 +00:00
<TimePicker defaultValue={moment()} showHour={false} showSecond={false} />
2018-03-08 15:02:04 +00:00
<TimePicker defaultValue={moment()} showHour={false} showMinute={false} />
</div>
<TimePicker
format={str}
showSecond={showSecond}
// use to control utfOffset, locale, default open value
defaultOpenValue={moment()}
2019-09-28 12:45:07 +00:00
class="xxx"
2018-03-08 15:02:04 +00:00
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>
2019-09-28 12:45:07 +00:00
<TimePicker open={this.open} onOpen={this.setOpen} onClose={this.setOpen} focusOnOpen />
2018-03-08 15:02:04 +00:00
</div>
<TimePicker
style={{ width: '100px' }}
showSecond={showSecond}
defaultValue={moment()}
2019-09-28 12:45:07 +00:00
class="xxx"
2018-03-08 15:02:04 +00:00
onChange={onChange}
/>
<TimePicker defaultValue={moment()} showSecond={false} minuteStep={15} />
<div>
2019-09-28 12:45:07 +00:00
<TimePicker defaultValue={this.value} onChange={this.handleValueChange} />
<TimePicker value={this.value} onChange={this.handleValueChange} />
2018-03-08 15:02:04 +00:00
<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>