chore: update pom.xml Lombok config and deploy settings
- Update Maven compiler plugin to support Lombok annotation processing - Add deploy.conf for automated deployment - Update backend models and controllers - Update frontend pages and API
This commit is contained in:
@@ -103,7 +103,12 @@
|
||||
@click="goToFoodDetail(item)"
|
||||
>
|
||||
<view class="food-image-wrapper">
|
||||
<image class="food-image" :src="getFoodImage(item)" mode="aspectFill"></image>
|
||||
<image
|
||||
class="food-image"
|
||||
:src="getFoodImage(item)"
|
||||
mode="aspectFill"
|
||||
@error="onFoodImageError(item)"
|
||||
></image>
|
||||
<view v-if="item.warning" class="warning-badge">⚠️</view>
|
||||
</view>
|
||||
<view class="food-info">
|
||||
@@ -148,6 +153,7 @@ export default {
|
||||
currentCategory: 'all',
|
||||
searchTimer: null,
|
||||
defaultPlaceholder,
|
||||
imageErrorIds: {}, // 图片加载失败时用占位图,key 为 item.id
|
||||
foodList: [
|
||||
{
|
||||
name: '香蕉',
|
||||
@@ -256,17 +262,35 @@ export default {
|
||||
page: 1,
|
||||
limit: 100
|
||||
});
|
||||
const rawList = result.data && (result.data.list || (Array.isArray(result.data) ? result.data : []));
|
||||
const rawList = this.getRawFoodList(result);
|
||||
this.imageErrorIds = {};
|
||||
this.foodList = (rawList || []).map(item => this.normalizeFoodItem(item));
|
||||
} catch (error) {
|
||||
console.error('加载食物列表失败:', error);
|
||||
}
|
||||
},
|
||||
// 兼容 result.data.list / result.list / result.data 为数组 等响应结构
|
||||
getRawFoodList(result) {
|
||||
if (!result) return [];
|
||||
const page = result.data !== undefined && result.data !== null ? result.data : result;
|
||||
if (page && Array.isArray(page.list)) return page.list;
|
||||
if (Array.isArray(page)) return page;
|
||||
return [];
|
||||
},
|
||||
getFoodImage(item) {
|
||||
const raw = item.imageUrl || item.image || item.img || '';
|
||||
const id = item.id != null ? item.id : item.foodId;
|
||||
if (id != null && this.imageErrorIds[String(id)]) return this.defaultPlaceholder;
|
||||
const raw = item.imageUrl || item.image || item.img || item.pic || item.coverImage || '';
|
||||
const url = raw && (raw.startsWith('//') || raw.startsWith('http')) ? raw : (raw && raw.startsWith('/') ? (HTTP_REQUEST_URL || '') + raw : raw);
|
||||
return (url && String(url).trim()) ? url : this.defaultPlaceholder;
|
||||
},
|
||||
onFoodImageError(item) {
|
||||
const id = item.id != null ? item.id : item.foodId;
|
||||
if (id != null && !this.imageErrorIds[String(id)]) {
|
||||
this.imageErrorIds[String(id)] = true;
|
||||
this.imageErrorIds = { ...this.imageErrorIds };
|
||||
}
|
||||
},
|
||||
normalizeFoodItem(item) {
|
||||
const safetyMap = {
|
||||
suitable: { safety: '放心吃', safetyClass: 'safe' },
|
||||
@@ -276,12 +300,12 @@ export default {
|
||||
};
|
||||
const safety = item.safety != null ? { safety: item.safety, safetyClass: item.safetyClass || 'safe' } : (safetyMap[item.suitabilityLevel] || { safety: '—', safetyClass: 'safe' });
|
||||
|
||||
// 图片:统一为 image / imageUrl,相对路径补全为完整 URL
|
||||
const rawImg = item.imageUrl || item.image || item.img || '';
|
||||
// 图片:兼容 image/imageUrl/img/pic/coverImage,相对路径补全为完整 URL,空则留空由 getFoodImage 用占位图
|
||||
const rawImg = item.imageUrl || item.image || item.img || item.pic || item.coverImage || '';
|
||||
const imageUrl = (rawImg && (rawImg.startsWith('//') || rawImg.startsWith('http'))) ? rawImg : (rawImg && rawImg.startsWith('/') ? (HTTP_REQUEST_URL || '') + rawImg : rawImg);
|
||||
const image = imageUrl || '';
|
||||
|
||||
// 营养简介:优先 item.nutrition,其次 item.nutrients(兼容后端不同字段),否则由扁平字段组装
|
||||
// 营养简介:优先 item.nutrition,其次 item.nutrients(兼容后端),否则由扁平字段 energy/protein/potassium 等组装
|
||||
let nutrition = item.nutrition;
|
||||
if (Array.isArray(nutrition) && nutrition.length > 0) {
|
||||
nutrition = nutrition.map(n => ({
|
||||
@@ -308,12 +332,13 @@ export default {
|
||||
|
||||
return {
|
||||
...item,
|
||||
id: item.id != null ? item.id : item.foodId,
|
||||
image,
|
||||
imageUrl: image || undefined,
|
||||
category: item.category || '',
|
||||
safety: safety.safety,
|
||||
safetyClass: safety.safetyClass,
|
||||
nutrition
|
||||
nutrition: Array.isArray(nutrition) ? nutrition : []
|
||||
};
|
||||
},
|
||||
async selectCategory(category) {
|
||||
@@ -339,7 +364,8 @@ export default {
|
||||
page: 1,
|
||||
limit: 100
|
||||
});
|
||||
const rawList = result.data && (result.data.list || (Array.isArray(result.data) ? result.data : []));
|
||||
const rawList = this.getRawFoodList(result);
|
||||
this.imageErrorIds = {};
|
||||
this.foodList = (rawList || []).map(item => this.normalizeFoodItem(item));
|
||||
} catch (error) {
|
||||
console.error('搜索失败:', error);
|
||||
|
||||
Reference in New Issue
Block a user