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

213 lines
5.0 KiB

2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
  1. <template>
  2. <view class="activity-detail">
  3. <image class="activity-img" :src="detail.imgUrl" mode="aspectFill"></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="rich-content">
  16. <text class="content-title">活动介绍/回顾</text>
  17. <rich-text :nodes="contentNodes"></rich-text>
  18. </view>
  19. <view class="detail-bottom">
  20. <view class="detail-left">
  21. <button open-type="share" class="handle-btn">
  22. <uni-icons custom-prefix="iconfont" type="icon-fenxiang01" size="20"></uni-icons>
  23. <text>分享</text>
  24. </button>
  25. <!-- <button class="handle-btn" @click="toggleCollect">
  26. <uni-icons :type="isCollected ? 'heart-filled' : 'heart'" size="20" color="#ff4444"></uni-icons>
  27. <text>{{ isCollected ? '已收藏' : '收藏' }}</text>
  28. </button> -->
  29. </view>
  30. <button class="join-btn" :class="detail.status === 0 ? 'disabled-btn' : ''">
  31. {{ detail.status === 1 ? '我要参加' : '活动结束' }}
  32. </button>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. detail: {},
  41. isCollected: false,
  42. activityId: "",
  43. contentNodes: ""
  44. };
  45. },
  46. onLoad(options) {
  47. const item = JSON.parse(decodeURIComponent(options.item));
  48. this.detail = item;
  49. this.activityId = item.title;
  50. this.formatContent();
  51. this.checkCollectStatus();
  52. },
  53. methods: {
  54. formatContent() {
  55. let content = this.detail.content || "";
  56. // ======================================
  57. // 1. 把 content 里的 <image src="@/static/..."> 转成 <img> 标签
  58. // ======================================
  59. const localImgReg = /<image[^>]*\s+src\s*=\s*['"]@\/static\/([^'"]+)['"][^>]*>/gi;
  60. content = content.replace(localImgReg, (match, path) => {
  61. const imgPath = path.startsWith('/') ? path : '/' + path;
  62. return `
  63. <div style="text-align:center; margin:12px 0;">
  64. <img src="/static${imgPath}" style="width:90%; border-radius:8px;">
  65. </div>
  66. `;
  67. });
  68. // ======================================
  69. // 2. 把 https://mmbiz.qpic.cn 图片链接转成图片
  70. // ======================================
  71. const httpImgReg = /https:\/\/mmbiz\.qpic\.cn[^ \n\r'"]+/g;
  72. content = content.replace(httpImgReg, url => {
  73. return `
  74. <div style="text-align:center; margin:12px 0;">
  75. <img src="${url}" style="width:90%; border-radius:8px;">
  76. </div>
  77. `;
  78. });
  79. this.contentNodes = content;
  80. },
  81. checkCollectStatus() {
  82. const list = uni.getStorageSync('activityCollectList') || [];
  83. this.isCollected = list.includes(this.activityId);
  84. },
  85. toggleCollect() {
  86. let list = uni.getStorageSync('activityCollectList') || [];
  87. if (this.isCollected) {
  88. list = list.filter(i => i !== this.activityId);
  89. uni.showToast({ title: "取消收藏" });
  90. } else {
  91. list.push(this.activityId);
  92. uni.showToast({ title: "收藏成功", icon: "success" });
  93. }
  94. uni.setStorageSync('activityCollectList', list);
  95. this.isCollected = !this.isCollected;
  96. }
  97. },
  98. onShareAppMessage() {
  99. return {
  100. title: this.detail.title,
  101. path: "/subpkg/pages/activity-detail/activity-detail?item=" + encodeURIComponent(JSON.stringify(this.detail)),
  102. imageUrl: this.detail.imgUrl
  103. };
  104. }
  105. };
  106. </script>
  107. <style lang="scss" scoped>
  108. .activity-detail {
  109. padding-bottom: 60px;
  110. background: #f5f5f5;
  111. }
  112. .activity-img {
  113. width: 100%;
  114. height: 180px;
  115. }
  116. .activity-base {
  117. background: #fff;
  118. padding: 15px;
  119. margin-bottom: 10px;
  120. .title {
  121. font-size: 16px;
  122. font-weight: bold;
  123. padding-bottom: 10px;
  124. }
  125. .time,
  126. .location {
  127. display: flex;
  128. align-items: center;
  129. font-size: 12px;
  130. color: #999;
  131. padding-top: 10px;
  132. .detail-icon {
  133. padding-right: 4px;
  134. }
  135. }
  136. .time{
  137. padding-left: 3px;
  138. }
  139. }
  140. .rich-content {
  141. background: #fff;
  142. padding: 10px 0;
  143. .content-title{
  144. position: relative;
  145. font-size: 16px;
  146. font-weight: bold;
  147. color: #333;
  148. padding-left: 12px;
  149. &::before{
  150. position: absolute;
  151. left: 0;
  152. top: 50%;
  153. margin-top: -9px;
  154. content: "";
  155. width: 4px;
  156. height: 18px;
  157. background-color: #01a4fe;
  158. }
  159. }
  160. }
  161. .detail-bottom {
  162. position: fixed;
  163. bottom: 0;
  164. left: 0;
  165. right: 0;
  166. height: 50px;
  167. background: #fff;
  168. display: flex;
  169. align-items: center;
  170. justify-content: space-between;
  171. padding: 0 15px;
  172. box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.05);
  173. }
  174. .detail-left {
  175. display: flex;
  176. gap: 10px;
  177. }
  178. .handle-btn {
  179. display: flex;
  180. align-items: center;
  181. gap: 4px;
  182. background: #f5f5f5;
  183. border-radius: 30px;
  184. padding: 0 12px;
  185. height: 36px;
  186. font-size: 14px;
  187. }
  188. .join-btn {
  189. background: #01a4fe;
  190. color: #fff;
  191. border-radius: 30px;
  192. padding: 0 20px;
  193. height: 36px;
  194. }
  195. .disabled-btn {
  196. background: #ccc !important;
  197. }
  198. </style>