// pages/tomato/tomato.js
const { http } = require('../../lib/http.js');
Page({
timer: null,
data: {
defalutSecond: 1500,
time: "",
timerStatus: 'stop',
confirmVisible: false,
againButtonVisible: false,
finishConfirmVisible: false,
tomato: {}
},
onShow: function () {
this.startTimer()
http.post('/tomatoes').then(response => {
this.setData({ tomato: response.data.resource })
})
},
startTimer(){
this.setData({ timerStatus: 'start' })
this.changeTime()
this.timer = setInterval(() => {
this.data.defalutSecond = this.data.defalutSecond - 1
this.changeTime()
if (this.data.defalutSecond <= 0){
this.setData({ againButtonVisible: true })
this.setData({ finishConfirmVisible: true })
return this.clearTimer()
}
}, 1000)
},
againTimer(){
this.data.defalutSecond = 1500
this.setData({ againButtonVisible: false })
this.startTimer()
},
clearTimer(){
clearInterval(this.timer)
this.timer = null
this.setData({ timerStatus: 'stop' })
},
changeTime(){
let m = Math.floor(this.data.defalutSecond/60)
let s = Math.floor(this.data.defalutSecond%60)
if(s === 0){
s = "00"
}
if((s+"").length === 1){
s = "0" + s
}
if ((m + "").length === 1) {
m = "0" + m
}
this.setData({ time: `${m}:${s}` })
},
confirmAbandon(event){
let content = event.detail
http.put(`/tomatoes/${this.data.tomato.id}`,{
description: content,
aborted: true
})
.then(response => {
wx.navigateBack({ to: -1 })
})
},
confirmFinish(event){
let content = event.detail
},
confirmCancel(){
this.setData({ finishConfirmVisible: false })
},
showConfirm(){
this.setData({ confirmVisible: true })
this.clearTimer()
},
hideConfirm(){
this.setData({ confirmVisible: false })
this.startTimer()
},
onHide() {
this.clearTimer()
http.put(`/tomatoes/${this.data.tomato.id}`, {
description: "退出放弃",
aborted: true
})
},
onUnload() {
this.clearTimer()
http.put(`/tomatoes/${this.data.tomato.id}`, {
description: "退出放弃",
aborted: true
})
},
})
没有合适的资源?快使用搜索试试~ 我知道了~
基于JavaScript开发的番茄小闹钟小程序源码.zip
共53个文件
json:11个
js:11个
wxss:10个
需积分: 7 0 下载量 121 浏览量
2023-03-10
15:34:37
上传
评论
收藏 505KB ZIP 举报
温馨提示
最简单的闹钟 js代码 基于JavaScript开发的番茄小闹钟小程序源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于JavaScript开发的番茄小闹钟小程序源码.zip (53个子文件)
pages
binding
binding.json 79B
binding.wxss 529B
binding.js 548B
binding.wxml 496B
tomato
tomato.wxml 939B
tomato.wxss 179B
tomato.js 2KB
tomato.json 179B
home
home.wxml 1KB
home.json 179B
home.wxss 2KB
home.js 2KB
test
test.wxs 128B
test.json 27B
test.wxss 48B
test.wxml 1KB
test.js 1KB
me
me.json 27B
me.wxss 2KB
me.wxml 2KB
me.js 692B
login
login.js 939B
login.json 27B
login.wxml 363B
login.wxss 1KB
lib
formattor.wxs 992B
util.js 480B
http.js 1KB
说明.md 22B
app.json 838B
project.config.json 662B
app.wxss 194B
components
confirm
confirm.wxss 981B
confirm.wxml 355B
confirm.json 23B
confirm.js 617B
button
button.json 23B
button.wxml 124B
button.wxss 541B
button.js 205B
clock
clock.wxml 161B
clock.js 149B
clock.wxss 314B
clock.json 23B
.gitignore 6B
images
tomato-bg.png 199KB
me.png 3KB
home.png 2KB
tomato.png 272KB
me-active.png 3KB
total-active.png 3KB
home-active.png 3KB
total.png 3KB
共 53 条
- 1
资源评论
z同学的编程之路
- 粉丝: 1866
- 资源: 2130
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功