feat: 任务和社区页面
This commit is contained in:
+104
-116
@@ -1,103 +1,5 @@
|
||||
// pages/plant-detail/index.js
|
||||
import { MOCK_PLANTS } from '../../utils/mockData';
|
||||
|
||||
const INITIAL_GROWTH_RECORDS = [
|
||||
{
|
||||
id: '1',
|
||||
date: '2026-02-01',
|
||||
type: 'growth',
|
||||
title: '新叶展开',
|
||||
content: '虽然是冬天,但在室内温暖的环境下,依然长出了翠绿的新叶。',
|
||||
image: 'monstera_plant_1769757312755.png'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
date: '2026-01-20',
|
||||
type: 'growth',
|
||||
title: '茎秆长高',
|
||||
content: '主茎又长高了约5cm,状态良好。'
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
date: '2025-12-15',
|
||||
type: 'repot',
|
||||
title: '换盆记录',
|
||||
content: '原来的盆有点小了,换了一个大一号的陶盆,底部加了陶粒。'
|
||||
},
|
||||
{
|
||||
id: '4',
|
||||
date: '2025-11-28',
|
||||
type: 'pest',
|
||||
title: '发现蚜虫',
|
||||
content: '叶片背面发现少量蚜虫,已用肥皂水清洗处理。'
|
||||
},
|
||||
{
|
||||
id: '5',
|
||||
date: '2025-11-10',
|
||||
type: 'growth',
|
||||
title: '气根生长',
|
||||
content: '节点处长出了新的气根,说明生长环境湿度适宜。'
|
||||
},
|
||||
{
|
||||
id: '6',
|
||||
date: '2025-10-25',
|
||||
type: 'other',
|
||||
title: '调整位置',
|
||||
content: '从北窗移到了东窗,增加早晨的光照。'
|
||||
},
|
||||
{
|
||||
id: '7',
|
||||
date: '2025-10-12',
|
||||
type: 'other',
|
||||
title: '加入花园',
|
||||
content: '欢迎名为"小怪兽"的小家伙正式入住!'
|
||||
},
|
||||
{
|
||||
id: '8',
|
||||
date: '2025-09-28',
|
||||
type: 'growth',
|
||||
title: '购入记录',
|
||||
content: '在花市购入,高度约30cm,有5片成熟叶子。',
|
||||
image: 'monstera_plant_1769757312755.png'
|
||||
},
|
||||
{
|
||||
id: '9',
|
||||
date: '2025-08-15',
|
||||
type: 'growth',
|
||||
title: '生机勃勃',
|
||||
content: '夏天长得飞快,已经是一盆茂盛的小森林了。',
|
||||
image: 'succulent_garden_1769757406309.png'
|
||||
},
|
||||
{
|
||||
id: '10',
|
||||
date: '2025-07-01',
|
||||
type: 'growth',
|
||||
title: '第一片叶子',
|
||||
content: '入手后的第一片新叶,浅绿色的非常娇嫩。',
|
||||
image: 'snake_plant_1769757638773.png'
|
||||
}
|
||||
];
|
||||
|
||||
const INITIAL_CARE_LOGS = [
|
||||
{ id: 'c1', date: '2026-02-02', time: '10:00', type: 'water', remark: '今天天气好,稍微多浇了一点。' },
|
||||
{ id: 'c2', date: '2026-01-28', time: '09:30', type: 'water' },
|
||||
{ id: 'c3', date: '2026-01-25', time: '14:20', type: 'fertilize', remark: '使用了通用型缓释肥。' },
|
||||
{ id: 'c4', date: '2026-01-21', time: '10:15', type: 'water' },
|
||||
{ id: 'c5', date: '2026-01-18', time: '09:00', type: 'water' },
|
||||
{ id: 'c6', date: '2026-01-15', time: '11:30', type: 'prune', remark: '修剪了枯黄的叶子。' },
|
||||
{ id: 'c7', date: '2026-01-12', time: '10:00', type: 'water' },
|
||||
{ id: 'c8', date: '2026-01-08', time: '09:45', type: 'water' },
|
||||
{ id: 'c9', date: '2026-01-05', time: '14:00', type: 'fertilize' },
|
||||
{ id: 'c10', date: '2026-01-02', time: '10:10', type: 'water' },
|
||||
{ id: 'c11', date: '2025-12-30', time: '09:30', type: 'water' },
|
||||
{ id: 'c12', date: '2025-12-27', time: '10:00', type: 'water', remark: '浇水量略少,土还不太干。' },
|
||||
{ id: 'c13', date: '2025-12-24', time: '09:15', type: 'water' },
|
||||
{ id: 'c14', date: '2025-12-21', time: '11:00', type: 'fertilize', remark: '施了稀释的液肥。' },
|
||||
{ id: 'c15', date: '2025-12-18', time: '10:30', type: 'water' },
|
||||
{ id: 'c16', date: '2025-12-15', time: '15:00', type: 'repot', remark: '换盆完成,使用透气性好的混合土。' },
|
||||
{ id: 'c17', date: '2025-12-12', time: '09:45', type: 'water' },
|
||||
{ id: 'c18', date: '2025-12-09', time: '10:20', type: 'water' },
|
||||
];
|
||||
import request from '../../utils/request';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -120,7 +22,9 @@ Page({
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.initData(options.id);
|
||||
if (options.id) {
|
||||
this.initData(options.id);
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
@@ -130,27 +34,102 @@ Page({
|
||||
},
|
||||
|
||||
initData(id) {
|
||||
const plant = MOCK_PLANTS.find(p => p.id === id);
|
||||
if (plant) {
|
||||
this.setData({
|
||||
currentPlant: plant,
|
||||
swiperImages: (plant.images || ['monstera_plant_1769757312755.png']).map(img => (img.indexOf('http') === 0 || img.indexOf('wxfile') === 0) ? img : `/assets/${img}`),
|
||||
careLogs: this.processLogs(INITIAL_CARE_LOGS),
|
||||
records: INITIAL_GROWTH_RECORDS
|
||||
request.get('/plant/detail', { id }).then(plant => {
|
||||
const swiperImages = plant.imgList.map(img => {
|
||||
return img.url;
|
||||
});
|
||||
// Parse carePlans icon if it's a string
|
||||
const carePlans = (plant.carePlans || []).map(cp => {
|
||||
let iconObj = {};
|
||||
if (typeof cp.icon === 'string' && cp.icon.startsWith('{')) {
|
||||
try {
|
||||
iconObj = JSON.parse(cp.icon);
|
||||
} catch (e) {
|
||||
console.error('Parse icon error', e);
|
||||
}
|
||||
}
|
||||
return { ...cp, taskIcon: iconObj };
|
||||
});
|
||||
|
||||
this.setData({
|
||||
currentPlant: {
|
||||
...plant,
|
||||
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 : ''
|
||||
}))
|
||||
});
|
||||
|
||||
this.updateDisplayLogs();
|
||||
this.updateDisplayRecords();
|
||||
}
|
||||
|
||||
}).catch(err => {
|
||||
console.error('Fetch detail failed', err);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
processLogs(logs) {
|
||||
return logs.map(log => {
|
||||
const parts = log.date.split('-');
|
||||
// Handle time format (e.g., 2025-02-02 10:00:00)
|
||||
const timeStr = log.createdAtStr || log.opTime || log.createTime || '';
|
||||
let dateStr = timeStr;
|
||||
let timeOnly = '';
|
||||
|
||||
if (timeStr.includes(' ')) {
|
||||
const parts = timeStr.split(' ');
|
||||
dateStr = parts[0];
|
||||
timeOnly = parts[1].substring(0, 5); // HH:mm
|
||||
}
|
||||
|
||||
const dateParts = dateStr.split('-');
|
||||
const month = dateParts.length > 1 ? dateParts[1] : '';
|
||||
const day = dateParts.length > 2 ? dateParts[2] : '';
|
||||
|
||||
// Map icon properties from icon JSON
|
||||
let type = 'other';
|
||||
let taskIcon = 'assignment'; // Default TDesign icon
|
||||
let iconColor = '#8D6E63';
|
||||
let iconBgColor = '#EFEBE9';
|
||||
|
||||
if (log.icon && typeof log.icon === 'string' && log.icon.startsWith('{')) {
|
||||
try {
|
||||
const iconObj = JSON.parse(log.icon);
|
||||
if (iconObj.id) type = iconObj.id;
|
||||
if (iconObj.icon) taskIcon = iconObj.icon;
|
||||
if (iconObj.color) iconColor = iconObj.color;
|
||||
if (iconObj.bgColor) iconBgColor = iconObj.bgColor;
|
||||
} catch (e) { }
|
||||
} else if (log.opType) {
|
||||
type = log.opType;
|
||||
}
|
||||
|
||||
// Use name directly if available
|
||||
const typeLabel = log.name || this.getCareTypeLabel(type);
|
||||
|
||||
return {
|
||||
...log,
|
||||
day: parts[2],
|
||||
month: parts[1],
|
||||
typeLabel: this.getCareTypeLabel(log.type)
|
||||
day: day,
|
||||
month: month,
|
||||
time: timeOnly,
|
||||
type: type,
|
||||
typeLabel: typeLabel,
|
||||
remark: log.remark || log.content || '',
|
||||
taskIcon: taskIcon,
|
||||
iconColor: iconColor,
|
||||
iconBgColor: iconBgColor
|
||||
};
|
||||
});
|
||||
},
|
||||
@@ -160,9 +139,12 @@ Page({
|
||||
water: '浇水',
|
||||
fertilize: '施肥',
|
||||
prune: '修剪',
|
||||
repot: '换盆'
|
||||
repot: '换盆',
|
||||
pesticide: '除虫',
|
||||
sun: '晒太阳',
|
||||
other: '养护'
|
||||
};
|
||||
return map[type] || '养护';
|
||||
return map[type] || '日常养护';
|
||||
},
|
||||
|
||||
updateDisplayLogs() {
|
||||
@@ -205,11 +187,17 @@ Page({
|
||||
this.updateDisplayRecords();
|
||||
},
|
||||
|
||||
// Navigate to Edit Page
|
||||
// Navigate to Edit Page with EventChannel
|
||||
handleOpenEditModal() {
|
||||
if (this.data.currentPlant && this.data.currentPlant.id) {
|
||||
wx.navigateTo({
|
||||
url: `/pages/plant-detail/edit/index?id=${this.data.currentPlant.id}`
|
||||
url: `/pages/plant-detail/edit/index?id=${this.data.currentPlant.id}&source=detail`,
|
||||
success: (res) => {
|
||||
// Send current data to the opened page
|
||||
res.eventChannel.emit('acceptDataFromOpenerPage', {
|
||||
plant: this.data.currentPlant
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user