feat: Add plant identification feature with image upload, classification results display, and integration into the wiki page.

This commit is contained in:
Blizzard
2026-02-10 14:02:35 +08:00
parent 6ea77c00ce
commit 6f88bc656b
15 changed files with 1481 additions and 491 deletions
+38 -12
View File
@@ -15,6 +15,12 @@ Page({
uploadedImageId: '', // Store the uploaded image ID
// Extra fields
potMaterial: '',
potSize: '',
sunlight: '',
plantingMaterial: '',
showActionSheet: false,
actionSheetItems: [
{ label: '拍摄', value: 'camera' },
@@ -85,7 +91,7 @@ Page({
});
// Show loading
wx.showLoading({ title: 'Uploading...' });
wx.showLoading({ title: '上传中...' });
// Call upload API
request.upload(tempFilePath).then(data => {
@@ -103,13 +109,11 @@ Page({
uploadedImageId: imageId,
isLocalImage: true
});
wx.showToast({ title: 'Success', icon: 'success' });
} else {
wx.showToast({ title: 'No URL returned', icon: 'none' });
}
}).catch(err => {
wx.hideLoading();
wx.showToast({ title: 'Upload Failed', icon: 'none' });
wx.showToast({ title: '上传失败', icon: 'none' });
});
},
fail: (err) => {
@@ -123,6 +127,12 @@ Page({
onLocationInput(e) { this.setData({ newPlantLocation: e.detail.value }); },
onDateChange(e) { this.setData({ newPlantDate: e.detail.value }); },
// Extra field inputs
onPotMaterialInput(e) { this.setData({ potMaterial: e.detail.value }); },
onPotSizeInput(e) { this.setData({ potSize: e.detail.value }); },
onSunlightInput(e) { this.setData({ sunlight: e.detail.value }); },
onPlantingMaterialInput(e) { this.setData({ plantingMaterial: e.detail.value }); },
handleAddCareTask() {
const tasks = this.data.newCareTasks;
const defaultIcon = CARE_TASK_ICONS.find(i => i.id === 'other');
@@ -162,7 +172,14 @@ Page({
onTaskFreqInput(e) {
const { id } = e.currentTarget.dataset;
const tasks = this.data.newCareTasks.map(t => t.id === id ? { ...t, frequencyValue: parseInt(e.detail.value) || 1 } : t);
const raw = e.detail.value;
// Allow empty while editing; validate on save
const tasks = this.data.newCareTasks.map(t => {
if (t.id === id) {
return { ...t, frequencyValue: raw === '' ? '' : (parseInt(raw) || '') };
}
return t;
});
this.setData({ newCareTasks: tasks });
},
@@ -223,10 +240,19 @@ Page({
return;
}
// Validate care task periods
for (const task of newCareTasks) {
const p = parseInt(task.frequencyValue);
if (!p || p < 1) {
wx.showToast({ title: `"${task.taskName || '未命名事项'}" 的周期天数不合法`, icon: 'none' });
return;
}
}
// Construct Care Plans
const carePlans = newCareTasks.map(task => ({
name: task.taskName || '未命名事项',
period: task.frequencyValue || 1,
period: parseInt(task.frequencyValue) || 1,
icon: JSON.stringify(task.taskIcon || {}) // Serialize icon details
}));
@@ -237,14 +263,14 @@ Page({
placement: newPlantLocation || '',
ossIds: [uploadedImageId],
carePlans: carePlans,
potMaterial: '',
potSize: '',
sunlight: '',
plantingMaterial: ''
potMaterial: this.data.potMaterial || '',
potSize: this.data.potSize || '',
sunlight: this.data.sunlight || '',
plantingMaterial: this.data.plantingMaterial || ''
};
// Submit
wx.showLoading({ title: 'Creating...' });
wx.showLoading({ title: '植物种植中...' });
request.post('/plant/add', payload).then(async () => {
wx.hideLoading();
wx.showToast({ title: '添加成功', icon: 'success' });