木邻有你前端代码仓库
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.

305 lines
8.3 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <view class="activity-calendar">
  3. <!-- 活动列表 -->
  4. <view class="calendar-content">
  5. <view
  6. v-for="(dayData, index) in activityData"
  7. :key="index"
  8. class="day-section"
  9. >
  10. <!-- 日期和日历图标 (在容器外部) -->
  11. <view class="date-header">
  12. <image
  13. src="/subPages/static/活动日历_图标@2x.png"
  14. class="calendar-icon"
  15. ></image>
  16. <text class="date-text">{{ dayData.activityTime }} {{ dayData.dayOfWeek }}</text>
  17. </view>
  18. <!-- 活动列表容器 -->
  19. <view class="activities-container">
  20. <view
  21. v-for="(activity, actIndex) in dayData.activities"
  22. :key="actIndex"
  23. class="activity-item"
  24. @click="viewActivityDetail(activity)"
  25. >
  26. <!-- 活动图片 -->
  27. <image class="activity-image" :src="activity.image" mode="aspectFill"></image>
  28. <!-- 活动信息 -->
  29. <view class="activity-info">
  30. <view class="title-row">
  31. <view class="activity-badge">
  32. <text class="badge-text">{{ activity.score }}</text>
  33. </view>
  34. <text class="activity-title">{{ activity.title }}</text>
  35. </view>
  36. <view class="activity-location">
  37. <uv-icon name="map-fill" size="14" color="#999"></uv-icon>
  38. <text class="location-text">{{ activity.address }}</text>
  39. </view>
  40. <view class="activity-time">
  41. <uv-icon name="calendar" size="14" color="#999"></uv-icon>
  42. <text class="time-text">{{ activity.activityTime }}</text>
  43. </view>
  44. <view class="activity-participants">
  45. <uv-icon name="account-fill" size="14" color="#999"></uv-icon>
  46. <text class="participants-text">{{ activity.numActivity }}/{{ activity.numLimit }}人已报名</text>
  47. </view>
  48. </view>
  49. <!-- 查看详情按钮 -->
  50. <view class="activity-action">
  51. <view class="detail-btn" @click.stop="viewActivityDetail(activity)">
  52. <text class="detail-btn-text">查看详情</text>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. export default {
  63. name: 'ActivityCalendar',
  64. data() {
  65. return {
  66. activityData: [],
  67. pageNo: 1,
  68. pageSize: 10,
  69. hasMore: true
  70. }
  71. },
  72. methods: {
  73. viewActivityDetail(activity) {
  74. // 跳转到活动详情页面
  75. uni.navigateTo({
  76. url: `/subPages/index/activityDetail?id=${activity.id}`
  77. });
  78. },
  79. // 处理后端返回的时间格式
  80. formatTime(timeString) {
  81. // 只截取年月日 中间有空格区分年月日和具体时间
  82. const [datePart, timePart] = timeString.split(' ');
  83. return datePart;
  84. },
  85. // 转化为时间格式
  86. changeData(arr) {
  87. arr.forEach(item => {
  88. // 先查找是否存在相同日期的数据
  89. const existingDay = this.activityData.find(day =>
  90. day.dayOfWeek === item.dayOfWeek && this.formatTime(day.activityTime) === this.formatTime(item.activityTime)
  91. );
  92. if (existingDay) {
  93. // 如果找到了,添加到现有的activities数组中
  94. existingDay.activities.push(item);
  95. } else {
  96. // 如果没找到,创建新的日期条目
  97. this.activityData.push({
  98. activityTime: this.formatTime(item.activityTime),
  99. dayOfWeek: item.dayOfWeek,
  100. activities: [item]
  101. });
  102. }
  103. });
  104. },
  105. async getActivityData() {
  106. if (!this.hasMore) return
  107. const res = await this.$api.activity.queryActivityList({
  108. pageNo: this.pageNo,
  109. pageSize: this.pageSize
  110. })
  111. if (res.result.records.length){
  112. this.changeData(res.result.records)
  113. this.pageNo++
  114. }else {
  115. uni.showToast({
  116. title: '暂无数据',
  117. icon: 'none'
  118. })
  119. this.hasMore = false
  120. }
  121. },
  122. initData() {
  123. this.hasMore = true
  124. this.activityData = []
  125. this.pageNo = 1
  126. }
  127. },
  128. async onShow() {
  129. this.initData()
  130. await this.getActivityData();
  131. },
  132. onReachBottom() {
  133. this.getActivityData();
  134. },
  135. async onPullDownRefresh() {
  136. this.initData()
  137. await this.getActivityData();
  138. uni.stopPullDownRefresh()
  139. }
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. // @import '@/uni.scss';
  144. .activity-calendar {
  145. background-color: #f5f5f5;
  146. min-height: 100vh;
  147. .calendar-content {
  148. padding: 40rpx 30rpx;
  149. .day-section {
  150. margin-bottom: 60rpx;
  151. &:last-child {
  152. margin-bottom: 0;
  153. }
  154. .date-header {
  155. display: flex;
  156. align-items: center;
  157. margin-bottom: 30rpx;
  158. .calendar-icon {
  159. width: 48rpx;
  160. height: 48rpx;
  161. margin-right: 20rpx;
  162. }
  163. .date-text {
  164. font-size: 32rpx;
  165. font-weight: bold;
  166. color: #000000;
  167. }
  168. }
  169. .activities-container {
  170. .activity-item {
  171. background: #ffffff;
  172. // border-radius: 16rpx;
  173. padding: 24rpx;
  174. margin-bottom: 20rpx;
  175. // box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  176. display: flex;
  177. align-items: flex-start;
  178. transition: all 0.3s ease;
  179. position: relative;
  180. &:last-child {
  181. margin-bottom: 0;
  182. }
  183. &:active {
  184. transform: scale(0.98);
  185. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.12);
  186. }
  187. .activity-image {
  188. width: 190rpx;
  189. height: 190rpx;
  190. border-radius: 8rpx;
  191. margin-right: 20rpx;
  192. }
  193. .activity-info {
  194. flex: 1;
  195. display: flex;
  196. flex-direction: column;
  197. justify-content: space-between;
  198. .title-row {
  199. display: flex;
  200. align-items: center;
  201. margin-bottom: 10rpx;
  202. .activity-badge {
  203. width: 31px;
  204. height: 20px;
  205. background: #218cdd;
  206. border-radius: 3.5px;
  207. margin-right: 7rpx;
  208. display: flex;
  209. align-items: center;
  210. justify-content: center;
  211. .badge-text {
  212. font-size: 18rpx;
  213. color: #fff;
  214. }
  215. }
  216. }
  217. .activity-title {
  218. font-size: 28rpx;
  219. font-weight: bold;
  220. color: $uni-text-color;
  221. overflow: hidden;
  222. text-overflow: ellipsis;
  223. white-space: nowrap;
  224. }
  225. .activity-location,
  226. .activity-time,
  227. .activity-participants {
  228. display: flex;
  229. align-items: center;
  230. margin-bottom: 6rpx;
  231. .location-text,
  232. .time-text,
  233. .participants-text {
  234. font-size: 24rpx;
  235. color: $uni-text-color-grey;
  236. margin-left: 6rpx;
  237. overflow: hidden;
  238. text-overflow: ellipsis;
  239. white-space: nowrap;
  240. flex: 1;
  241. }
  242. }
  243. }
  244. .activity-action {
  245. position: absolute;
  246. bottom: 20rpx;
  247. right: 20rpx;
  248. .detail-btn {
  249. background: #218CDD;
  250. border-radius: 26rpx;
  251. width: 140rpx;
  252. height: 52rpx;
  253. text-align: center;
  254. line-height: 44rpx;
  255. .detail-btn-text {
  256. font-size: 26rpx;
  257. color: #ffffff;
  258. font-weight: 500;
  259. }
  260. }
  261. .detail-btn:active {
  262. background: #1976C7;
  263. transform: scale(0.95);
  264. }
  265. }
  266. }
  267. }
  268. }
  269. }
  270. }
  271. </style>