Browse Source

修复收藏页面显示问题和eventBus错误

pull/1/head
Default User 2 months ago
parent
commit
b07847d0ae
  1. 23
      app.js
  2. 23
      server-example/server-mysql.js

23
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;

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

Loading…
Cancel
Save