Browse Source

修复商品详情页面产品包装字段显示问题

- 修正前端数据绑定:从packaging改为producting字段
- 更新API调用:添加producting字段到商品详情和列表查询
- 后端查询优化:确保producting字段在SQL查询中被正确包含
- 添加调试日志:便于追踪producting字段的数据流

解决商品详情页面无法显示数据库中products表producting字段的问题。
pull/3/head
徐飞洋 2 months ago
parent
commit
1c609511db
  1. 3
      pages/goods-detail/goods-detail.js
  2. 6
      server-example/server-mysql.js
  3. 2
      utils/api.js

3
pages/goods-detail/goods-detail.js

@ -320,6 +320,7 @@ Page({
// 合并预加载数据中的字段
...(preloadedData || {}),
// 添加产品包装字段(放在product之后,确保不被覆盖)
// 修复:使用正确的数据库字段名producting
producting: product.producting || '',
// 直接使用数据库字段名,确保与表结构完全一致,放在后面覆盖前面的值
product_contact: contactName,
@ -332,7 +333,7 @@ Page({
product_contact: formattedGoods.product_contact,
contact_phone: formattedGoods.contact_phone,
region: formattedGoods.region,
producting: formattedGoods.producting
packaging: formattedGoods.packaging
});
// 保存预加载数据中的isFavorite状态,确保是布尔值

6
server-example/server-mysql.js

@ -1937,7 +1937,8 @@ app.post('/api/product/list', async (req, res) => {
'region', // 【新增】确保返回地区字段
'sourceType', // 【新增】确保返回货源类型字段
'supplyStatus', // 【新增】确保返回供应状态字段
'category' // 【新增】确保返回商品种类字段
'category', // 【新增】确保返回商品种类字段
'producting' // 【新增】确保返回产品包装字段
]
},
order: [['created_at', 'DESC']],
@ -3771,7 +3772,7 @@ app.post('/api/products/detail', async (req, res) => {
// 查询商品详情 - 排除hidden状态商品,直接使用Product表中的reservedCount字段
const product = await Product.findOne({
attributes: ['productId', 'productName', 'price', 'quantity', 'grossWeight', 'imageUrls', 'created_at', 'specification', 'yolk', 'sourceType', 'supplyStatus'],
attributes: ['productId', 'productName', 'price', 'quantity', 'grossWeight', 'imageUrls', 'created_at', 'specification', 'yolk', 'sourceType', 'supplyStatus', 'producting'],
where: {
productId,
status: { [Sequelize.Op.not]: 'hidden' }
@ -3848,6 +3849,7 @@ app.post('/api/products/detail', async (req, res) => {
console.log('商品详情 - 最终返回的毛重值:', updatedProduct.grossWeight, '类型:', typeof updatedProduct.grossWeight);
console.log('商品详情 - 返回的收藏人数:', updatedProduct.reservedCount, '类型:', typeof updatedProduct.reservedCount);
console.log('商品详情 - producting字段:', updatedProduct.producting, '类型:', typeof updatedProduct.producting);
res.json({
success: true,

2
utils/api.js

@ -3481,6 +3481,8 @@ module.exports = {
console.log('- 是否包含contact_phone:', 'contact_phone' in data.data);
console.log('- product_contact值:', data.data.product_contact);
console.log('- contact_phone值:', data.data.contact_phone);
console.log('- 是否包含producting字段:', 'producting' in data.data);
console.log('- producting值:', data.data.producting);
console.log('- 完整字段:', Object.keys(data.data));
}
return data;

Loading…
Cancel
Save