1、关于Element-UI日期范围选择器控件添加清空、确定按钮

1、日期控件原来样式

在这里插入图片描述
现在我们需要在日期控件右下角添加按钮(如下方示例)
在这里插入图片描述

2、实现方式

<el-date-picker class="date-down" ref="datePick" align="right" v-model="comSearch.time"
type="daterange" :clearable="false" :picker-options="dateButton" range-separator="——" 
start-placeholder="开始日期"  end-placeholder="结束日期"  format="yyyy-MM-dd"
value-format="yyyy-MM-dd" @change="changeTime">
</el-date-picker>
<!--
align="right"  					默认与日期框左侧对齐,我这边给他设置的居右对齐
:clearable="false"      		默认在日期框上显示清空icon,false表示不显示
:picker-options="dateButton"	默认表示为日期选择框左侧的快捷日期选择,我这边为了方便添加清空、
								确定,直接在快捷设置里面添加
-->
data(){
	var that = this;
	return{
		// 日期清空 确定
      dateButton: {
      	time:'',
        shortcuts: [
          {
            text: "清空",
            onClick() {
              that.time = "";
            },
          },
          {
            text: "确定",
            onClick() {
              that.$refs.datePick.handleClose();
              //通过$ref设置 点击确定时,关闭日期选择的弹窗
            },
          },
        ],
      },
	}
},
methods(){
	// 当日期改变时触发
    changeTime(e) {
      //保证在选择完时间后,日期弹出框不会消失
      this.$refs.datePick.focus();
      this.time = e;
    },
}
/* 日期控件样式 */
/* input框placeholder样式 */
.el-date-editor input::-webkit-input-placeholder {
   color: #fff;
}
.el-date-editor input::-moz-input-placeholder {
   color: #fff;
}
.el-date-editor input::-ms-input-placeholder {
   color: #fff;
}
/* 日期选择框面板样式 */
.el-picker-panel,
.el-date-picke {
   width: 506px !important;
   height: 323px !important;
   background: rgba(0, 0, 0, 1) !important;
   border: 1px solid rgba(255, 255, 255, 0.3);
   margin: 0;
   font-size: 1rem !important;
   font-family: 'HelveticaNeue-Medium, HelveticaNeue';
   font-weight: 500;
   color: #FFFFFF;
}
.el-popper[x-placement^=bottom] {
   margin-top: 0px !important;
}

.el-popper[x-placement^=bottom] .popper__arrow::after {
   border-bottom-color: rgba(0, 0, 0, 0) !important;
}

.el-popper[x-placement^=bottom] .popper__arrow {
   border-bottom-color: rgba(0, 0, 0, 0) !important;
}

.el-date-range-picker .el-picker-panel__body {
   min-width: 506px;
}

/* 日期选择器左侧快捷方式样式重写 定位到底部 */
.el-picker-panel__sidebar {
   width: 506px;
   height: 40px;
   padding: 0;
   display: flex;
   justify-content: right;
   align-items: center;
   margin-top: 283px;
   background: rgba(0, 0, 0, 0) !important;
   border-right: 1px solid rgba(0, 0, 0, 0);
}

.el-picker-panel__sidebar :nth-child(2) {
   background-color: #3AA0B8;
   border: none;
}

.el-picker-panel__sidebar>button {
   width: 56px;
   height: 24px;
   line-height: 20px;
   margin-right: 16px;
   border: 1px solid #6DE3FF;
   font-size: 12px;
   font-family: 'PingFangSC-Regular, PingFang SC';
   font-weight: 400;
   color: #FFFFFF;
   padding: 0;
   text-align: center;
   border-radius: 2px;
}

.el-picker-panel__shortcut:hover {
   color: #fff;
   border: 1px solid #fff;
}
/* 日期选择器日历部分样式*/
.el-picker-panel__body-wrapper {
   width: 506px;
   height: 323px;
   display: flex;
   flex-wrap: wrap;
}

.el-picker-panel__body {
   margin: 0 !important;
   width: 506px;
   height: 283px;
}

.el-date-range-picker__header {
   box-sizing: border-box;
   padding: 0 10px;
   font-size: 0.16rem !important;
   font-family: 'HelveticaNeue-Medium, HelveticaNeue';
   font-weight: 500 !important;
   color: #FFFFFF !important;
}

.el-date-picker__header-label {
   font-size: 16px;
   font-weight: 500;
   padding: 0 5px;
   line-height: 22px;
   text-align: center;
   cursor: pointer;
   color: #fff;
}

.el-picker-panel__content {
   height: 283px;
   padding: 0px;
   border-bottom: 1px solid #e4e4e4;
   box-sizing: border-box !important;
}

.el-picker-panel__icon-btn {
   font-size: 12px;
   color: #fff;
   border: 0;
   background: 0 0;
   cursor: pointer;
   outline: 0;
   margin-top: 8px;
}

.el-date-table {
   box-sizing: border-box;
   padding: 5px;
}

.el-date-table th {
   padding: 5px;
   color: #fff;
   font-weight: 400;
   border-bottom: solid 1px rgba(255, 255, 255, 0.3);
}

.el-date-table td {
   padding: 2px 0px !important;
}

.el-date-table td.end-date span,
.el-date-table td.start-date span {
   background-color: #3AA0B8;
}
/* 选中范围背景色 */
.el-date-table td.in-range div,
.el-date-table td.in-range div:hover,
.el-date-table.is-week-mode .el-date-table__row.current div,
.el-date-table.is-week-mode .el-date-table__row:hover div {
   background-color: rgba(255, 255, 255, 0.2) !important;
}
  • 5
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
el-date-pickerElement UI库中的日期选择器组件picker-options是该组件的配置选项。 使用picker-options可以对日期选择器进行个性化的设置,包括但不限于以下选项: 1. disabledDate:自定义禁用日期的函数,可以根据具体需求设置某些日期不可选。 2. shortcuts:预设快捷选项,可以快速选择常用的日期范围。 3. format:指定日期的显示格式,默认为yyyy-MM-dd。 4. clearable:是否显示清空按钮,默认为true。 5. readonly:是否为只读状态,默认为false。 6. editable:是否可输入,默认为true。 7. align:对齐方式,可选值为left、center、right,默认为left。 8. popperClass:自定义弹出框样式的类名。 9. pickerOptions:配置日期选择器弹出框的选项,例如禁用时间、时间间隔等。 示例代码如下: ```html <el-date-picker v-model="date" :picker-options="{ disabledDate: (time) => { return time.getTime() < Date.now(); // 禁用过去的日期 }, shortcuts: [ { text: '最近一周', onClick: () => { const start = new Date(); const end = new Date(); start.setDate(start.getDate() - 6); this.date = [start, end]; } }, { text: '最近一个月', onClick: () => { const start = new Date(); const end = new Date(); start.setMonth(start.getMonth() - 1); this.date = [start, end]; } } ], format: 'yyyy-MM-dd', clearable: true, readonly: false, editable: true, align: 'left', popperClass: 'my-popper-class', pickerOptions: { disabledMinutes: [0, 30] // 禁用0分和30分 } }" ></el-date-picker> ``` 以上是一些常见的picker-options选项,你可以根据自己的需求进行配置。更多详细的选项和用法,请参考Element UI官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只小 Ziyi.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值