Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Countdown.js): 新增节假日(holiday)模式 #1499

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/behaviors/countdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,32 @@ export default Behavior({
console.error('time传值错误');
}
}

} else if (countdownType === 'holiday') { // 当countdownType === holiday时,节假日模式
if (timeType === 'second') { // 纪念日模式不能设置timeType === second
console.error(`countdownType为${countdownType}类型时,不可设置timeType值为second`);
} else {
countDownTime = typeof time === 'string' ? countDownTime.replace(/-/g, '/') : countDownTime;
var fullYear = new Date().getFullYear();
countDownTime = fullYear + '-' + countDownTime;
countDownTime = Math.ceil((new Date(countDownTime).getTime() - new Date().getTime()) / 1000);
if (countDownTime < 0) { // countDownTime为负数时候 添加一年时间戳
countDownTime += 31536000;
}
if (countDownTime - initAddTime > 0) {
this.getLatestForCountDown(countDownTime);
} else if (countDownTime - initAddTime < 0) {
this.getLatestForAddTime(countDownTime);
} else if (countDownTime - initAddTime === 0) {
if (initAddTime <= 0) {
this._getTimeValue(countDownTime);
}
this.CountdownEnd();
}
if (status && countDownTime - initAddTime !== 0) {
this.init.call(this);
}
}
} else { // countdownType 不能设置为 normal,anniversary 以外的值
console.error('错误的countdownType类型');
}
Expand Down Expand Up @@ -219,4 +245,4 @@ export default Behavior({
this.triggerEvent('linend', {});
},
}
});
});