当前位置: 首页 > news >正文

基于element-ui 日期选择器el-date-picker, 即对日期做区间限制

需求:

有时候需求会让我们对日期选择器做限制,即控制最多可跨越多少个月份,其中涉及到不同年份该如何计算。

HTML:

<el-date-pickerv-model="timePeriod"type="monthrange"value-format="yyyyMM"format="yyyyMM"range-separator="至"start-placeholder="开始月份"end-placeholder="结束月份"
>
</el-date-picker>

功能代码:

this.timePeriod = ['201402','201409'] //演示数据let stagingList = []if(this.timePeriod && this.timePeriod.length >0){let time = new Date().getFullYear().toString()let lists = []let yearComparison_1 = this.timePeriod[0].substr(0,time.length)let yearComparison_2 = this.timePeriod[1].substr(0,time.length)let compareTheMonthsTo_1 = this.timePeriod[0].substr(time.length,2)let compareTheMonthsTo_2 = this.timePeriod[1].substr(time.length,2)let monthlyDifference = compareTheMonthsTo_2 - compareTheMonthsTo_1if (yearComparison_1 == yearComparison_2) {if(monthlyDifference == 0){let deduplication = []for (let k = 0; k < this.timePeriod.length; k++) {if (deduplication.indexOf(this.timePeriod[k]) === -1) {deduplication.push(this.timePeriod[k])}}lists = deduplication} else if(monthlyDifference > 0){let incrementalStorage = []for (let j = 0; j < monthlyDifference + 1; j++){let moon = (compareTheMonthsTo_1 * 1)  + jif(moon < 10){moon = "0" + moon;}incrementalStorage.push(yearComparison_1 + moon)}lists = incrementalStorage}}else if(yearComparison_1 != yearComparison_2){let length_1 = 12 -compareTheMonthsTo_1let storingData1 = []let length_2 = compareTheMonthsTo_2 * 1let storingData2 = []let storingData3 = []for (let i = 0; i < length_1 + 1; i++) {let moon_1 = (compareTheMonthsTo_1 * 1)  + iif(moon_1 < 10){moon_1 = "0" + moon_1;}storingData1.push(yearComparison_1 + moon_1)}let th = yearComparison_2 - yearComparison_1if(th > 1){var newYearSEve = []let N = yearComparison_1for (let index = 1; index < th; index++) {N = (N * 1) + indexfor (let q = 1; q < 13; q++) {if(q < 10){q = "0" + q;}newYearSEve.push(N.toString() + q)}}storingData1.push(...newYearSEve);}for (let j = 0; j < length_2; j++) {let moon_2 = j + 1if(moon_2 < 10){moon_2 = "0" + moon_2;}storingData2.push(yearComparison_2 + moon_2)}storingData3 = storingData1.concat(storingData2)lists = storingData3  }stagingList = lists}if (stagingList.length > 13) {this.$message.warning('账期至多只可选择13个月!')return}

打印结果:

console.log(stagingList);


http://www.mrgr.cn/news/8900.html

相关文章:

  • 设计模式-访问器模式
  • TypeScript 面试题汇总
  • 掌握CSS3的transform-origin:让你的网页动画更生动
  • Lumos学习王佩丰Excel第十三讲:邮件合并
  • 基于vue框架的比赛门票出售的系统12lh6(程序+源码+数据库+调试部署+开发环境)系统界面在最后面。
  • [数据集][目标检测]建筑工地楼层空洞检测数据集VOC+YOLO格式2588张1类别
  • 解密巴黎奥运会中的阿里云AI技术
  • 爬取央视热榜并存储到MongoDB
  • vue3 安装element-plus进行一些简单的测试
  • 实现el-table 两列多选框且不可同时勾选,可单选,可多选
  • java中的Collections
  • docker的安装+docker镜像的基本操作
  • Flutter-->Widget上屏之路
  • 高等数学精解【12】
  • shell程序设计入门(二)
  • 在Python中使用OpenCV录制视频并保存
  • 【Kubernetes】K8s 持久化存储方式
  • CSS的简单介绍
  • python小游戏——躲避球(可当课设)
  • Spark MLlib 特征工程系列—特征转换Polynomial Expansion