import 'wx.request.js';
// 创建App实例 App({ // 全局数据 globalData: { alarmList: [], // 闹钟列表 currentAlarm: null // 当前选中的闹钟 },
// 应用启动时触发 onLaunch: function () { // 从本地存储中加载闹钟列表 const alarmList = wx.getStorageSync('alarmList') || []; this.globalData.alarmList = alarmList;
// 设置闹钟提醒
this.setAlarmReminder();
},
// 设置闹钟提醒 setAlarmReminder: function () { const alarmList = this.globalData.alarmList; alarmList.forEach(function (alarm) { // 设置定时器,到达设定的时间时触发提醒 const timestamp = new Date(alarm.time).getTime(); const now = new Date().getTime(); const timeDiff = timestamp - now;
if (timeDiff > 0) {
setTimeout(function () {
this.showAlarmReminder(alarm);
}, timeDiff);