From b07847d0ae446f68014f287ee08148cbd78cb444 Mon Sep 17 00:00:00 2001 From: Default User Date: Mon, 22 Dec 2025 14:47:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=94=B6=E8=97=8F=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98=E5=92=8CeventBus?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 23 +++++++++++++++++++++++ server-example/server-mysql.js | 23 +++++++++++------------ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app.js b/app.js index 493c28d..7702d4a 100644 --- a/app.js +++ b/app.js @@ -5,6 +5,29 @@ App({ 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; diff --git a/server-example/server-mysql.js b/server-example/server-mysql.js index 3a6d6e8..7036c57 100644 --- a/server-example/server-mysql.js +++ b/server-example/server-mysql.js @@ -675,17 +675,6 @@ User.init({ defaultValue: Sequelize.NOW, onUpdate: Sequelize.NOW }, - // 新增字段 - sourceType: { - type: DataTypes.STRING(50), - allowNull: true, - comment: '货源类型' - }, - supplyStatus: { - type: DataTypes.STRING(50), - allowNull: true, - comment: '供应状态' - }, }, { sequelize, @@ -782,6 +771,16 @@ Product.init({ type: DataTypes.DATE, defaultValue: Sequelize.NOW, onUpdate: Sequelize.NOW + }, + sourceType: { + type: DataTypes.STRING(50), + allowNull: true, + comment: '货源类型' + }, + supplyStatus: { + type: DataTypes.STRING(50), + allowNull: true, + comment: '供应状态' } }, { sequelize, @@ -3458,7 +3457,7 @@ app.post('/api/favorites/list', async (req, res) => { { model: Product, as: 'Product', // 与关联定义中的别名一致 - attributes: ['productId', 'productName', 'price', 'quantity', 'grossWeight', 'imageUrls', 'created_at', 'specification', 'yolk'] + attributes: ['productId', 'productName', 'price', 'quantity', 'grossWeight', 'imageUrls', 'created_at', 'specification', 'yolk', 'sourceType', 'supplyStatus'] } ], order: [['date', 'DESC']]