let timeout = null; Component({ /** * 组件的属性列表 */ properties: { tab: Number, floor: String, progress: Number, end: Boolean, warningCount: Number, }, /** * 组件的初始数据 */ data: { tabs: ["平面地图", "导航", "目的地"], progressText: "0%", progressNum: 0, showWarning: false, }, observers: { warningCount(val) { if (!val) return; if (this.data.showWarning && timeout) clearTimeout(timeout); this.setData({ showWarning: true }); timeout = setTimeout(() => { this.setData({ showWarning: false }); timeout = null; }, 3000); }, progress(val) { let progressNum = this.data.end ? 1 : val; if (isNaN(progressNum)) return; if (progressNum < 0) progressNum = 0; if (progressNum > 1) progressNum = 1; this.setData({ progressText: parseInt(progressNum * 100) + "%", progressNum, }); }, }, /** * 组件的方法列表 */ methods: { handleTap({ currentTarget: { id } }) { this.triggerEvent("change", Number(id)); }, handleRelocate() { this.triggerEvent("relocate"); }, handleToMap() { this.triggerEvent("tomap"); }, }, });