图书馆小程序
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.

211 lines
5.6 KiB

2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
1 week ago
2 weeks ago
  1. <template>
  2. <view class="activity-detail">
  3. <image class="activity-img" :src="detail.imgUrl"></image>
  4. <view class="activity-base">
  5. <text class="title">{{ detail.title }}</text>
  6. <view class="time">
  7. <uni-icons class="detail-icon" custom-prefix="iconfont" type="icon-shijian" size="15"></uni-icons>
  8. <text>{{ detail.time }}</text>
  9. </view>
  10. <view class="location">
  11. <uni-icons class="detail-icon" type="location" size="20"></uni-icons>
  12. <text>{{ detail.location }}</text>
  13. </view>
  14. </view>
  15. <view class="activity-content">
  16. <text class="content-title">活动介绍</text>
  17. <text class="content-desc">{{ detail.content }}</text>
  18. </view>
  19. <view class="detail-bottom">
  20. <view class="detail-left">
  21. <!-- #ifdef MP-WEIXIN -->
  22. <button open-type="share" class="handle-btn">
  23. <uni-icons custom-prefix="iconfont" type="icon-fenxiang01" size="20"></uni-icons>
  24. <text class="share-text">分享</text>
  25. </button>
  26. <!-- #endif -->
  27. <button class="handle-btn" @click="toggleCollect">
  28. <!-- 已收藏 / 未收藏 自动切换图标 -->
  29. <uni-icons :type="isCollected ? 'heart-filled' : 'heart'" size="20" color="#ff4444"></uni-icons>
  30. <text class="share-text">{{ isCollected ? '已收藏' : '收藏' }}</text>
  31. </button>
  32. </view>
  33. <button class="join-btn" :class="detail.status === 0 ? 'disabled-btn' : ''">
  34. <text>{{ detail.status === 1 ? '我要参加' : '活动结束' }}</text>
  35. </button>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. data() {
  42. return {
  43. detail: {
  44. imgUrl: "",
  45. title: "",
  46. time: "",
  47. location: "",
  48. content: "",
  49. status: 1 // 1=可参加 0=已结束
  50. },
  51. isCollected: false, // 收藏状态
  52. activityId: "" // 活动唯一标识(用标题作为唯一ID)
  53. };
  54. },
  55. onLoad(options) {
  56. const title = options.title || "";
  57. this.activityId = title; // 用活动标题作为唯一标识
  58. this.getActivityDetail(title);
  59. },
  60. methods: {
  61. /**
  62. * 模拟 获取活动详情接口
  63. * @param {String} title 活动标题
  64. */
  65. getActivityDetail(title) {
  66. uni.showLoading({ title: "加载中..." });
  67. setTimeout(() => {
  68. const res = {
  69. imgUrl: "https://qiniu.aiyxlib.com/1605060269830",
  70. title: title,
  71. time: "2025-11-03 00:00 ~ 2025-11-09 00:00",
  72. location: "图书馆一楼",
  73. content: "“酷爱书荟书香满园”作为酷车小镇的品牌活动,此次活动以“世界读书日”为契机,旨在推动“全民阅读”的文化风尚,激发公众的阅读兴趣,营造浓厚的阅读氛围。",
  74. // 模拟状态:标题包含数字3/6/9则结束
  75. status: title.includes("3") || title.includes("6") || title.includes("9") ? 0 : 1
  76. };
  77. this.detail = res;
  78. // 加载完活动数据后,检查收藏状态
  79. this.checkCollectStatus();
  80. uni.hideLoading();
  81. }, 1000);
  82. },
  83. // 检查当前活动是否已收藏
  84. checkCollectStatus() {
  85. const collectList = uni.getStorageSync('activityCollectList') || [];
  86. this.isCollected = collectList.includes(this.activityId);
  87. },
  88. // 切换收藏 / 取消收藏
  89. toggleCollect() {
  90. let collectList = uni.getStorageSync('activityCollectList') || [];
  91. if (this.isCollected) {
  92. // 取消收藏
  93. collectList = collectList.filter(id => id !== this.activityId);
  94. uni.showToast({ title: '取消收藏成功', icon: 'success' });
  95. } else {
  96. // 添加收藏
  97. collectList.push(this.activityId);
  98. uni.showToast({ title: '收藏成功', icon: 'success' });
  99. }
  100. // 保存到本地缓存
  101. uni.setStorageSync('activityCollectList', collectList);
  102. // 更新状态
  103. this.isCollected = !this.isCollected;
  104. }
  105. // 真实接口示例(备用)
  106. // getActivityDetail(title) {
  107. // uni.showLoading();
  108. // uni.request({
  109. // url: "https://xxx.com/api/activity/detail",
  110. // method: "GET",
  111. // data: { title: title },
  112. // success: (res) => {
  113. // this.detail = res.data;
  114. // this.checkCollectStatus();
  115. // },
  116. // complete: () => {
  117. // uni.hideLoading();
  118. // }
  119. // });
  120. // }
  121. },
  122. // 微信分享
  123. onShareAppMessage() {
  124. return {
  125. title: this.detail.title,
  126. path: "/subpkg/pages/activity-detail/activity-detail?title=" + this.detail.title,
  127. imageUrl: this.detail.imgUrl
  128. };
  129. }
  130. };
  131. </script>
  132. <style lang="scss" scoped>
  133. .activity-img{
  134. width: 100%;
  135. height: 150px;
  136. }
  137. .activity-base{
  138. display: flex;
  139. flex-direction: column;
  140. justify-content: flex-start;
  141. background-color: #fff;
  142. padding: 15px;
  143. .title{
  144. font-size: 16px;
  145. font-weight: bold;
  146. color: #333;
  147. padding-bottom: 10px;
  148. }
  149. .time,
  150. .location {
  151. display: flex;
  152. justify-content: flex-start;
  153. align-items: center;
  154. font-size: 12px;
  155. color: #999;
  156. .detail-icon{
  157. width: 20px;
  158. }
  159. }
  160. .time {
  161. padding-bottom: 10px;
  162. .detail-icon{
  163. margin-top: 2px;
  164. margin-left: 2px;
  165. }
  166. }
  167. }
  168. .activity-content{
  169. display: flex;
  170. flex-direction: column;
  171. justify-content: flex-start;
  172. background-color: #fff;
  173. margin-top: 20px;
  174. padding: 15px 0;
  175. .content-title{
  176. position: relative;
  177. font-size: 16px;
  178. font-weight: bold;
  179. color: #333;
  180. padding-left: 12px;
  181. &::before{
  182. position: absolute;
  183. left: 0;
  184. top: 50%;
  185. margin-top: -9px;
  186. content: "";
  187. width: 4px;
  188. height: 18px;
  189. background-color: #01a4fe;
  190. }
  191. }
  192. .content-desc{
  193. padding: 15px;
  194. font-size: 14px;
  195. line-height: 24px;
  196. }
  197. }
  198. </style>