|
@@ -20,7 +20,11 @@ Page({
|
|
|
//是否暂停
|
|
|
isstop:false,
|
|
|
//标题
|
|
|
- title:''
|
|
|
+ title:'',
|
|
|
+
|
|
|
+ percentage: '',
|
|
|
+ timer: null,
|
|
|
+ startTime: 0,
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -172,4 +176,55 @@ Page({
|
|
|
})
|
|
|
console.log(this.data.isstop);
|
|
|
},
|
|
|
+ startIncrease() {
|
|
|
+ // 记录开始时间
|
|
|
+ this.setData({
|
|
|
+ startTime: Date.now(),
|
|
|
+ });
|
|
|
+
|
|
|
+ // 清除之前的定时器
|
|
|
+ if (this.data.timer) {
|
|
|
+ clearInterval(this.data.timer);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置定时器,每隔 40 毫秒更新一次 percentage
|
|
|
+ this.setData({
|
|
|
+ timer: setInterval(() => {
|
|
|
+ const currentTime = Date.now();
|
|
|
+ const elapsedTime = currentTime - this.data.startTime;
|
|
|
+ const percentage = Math.min((elapsedTime / 4000) * 100, 100);
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ percentage: `conic-gradient(from 0deg, #015EEA ${percentage}%, white 0%)`,
|
|
|
+ });
|
|
|
+
|
|
|
+ // 如果达到 100%,清除定时器
|
|
|
+ if (percentage >= 100) {
|
|
|
+ clearInterval(this.data.timer);
|
|
|
+ this.setData({
|
|
|
+ timer: null,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, 40),
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ stopIncrease() {
|
|
|
+ // 清除定时器
|
|
|
+ if (this.data.timer) {
|
|
|
+ clearInterval(this.data.timer);
|
|
|
+ this.setData({
|
|
|
+ timer: null,
|
|
|
+ });
|
|
|
+
|
|
|
+ // 如果未达到 100%,清零 percentage
|
|
|
+ const elapsedTime = Date.now() - this.data.startTime;
|
|
|
+ if (elapsedTime < 4000) {
|
|
|
+ this.setData({
|
|
|
+ percentage: '',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
})
|