feat: 百科页面

This commit is contained in:
Blizzard
2026-02-10 09:20:24 +08:00
parent b800ea03b5
commit 6ea77c00ce
11 changed files with 476 additions and 196 deletions
+92 -25
View File
@@ -1,5 +1,5 @@
// pages/wiki/detail/index.js
import { MOCK_WIKI } from '../../../utils/mockData';
import request from '../../../utils/request';
Page({
data: {
@@ -15,38 +15,105 @@ Page({
},
loadPlantDetail(id) {
// Find plant in MOCK_WIKI
const plant = MOCK_WIKI.find(p => p.id === id);
if (plant) {
// Fetch detail via wiki/page with specific ID
// Since there's no /wiki/detail endpoint, we use /wiki/page to get it
request.post('/wiki/page', {
current: 1,
pageSize: 1,
id: id
}).then(res => {
const data = res || {};
const list = data.list || [];
const item = list.length > 0 ? list[0] : null;
if (!item) {
wx.showToast({ title: '未找到该植物', icon: 'none' });
return;
}
// Set Page Title
wx.setNavigationBarTitle({
title: plant.name
});
wx.setNavigationBarTitle({ title: item.name });
// Prepare swiper list
const swiperList = (plant.images || []).map(img => {
return (img.indexOf('http') === 0 || img.indexOf('wxfile') === 0) ? img : `/assets/${img}`;
});
// Prepare swiper list from imgList
const swiperList = (item.imgList || []).map(img => img.url);
// Ensure some default values if missing
const enrichedPlant = {
...plant,
light: plant.light || { level: '中等', description: '适合明亮的散射光' },
water: plant.water || { frequency: '每周1-2次', description: '保持土壤微润' },
temperature: plant.temperature || '15-28℃',
humidity: plant.humidity || '50%-70%',
soil: plant.soil || '疏松透气的营养土',
fertilizer: plant.fertilizer || '生长季每月施一次薄肥',
toxicity: plant.toxicity || '无毒',
commonPests: plant.commonPests || ['红蜘蛛'],
careTips: plant.careTips || ['注意通风', '定期清洁叶面']
// Parse pest/disease list
const commonPests = item.pestsDiseases
? item.pestsDiseases.split(',').map(s => s.trim()).filter(Boolean)
: [];
// Parse aliases
const aliasesList = item.aliases
? item.aliases.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
: [];
// Parse reproduction methods
const reproductionList = item.reproductionMethod
? item.reproductionMethod.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
: [];
// Difficulty label
const diffLabels = { 1: '简单', 2: '中等', 3: '较难', 4: '困难', 5: '专家' };
// Map API data to display model
const plant = {
id: item.id,
name: item.name,
latinName: item.latinName || '',
aliases: item.aliases || '',
aliasesList: aliasesList,
genus: item.genus || '',
distributionArea: item.distributionArea || '',
difficulty: item.difficulty || 0,
difficultyLabel: diffLabels[item.difficulty] || '未知',
isHot: item.isHot === 1,
lifeCycle: item.lifeCycle || '',
growthHabit: item.growthHabit || '',
reproductionMethod: item.reproductionMethod || '',
reproductionList: reproductionList,
// Light
lightIntensity: item.lightIntensity || '',
lightType: item.lightType || '',
// Temperature
optimalTempPeriod: item.optimalTempPeriod || '',
// Morphology
stem: item.stem || '',
foliageType: item.foliageType || '',
foliageColor: item.foliageColor || '',
foliageShape: item.foliageShape || '',
height: item.height || 0,
// Flowering
floweringPeriod: item.floweringPeriod || '',
floweringColor: item.floweringColor || '',
floweringShape: item.floweringShape || '',
flowerDiameter: item.flowerDiameter || 0,
// Fruit
fruit: item.fruit || '',
// Pests
pestsDiseases: item.pestsDiseases || '',
commonPests: commonPests,
// Classes
classes: (item.classes || []).map(c => c.name),
// Images
imgList: item.imgList || []
};
this.setData({
plant: enrichedPlant,
plant: plant,
swiperList: swiperList
});
}
}).catch(err => {
console.error('Load plant detail failed', err);
wx.showToast({ title: '加载失败', icon: 'none' });
});
},
onSwiperChange(e) {