⼩程序连续签到7天积分获得功能的⽰例代码
每周每天签到获得积分的案例
功能设计:计算每天签到得1分,显⽰得到的签到积分,连续签到3天[周⼀⼆三]即得+多3分,连续签到7天[周⼀⼆三四五六⽇]+多7分,没有连续即不显⽰多余的3分或7分的提⽰…
wxml结构:
<!--pages/signIn2/signIn2.wxml-->
<view class='sign-new'>
<view class='in'>
<view class='new-head'>
<view class='sig-tl'>
<view class='tln'>已连续签到<label class='n'>{{newSignNum}}</label>天</view> <view class='tlf'>积分:<label class='f'>{{newSignIntegral}}</label></view>
</view>
<!-- 未签到 -->
<view wx:if='{{!newSignBtnState}}' class='sig-qiu sig-qiu-no' bindtap='bindSignFn' > <label class='ti'>签到</label>
</view>
<!-- 已签到 -->
<view wx:else class='sig-qiu sig-qiu-yes'>
<label class='ti'>已签到</label>
</view>
</view>
<view class='new-week' >
<view class='we-mod'>
<view class='mo-fen'>
<label class='f f3' wx:if='{{continuityDays3}}'>+3积分</label>
<label class='f f7' wx:if='{{continuityDays7}}'>+7积分</label>
</view>
<view class='mo-line'>
<block wx:for="{{isNewSignedArr}}" wx:for-item="v" wx:key="k">
<label class="q {{v.isSigned?'hover':''}}"></label>
</block>
</view>
<view class='mo-ri'>
<block wx:for="{{isNewSignedArr}}" wx:for-item="v" wx:key="k">
<label class="t">{{v.day}}</label>
</block>
</view>
</view>
</view>
</view>
</view>
js⽅法:
Page({
/**
* 页⾯的初始数据
*/
data: {
newSignBtnState: false, //按钮签到状态
continuityDays7: false, //连续7
continuityDays3: false, //连续3
myToday: '', //周⼏
newSignNum: 0, //签到天数
newSignIntegral:0, //签到积分
//签到数组
isNewSignedArr: [
{
"day": "⼀",
"isSigned": false
},
{
"day": "⼆",
"isSigned": false
},
{
"day": "三",
"isSigned": false
},
{
"day": "四",
"isSigned": false
},
{
"day": "五",
"isSigned": false
},
{
"day": "六",
"isSigned": false
},
{
"day": "⽇",
写文章的小程序
"isSigned": false
}
],
},
//-------点击签到---------
bindSignFn(e){
var that = this,
newSignNum = wSignNum,
today = Today;
const arr = [],
newSignArr = [...arr, ...that.data.isNewSignedArr]; //
today = today - 1 > 0 ? today - 1 : 6;
newSignArr[today].isSigned = true;
//当前积分
newSignNum++;
var curFen = wSignIntegral + 1;
that.setData({
newSignBtnState: true,
newSignNum: newSignNum,
newSignIntegral: curFen,
isNewSignedArr: newSignArr,
})
that.signAddFen();
},
//签到积分函数
//连续天数-积分:周三+3:周⼀,周⼆,周三(1+1+3=5);周六+7:周⽇到周六(1+1+3+1+1+1+7=15)
signAddFen(e) {
var that = this,
oneIsSigned = that.data.isNewSignedArr[0].isSigned,
twoIsSigned = that.data.isNewSignedArr[1].isSigned,
threeIsSigned = that.data.isNewSignedArr[2].isSigned,
fourIsSigned = that.data.isNewSignedArr[3].isSigned,
fiveIsSigned = that.data.isNewSignedArr[4].isSigned,
sixIsSigned = that.data.isNewSignedArr[5].isSigned,
sevenIsSigned = that.data.isNewSignedArr[6].isSigned;
// 另外加分-黄⾊⼩框显⽰周三+3 , 周⽇+7
if (oneIsSigned && twoIsSigned && Today == 3) {
that.setData({
continuityDays3: true
})
} else if (oneIsSigned && twoIsSigned && threeIsSigned && fourIsSigned && fiveIsSigned && sixIsSigned && Today == 0) {
that.setData({
continuityDays7: true
})
}
//签到后执⾏
if (wSignBtnState) {
// 周三:⼀⼆三
if (oneIsSigned && twoIsSigned && threeIsSigned) {
var fens = wSignIntegral + 3 - 1;
that.setData({
newSignIntegral: fens
})
}
// 所有签了:⼀⼆三四五六⽇
if (oneIsSigned && twoIsSigned && threeIsSigned && fourIsSigned && fiveIsSigned && sixIsSigned && sevenIsSigned) {
var fens = wSignIntegral + 7 - 1;
that.setData({
newSignIntegral: fens
})
}
}
},
/**
* ⽣命周期函数--监听页⾯加载
*/
onLoad: function (options) {
var that = this,
myDate = new Date(),
myToday = Day(); //周⼏ 0 1 2 3 4 5 6
that.setData({
myToday: myToday
})
that.signAddFen();
},
})
ps:
到此这篇关于⼩程序连续签到7天积分获得功能的⽰例代码的⽂章就介绍到这了,更多相关⼩程序签到功能内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论