绿色在线网站模板下载,住建网站需多少钱,昆明seo建站,蔬菜网站模板需求背景解决效果视频效果balancedTimeElement.vue 需求背景
实现一个分片的时间间隔选择器#xff0c;需要把显示时间段显示成图表#xff0c;涉及一下集中数据转换
[“02:30-05:30”,“07:30-10:30”,“14:30-17:30”]‘[(2,5),(7,10),(14,17)]’[4, 5, 6, 7, 8, 9, 10, … 需求背景解决效果视频效果balancedTimeElement.vue 需求背景
实现一个分片的时间间隔选择器需要把显示时间段显示成图表涉及一下集中数据转换
[“02:30-05:30”,“07:30-10:30”,“14:30-17:30”]‘[(2,5),(7,10),(14,17)]’[4, 5, 6, 7, 8, 9, 10, 14, 15, 16, 17, 18, 19, 20, 28, 29, 30, 31, 32, 33, 34]
解决效果 视频效果 时间间隔选择器 balancedTimeElement.vue
!--/*** author: liuk* date: 2023/11/28* describe: 时间间隔选择器* CSDN:https://blog.csdn.net/hr_beginner?typeblog*/--
templatedivdiv classhours-containerdiv classhours-item-header-boxdiv classhours-item-header v-for(_, i) in hours.slice(0,24) :keyi{{(i 1 ).padStart(2, 0)}}/div/divdiv classhours-item-box refhoursItemReftemplate v-for(_, i) in hours :keyidiv classhours-item :classcompClass(i) clickhandleClick(i) mouseoverhandleHover(i)/div/template/div/divdiv classtips提示 向右选中向左取消选择/div/div
/templatescript langts setup
import {reactive, toRefs, ref, watch} from vue;// Props
const props defineProps([manual_period])// Emits
const emit defineEmits([data-passed])// Ref
const hoursItemRef ref(null)type numOrstr number | string
type arrOrstr any[] | stringinterface ModelType {hours: number[]selectStart: booleanstartIndex: numOrstrtimeRangeList: string[]timeRangeListIndex: numOrstr[]tempRangeIndex: number[]tips: arrOrstr
}const model: ModelType reactive({hours: new Array(48).fill().map((_, i) i),selectStart: false,// 开始startIndex: ,// 开始下标timeRangeList: [],// 选择的时间段timeRangeListIndex: [],// 选中的下标tempRangeIndex: [],// 预选下标tips: ,})
const {hours,selectStart,startIndex,timeRangeList,timeRangeListIndex,tempRangeIndex,tips,
} toRefs(model)watch(() props.manual_period, (data) {//[(2,5),(7,10),(14,17)]const str data.replace(/\(|\)/g, (val) { // [[2,5],[7,10],[14,17]]switch (val) {case (:return [case ):return ]}})model.timeRangeListIndex JSON.parse(str).map(item {const [x, y] itemreturn new Array(2 * y - 2 * x 1).fill(0).map((_, i) i 2 * x)}).flat()// [4, 5, 6, 7, 8, 9, 10, 14, 15, 16, 17, 18, 19, 20, 28, 29, 30, 31, 32, 33, 34]Array.from(hoursItemRef.value.children).forEach((dom: HTMLDivElement, index) {if (model.timeRangeListIndex.includes(index)) {dom.className selected}})
})// 下标区间转换成时间区间
const transformedSection () {model.timeRangeList [];let startTime , endTime , len model.hours.length;for (let index model.hours[0] * 2; index 2 * (len 1); index) {if (model.timeRangeListIndex.indexOf(index) -1) {if (startTime) {// 如果有开始时间直接确定结束时间let endHour Math.floor((index 1) / 2);let endMin (index 1) % 2 0 ? 00 : 30;endTime ${endHour 10 ? 0 endHour : endHour}:${endMin};} else {// 没有开始时间确定当前点为开始时间let startHour Math.floor(index / 2);let startMin index % 2 0 ? 00 : 30;startTime ${startHour 10 ? 0 startHour : startHour}:${startMin};}if (index 2 * model.hours.length 1) { // 如果是最后一格直接结束endTime ${Math.floor((index 1) / 2)}:00;model.timeRangeList.push(${startTime ? startTime : 23:30}-${endTime});startTime ;endTime ;}} else { // 若这个点不在选择区间确定一个时间段if (startTime endTime) {model.timeRangeList.push(${startTime}-${endTime});startTime ;endTime ;} else if (startTime !endTime) {// 这里可能只选半个小时let endHour Math.floor(index / 2);let endMin index % 2 0 ? 00 : 30;endTime ${endHour 10 ? 0 endHour : endHour}:${endMin};model.timeRangeList.push(${startTime}-${endTime});startTime ;endTime ;}}}model.tips model.timeRangeList model.timeRangeList.length 0 ? model.timeRangeList : ;emit(data-passed, model.tips);
}// 点击事件
const handleClick (index) {if (model.selectStart) {if (index model.startIndex) {// 双击取反if (model.timeRangeListIndex.indexOf(index) -1) {model.timeRangeListIndex.splice(model.timeRangeListIndex.indexOf(index), 1);} else {model.timeRangeListIndex.push(model.startIndex);}} else if (index model.startIndex) {// 选取数据--向右添加向左取消while (index model.startIndex) {model.timeRangeListIndex.push(model.startIndex);model.startIndex model.startIndex 1;}model.timeRangeListIndex Array.from(new Set(model.timeRangeListIndex));} else {// 删除数据while (model.startIndex index) {if (model.timeRangeListIndex.indexOf(index) -1) {model.timeRangeListIndex.splice(model.timeRangeListIndex.indexOf(index), 1);}index;}}model.startIndex ;transformedSection();model.tempRangeIndex [];} else {model.startIndex index;}model.selectStart !model.selectStart;
}
// 预选区间
const handleHover (index) {if (model.selectStart) {model.tempRangeIndex [];if (index model.startIndex) {// 选取数据--向右添加向左取消while (index model.startIndex) {model.tempRangeIndex.push(index);index--;}} else {// 删除数据while (model.startIndex index) {model.tempRangeIndex.push(index);index;}}}
}
// 是否选中计算className
const compClass (index) {if (index model.startIndex) {return hours-item-left preSelected;}if (index model.startIndex) {if (model.tempRangeIndex.indexOf(index) -1) {return hours-item-left preSelected;}} else {if (model.tempRangeIndex.indexOf(index) -1) {return hours-item-left unSelected;}}return model.timeRangeListIndex.indexOf(index) -1 ? hours-item-left selected : hours-item-left;
}
/scriptstyle langscss scoped
.hours-container {cursor: pointer;color: slategray;.hours-item-header-box {display: flex;width: 100%;height: 30px;.hours-item-header {width: 30px;height: 30px;text-align: center;box-sizing: border-box;line-height: 30px;border: 1px solid #5a5a5a;border-left: none;border-bottom: none;:first-child {border-left: 1px solid #5a5a5a;}}}.hours-item-box {display: flex;width: 100%;.hours-item {width: 15px;height: 30px;border: 1px solid #474747;box-sizing: border-box;.selected {background-color: #ffbf00 !important;border-bottom: 1px solid #c2d0f3;}.preSelected {background-color: rgb(255, 191, 0);border-bottom: 1px solid #c2d0f3;}.unSelected {background-color: #ffffff;border-bottom: 1px solid #c2d0f3;}}}
}.tips {width: 100%;line-height: 30px;margin-top: 10px;
}/style 文章转载自: http://www.morning.jkbqs.cn.gov.cn.jkbqs.cn http://www.morning.zpnfc.cn.gov.cn.zpnfc.cn http://www.morning.zlgth.cn.gov.cn.zlgth.cn http://www.morning.ryglh.cn.gov.cn.ryglh.cn http://www.morning.zmpsl.cn.gov.cn.zmpsl.cn http://www.morning.rjfr.cn.gov.cn.rjfr.cn http://www.morning.zdsdn.cn.gov.cn.zdsdn.cn http://www.morning.shxmr.cn.gov.cn.shxmr.cn http://www.morning.nffwl.cn.gov.cn.nffwl.cn http://www.morning.tkgxg.cn.gov.cn.tkgxg.cn http://www.morning.zhiheliuxue.com.gov.cn.zhiheliuxue.com http://www.morning.jkrrg.cn.gov.cn.jkrrg.cn http://www.morning.fhkr.cn.gov.cn.fhkr.cn http://www.morning.ykqbs.cn.gov.cn.ykqbs.cn http://www.morning.xhwty.cn.gov.cn.xhwty.cn http://www.morning.dsncg.cn.gov.cn.dsncg.cn http://www.morning.wnjsp.cn.gov.cn.wnjsp.cn http://www.morning.ztfzm.cn.gov.cn.ztfzm.cn http://www.morning.mpsnb.cn.gov.cn.mpsnb.cn http://www.morning.rbmnq.cn.gov.cn.rbmnq.cn http://www.morning.yrycb.cn.gov.cn.yrycb.cn http://www.morning.pwmm.cn.gov.cn.pwmm.cn http://www.morning.wngpq.cn.gov.cn.wngpq.cn http://www.morning.nsyzm.cn.gov.cn.nsyzm.cn http://www.morning.fcxt.cn.gov.cn.fcxt.cn http://www.morning.cybch.cn.gov.cn.cybch.cn http://www.morning.tygn.cn.gov.cn.tygn.cn http://www.morning.mnsts.cn.gov.cn.mnsts.cn http://www.morning.zjrnq.cn.gov.cn.zjrnq.cn http://www.morning.qfplp.cn.gov.cn.qfplp.cn http://www.morning.kaylyea.com.gov.cn.kaylyea.com http://www.morning.yqndr.cn.gov.cn.yqndr.cn http://www.morning.ubpsa.cn.gov.cn.ubpsa.cn http://www.morning.fbmjw.cn.gov.cn.fbmjw.cn http://www.morning.lthgy.cn.gov.cn.lthgy.cn http://www.morning.wqjpl.cn.gov.cn.wqjpl.cn http://www.morning.mkydt.cn.gov.cn.mkydt.cn http://www.morning.hjwxm.cn.gov.cn.hjwxm.cn http://www.morning.diuchai.com.gov.cn.diuchai.com http://www.morning.pmdzd.cn.gov.cn.pmdzd.cn http://www.morning.rkkpr.cn.gov.cn.rkkpr.cn http://www.morning.gwqq.cn.gov.cn.gwqq.cn http://www.morning.lsnhs.cn.gov.cn.lsnhs.cn http://www.morning.jqjnx.cn.gov.cn.jqjnx.cn http://www.morning.ddxjr.cn.gov.cn.ddxjr.cn http://www.morning.xpfwr.cn.gov.cn.xpfwr.cn http://www.morning.qfdmh.cn.gov.cn.qfdmh.cn http://www.morning.pcshb.cn.gov.cn.pcshb.cn http://www.morning.bsqbg.cn.gov.cn.bsqbg.cn http://www.morning.yxmcx.cn.gov.cn.yxmcx.cn http://www.morning.rwfp.cn.gov.cn.rwfp.cn http://www.morning.tckxl.cn.gov.cn.tckxl.cn http://www.morning.tgfjm.cn.gov.cn.tgfjm.cn http://www.morning.fbjnr.cn.gov.cn.fbjnr.cn http://www.morning.zwmjq.cn.gov.cn.zwmjq.cn http://www.morning.sfdsn.cn.gov.cn.sfdsn.cn http://www.morning.rxtxf.cn.gov.cn.rxtxf.cn http://www.morning.wkjzt.cn.gov.cn.wkjzt.cn http://www.morning.xfxqj.cn.gov.cn.xfxqj.cn http://www.morning.jphxt.cn.gov.cn.jphxt.cn http://www.morning.yhgbd.cn.gov.cn.yhgbd.cn http://www.morning.kjsft.cn.gov.cn.kjsft.cn http://www.morning.lxcwh.cn.gov.cn.lxcwh.cn http://www.morning.brjq.cn.gov.cn.brjq.cn http://www.morning.hrzymy.com.gov.cn.hrzymy.com http://www.morning.lrgfd.cn.gov.cn.lrgfd.cn http://www.morning.kqpsj.cn.gov.cn.kqpsj.cn http://www.morning.jcnmy.cn.gov.cn.jcnmy.cn http://www.morning.rdxnt.cn.gov.cn.rdxnt.cn http://www.morning.znnsk.cn.gov.cn.znnsk.cn http://www.morning.clpkp.cn.gov.cn.clpkp.cn http://www.morning.rfrx.cn.gov.cn.rfrx.cn http://www.morning.ghkgl.cn.gov.cn.ghkgl.cn http://www.morning.kggxj.cn.gov.cn.kggxj.cn http://www.morning.zrdqz.cn.gov.cn.zrdqz.cn http://www.morning.rltsx.cn.gov.cn.rltsx.cn http://www.morning.uytae.cn.gov.cn.uytae.cn http://www.morning.qdlr.cn.gov.cn.qdlr.cn http://www.morning.mtymb.cn.gov.cn.mtymb.cn http://www.morning.fhrt.cn.gov.cn.fhrt.cn