feat: 后端版本迁移修改
This commit is contained in:
+44
-39
@@ -26,10 +26,10 @@ Page({
|
||||
},
|
||||
|
||||
loadPlantDetail(id) {
|
||||
request.get('/wiki/detail', { id: id }).then(res => {
|
||||
request.get('/plant/wiki/detail', { id: id }).then(res => {
|
||||
const item = res || null;
|
||||
|
||||
if (!item) {
|
||||
if (!item || !item.wiki) {
|
||||
wx.showToast({ title: '未找到该植物', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
@@ -44,57 +44,62 @@ Page({
|
||||
setPlantData(item) {
|
||||
if (!item) return;
|
||||
|
||||
wx.setNavigationBarTitle({ title: item.name });
|
||||
// 兼容两种数据来源:
|
||||
// 1. 从 API 获取: {wiki: {name:...}, imgList: [...]}
|
||||
// 2. 从列表页导航: {id:..., name:..., imgList: [...]} (raw item)
|
||||
const wiki = item.wiki || item;
|
||||
|
||||
// Prepare swiper list
|
||||
wx.setNavigationBarTitle({ title: wiki.name });
|
||||
|
||||
// Prepare swiper list — imgList 在顶层
|
||||
const swiperList = (item.imgList || []).map(img => img.url);
|
||||
|
||||
// Parse lists
|
||||
const commonPests = item.pestsDiseases
|
||||
? item.pestsDiseases.split(',').map(s => s.trim()).filter(Boolean)
|
||||
const commonPests = wiki.pestsDiseases
|
||||
? wiki.pestsDiseases.split(',').map(s => s.trim()).filter(Boolean)
|
||||
: [];
|
||||
const aliasesList = item.aliases
|
||||
? item.aliases.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
|
||||
const aliasesList = wiki.aliases
|
||||
? wiki.aliases.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
|
||||
: [];
|
||||
const reproductionList = item.reproductionMethod
|
||||
? item.reproductionMethod.split(/[,,、]/).map(s => s.trim()).filter(Boolean)
|
||||
const reproductionList = wiki.reproductionMethod
|
||||
? wiki.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 || '',
|
||||
id: wiki.id,
|
||||
name: wiki.name,
|
||||
latinName: wiki.latinName || '',
|
||||
aliases: wiki.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 || '',
|
||||
genus: wiki.genus || '',
|
||||
distributionArea: wiki.distributionArea || '',
|
||||
difficulty: wiki.difficulty || 0,
|
||||
difficultyLabel: diffLabels[wiki.difficulty] || '未知',
|
||||
isHot: wiki.isHot === true || wiki.isHot === 1,
|
||||
lifeCycle: wiki.lifeCycle || '',
|
||||
growthHabit: wiki.growthHabit || '',
|
||||
reproductionMethod: wiki.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 || '',
|
||||
lightIntensity: wiki.lightIntensity || '',
|
||||
lightType: wiki.lightType || '',
|
||||
optimalTempPeriod: wiki.optimalTempPeriod || '',
|
||||
stem: wiki.stem || '',
|
||||
foliageType: wiki.foliageType || '',
|
||||
foliageColor: wiki.foliageColor || '',
|
||||
foliageShape: wiki.foliageShape || '',
|
||||
height: wiki.height || 0,
|
||||
floweringPeriod: wiki.floweringPeriod || '',
|
||||
floweringColor: wiki.floweringColor || '',
|
||||
floweringShape: wiki.floweringShape || '',
|
||||
flowerDiameter: wiki.floweringDiameter || 0,
|
||||
fruit: wiki.fruit || '',
|
||||
pestsDiseases: wiki.pestsDiseases || '',
|
||||
commonPests,
|
||||
classes: (item.classes || []).map(c => c.name),
|
||||
classes: (item.classIds || []).map(id => ({ id })),
|
||||
imgList: item.imgList || [],
|
||||
isFavorited: (item.hasStar === 1 || item.hasStar === '1')
|
||||
isFavorited: wiki.isStar === true || wiki.isStar === 1
|
||||
};
|
||||
|
||||
this.setData({
|
||||
@@ -109,7 +114,7 @@ Page({
|
||||
const { id, isFavorited } = this.data.plant;
|
||||
const type = isFavorited ? 2 : 1;
|
||||
|
||||
request.get('/wiki/star', { id, type }).then(() => {
|
||||
request.get('/plant/wiki/star', { id, type }).then(() => {
|
||||
const newStatus = !isFavorited;
|
||||
this.setData({
|
||||
'plant.isFavorited': newStatus
|
||||
|
||||
Reference in New Issue
Block a user