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

301 lines
8.2 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. <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. }
  70. },
  71. methods: {
  72. viewActivityDetail(activity) {
  73. // 跳转到活动详情页面
  74. uni.navigateTo({
  75. url: `/subPages/index/activityDetail?id=${activity.id}`
  76. });
  77. },
  78. // 处理后端返回的时间格式
  79. formatTime(timeString) {
  80. // 只截取年月日 中间有空格区分年月日和具体时间
  81. const [datePart, timePart] = timeString.split(' ');
  82. return datePart;
  83. },
  84. // 转化为时间格式
  85. changeData(arr) {
  86. arr.forEach(item => {
  87. // 先查找是否存在相同日期的数据
  88. const existingDay = this.activityData.find(day =>
  89. day.dayOfWeek === item.dayOfWeek && this.formatTime(day.activityTime) === this.formatTime(item.activityTime)
  90. );
  91. if (existingDay) {
  92. // 如果找到了,添加到现有的activities数组中
  93. existingDay.activities.push(item);
  94. } else {
  95. // 如果没找到,创建新的日期条目
  96. this.activityData.push({
  97. activityTime: this.formatTime(item.activityTime),
  98. dayOfWeek: item.dayOfWeek,
  99. activities: [item]
  100. });
  101. }
  102. });
  103. },
  104. async getActivityData() {
  105. const res = await this.$api.activity.queryActivityList({
  106. pageNo: this.pageNo,
  107. pageSize: this.pageSize
  108. })
  109. if (res.result.records.length){
  110. this.changeData(res.result.records)
  111. this.pageNo++
  112. }else {
  113. uni.showToast({
  114. title: '暂无数据',
  115. icon: 'none'
  116. })
  117. }
  118. },
  119. initData() {
  120. this.activityData = []
  121. this.pageNo = 1
  122. }
  123. },
  124. async onShow() {
  125. this.initData()
  126. await this.getActivityData();
  127. },
  128. onReachBottom() {
  129. this.getActivityData();
  130. },
  131. async onPullDownRefresh() {
  132. this.initData()
  133. await this.getActivityData();
  134. uni.stopPullDownRefresh()
  135. }
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. // @import '@/uni.scss';
  140. .activity-calendar {
  141. background-color: #f5f5f5;
  142. min-height: 100vh;
  143. .calendar-content {
  144. padding: 40rpx 30rpx;
  145. .day-section {
  146. margin-bottom: 60rpx;
  147. &:last-child {
  148. margin-bottom: 0;
  149. }
  150. .date-header {
  151. display: flex;
  152. align-items: center;
  153. margin-bottom: 30rpx;
  154. .calendar-icon {
  155. width: 48rpx;
  156. height: 48rpx;
  157. margin-right: 20rpx;
  158. }
  159. .date-text {
  160. font-size: 32rpx;
  161. font-weight: bold;
  162. color: $uni-color-primary;
  163. }
  164. }
  165. .activities-container {
  166. .activity-item {
  167. background: #ffffff;
  168. // border-radius: 16rpx;
  169. padding: 24rpx;
  170. margin-bottom: 20rpx;
  171. // box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  172. display: flex;
  173. align-items: flex-start;
  174. transition: all 0.3s ease;
  175. position: relative;
  176. &:last-child {
  177. margin-bottom: 0;
  178. }
  179. &:active {
  180. transform: scale(0.98);
  181. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.12);
  182. }
  183. .activity-image {
  184. width: 190rpx;
  185. height: 190rpx;
  186. border-radius: 8rpx;
  187. margin-right: 20rpx;
  188. }
  189. .activity-info {
  190. flex: 1;
  191. display: flex;
  192. flex-direction: column;
  193. justify-content: space-between;
  194. .title-row {
  195. display: flex;
  196. align-items: center;
  197. margin-bottom: 10rpx;
  198. .activity-badge {
  199. width: 31px;
  200. height: 20px;
  201. background: #218cdd;
  202. border-radius: 3.5px;
  203. margin-right: 7rpx;
  204. display: flex;
  205. align-items: center;
  206. justify-content: center;
  207. .badge-text {
  208. font-size: 18rpx;
  209. color: #fff;
  210. }
  211. }
  212. }
  213. .activity-title {
  214. font-size: 28rpx;
  215. font-weight: bold;
  216. color: $uni-text-color;
  217. overflow: hidden;
  218. text-overflow: ellipsis;
  219. white-space: nowrap;
  220. }
  221. .activity-location,
  222. .activity-time,
  223. .activity-participants {
  224. display: flex;
  225. align-items: center;
  226. margin-bottom: 6rpx;
  227. .location-text,
  228. .time-text,
  229. .participants-text {
  230. font-size: 24rpx;
  231. color: $uni-text-color-grey;
  232. margin-left: 6rpx;
  233. overflow: hidden;
  234. text-overflow: ellipsis;
  235. white-space: nowrap;
  236. flex: 1;
  237. }
  238. }
  239. }
  240. .activity-action {
  241. position: absolute;
  242. bottom: 20rpx;
  243. right: 20rpx;
  244. .detail-btn {
  245. background: #218CDD;
  246. border-radius: 26rpx;
  247. width: 140rpx;
  248. height: 52rpx;
  249. text-align: center;
  250. line-height: 44rpx;
  251. .detail-btn-text {
  252. font-size: 26rpx;
  253. color: #ffffff;
  254. font-weight: 500;
  255. }
  256. }
  257. .detail-btn:active {
  258. background: #1976C7;
  259. transform: scale(0.95);
  260. }
  261. }
  262. }
  263. }
  264. }
  265. }
  266. }
  267. </style>