feat: 整体页面优化,删除无用svg
This commit is contained in:
@@ -10,24 +10,18 @@ Page({
|
||||
|
||||
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) {
|
||||
// Give event channel a chance to fire
|
||||
setTimeout(() => {
|
||||
if (!loadedFromEvent && !this.data.plant) {
|
||||
this.loadPlantDetail(options.id);
|
||||
}
|
||||
}, 100);
|
||||
// Always fetch latest data (especially favorites status)
|
||||
this.loadPlantDetail(options.id);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -99,7 +93,8 @@ Page({
|
||||
pestsDiseases: item.pestsDiseases || '',
|
||||
commonPests,
|
||||
classes: (item.classes || []).map(c => c.name),
|
||||
imgList: item.imgList || []
|
||||
imgList: item.imgList || [],
|
||||
isFavorited: (item.hasStar === 1 || item.hasStar === '1')
|
||||
};
|
||||
|
||||
this.setData({
|
||||
@@ -108,6 +103,23 @@ Page({
|
||||
});
|
||||
},
|
||||
|
||||
toggleFavorite() {
|
||||
if (!this.data.plant) return;
|
||||
|
||||
const { id, isFavorited } = this.data.plant;
|
||||
const type = isFavorited ? 2 : 1;
|
||||
|
||||
request.get('/wiki/star', { id, type }).then(() => {
|
||||
this.setData({
|
||||
'plant.isFavorited': !isFavorited
|
||||
});
|
||||
wx.showToast({ title: type === 1 ? '已收藏' : '已取消', icon: 'success' });
|
||||
}).catch(err => {
|
||||
console.error('Toggle favorite failed', err);
|
||||
wx.showToast({ title: '操作失败', icon: 'none' });
|
||||
});
|
||||
},
|
||||
|
||||
onSwiperChange(e) {
|
||||
this.setData({
|
||||
activeImageIndex: e.detail.current
|
||||
|
||||
Reference in New Issue
Block a user