1
This commit is contained in:
159
pages/countdown/countdown.js
Normal file
159
pages/countdown/countdown.js
Normal file
@@ -0,0 +1,159 @@
|
||||
// pages/countdown/countdown.js
|
||||
const { getCountdown, showSuccess, showError } = require('../../utils/util.js')
|
||||
const learningTracker = require('../../utils/learningTracker.js')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
countdowns: [],
|
||||
newEventName: '',
|
||||
newEventDate: ''
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadCountdowns()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
// 开始跟踪学习时间
|
||||
learningTracker.onPageShow('tools')
|
||||
|
||||
this.startTimer()
|
||||
},
|
||||
|
||||
onHide() {
|
||||
// 停止跟踪学习时间
|
||||
learningTracker.onPageHide()
|
||||
|
||||
this.stopTimer()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
// 记录学习时长
|
||||
learningTracker.onPageUnload()
|
||||
|
||||
this.stopTimer()
|
||||
},
|
||||
|
||||
// 加载倒计时
|
||||
loadCountdowns() {
|
||||
let countdowns = wx.getStorageSync('countdowns') || []
|
||||
|
||||
// 默认示例数据
|
||||
if (countdowns.length === 0) {
|
||||
countdowns = [
|
||||
{
|
||||
id: 1,
|
||||
name: '高等数学期末考试',
|
||||
date: '2025-12-20',
|
||||
color: '#FF6B6B'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: '英语四级考试',
|
||||
date: '2025-12-15',
|
||||
color: '#4A90E2'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: '课程设计答辩',
|
||||
date: '2025-12-25',
|
||||
color: '#50C878'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
this.setData({ countdowns })
|
||||
this.updateAllCountdowns()
|
||||
},
|
||||
|
||||
// 开始定时器
|
||||
startTimer() {
|
||||
this.timer = setInterval(() => {
|
||||
this.updateAllCountdowns()
|
||||
}, 1000)
|
||||
},
|
||||
|
||||
// 停止定时器
|
||||
stopTimer() {
|
||||
if (this.timer) {
|
||||
clearInterval(this.timer)
|
||||
this.timer = null
|
||||
}
|
||||
},
|
||||
|
||||
// 更新所有倒计时
|
||||
updateAllCountdowns() {
|
||||
const { countdowns } = this.data
|
||||
const updated = countdowns.map(item => ({
|
||||
...item,
|
||||
...getCountdown(item.date)
|
||||
}))
|
||||
this.setData({ countdowns: updated })
|
||||
},
|
||||
|
||||
// 事件名称输入
|
||||
onNameInput(e) {
|
||||
this.setData({ newEventName: e.detail.value })
|
||||
},
|
||||
|
||||
// 日期选择
|
||||
onDateChange(e) {
|
||||
this.setData({ newEventDate: e.detail.value })
|
||||
},
|
||||
|
||||
// 添加倒计时
|
||||
onAddCountdown() {
|
||||
const { newEventName, newEventDate, countdowns } = this.data
|
||||
|
||||
if (!newEventName.trim()) {
|
||||
showError('请输入事件名称')
|
||||
return
|
||||
}
|
||||
|
||||
if (!newEventDate) {
|
||||
showError('请选择日期')
|
||||
return
|
||||
}
|
||||
|
||||
const colors = ['#FF6B6B', '#4A90E2', '#50C878', '#F39C12', '#9B59B6']
|
||||
|
||||
const newCountdown = {
|
||||
id: Date.now(),
|
||||
name: newEventName.trim(),
|
||||
date: newEventDate,
|
||||
color: colors[Math.floor(Math.random() * colors.length)]
|
||||
}
|
||||
|
||||
countdowns.push(newCountdown)
|
||||
wx.setStorageSync('countdowns', countdowns)
|
||||
|
||||
this.setData({
|
||||
countdowns,
|
||||
newEventName: '',
|
||||
newEventDate: ''
|
||||
})
|
||||
|
||||
this.updateAllCountdowns()
|
||||
showSuccess('添加成功')
|
||||
},
|
||||
|
||||
// 删除倒计时
|
||||
onDelete(e) {
|
||||
const { id } = e.currentTarget.dataset
|
||||
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除这个倒计时吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
let { countdowns } = this.data
|
||||
countdowns = countdowns.filter(item => item.id !== id)
|
||||
wx.setStorageSync('countdowns', countdowns)
|
||||
|
||||
this.setData({ countdowns })
|
||||
showSuccess('删除成功')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
3
pages/countdown/countdown.json
Normal file
3
pages/countdown/countdown.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "考试倒计时"
|
||||
}
|
||||
78
pages/countdown/countdown.wxml
Normal file
78
pages/countdown/countdown.wxml
Normal file
@@ -0,0 +1,78 @@
|
||||
<!--pages/countdown/countdown.wxml-->
|
||||
<view class="container">
|
||||
<!-- 添加倒计时 -->
|
||||
<view class="add-section">
|
||||
<view class="add-title">添加新倒计时</view>
|
||||
<view class="add-form">
|
||||
<input
|
||||
class="form-input"
|
||||
placeholder="事件名称"
|
||||
value="{{newEventName}}"
|
||||
bindinput="onNameInput"
|
||||
/>
|
||||
<picker
|
||||
mode="date"
|
||||
value="{{newEventDate}}"
|
||||
bindchange="onDateChange"
|
||||
>
|
||||
<view class="date-picker">
|
||||
{{newEventDate || '选择日期'}}
|
||||
</view>
|
||||
</picker>
|
||||
<button class="add-btn" bindtap="onAddCountdown">添加</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 倒计时列表 -->
|
||||
<view class="countdown-list">
|
||||
<view
|
||||
class="countdown-card"
|
||||
wx:for="{{countdowns}}"
|
||||
wx:key="id"
|
||||
style="border-left-color: {{item.color}};"
|
||||
>
|
||||
<view class="card-header">
|
||||
<view class="event-name">{{item.name}}</view>
|
||||
<view
|
||||
class="delete-btn"
|
||||
data-id="{{item.id}}"
|
||||
bindtap="onDelete"
|
||||
>
|
||||
×
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="event-date">📅 {{item.date}}</view>
|
||||
|
||||
<view class="countdown-display" wx:if="{{!item.isExpired}}">
|
||||
<view class="time-block">
|
||||
<view class="time-value" style="background-color: {{item.color}};">{{item.days}}</view>
|
||||
<view class="time-label">天</view>
|
||||
</view>
|
||||
<view class="time-block">
|
||||
<view class="time-value" style="background-color: {{item.color}};">{{item.hours}}</view>
|
||||
<view class="time-label">时</view>
|
||||
</view>
|
||||
<view class="time-block">
|
||||
<view class="time-value" style="background-color: {{item.color}};">{{item.minutes}}</view>
|
||||
<view class="time-label">分</view>
|
||||
</view>
|
||||
<view class="time-block">
|
||||
<view class="time-value" style="background-color: {{item.color}};">{{item.seconds}}</view>
|
||||
<view class="time-label">秒</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="expired-tip" wx:if="{{item.isExpired}}">
|
||||
<text class="expired-icon">⏰</text>
|
||||
<text class="expired-text">已到期</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view class="empty-state" wx:if="{{countdowns.length === 0}}">
|
||||
<text class="empty-icon">⏰</text>
|
||||
<text class="empty-text">暂无倒计时,快来添加一个吧</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
163
pages/countdown/countdown.wxss
Normal file
163
pages/countdown/countdown.wxss
Normal file
@@ -0,0 +1,163 @@
|
||||
/* pages/countdown/countdown.wxss */
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background-color: #F5F5F5;
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
/* 添加区域 */
|
||||
.add-section {
|
||||
background-color: #ffffff;
|
||||
border-radius: 16rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.add-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
margin-bottom: 25rpx;
|
||||
}
|
||||
|
||||
.add-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.form-input, .date-picker {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
padding: 0 25rpx;
|
||||
background-color: #F5F5F5;
|
||||
border-radius: 12rpx;
|
||||
font-size: 28rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.date-picker {
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
background-color: #F39C12;
|
||||
color: #ffffff;
|
||||
border-radius: 40rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 倒计时列表 */
|
||||
.countdown-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.countdown-card {
|
||||
background-color: #ffffff;
|
||||
border-radius: 16rpx;
|
||||
padding: 30rpx;
|
||||
border-left: 8rpx solid #4A90E2;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15rpx;
|
||||
}
|
||||
|
||||
.event-name {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
width: 50rpx;
|
||||
height: 50rpx;
|
||||
line-height: 50rpx;
|
||||
text-align: center;
|
||||
font-size: 48rpx;
|
||||
color: #CCCCCC;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.event-date {
|
||||
font-size: 26rpx;
|
||||
color: #999999;
|
||||
margin-bottom: 25rpx;
|
||||
}
|
||||
|
||||
.countdown-display {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 15rpx;
|
||||
}
|
||||
|
||||
.time-block {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.time-value {
|
||||
height: 90rpx;
|
||||
line-height: 90rpx;
|
||||
background-color: #4A90E2;
|
||||
color: #ffffff;
|
||||
border-radius: 12rpx;
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.time-label {
|
||||
font-size: 22rpx;
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
.expired-tip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10rpx;
|
||||
padding: 30rpx;
|
||||
background-color: #FFF0E6;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.expired-icon {
|
||||
font-size: 40rpx;
|
||||
}
|
||||
|
||||
.expired-text {
|
||||
font-size: 28rpx;
|
||||
color: #F39C12;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 空状态 */
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 100rpx 0;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 100rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999999;
|
||||
}
|
||||
Reference in New Issue
Block a user