var app = new Vue({
el: "#app",
data: {
minutes: 15,
hour: 8,
showTimePicker: false,
current: 0 //0为时、1为分
},
created: function(){
this.$on("closeTimePicker",function() { //监听关闭time-picker
this.showTimePicker = false;
}),
this.$on("openTimePicker",function() {
this.showTimePicker = true;
}),
this.$on("getTime",function(h,m) { //获取time-picker返回的点击后的数值,然后动态改变
this.minutes = m;
this.hour = h;
})
}
})
Vue.component('time-box',{
template:'\
<div class="timeBox" @click="openTime">\
<span @click="changeCurrent(\'h\')">{{hour}}</span>\
<span> : </span>\
<span @click="changeCurrent(\'m\')">{{minutes}}<span/>\
</div>',
props: ['hour','minutes'],
methods: {
openTime: function() {
app.$emit("openTimePicker");
},
changeCurrent: function(type) {
if(type == 'h' ){
app.current = 0;
} else {
app.current = 1;
}
}
}
});
props: ['h','m','mode'],
data: function() {
return {
current: this.mode,
hour: this.h,
minutes: this.m
}
},
//时分保证是两位数
fixHour: function() {
return (this.hour < 10 && this.hour.toString().indexOf(0) !== 0) ? "0" + this.hour : this.hour
}
fixMinutes: function() {
return (this.minutes < 10 && this.minutes.toString().indexOf(0) !== 0) ? "0" + this.minutes : this.minutes
},
<div class="showtime">
<span @click="current = 0" :style="{opacity: current == 0 ? 1 : 0.7}">{{fixHour(hour)}}</span>
<span>:</span>
<span @click="current = 1" :style="{opacity: current == 1 ? 1 : 0.7}">{{fixMinutes(minutes)}}</span>
</div>
<template>
<div class="hourpicker">
<div class="selector" :style="selectorRotateAngle()"></div>
<span class="hourtxt" v-for="i in 12" :style="getHourStyle(i)" @click="current === 0 ? hour = i : minutes = ((5 * i) % 60 || \'00\')">{{current === 0 ? i : ((5 * i) % 60 || "00")}}</span>\
</div>
</template>
methods: {
//分时针的样式
selectorRotateAngle: function(i) {
if(this.current === 0) {
return {
transform: 'rotateZ('+(this.hour * 30)+'deg)'
}
} else {
return {
transform: 'rotateZ('+(this.minutes * 6)+'deg)'
}
}
},
//12格样式
getHourStyle: function(i) {
var hasSelected = (this.current === 0 && this.hour % 12 === i)
|| (this.current === 1 && this.minutes % 60 == (i * 5)); //判断到底是哪个数值被选中
var styleObj = {
transform: 'translate(' + positions[i][0] + "px, " + positions[i][1] + "px)",
background: hasSelected ? 'rgb(0, 188, 212)' : 'rgba(255, 255, 255, 0)',
color: !hasSelected ? '#2c3e50' : '#FFF'
}
return styleObj;
}
}
//关闭timepicker
closePicker: function() {
app.$emit('closeTimePicker');
},
//获取时间
getTime: function() {
app.$emit('getTime',this.fixHour(this.hour),this.fixMinutes(this.minutes));
app.$emit('closeTimePicker');
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有