feat: 后端版本迁移修改

This commit is contained in:
Blizzard
2026-05-24 01:38:28 +08:00
parent 058a575e10
commit f8d71ee800
29 changed files with 304 additions and 291 deletions
+20 -12
View File
@@ -36,11 +36,17 @@ Page({
initData(id) {
request.get('/plant/detail', { id }).then(plant => {
const swiperImages = plant.imgList.map(img => {
return img.url;
});
// Legacy handler returns {plant: PlantInfo, carePlans: [...], growthRecords: [...], imgList: [...], careRecords: [...]}
const plantData = plant.plant || {};
const carePlansList = plant.carePlans || [];
const careRecordsList = plant.careRecords || [];
const growthRecordsList = plant.growthRecords || [];
const imgList = plant.imgList || [];
const swiperImages = imgList.map(img => img.url);
// Parse carePlans icon if it's a string
const carePlans = (plant.carePlans || []).map(cp => {
const carePlans = carePlansList.map(cp => {
let iconObj = {};
if (typeof cp.icon === 'string' && cp.icon.startsWith('{')) {
try {
@@ -54,16 +60,16 @@ Page({
// Calculate days planted and format date
let adoptionDate = '未知';
const daysPlanted = calculateDaysSince(plant.plantTime);
const daysPlanted = calculateDaysSince(plantData.plantTime);
const ageBadge = getPlantAgeBadge(daysPlanted);
if (plant.plantTime) {
adoptionDate = plant.plantTime.split('T')[0];
if (plantData.plantTime) {
adoptionDate = plantData.plantTime.split('T')[0];
}
this.setData({
currentPlant: {
...plant,
location: plant.placement || '',
...plantData,
location: plantData.placement || '',
adoptionDate: adoptionDate,
daysPlanted: daysPlanted,
ageBadge: ageBadge,
@@ -71,8 +77,8 @@ Page({
},
swiperImages: swiperImages,
// Map logs and records directly from plant detail response
careLogs: this.processLogs(plant.careRecords || []),
records: (plant.growthRecords || plant.recordList || []).map(item => {
careLogs: this.processLogs(careRecordsList),
records: growthRecordsList.map(item => {
// Extract image URL safely
let imageUrl = '';
if (item.imgList && item.imgList.length > 0) {
@@ -235,7 +241,9 @@ Page({
success: (res) => {
// Send current data to the opened page
res.eventChannel.emit('acceptDataFromOpenerPage', {
plant: this.data.currentPlant
plant: this.data.currentPlant,
imgList: this.data.swiperImages.map((url, i) => ({ id: i === 0 ? this.data.currentPlant.imageId || 'primary' : '', url })),
carePlans: this.data.currentPlant.careSchedule
});
}
});