feat: 后端版本迁移修改
This commit is contained in:
@@ -42,9 +42,9 @@ Page({
|
||||
|
||||
if (eventChannel) {
|
||||
eventChannel.on('acceptDataFromOpenerPage', (data) => {
|
||||
if (data && data.plant) {
|
||||
if (data) {
|
||||
hasReceivedData = true;
|
||||
this.renderPlantUI(data.plant);
|
||||
this.renderPlantUI(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -63,20 +63,24 @@ Page({
|
||||
});
|
||||
},
|
||||
|
||||
renderPlantUI(plant) {
|
||||
renderPlantUI(data) {
|
||||
if (!data) return;
|
||||
|
||||
// Detect if data is the raw API response or a flat eventChannel payload
|
||||
const isRawResponse = data.hasOwnProperty('plant') && typeof data.plant === 'object';
|
||||
const plant = isRawResponse ? data.plant : (data.plant || data);
|
||||
const imgList = data.imgList || [];
|
||||
|
||||
const defaultIcon = CARE_TASK_ICONS.find(i => i.id === 'water') || CARE_TASK_ICONS[0];
|
||||
|
||||
let tasks = [];
|
||||
if (plant.careSchedule) {
|
||||
tasks = plant.careSchedule.map(cp => ({
|
||||
id: cp.id, name: cp.name, period: cp.period,
|
||||
taskIcon: cp.taskIcon, isNew: false,
|
||||
_original: { name: cp.name, period: cp.period, icon: JSON.stringify(cp.taskIcon || {}) }
|
||||
}));
|
||||
} else if (plant.carePlans) {
|
||||
tasks = plant.carePlans.map(cp => {
|
||||
const carePlansSrc = isRawResponse ? (data.carePlans || []) : (data.carePlans || plant.careSchedule || []);
|
||||
if (carePlansSrc && carePlansSrc.length > 0) {
|
||||
tasks = carePlansSrc.map(cp => {
|
||||
let iconObj = defaultIcon;
|
||||
if (typeof cp.icon === 'string' && cp.icon.startsWith('{')) {
|
||||
if (cp.taskIcon) {
|
||||
iconObj = cp.taskIcon;
|
||||
} else if (typeof cp.icon === 'string' && cp.icon.startsWith('{')) {
|
||||
try { iconObj = JSON.parse(cp.icon); } catch (e) { }
|
||||
}
|
||||
const iconStr = JSON.stringify(iconObj);
|
||||
@@ -89,12 +93,11 @@ Page({
|
||||
}
|
||||
|
||||
let imageUrl = '', imageId = '';
|
||||
if (plant.imgList && plant.imgList.length > 0) {
|
||||
imageUrl = plant.imgList[0].url || '';
|
||||
imageId = plant.imgList[0].id || '';
|
||||
if (imgList && imgList.length > 0) {
|
||||
imageUrl = imgList[0].url || '';
|
||||
imageId = imgList[0].id || '';
|
||||
}
|
||||
|
||||
|
||||
let adoptionDate = plant.plantTime || '';
|
||||
if (adoptionDate.includes('T')) adoptionDate = adoptionDate.split('T')[0];
|
||||
|
||||
@@ -142,9 +145,10 @@ Page({
|
||||
wx.showLoading({ title: '上传中...' });
|
||||
request.upload(tempFilePath).then(data => {
|
||||
wx.hideLoading();
|
||||
const fileData = data?.file || {};
|
||||
if (fileData.id) {
|
||||
this.setData({ uploadedImageId: fileData.id, newPlantImage: fileData.url });
|
||||
const imageUrl = data?.url || '';
|
||||
const imageId = data?.id || '';
|
||||
if (imageId) {
|
||||
this.setData({ uploadedImageId: imageId, newPlantImage: imageUrl });
|
||||
}
|
||||
}).catch(() => {
|
||||
wx.hideLoading();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
>
|
||||
<!-- Upload Area -->
|
||||
<view class="upload-section">
|
||||
<view class="image-upload-area {{newPlantImage ? 'has-image' : ''}}" bindtap="showActionSheet">
|
||||
<view class="image-upload-area {{newPlantImage ? 'has-image' : ''}}">
|
||||
<t-image
|
||||
wx:if="{{newPlantImage}}"
|
||||
src="{{newPlantImage}}"
|
||||
@@ -23,10 +23,6 @@
|
||||
<t-icon name="upload" size="64rpx" color="#999" />
|
||||
<text>点击设置封面图</text>
|
||||
</view>
|
||||
<view wx:if="{{newPlantImage}}" class="edit-overlay">
|
||||
<t-icon name="camera" size="32rpx" color="#FFF" />
|
||||
<text>更换照片</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user