年至年的选择仿elementui的样式

在这里插入图片描述

组件:
<!--* @Author: liuyu liuyu@xizhengtech.com* @Date: 2023-02-01 16:57:27* @LastEditors: wangping wangping@xizhengtech.com* @LastEditTime: 2023-06-30 17:25:14* @Description: 时间选择年 --->
<template><div class="yearPicker" ref="yearPicker" :width="width"><input class="_inner" :style="bindInputStyle" ref="inputLeft" v-model="startShowYear" @focus="onFocus" @blur="onBlur" type="text" name="yearInput" @keyup="checkStartInput($event)" placeholder="开始年份" /><span>{{ sp }}</span><input class="_inner" :style="bindInputStyle" ref="inputRight" v-model="endShowYear" @focus="onFocus" @blur="onBlur" type="text" name="yearInput" @keyup="checkEndInput($event)" placeholder="结束年份" /><!-- <i class="dateIcon el-icon-date"></i> 按照自己标准库里面的图标设置--><!-- <span class="_inner labelText"></span> --><i class="_inner labelText el-icon-date"></i><div class="_inner floatPanel" v-if="showPanel"><div class="_inner leftPanel"><div class="_inner panelHead"><i class="_inner el-icon-d-arrow-left" @click="onClickLeft"></i>{{ leftYearList[0] + " - " + leftYearList[9] }}</div><div class="_inner panelContent"><div :class="{oneSelected: item === startYear && oneSelected,startSelected: item === startYear,endSelected: item === endYear,betweenSelected: item > startYear && item < endYear,}" v-for="item in leftYearList" :key="item"><a :class="{cell: true,_inner: true,selected: item === startYear || item === endYear,}" @click="onClickItem(item)" @mouseover="onHoverItem(item)">{{ item }}</a></div></div></div><div class="line"></div><div class="_inner rightPanel"><div class="_inner panelHead"><i class="_inner el-icon-d-arrow-right" @click="onClickRight"></i>{{ rightYearList[0] + " - " + rightYearList[9] }}</div><div class="_inner panelContent"><div :class="{startSelected: item === startYear,endSelected: item === endYear,betweenSelected: item > startYear && item < endYear,}" v-for="item in rightYearList" :key="item"><a :class="{cell: true,_inner: true,selected: item === endYear || item === startYear,}" @click="onClickItem(item)" @mouseover="onHoverItem(item)">{{ item }}</a></div></div></div></div></div>
</template><script>
import moment from "moment";
const SELECT_STATE = {unselect: 0,selecting: 1,selected: 2,
};
export default {name: "yearPicker",computed: {bindInputStyle() {return {"--placeholderColor": "#c0c4cc",};},oneSelected() {return (this.curState === SELECT_STATE.selecting &&(this.startYear === this.endYear || this.endYear == null));},startDate() {return this.startYear;},leftYearList() {return this.yearList.slice(0, 10);},rightYearList() {return this.yearList.slice(10, 20);},startYearFormat() {if (this._.isNil(this.startYear)) {return null;}return moment(this.startYear).startOf("year").format("yyyy");},endYearFormat() {if (this._.isNil(this.endYear)) {return null;}return moment(this.endYear).endOf("year").format("yyyy");},},props: {width: {default: 200,},labelWidth: {default: 40,},sp: {default: "-",},initYear: {default: null,},},data() {return {itemBg: {},startShowYear: null,endShowYear: null,yearList: [],showPanel: false,startYear: null,endYear: null,curYear: 0,curSelectedYear: 0,curState: SELECT_STATE.unselect,};},methods: {checkStartInput(event) {if (isNaN(this.startShowYear)) {this.startShowYear = this.startYear;} else {this.startYear = this.startShowYear * 1;this.changeYear();}},checkEndInput() {if (isNaN(this.endShowYear)) {this.endShowYear = this.endYear;} else {this.endYear = this.endShowYear * 1;this.changeYear();}},changeYear() {if (this.startYear > this.endYear) {let tmp = this.endYear;this.endYear = this.startYear;this.startYear = tmp;this.startShowYear = this.startYear;this.endShowYear = this.endYear;}if (this.startYear && this.endYear) {this.$emit("updateTimeRange", {startYear: moment(this.startYear + "").startOf("year").valueOf(),endYear:moment(this.endYear + "").endOf("year").valueOf() + 1,});} else {console.warn("WARN:年份不合法", this.startYear, this.endYear);}},onHoverItem(iYear) {if (this.curState === SELECT_STATE.selecting) {let tmpStart = this.curSelectedYear;this.endYear = Math.max(tmpStart, iYear);this.startYear = Math.min(tmpStart, iYear);}},onClickItem(iYear) {if (this.curState === SELECT_STATE.unselect ||this.curState === SELECT_STATE.selected) {this.startYear = iYear;this.curSelectedYear = iYear;this.endYear = null;this.curState = SELECT_STATE.selecting;} else if (this.curState === SELECT_STATE.selecting) {this.endShowYear = this.endYear;this.startShowYear = this.startYear;this.curState = SELECT_STATE.selected;this.$emit("updateTimeRange", {startYear: moment(this.startYear + "").startOf("year").valueOf(),endYear:moment(this.endYear + "").endOf("year").valueOf() + 1,});setTimeout(() => {//为动画留的时间,可优化this.showPanel = false;}, 300);}},onFocus() {this.$nextTick(() => {this.showPanel = true;});},onBlur() {//   this.showPanel = false;},updateYearList() {let iStart = Math.floor(this.curYear / 10) * 10 - 10;iStart = iStart < 0 ? 0 : iStart;this.yearList = [];for (let index = 0; index < 20; index++) {this.yearList.push(iStart + index);}},closePanel(e) {if (!this.showPanel) {return;}if (typeof e.target.className !== "string") {this.$nextTick(() => {this.showPanel = false;});return;}if (e.target.className.indexOf("_inner") === -1 ||(e.target.name === "yearInput" &&e.target !== this.$refs.inputLeft &&e.target !== this.$refs.inputRight)) {this.$nextTick(() => {this.showPanel = false;});}e.stopPropagation();return false;},onClickLeft() {this.curYear = this.curYear * 1 - 10;this.updateYearList();},onClickRight() {this.curYear = this.curYear * 1 + 10;this.updateYearList();},//------------------对外接口------------------------//直接传时间戳setYear(startYearStamp, endYearStamp) {if (!isNaN(startYearStamp) && !isNaN(endYearStamp)) {let startYear = moment(startYearStamp).format("yyyy");let endYear = moment(endYearStamp).format("yyyy");this.startYear = startYear * 1;this.endYear = endYear * 1;this.endShowYear = endYear * 1;this.startShowYear = startYear * 1;}},},created() {this.curYear = moment().format("yyyy");this.updateYearList();},beforeUnmount() {document.removeEventListener("click", this.closePanel.bind(this));},mounted() {this.$refs.yearPicker.style = "padding-left:" + this.labelWidth + "px";document.addEventListener("click", this.closePanel.bind(this));},
};
</script>
<style lang="scss" scoped>
.yearPicker {font-size: 14px;display: flex;position: relative;transition: all 0.3s;input {&::placeholder {color: var(--placeholderColor); // 动态值}}input:first-child {text-align: center;}.labelText {position: absolute;left: 10px;top: 10px;color: #c4c6d1;}background-color: #fff;span {padding: 0 8px;height: 36px;line-height: 36px;}border: 1px solid #eff1f3;height: 36px;line-height: 36px;border-radius: 4px;padding: 0 28px 0 8px;box-sizing: border-box;.floatPanel {> div {width: 50%;}// padding: 16px;position: absolute;display: flex;background-color: #fff;z-index: 9999 !important;border-radius: 4px;// width: 650px;height: 252px;top: 50px;left: 0px;box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);border: 1px solid #dfe4ed;.panelContent {display: grid;grid-template-columns: 25% 25% 25% 25%;// flex-wrap: wrap;width: 100%;height: calc(100% - 15px);margin-top: 8px;.oneSelected {border-top-right-radius: 24px;border-bottom-right-radius: 24px;}.startSelected {background-color: #f2f6fc;border-top-left-radius: 24px;border-bottom-left-radius: 24px;}.endSelected {background-color: #f2f6fc;border-top-right-radius: 24px;border-bottom-right-radius: 24px;}.betweenSelected {background-color: #f2f6fc;}> div {width: 75px;height: 48px;line-height: 48px;margin: 6px 0;// border-radius: 24px;text-align: center;a {display: inline-block;width: 60px;height: 36px;cursor: pointer;line-height: 36px;border-radius: 18px;color: #606266;}.selected {background-color: #1890ff;color: #fff;}}}.panelHead {height: 38px;line-height: 38px;position: relative;text-align: center;font-size: 16px;border-bottom: 1px solid #dfe4ed;i {position: absolute;cursor: pointer;&:hover {color: #1890ff;}}}.rightPanel {// padding-left: 8px;margin: 16px;display: flex;flex-direction: column;}.line {width: 1px;height: 100%;background: #dfe4ed;}.leftPanel {margin: 16px;display: flex;flex-direction: column;}.leftPanel .panelHead i {left: 0px;top: 10px;font-size: 14px;color: #717273;}.rightPanel .panelHead i {right: 0px;top: 8px;}.leftPanel .panelHead i:hover,.rightPanel .panelHead i:hover {cursor: pointer;}}.floatPanel::before {content: "";border-bottom: 6.5px solid #797979;border-left: 6.5px solid transparent;border-right: 6.5px solid transparent;position: absolute;left: 44px;-webkit-transform: translateX(-50%);transform: translateX(-50%);top: -5.5px;border-radius: 5px;}.floatPanel::after {content: "";border-bottom: 8px solid #fff;border-left: 8px solid transparent;border-right: 8px solid transparent;position: absolute;left: 44px;-webkit-transform: translateX(-50%);transform: translateX(-50%);top: -5px;border-radius: 5px;}
}
input {width: 100px;border: none;height: 37px;line-height: 37px;box-sizing: border-box;background-color: transparent;text-align: center;color: #606266;
}
input:focus {outline: none;background-color: transparent;
}
.yearPicker:hover {border-color: #1890ff;
}
.dateIcon {position: absolute;right: 16px;top: 9px;color: #adb2bc;
}
</style>
使用:
<YearYear1 style="width:300px" :initYear="dateValue2" @updateTimeRange="updateStatisticYear" />dateValue2: [],updateStatisticYear(val) {console.log("年", val);
},

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

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

相关文章

更多openEuler镜像加入AWS Marketplace!

自2023年7月openEuler 22.03 LTS SP1正式登陆AWS Marketplace后&#xff0c;openEuler社区一直持续于在AWS上提供更多版本。 目前&#xff0c;openEuler22.03 LTS SP1 ,SP2两个版本及 x86 arm64两种架构的四个镜像均可通过AWS对外提供&#xff0c;且在亚太及欧洲15个Region开放…

【HCIP】BGP总结

一、bgp介绍 1.概念 边界网关协议BGP&#xff08;Border Gateway Protocol&#xff09;是一种实现自治系统AS之间的路由可达&#xff0c;并选择最佳路由的路径矢量路由协议。目前在IPV4环境下主要使用BGPV4&#xff0c;目前市场上也存BGPV4&#xff0c;BGPV4在BGPV4的基础上支…

.net连接mysql,提示找不到请求的 .Net Framework Data Provider。可能没有安装

开发完成的.net程序需要连接mysql数据库&#xff0c;在个人电脑上运行没问题&#xff0c;别人运行时提示“提示找不到请求的 .Net Framework Data Provider。可能没有安装”。经过查询&#xff0c;安装Connector/NET 8.1.0&#xff0c;下载地址如下所示&#xff1a; https://d…

攻击LNMP架构Web应用

环境配置(centos7) 1.php56 php56-fpm //配置epel yum install epel-release rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm//安装php56&#xff0c;php56-fpm及其依赖 yum --enablereporemi install php56-php yum --enablereporemi install php…

SpringBoot的配置文件(properties与yml)

文章目录 1. 配置文件的作用2. 配置文件格式3. 配置文件的使用方法3.1. properties配置文件3.1.1. 基本语法和使用3.1.2. properties优缺点分析 3.2. yml配置文件3.2.1. 基本语法与使用3.2.2. yml中单双引号问题3.2.3. yml配置不同类型的数据类型及null3.2.4. 配置对象3.2.5. 配…

【计算机网络】13、ARP 包:广播自己的 mac 地址和 ip

机器启动时&#xff0c;会向外广播自己的 mac 地址和 ip 地址&#xff0c;这个即称为 arp 协议。范围是未经过路由器的部分&#xff0c;如下图的蓝色部分&#xff0c;范围内的设备都会在本地记录 mac 和 ip 的绑定信息&#xff0c;若有重复则覆盖更新&#xff08;例如先收到 ma…

ATF(TF-A)安全通告 TFV-5 (CVE-2017-15031)

安全之安全(security)博客目录导读 ATF(TF-A)安全通告汇总 目录 一、ATF(TF-A)安全通告 TFV-5 (CVE-2017-15031) 二、CVE-2017-15031 一、ATF(TF-A)安全通告 TFV-5 (CVE-2017-15031) Title 未初始化或保存/恢复PMCR_EL0可能会泄露安全世界的时间信息 CVE ID CVE-2017-1503…

Stable Diffusion入门修炼手册

简介 作为新入门的新手&#xff0c;通常安装完Stable Diffusion之后&#xff0c;一打开界面&#xff0c;在文生图输入girl或者dog&#xff0c;结果出来的画面比较糟糕&#xff0c;看起来像素很低&#xff0c;画面不清晰&#xff0c;人物也不怎么美&#xff0c;等等其他问题&am…

STM32 FLASH 读写数据

1. 《STM32 中文参考手册》&#xff0c;需要查看芯片数据手册&#xff0c;代码起始地址一般都是0x8000 0000&#xff0c;这是存放整个项目代码的起始地址 2. 编译信息查看代码大小&#xff0c;修改代码后第一次编译后会有这个提示信息 2.1 修改代码后编译&#xff0c;会有提示…

【数据结构】实现顺序表

目录 一.介绍顺序表二.实现顺序表1.创建多文件2.顺序表的存储方式3.函数的声明4.初始化顺序表5.清理顺序表6.打印顺序表7.扩容8.尾插8.尾删9.头插10.头删11.查找12.修改13.在pos位置插入13.在pos位置删除 三.全部代码1.SeqList.h2.SeqList.c3.Test.c 一.介绍顺序表 顺序表是用…

【Linux命令详解 | tar命令】 tar命令用于打包和解压文件,常用于备份和压缩文件

文章标题 简介一&#xff0c;参数列表二&#xff0c;使用介绍1. 打包文件和目录2. 解包归档文件3. 压缩归档文件4. 列出归档文件内容5. 排除特定文件6. 保留文件权限和所有权7. 保留时间戳8. 增量备份9. 使用文件列表10. 压缩级别控制 总结 简介 在Linux中&#xff0c;tar命令…

BTC硬币已实现价格分布

号外&#xff1a;刘教链新作&#xff0c;欢迎点击阅读&#xff1a; 公众号「刘教链内参」8.16发表&#xff1a;《内参&#xff1a;Vitalik亲口承认几乎所有二层roll-up都有后门》。 公众号「刘教链Pro」8.16发表&#xff1a;《作为投资组合保险的比特币》。 * * * * * * 熟悉比…