微信小程序:以7天为周期,连续签到7天功能效果

此功能以1,2,3,4,5,6,7这样为一周期,连续签到的功能;
通过计算是否为整除7天计算,每7天后切换数目,从而改变周期表、

如果图如下:
图1图2

wxml结构

<!--pages/signIn/signIn.wxml-->
<view class='signIn'>
  <view class='sign-com'>
    <view class='thead'>
      <view class='tt'>已连续签到</view>
      <view class='mm'><label class='n'>{{signNum}}</label></view>
      <view class='pp'>连续签到7日后每日得3分</view>
    </view>
    <view class='modle'>
        <view class='mol'>
          <view class='mol-line'></view>
            <view class='mol-ites'>
              <view class="ite {{signNum>=min?'hover':''}}" data-n='{{min}}'>
                <label class='n'>+{{min<7?1:3}}</label>
              </view>
              <view class="ite {{signNum>=min+1?'hover':''}}" data-n='{{min+1}}'>
                <label class='n'>+{{min+1<7?1:3}}</label>
              </view>
                <view class="ite {{signNum>=min+2?'hover':''}}" data-n='{{min+2}}'>
                <label class='n'>+{{min+2<7?1:3}}</label>
              </view>
              <view class="ite {{signNum>=min+3?'hover':''}}" data-n='{{min+3}}'>
                <label class='n'>+{{min+3<7?1:3}}</label>
              </view>
              <view class="ite {{signNum>=min+4?'hover':''}}" data-n='{{min+4}}'>
                <label class='n'>+{{min+4<7?1:3}}</label>
              </view>
              <view class="ite {{signNum>=min+5?'hover':''}}" data-n='{{min+5}}'>
                <label class='n'>+{{min+5<7?1:3}}</label>
              </view>
              <view class="ite {{signNum>=min+6?'hover':''}}" data-n='{{max}}'>
                <label class='n'>+{{min+6<7?1:3}}</label>
              </view>
            </view>
        </view>
        <view class='moday'>
          <label class='dd'>{{min}}</label>
          <label class='dd'>{{min+1}}</label>
          <label class='dd'>{{min+2}}</label>
          <label class='dd'>{{min+3}}</label>
          <label class='dd'>{{min+4}}</label>
          <label class='dd'>{{min+5}}</label>
          <label class='dd'>{{max}}</label>
        </view>
      </view>

    <view class='the-btn'>
      <button type='button' class='btn' bindtap='bindSignIn' data-num="{{signNum}}" disabled='{{signState}}'
        data-min="{{min}}" data-max="{{max}}" data-be="{{be}}"
      >签到</button>
    </view>
  </view>
</view>

<view class='explax'>
  <view class=''>日期开始:{{min}} </view>
  <view class=''>日期结束:{{max}} </view>
  <view class=''>签到数:{{signNum}}</view>
  <view class=''>切换周期的倍数:{{be}}</view>
</view>

wxss样式

/* pages/signIn/signIn.wxss */
.signIn{ width: 100%; height: auto;}

.sign-com{ width: 100%; height: auto; padding: 0 30rpx; box-sizing: border-box; overflow: hidden; }
.sign-com .thead{ width: 100%; text-align: center; padding: 50rpx 0 35rpx;}
.sign-com .thead .tt{ font-size: 24rpx;}
.sign-com .thead .mm{ margin-top: 10rpx; font-size: 24rpx;}
.sign-com .thead .mm .n{ font-size: 66rpx; margin-right: 25rpx;}
.sign-com .thead .pp{ color: #999; font-size: 24rpx; margin-top: 10rpx;}

.sign-com .modle{ width: 100%; height: 100rpx; margin-top: 10rpx; }
.sign-com .modle .mol{ width: 100%; height: 52rpx; position: relative;  }
.sign-com .mol-line{ width: 100%; height: 4rpx; background-color: #e6e6e6; position: absolute; left: 0; top: 50%; transform: translateY(-50%);}
.sign-com .mol-ites{ width: 100%; height: 100%;position: absolute;}
.mol-ites .ite{ width: 52rpx; height: 52rpx; border-radius: 50%; border: 1px solid #f5f5f5;
 background-color: #fff; box-sizing: border-box;  position: absolute; left: 0; top: 0; z-index: 2;}
.mol-ites .ite .n{ width: 44rpx; height: 44rpx; line-height: 44rpx; text-align: center; border-radius: 50%; background-color: #f5f5f5;position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); font-size: 22rpx;}
.mol-ites .ite::after{ content: ""; width: 80rpx; height: 4rpx; background-color: transparent; 
position: absolute; left: 52rpx; top: 50%; margin-top: -2rpx; z-index: 2;}
.mol-ites .ite:last-of-type::after{ width: 0;}
.mol-ites .ite:nth-of-type(2){ left: 107rpx;}
.mol-ites .ite:nth-of-type(3){ left: 214rpx;}
.mol-ites .ite:nth-of-type(4){ left: 321rpx;}
.mol-ites .ite:nth-of-type(5){ left: 428rpx;}
.mol-ites .ite:nth-of-type(6){ left: 535rpx;}
.mol-ites .ite:nth-of-type(7){ left: 642rpx;}
.mol-ites .ite.hover{ border-color: #ff614a;}
.mol-ites .ite.hover .n{ background-color: #ff614a; color: #fff;}
.mol-ites .ite.hover::after{ background-color: #ff614a; }
.moday{ width: 100%; height:40rpx; overflow: hidden; position: relative; margin-top:20rpx;}
.moday .dd{ width: 52rpx; height: 40rpx; line-height: 1; text-align: center; font-size: 22rpx;
 position: absolute; left: 0; bottom: 0;}
.moday .dd:nth-of-type(2){ left: 107rpx;}
.moday .dd:nth-of-type(3){ left: 214rpx;}
.moday .dd:nth-of-type(4){ left: 321rpx;}
.moday .dd:nth-of-type(5){ left: 428rpx;}
.moday .dd:nth-of-type(6){ left: 535rpx;}
.moday .dd:nth-of-type(7){ left: 642rpx;}

.the-btn{ margin: 50rpx 0;}
.the-btn .btn{ background-color: #ff614a; color: #fff;}
.the-btn.signed .btn{ background-color: rgba(153, 153, 153, 0.61); }

.explax{ padding: 0 30rpx; font-size: 28rpx; color: #666;}

js功能

// pages/signIn/signIn.js
//获取应用实例
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    //img_url: config.imgUrl, //图片地址

    //签到模块
    signNum: 0,  //签到数
    signState: false, //签到状态
    min: 1,  //默认值日期第一天1
    max: 7,  //默认值日期最后一天7
    be: 0    //默认倍数


  },

  //签到
  bindSignIn(e) {
    var that = this,
      num = e.currentTarget.dataset.num;
    num++
    wx.showToast({
      icon: 'success',
      title: '签到成功',
    })
    that.setData({
      signNum: num,
      //signState: true
    })

    var min = e.currentTarget.dataset.min,
      max = e.currentTarget.dataset.max,
      be = e.currentTarget.dataset.be;

    if (num % 7 == 0) {
      be += 1;
      that.setData({
        be: be
      })
    }

    if (num == 7 * be + 1) {
      that.setData({
        min: 7 * be + 1,
        max: 7 * be + 7
      })
    }

  },


})

有什么错误或优化的地方,可以提出来,大家一起学习研究….

完整案例可到下载https://github.com/xiexikang/xcx-signIn

猜你喜欢

转载自blog.csdn.net/weixin_42211816/article/details/81985084
今日推荐