使用vue把一周的时间划分为可以选择多个阶段

提示:使用vue把一周的时间划分为可以选择多个阶段段(亲测有效)

一、直接复制以下代码

在这里插入图片描述

代码如下(示例):


<template><div class="byted-weektime" @mousedown="dian" @mousemove="yi" @mouseup="li"><div class="calendar"><table class="calendar-table" style="width:610px"><thead class="calendar-head"><tr><th rowspan="6" class="week-td">星期/时间</th><th colspan="24">00:00 - 12:00</th><th colspan="24">12:00 - 24:00</th></tr><tr><td colspan="2" v-for="(item,index) in tableHeader" :key="index">{{item}}</td></tr></thead><tbody id="tableBody"><divid="kuang":style="{width:kuangObj.width+'px',height:kuangObj.height+'px',top:kuangObj.top+'px',left:kuangObj.left+'px',bottom:kuangObj.bottom+'px',right:kuangObj.right+'px'}"></div><tr><td>星期一</td><td@mousedown.prevent="handleMouseDown(i,0)"@mouseup.prevent="handleMouseUp(i,0)"class="calendar-atom-time":class="item.class"v-for="(item,i) in rowUnit[0]":key="i"></td></tr><tr><td>星期二</td><td@mousedown.prevent="handleMouseDown(i,1)"@mouseup.prevent="handleMouseUp(i,1)"class="calendar-atom-time":class="item.class"v-for="(item,i) in rowUnit[1]":key="i"></td></tr><tr><td>星期三</td><td@mousedown.prevent="handleMouseDown(i,2)"@mouseup.prevent="handleMouseUp(i,2)"class="calendar-atom-time":class="item.class"v-for="(item,i) in rowUnit[2]":key="i"></td></tr><tr><td>星期四</td><td@mousedown.prevent="handleMouseDown(i,3)"@mouseup.prevent="handleMouseUp(i,3)"class="calendar-atom-time":class="item.class"v-for="(item,i) in rowUnit[3]":key="i"></td></tr><tr><td>星期五</td><td@mousedown.prevent="handleMouseDown(i,4)"@mouseup.prevent="handleMouseUp(i,4)"class="calendar-atom-time":class="item.class"v-for="(item,i) in rowUnit[4]":key="i"></td></tr><tr><td>星期六</td><td@mousedown.prevent="handleMouseDown(i,5)"@mouseup.prevent="handleMouseUp(i,5)"class="calendar-atom-time":class="item.class"v-for="(item,i) in rowUnit[5]":key="i"></td></tr><tr><td>星期日</td><td@mousedown.prevent="handleMouseDown(i,6)"@mouseup.prevent="handleMouseUp(i,6)"class="calendar-atom-time":class="item.class"v-for="(item,i) in rowUnit[6]":key="i"></td></tr><tr><td colspan="49" class="td-table-tip"><div class="clearfix"><span class="pull-left tip-text">请用鼠标点选时间段</span><a @click="clear" class="pull-right">清空</a></div></td></tr><tr><td colspan="49" class="timeContent"><div v-for="(item,index) in timeStr" :key="index" v-show="item.length"><span>{{weekDate[index+1]}}:</span><strong><span>{{item}}</span></strong></div></td></tr></tbody></table></div><!-- 鼠标的画框的效果 --><divid="container"v-bind:style="{backgroundColor:back,height:h+'px',width:w+'px',position:'absolute',left:left+'px',top:top+'px',opacity:0.2,border:len+'px dashed #000',zIndex:-1}"></div></div>
</template><script>
export default {name: "timeSelect",data() {return {tableHeader: ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"],weekDate: {"1": "星期一","2": "星期二","3": "星期三","4": "星期四","5": "星期五","6": "星期六","7": "星期日"},rowUnit: [], //每一个单元格timeContent: [], //选中的时间段原始数据timeSection: [], //时间段,可以返回给后台的数据timeStr: [], //时间段,前端显示的数据beginDay: 0,beginTime: 0,downEvent: false,kuangObj: {width: 0,height: 0,top: 0,left: 0,bottom: 0,right: 0,oldLeft: 0,oldTop: 0,flag: false},py: "",px: "",back: "#31676f",h: "",w: "",top: "",left: "",len: 0};},created() {this.init();},mounted() {},methods: {init() {for (let i = 0; i < 7; i++) {let arr = [];for (let j = 0; j < 48; j++) {arr.push({ class: null, timeData: j });}this.rowUnit.push(arr);this.timeContent.push({ arr: [] });this.timeSection.push([]);this.timeStr.push("");}},handleMouseDown(i, day) {this.downEvent = true; //按下时鼠标不在范围内则不算this.beginDay = day;this.beginTime = i;},dian(event) {// console.log(event);this.px = event.pageX; //获取x坐标this.py = event.pageY;},yi(event) {if (this.px == "" || this.py == "") {return;}var px1 = this.px;var px2 = this.py;this.left = event.pageX;this.top = event.pageY;this.h = this.top - this.py;this.w = this.left - this.px;var hc = -this.h;var wc = -this.w;this.len = 1;this.back = "#31676f";if (this.h < 0 && this.w >= 0) {// console.log(1);this.h = hc;this.left = px1;} else if (this.h >= 0 && this.w < 0) {// console.log(2);this.w = wc;this.top = px2;} else if (this.h < 0 && this.w < 0) {// console.log(3);this.h = hc;this.w = wc;} else {// console.log(4);this.left = this.px;this.top = this.py;}if (this.w < 0) {this.w = 0 - this.w;}if (this.h < 0) {this.h = 0 - this.h;}},li() {this.px = "";this.py = "";this.h = "";this.w = "";this.top = "";this.left = "";this.len = 0;this.back = "";},handleMouseUp(i, day) {let _this = this;let begin = this.beginTime;let start = begin <= i ? begin : i; //x轴 起点let length = Math.abs(begin - i);let end = start + length; //x轴 终点let dayStart = this.beginDay <= day ? this.beginDay : day; //y轴 起点let dayLength = Math.abs(this.beginDay - day);let dayEnd = dayStart + dayLength; //y轴 终点//当框选范围内所有块都是选中状态时,执行反选function isAdd() {for (let x = dayStart; x < dayEnd + 1; x++) {for (let y = start; y < end + 1; y++) {if (_this.rowUnit[x][y].class == null) return true;}}return false;}//当点击事件是在table内才触发选取数据操作if (this.downEvent) {//选时间段if (isAdd()) {//没选中的全都选上for (let x = dayStart; x < dayEnd + 1; x++) {for (let y = start; y < end + 1; y++) {if (this.rowUnit[x][y].class == null) {this.rowUnit[x][y].class = "ui-selected";this.timeContent[x].arr.push(this.rowUnit[x][y].timeData);}}}} else {//反选for (let x = dayStart; x < dayEnd + 1; x++) {for (let y = start; y < end + 1; y++) {if (this.rowUnit[x][y].class == "ui-selected") {this.rowUnit[x][y].class = null;var c = this.rowUnit[x][y].timeData;var kong = "";for (let i = 0; i < this.timeContent[x].arr.length; i++) {if (c == this.timeContent[x].arr[i]) {kong = i;}}console.log(kong);this.timeContent[x].arr.splice(kong, 1);}}}}//过滤时间段,将临近的时间段合并this.filterTime(dayStart, dayEnd);}this.downEvent = false;},filterTime(start, end) {//选中的x,y坐标信息 x:0-47  y:0-6function sortCut(arr) {//提取连续的数字var result = [];arr.forEach(function(v, i) {var temp = result[result.length - 1];if (!i) {result.push([v]);} else if (v % 1 === 0 && v - temp[temp.length - 1] == 1) {temp.push(v);} else {result.push([v]);}});return result;}function toStr(num) {if (Number.isInteger(num)) {let str = num < 10 ? "0" + num : num.toString();return str + ":00";} else {let str =Math.floor(num) < 10? "0" + Math.floor(num): Math.floor(num).toString();return str + ":30";}}function timeToStr(arr) {//把数组转成方便人看到字符串let str = "";arr.forEach((arr, index) => {let str1 = "";if (index == 0) {str1 = toStr(arr[0]) + "~" + toStr(arr[1]);} else {str1 = " , " + toStr(arr[0]) + "~" + toStr(arr[1]);}str += str1;});return str;}//排序,分割成for (let i = start; i < end + 1; i++) {let arr1 = sortCut(this.timeContent[i].arr.sort((a, b) => a - b));let arr2 = [];arr1.forEach(arr => {//转成带小数点的时间段,以及供前端显示的字符串let arr3 = [];arr3.push(arr[0] / 2);arr3.push(arr[arr.length - 1] / 2 + 0.5);arr2.push(arr3);});this.timeStr[i] = timeToStr(arr2);this.timeSection[i] = arr2;}// console.log(this.timeSection)},clear() {this.rowUnit.forEach(item => {item.forEach(item1 => {item1.class = null;});});this.timeContent.forEach(item => {item.arr = [];});this.timeSection.forEach(item => {//赋值成空数组[]出问题item.length = 0;});//遍历赋值成'',不管用this.timeStr.length = 0;for (let i = 0; i < 7; i++) {this.timeStr.push("");}//this.initState = true},}
};
</script><style scoped>
.byted-weektime .calendar {-webkit-user-select: none;position: relative;display: inline-block;
}
#tableBody {/* position: relative; */
}
/*.byted-weektime .calendar .schedule{background:#2F88FF;width:0;height:0;position:fixed;display:none;top:0;left:0;pointer-events:none;-webkit-transition:all 400ms ease;-moz-transition:all 400ms ease;-ms-transition:all 400ms ease;transition:all 400ms ease}*/
.byted-weektime .calendar .calendar-table {border-collapse: collapse;border-radius: 4px;
}
.byted-weektime .calendar .calendar-table tr .calendar-atom-time:hover {background: #ccc;
}
.byted-weektime .calendar .calendar-table tr .ui-selected {background: #2f88ff;
}
.byted-weektime .calendar .calendar-table tr .ui-selected:hover {background: #2f88ff;
}
.byted-weektime .calendar .calendar-table tr,
.byted-weektime .calendar .calendar-table td,
.byted-weektime .calendar .calendar-table th {border: 1px solid #ccc;font-size: 12px;text-align: center;line-height: 1.8em;-webkit-transition: background 200ms ease;-moz-transition: background 200ms ease;-ms-transition: background 200ms ease;transition: background 200ms ease;
}
.byted-weektime .calendar .calendar-table tbody tr {height: 30px;
}
.byted-weektime .calendar .calendar-table tbody tr td:first-child {background: #f8f9fa;
}
.byted-weektime .calendar .calendar-table thead th,
.byted-weektime .calendar .calendar-table thead td {background: #f8f9fa;
}
.byted-weektime .calendar .calendar-table .td-table-tip {line-height: 2.4em;padding: 0 12px 0 19px;background: #fff !important;
}
.byted-weektime .calendar .calendar-table .td-table-tip .clearfix {height: 46px;line-height: 46px;
}
.byted-weektime .calendar .calendar-table .td-table-tip .pull-left {font-size: 14px;color: #333333;
}
.byted-weektime .week-td {width: 75px;padding: 20px 0;
}
.byted-weektime a {cursor: pointer;color: #2f88ff;font-size: 14px;
}
#kuang {position: absolute;background-color: blue;opacity: 0.3;
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/498464.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第四十五回 病关索大闹翠屏山 拚命三火烧祝家店-Python函数接受任意关键字参数

官府得到上报&#xff0c;被杀死的僧人是报恩寺的裴如海&#xff0c;旁边的头陀是寺后面的人叫胡道。孔目说他们两个互相杀死&#xff0c;没有其他人什么事&#xff0c;这件事也就过去了。 杨雄听说了这件事&#xff0c;知道是石秀干的&#xff0c;找石秀为自己错怪他道歉。两…

请你画出一个微服务项目架构图

第一种 架构图 第二种 架构图

为您提供互联网一站式服务代采系统

1688跨境“寻源通”产品背景 11月19日, 1688跨境“寻源通”产品发布会在杭州举办。 1688跨境“寻源通”分别针对跨境ERP、跨境代采商、跨境超买和SaaS,为他们提供基于 AI 技术的搜索比价引擎,通过和官方合作把1688 的1亿官方源头货盘铺出去。 该计划的推出是为了解决跨境生意…

【Ansys Fluent Web 】全新用户界面支持访问大规模多GPU CFD仿真

基于Web的技术将释放云计算的强大功能&#xff0c;加速CFD仿真&#xff0c;从而减少对硬件资源的依赖。 主要亮点 ✔ 使用Ansys Fluent Web用户界面™&#xff08;UI&#xff09;&#xff0c;用户可通过任何设备与云端运行的仿真进行远程交互 ✔ 该界面通过利用多GPU和云计算功…

项目流程图

实现便利店自助付款项目 服务器&#xff1a; 1、并发服务器&#xff08;多进程、多线程、IO多路复用&#xff09; 2、SQL数据库的创建和使用&#xff08;增删改查&#xff09; 3、以模块化编写项目代码&#xff0c;按照不同模块编写.h/.c文件 客户端&#xff1a; 1、QT客户端界…

面试官:说一下Filter过滤器的执行顺序

背景说明 各位小伙伴大家好&#xff0c;我是全栈小白 相信各位小伙伴都用过Filter过滤器吧&#xff0c;在学习servlet的时候&#xff0c;Filter可是我们认证的好帮手&#xff0c;但是在学习了SpringBoot框架之后&#xff0c;Filter可能被大家遗忘了&#xff0c;相对Spring框架…

简析:网红老隋分享的temu蓝海项目能赚钱吗?

在如今这个信息化时代&#xff0c;网红老隋凭借其丰富的投资经验和市场洞察力&#xff0c;分享了许多具有潜力的蓝海项目。其中&#xff0c;temu项目备受关注&#xff0c;许多人好奇这个项目能否带来收益。下面&#xff0c;我将从市场前景、竞争状况、盈利模式等方面进行分析&a…

Edge 开启网页选择功能(Web Select)

微软禁用了Web Select功能 本着什么功能好用就禁用什么的原则, 微软又禁用了Web Select的功能, 相信这个功能用过的人都说好, 还有好多人不知道这个功能 开启方式, 快捷方式添加启动参数 --enable-featuresmsEdgeAreaSelect 如图 重启电脑或者杀掉进程才能生效 kill命令 kil…

BY组态功能清单

演示地址 &#xff1a;http://www.byzt.net:60/sm/ 官网地址&#xff1a;http://www.hcy-soft.com BY组态是一款非常优秀的纯前端的【web组态插件工具】&#xff0c;可无缝嵌入到vue项目&#xff0c;react项目等&#xff0c;由于是原生js开发&#xff0c;对于前端的集成没有框架…

SpringBoot案例(黑马学习笔记)

这个案例呢&#xff0c;就是Tlias智能学习辅助系统。 参考接口文档完成后端功能的开 发&#xff0c;然后结合前端工程进行联调测试即可。 完成后的成品效果展示&#xff1a; 准备工作 需求&环境搭建 需求说明 部门管理 部门管理功能开发包括&#xff1a; ● 查询部门列…

c# .net8 香橙派orangepi + hc-04蓝牙 实例

这些使用c# .net8开发&#xff0c;硬件 香橙派 orangepi 3lts和 hc-04蓝牙 使用场景&#xff1a;可以通过这个功能&#xff0c;手机连接orangepi进行wifi等参数配置 硬件&#xff1a; 1、带USB口的linux开发板orangepi 2、USB 转TTL 中转接蓝牙&#xff08;HC-04) 某宝上买…

Groovy - 大数据共享搜索配置

数据共享搜索列中配置了搜索列&#xff0c;相应的数据共享接口中也需要支持根据配置的字段搜索&#xff0c;配置实体时&#xff0c;支持搜索的入参code必须是searchKeys&#xff0c;且接口应该是需要支持分页&#xff08;入参必须是 current、pageSize&#xff09;的。current …