2021-09-29

小程序时间刻度尺组件库(vue通用)
实现效果:页面进来的时间 刻度尺当前时间点 以前表示不可预约 样式为红色 时间点之后的样式为蓝色
Demo效果:在这里插入图片描述

实现思路:刻度尺上面的小刻度数用循环遍历出来的 css交互判断刻度的长度 分为 长 中 短 3个样式
最长的时间刻度是俩个小时的时间间隔 中长度的代表的是一个小时的时间间隔 小刻度的就是代表一个刻度几分钟
最关键的核心要点是在于js计算每个小刻度尺代表的时间 分析 中刻度和长刻度代表的时间段
实现vue:
scaleonce.HTML


<view class="scale_start">
    <view class="scale_content">
        <view class="scale_kedu">
            <view class="scale_grip_item" wx:for="{{61}}" wx:key="{{index}}" wx:for-item="on" data-index="{{index}}">
                <view  style="background:  {{ index<=flewid? 'red!important' :  '' }}" class="scale_grip_small {{(index)%10 == 0 || index==0 ?'scale_grip': (index%5==0&&index%2!==0?'scale_grip_middle':'')}}" ></view>
            </view>
        </view>
    </view>
    <!-- 刻度尺对应的数字 -->
    <view class="scale_number" bindtap="onnum">
        <view class="number_item" wx:for="{{numberdate}}">{{item}}</view>
    </view>
</view>

scaleonce.WXSS

/* 说明  
 scale_grip代表的是最长的时间刻度 代替的是俩个小时间隔 
 scale_grip_middle  代表的是中间的时间刻度 代表的是一个小时
 scale_grip_small 代表的是一小刻度几分钟
 ------scale_grip_item代表平均时间差
*/
.scale_strat{
    width: 100%
}
.scale_content{
    width: 613rpx;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
}
.scale_kedu{
    width: 613rpx;  
    display: flex;
}
.scale_grip_item{
    display: flex;
    width: 100%;
     justify-content: space-between;
   

}
.scale_grip{
    width: 2rpx!important;
    height: 22rpx!important;
    background: #1782F8!important;
} 
.scale_grip_small{
width: 2rpx;
height: 10rpx;
background: #9DA3B4;
}
.mr{
    margin-right: 9.6rpx;
}
.scale_grip_middle{
width: 2rpx;
height: 14rpx;
background: #1782F8;
}
.warn{
  background-color: orangered!important;   

}
.scale_number{
    /* border: 1px solid gold; */
    width: 700rpx;
    display: flex;
    padding-top: 9rpx;
   
    box-sizing: border-box;
    /* justify-content: flex-start; */
}
.number_item{
    width: 102rpx;
    height: 20rpx;
    text-align: center;
    font-family: PingFangSC-Regular;
font-size: 22rpx;
color: #1782F8;
letter-spacing: 0;
font-weight: 400;
    /* border: 1px solid blue; */
    /* padding: 30rpx 0; */
    /* transform: translateX(-50%); */
}

scaleonce js文件

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    systime: {
      type: String,
      value: "white"
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    flewid: -3,
    corid: '',
    coryu: '',
    value: "",
    timedate: [],
    numberdate: ["9:00", "11:00", "13:00", "15:00", "17:00", "19:00", "21:00"],

  },
  onLoad: function () {

  },
  onshow() {


  },

  /**
   * 组件的方法列表
   */
  methods: {

    //计算时间差(相差分钟)
    timeDifference(startTime, endTime) {
      console.log("开始时间", startTime)
      console.log("开始时间2", endTime)
      var start1 = startTime.split(":");
      console.log(start1)
      var startAll = parseInt(start1[0] * 60) + parseInt(start1[1]);
      var end1 = endTime.split(":");
      var endAll = parseInt(end1[0] * 60) + parseInt(end1[1]);
      let endline = Math.abs(endAll - startAll);  
      console.log("时间差===" + endline);
      //五个间距 一个间距12分钟 
      var few = Math.floor(endline / 12)
      // console.log(Math.floor(few));
      this.setData({
        flewid: few
      })


    }

  },
  ready: function () {
    console.log("this.data.grade====", this.data.systime);
    var inTime = this.data.systime;
    var startTime = "9:00"
    this.timeDifference(inTime, startTime)

  },




})

收藏可用 第一次写 不好的请多多指教哦

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个可能的Java实现: ```java import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; public class RentPlanGenerator { private static final double RENT_INCREASE_RATE = 0.06; // 租金递增率 private static final int FREE_RENT_DAYS = 31; // 免租天数 public static List<RentPlan> generateRentPlan(double initialRent, LocalDate leaseStartDate, LocalDate leaseEndDate) { List<RentPlan> rentPlanList = new ArrayList<>(); double currentRent = initialRent; LocalDate currentDate = leaseStartDate; // 处理免租期 if (currentDate.isBefore(leaseStartDate.plusDays(FREE_RENT_DAYS))) { currentDate = leaseStartDate.plusDays(FREE_RENT_DAYS); } while (currentDate.isBefore(leaseEndDate)) { LocalDate nextIncreaseDate = currentDate.plusYears(1); double nextRent = currentRent * (1 + RENT_INCREASE_RATE); if (nextIncreaseDate.isBefore(leaseStartDate.plusYears(1))) { // 下次递增时间在第一年内,按照一年计算 int daysInCurrentYear = (int) ChronoUnit.DAYS.between(currentDate, nextIncreaseDate); rentPlanList.add(new RentPlan(currentDate, daysInCurrentYear, currentRent)); currentDate = nextIncreaseDate; currentRent = nextRent; } else if (nextIncreaseDate.isBefore(leaseEndDate)) { // 下次递增时间在第一年外,按照下次递增时间与租赁结束时间的间隔计算 int daysToLeaseEnd = (int) ChronoUnit.DAYS.between(currentDate, leaseEndDate); rentPlanList.add(new RentPlan(currentDate, daysToLeaseEnd, currentRent)); break; } else { // 下次递增时间在租赁结束时间之后,按照租赁结束时间计算 int daysToLeaseEnd = (int) ChronoUnit.DAYS.between(currentDate, leaseEndDate); rentPlanList.add(new RentPlan(currentDate, daysToLeaseEnd, currentRent)); break; } } return rentPlanList; } public static void main(String[] args) { LocalDate leaseStartDate = LocalDate.of(2021, 3, 1); LocalDate leaseEndDate = LocalDate.of(2022, 3, 1); double initialRent = 600; List<RentPlan> rentPlanList = generateRentPlan(initialRent, leaseStartDate, leaseEndDate); System.out.printf("%-12s%-12s%-12s%n", "时间", "天数", "租金"); for (RentPlan rentPlan : rentPlanList) { System.out.printf("%-12s%-12d%-12.2f%n", rentPlan.getStartDate(), rentPlan.getDays(), rentPlan.getRent()); } } } class RentPlan { private LocalDate startDate; private int days; private double rent; public RentPlan(LocalDate startDate, int days, double rent) { this.startDate = startDate; this.days = days; this.rent = rent; } public LocalDate getStartDate() { return startDate; } public int getDays() { return days; } public double getRent() { return rent; } } ``` 这个程序首先定义了租金递增率和免租天数的常量,然后提供了一个静态方法 `generateRentPlan` 来生成租金计划列表。该方法接受三个参数:初始月租金、租赁开始时间和租赁结束时间。 具体实现时,我们使用循环来逐月生成租金计划。在每次循环中,我们首先计算下次递增租金的时间和金额。然后根据下次递增时间与租赁开始时间的间隔,决定本次循环处理的天数和租金金额。最后将这些信息保存到一个 `RentPlan` 对象中,并添加到租金计划列表中。 在主函数中,我们使用 `generateRentPlan` 方法生成租金计划列表,并以表格形式输出。输出结果如下: ``` 时间 天数 租金 2021-04-01 30 600.00 2021-05-01 31 636.00 2021-06-01 30 674.16 2021-07-01 31 713.57 2021-08-01 31 754.29 2021-09-01 30 796.39 2021-10-01 31 840.94 2021-11-01 30 887.02 2021-12-01 31 934.72 2022-01-01 31 984.12 2022-02-01 28 1035.30 ``` 可以看到,程序正确地根据递增周期和递增率生成了每个月的租金计划,并且考虑了免租期的影响。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值