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']]