feat: 样式修改
This commit is contained in:
+83
-91
@@ -5,117 +5,109 @@ Page({
|
||||
data: {
|
||||
plant: null,
|
||||
activeImageIndex: 0,
|
||||
swiperList: []
|
||||
swiperList: [],
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const eventChannel = this.getOpenerEventChannel();
|
||||
let loadedFromEvent = false;
|
||||
|
||||
if (eventChannel && eventChannel.on) {
|
||||
eventChannel.on('acceptDataFromOpenerPage', (res) => {
|
||||
if (res.data) {
|
||||
this.setPlantData(res.data);
|
||||
loadedFromEvent = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.id) {
|
||||
this.loadPlantDetail(options.id);
|
||||
// Give event channel a chance to fire
|
||||
setTimeout(() => {
|
||||
if (!loadedFromEvent && !this.data.plant) {
|
||||
this.loadPlantDetail(options.id);
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
|
||||
loadPlantDetail(id) {
|
||||
// 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;
|
||||
request.get('/wiki/detail', { id: id }).then(res => {
|
||||
const item = res || null;
|
||||
|
||||
if (!item) {
|
||||
wx.showToast({ title: '未找到该植物', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Set Page Title
|
||||
wx.setNavigationBarTitle({ title: item.name });
|
||||
|
||||
// Prepare swiper list from imgList
|
||||
const swiperList = (item.imgList || []).map(img => img.url);
|
||||
|
||||
// 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: plant,
|
||||
swiperList: swiperList
|
||||
});
|
||||
this.setPlantData(item);
|
||||
}).catch(err => {
|
||||
console.error('Load plant detail failed', err);
|
||||
wx.showToast({ title: '加载失败', icon: 'none' });
|
||||
});
|
||||
},
|
||||
|
||||
setPlantData(item) {
|
||||
if (!item) return;
|
||||
|
||||
wx.setNavigationBarTitle({ title: item.name });
|
||||
|
||||
// Prepare swiper list
|
||||
const swiperList = (item.imgList || []).map(img => img.url);
|
||||
|
||||
// Parse lists
|
||||
const commonPests = item.pestsDiseases
|
||||
? item.pestsDiseases.split(',').map(s => s.trim()).filter(Boolean)
|
||||
: [];
|
||||
const aliasesList = item.aliases
|
||||
? item.aliases.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
|
||||
: [];
|
||||
const reproductionList = item.reproductionMethod
|
||||
? item.reproductionMethod.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
|
||||
: [];
|
||||
|
||||
const diffLabels = { 1: '简单', 2: '中等', 3: '较难', 4: '困难', 5: '专家' };
|
||||
|
||||
const plant = {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
latinName: item.latinName || '',
|
||||
aliases: item.aliases || '',
|
||||
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,
|
||||
lightIntensity: item.lightIntensity || '',
|
||||
lightType: item.lightType || '',
|
||||
optimalTempPeriod: item.optimalTempPeriod || '',
|
||||
stem: item.stem || '',
|
||||
foliageType: item.foliageType || '',
|
||||
foliageColor: item.foliageColor || '',
|
||||
foliageShape: item.foliageShape || '',
|
||||
height: item.height || 0,
|
||||
floweringPeriod: item.floweringPeriod || '',
|
||||
floweringColor: item.floweringColor || '',
|
||||
floweringShape: item.floweringShape || '',
|
||||
flowerDiameter: item.flowerDiameter || 0,
|
||||
fruit: item.fruit || '',
|
||||
pestsDiseases: item.pestsDiseases || '',
|
||||
commonPests,
|
||||
classes: (item.classes || []).map(c => c.name),
|
||||
imgList: item.imgList || []
|
||||
};
|
||||
|
||||
this.setData({
|
||||
plant,
|
||||
swiperList
|
||||
});
|
||||
},
|
||||
|
||||
onSwiperChange(e) {
|
||||
this.setData({
|
||||
activeImageIndex: e.detail.current
|
||||
|
||||
Reference in New Issue
Block a user