Files
gecko/srde/miniprogram/components/cooldown-button/cooldown-button.ts
Daniel a94bd44c3a Initial commit
Made-with: Cursor
2026-02-28 18:43:09 +08:00

23 lines
611 B
TypeScript

Component({
properties: {
text: { type: String, value: '确认' },
duration: { type: Number, value: 3 },
},
data: { countdown: 0, loading: false },
methods: {
onTap() {
if (this.data.countdown > 0 || this.data.loading) return;
this.setData({ countdown: this.properties.duration });
const t = setInterval(() => {
const n = this.data.countdown - 1;
this.setData({ countdown: n });
if (n <= 0) clearInterval(t);
}, 1000);
this.triggerEvent('confirm');
},
setLoading(v: boolean) {
this.setData({ loading: v });
},
},
});