You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.0 KiB
47 lines
1.0 KiB
// app.js
|
|
App({
|
|
globalData: {
|
|
userInfo: null,
|
|
currentTab: 'index'
|
|
},
|
|
|
|
// 事件总线,用于页面间通信
|
|
eventBus: {
|
|
on(event, callback) {
|
|
if (!this.handlers) this.handlers = {};
|
|
if (!this.handlers[event]) this.handlers[event] = [];
|
|
this.handlers[event].push(callback);
|
|
},
|
|
off(event, callback) {
|
|
if (!this.handlers || !this.handlers[event]) return;
|
|
this.handlers[event] = this.handlers[event].filter(handler => handler !== callback);
|
|
},
|
|
emit(event, data) {
|
|
if (!this.handlers || !this.handlers[event]) return;
|
|
this.handlers[event].forEach(handler => {
|
|
try {
|
|
handler(data);
|
|
} catch (error) {
|
|
console.error('事件处理函数执行错误:', error);
|
|
}
|
|
});
|
|
}
|
|
},
|
|
|
|
// 更新当前选中的tab
|
|
updateCurrentTab(tabName) {
|
|
this.globalData.currentTab = tabName;
|
|
},
|
|
|
|
onLaunch() {
|
|
console.log('App launched');
|
|
},
|
|
|
|
onShow() {
|
|
console.log('App shown');
|
|
},
|
|
|
|
onHide() {
|
|
console.log('App hidden');
|
|
}
|
|
});
|
|
|