feat: login rest

This commit is contained in:
Blizzard
2026-02-12 09:26:39 +08:00
parent e97fd30fa3
commit 5553e2711a
115 changed files with 4090 additions and 3499 deletions
+43 -76
View File
@@ -5,7 +5,7 @@ Page({
data: {
currentPlant: null,
activeImageIndex: 0,
activeTab: 'care',
activeTab: 'info',
careLogs: [],
displayCareLogs: [],
displayCareLimit: 5,
@@ -51,22 +51,46 @@ Page({
return { ...cp, taskIcon: iconObj };
});
// Calculate days planted and format date
let adoptionDate = '未知';
let daysPlanted = 0;
if (plant.plantTime) {
const start = new Date(plant.plantTime);
const now = new Date();
const diffTime = now - start;
if (diffTime > 0) {
daysPlanted = Math.floor(diffTime / (1000 * 60 * 60 * 24));
}
adoptionDate = plant.plantTime.split('T')[0];
}
this.setData({
currentPlant: {
...plant,
location: plant.placement || '',
adoptionDate: adoptionDate,
daysPlanted: daysPlanted,
careSchedule: carePlans
},
swiperImages: swiperImages,
// Map logs and records directly from plant detail response
careLogs: this.processLogs(plant.careRecords || []),
records: (plant.growthRecords || plant.recordList || []).map(item => ({
id: item.id,
date: item.createdAtStr ? item.createdAtStr.split(' ')[0] : '',
type: item.recordType || 'growth',
title: item.title,
content: item.content,
image: (item.imgList && item.imgList.length > 0) ? item.imgList[0].url : ''
}))
records: (plant.growthRecords || plant.recordList || []).map(item => {
// Extract image URL safely
let imageUrl = '';
if (item.imgList && item.imgList.length > 0) {
imageUrl = item.imgList[0].url;
}
return {
id: item.id,
date: item.createdAtStr ? item.createdAtStr.split(' ')[0] : '',
type: item.tag || 'growth',
title: item.name || '成长记录',
content: item.content || item.desc || '',
image: imageUrl
};
})
});
this.updateDisplayLogs();
@@ -203,78 +227,21 @@ Page({
},
// Growth Record Logic
openGrowthModal() {
this.setData({
showGrowthModal: true,
newRecordContent: '',
newRecordType: 'growth',
newRecordImage: ''
});
},
onGrowthPopupVisibleChange(e) { this.setData({ showGrowthModal: e.detail.visible }); },
closeGrowthModal() { this.setData({ showGrowthModal: false }); },
setRecordType(e) {
const type = e.currentTarget.dataset.type;
if (e.detail.checked) {
this.setData({ newRecordType: type });
}
},
setRecordTypeByTap(e) {
const type = e.currentTarget.dataset.type;
this.setData({ newRecordType: type });
},
onRecordContentInput(e) { this.setData({ newRecordContent: e.detail.value }); },
handleChooseRecordImage() {
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album', 'camera'],
success: (res) => {
this.setData({
newRecordImage: res.tempFiles[0].tempFilePath
});
}
});
},
handleRemoveRecordImage() {
this.setData({ newRecordImage: '' });
},
handlePreviewRecordImage(e) {
const src = e.currentTarget.dataset.src;
const fullPath = (src.indexOf('http') === 0 || src.indexOf('wxfile') === 0) ? src : `/assets/${src}`;
if (!src) return;
wx.previewImage({
current: fullPath,
urls: [fullPath]
current: src,
urls: [src]
});
},
handleAddRecord() {
if (!this.data.newRecordContent.trim()) return;
const mapTitle = { growth: '生长记录', repot: '换盆记录', pest: '病虫害记录', other: '日常记录' };
const now = new Date();
const dateStr = `${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}`;
const record = {
id: Date.now().toString(),
date: dateStr,
type: this.data.newRecordType,
title: mapTitle[this.data.newRecordType],
content: this.data.newRecordContent,
image: this.data.newRecordImage
};
this.setData({
records: [record, ...this.data.records],
showGrowthModal: false
});
this.updateDisplayRecords();
wx.showToast({ title: '记录成功', icon: 'success' });
}
openGrowthModal() {
if (this.data.currentPlant && this.data.currentPlant.id) {
wx.navigateTo({
url: `/pages/plant-detail/growth-record/index?plantId=${this.data.currentPlant.id}`
});
}
},
})