与牧同行-兽医端小程序
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.

153 lines
3.0 KiB

  1. import http from '../../../utils/api';
  2. const baseUrl = require('../../../utils/baseUrl');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. baseUrl: baseUrl,
  9. detailInfo: {},
  10. id: null,
  11. cardAnimation: {} // 卡片动画数据
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad(options) {
  17. if (options.id) {
  18. this.setData({ id: options.id });
  19. this.getCarouselDetail(options.id);
  20. this.initAnimation();
  21. } else {
  22. wx.showToast({
  23. title: '参数错误',
  24. icon: 'none'
  25. });
  26. }
  27. },
  28. /**
  29. * 初始化卡片动画
  30. */
  31. initAnimation() {
  32. const animation = wx.createAnimation({
  33. duration: 600,
  34. timingFunction: 'ease-out',
  35. delay: 100
  36. });
  37. animation.translateY(0).opacity(1).step();
  38. this.setData({
  39. cardAnimation: animation.export()
  40. });
  41. },
  42. /**
  43. * 获取轮播详情
  44. */
  45. getCarouselDetail(id) {
  46. wx.showLoading({ title: '加载中...', mask: true });
  47. http.carouselDetail({
  48. data: { id: id },
  49. success: (res) => {
  50. wx.hideLoading();
  51. console.log('轮播详情:', res);
  52. if (res && res.code === 200 && res.data) {
  53. this.setData({
  54. detailInfo: res.data
  55. });
  56. wx.setNavigationBarTitle({
  57. title: res.data.title || '轮播详情'
  58. });
  59. } else {
  60. wx.showToast({
  61. title: res?.msg || '数据加载失败',
  62. icon: 'none'
  63. });
  64. }
  65. },
  66. fail: (err) => {
  67. wx.hideLoading();
  68. console.error('请求失败:', err);
  69. wx.showToast({
  70. title: '网络错误',
  71. icon: 'none'
  72. });
  73. }
  74. });
  75. },
  76. /**
  77. * 颜色调整函数用于渐变效果
  78. */
  79. adjustColor(hex, percent) {
  80. if (!hex) return '#4CAF50';
  81. // 简单实现:如果传入颜色,返回稍浅的版本
  82. // 这里为了简化,直接返回原色稍微变浅,实际项目中可使用颜色处理库
  83. return hex;
  84. },
  85. /**
  86. * 图片加载错误处理
  87. */
  88. imageLoadError(e) {
  89. console.warn('图片加载失败', e);
  90. },
  91. /**
  92. * 返回上一页
  93. */
  94. goBack() {
  95. wx.navigateBack({
  96. delta: 1
  97. });
  98. },
  99. /**
  100. * 生命周期函数--监听页面初次渲染完成
  101. */
  102. onReady() {},
  103. /**
  104. * 生命周期函数--监听页面显示
  105. */
  106. onShow() {},
  107. /**
  108. * 生命周期函数--监听页面隐藏
  109. */
  110. onHide() {},
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload() {},
  115. /**
  116. * 页面相关事件处理函数--监听用户下拉动作
  117. */
  118. onPullDownRefresh() {},
  119. /**
  120. * 页面上拉触底事件的处理函数
  121. */
  122. onReachBottom() {},
  123. /**
  124. * 用户点击右上角分享
  125. */
  126. onShareAppMessage() {
  127. const { title, imageUrl } = this.data.detailInfo;
  128. return {
  129. title: title || '轮播详情',
  130. imageUrl: this.data.baseUrl + (imageUrl || ''),
  131. path: `/pages/carousel/detail/detail?id=${this.data.id}`
  132. };
  133. }
  134. });