You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
3.0 KiB
154 lines
3.0 KiB
import http from '../../../utils/api';
|
|
const baseUrl = require('../../../utils/baseUrl');
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
baseUrl: baseUrl,
|
|
detailInfo: {},
|
|
id: null,
|
|
cardAnimation: {} // 卡片动画数据
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
if (options.id) {
|
|
this.setData({ id: options.id });
|
|
this.getCarouselDetail(options.id);
|
|
this.initAnimation();
|
|
} else {
|
|
wx.showToast({
|
|
title: '参数错误',
|
|
icon: 'none'
|
|
});
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 初始化卡片动画
|
|
*/
|
|
initAnimation() {
|
|
const animation = wx.createAnimation({
|
|
duration: 600,
|
|
timingFunction: 'ease-out',
|
|
delay: 100
|
|
});
|
|
|
|
animation.translateY(0).opacity(1).step();
|
|
|
|
this.setData({
|
|
cardAnimation: animation.export()
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 获取轮播详情
|
|
*/
|
|
getCarouselDetail(id) {
|
|
wx.showLoading({ title: '加载中...', mask: true });
|
|
|
|
http.carouselDetail({
|
|
data: { id: id },
|
|
success: (res) => {
|
|
wx.hideLoading();
|
|
console.log('轮播详情:', res);
|
|
|
|
if (res && res.code === 200 && res.data) {
|
|
this.setData({
|
|
detailInfo: res.data
|
|
});
|
|
wx.setNavigationBarTitle({
|
|
title: res.data.title || '轮播详情'
|
|
});
|
|
} else {
|
|
wx.showToast({
|
|
title: res?.msg || '数据加载失败',
|
|
icon: 'none'
|
|
});
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
wx.hideLoading();
|
|
console.error('请求失败:', err);
|
|
wx.showToast({
|
|
title: '网络错误',
|
|
icon: 'none'
|
|
});
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 颜色调整函数(用于渐变效果)
|
|
*/
|
|
adjustColor(hex, percent) {
|
|
if (!hex) return '#4CAF50';
|
|
// 简单实现:如果传入颜色,返回稍浅的版本
|
|
// 这里为了简化,直接返回原色稍微变浅,实际项目中可使用颜色处理库
|
|
return hex;
|
|
},
|
|
|
|
/**
|
|
* 图片加载错误处理
|
|
*/
|
|
imageLoadError(e) {
|
|
console.warn('图片加载失败', e);
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
* 返回上一页
|
|
*/
|
|
goBack() {
|
|
wx.navigateBack({
|
|
delta: 1
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
const { title, imageUrl } = this.data.detailInfo;
|
|
return {
|
|
title: title || '轮播详情',
|
|
imageUrl: this.data.baseUrl + (imageUrl || ''),
|
|
path: `/pages/carousel/detail/detail?id=${this.data.id}`
|
|
};
|
|
}
|
|
});
|