微信小程序以7天为周期连续签到7天功能效果的示例代码
时间:2020-12-30 14:18:01|栏目:JavaScript代码|点击: 次
此功能以1,2,3,4,5,6,7这样为一周期,连续签到的功能;
通过计算是否为整除7天计算,每7天后切换数目,从而改变周期表、
本案例只是提供案例的基本操作,进一步涉及:每日用户集的监听(日历表,签到统计,连续签到,签到中断,后端数据处理)等等功能需自行在搞掂哈~
如果图如下:
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>
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 }) } }, })
有什么错误或优化的地方,可以提出来,大家一起学习研究…
完整案例可访问本人github:https://github.com/xiexikang/xcx-signIn
参考:
[js仿淘宝收货地址列表,设置默认地址]
[微信小程序签到积分案列]
[微信小程序canvas生成分享图片到相册的案例]