DimensionActivities.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <template>
  2. <view class="section">
  3. <!-- 头部 -->
  4. <view class="section-header">
  5. <view class="section-header-left">
  6. <view class="section-icon-wrap">
  7. <text class="section-icon">{{ dimensionIcon }}</text>
  8. </view>
  9. <text class="section-title">推荐活动</text>
  10. </view>
  11. <view class="section-more" @click="$emit('moreActivities')">
  12. <text class="section-more-text">更多</text>
  13. <text class="section-more-arrow">›</text>
  14. </view>
  15. </view>
  16. <!-- 空状态 -->
  17. <view v-if="!displayActivities || displayActivities.length === 0" class="empty-state">
  18. <text class="empty-icon">{{ dimensionIcon }}</text>
  19. <text class="empty-tip">{{ isLoggedIn ? '暂无相关活动' : '登录后查看更多活动' }}</text>
  20. </view>
  21. <!-- 活动卡片轮播(行布局) -->
  22. <view class="activity-carousel" v-if="displayActivities && displayActivities.length > 0">
  23. <swiper
  24. class="activity-swiper"
  25. :indicator-dots="displayActivities.length > 1"
  26. :active-index="swiperIndex"
  27. @change="onSwiperChange"
  28. autoplay
  29. interval="3000"
  30. duration="500"
  31. circular
  32. >
  33. <swiper-item v-for="(act, index) in displayActivities" :key="act.id">
  34. <view class="activity-card" @click.stop="$emit('activityClick', act)">
  35. <!-- 封面图(占满卡片高度) -->
  36. <image
  37. class="card-cover-img"
  38. :src="act.coverImage || '/static/default-activity.png'"
  39. mode="aspectFill"
  40. />
  41. <!-- 右侧信息区 -->
  42. <view class="card-info">
  43. <text class="card-title line-clamp-1">{{ act.title }}</text>
  44. <view class="card-meta-row">
  45. <view class="card-time">
  46. <text class="meta-icon">🕐</text>
  47. <text class="meta-text">{{ formatTime(act.startTime) }}</text>
  48. </view>
  49. <view class="card-badges" v-if="act._badges && act._badges.length">
  50. <text
  51. class="card-badge"
  52. v-for="badge in act._badges"
  53. :key="badge.name"
  54. :style="{ color: badge.color, borderColor: badge.color + '40' }"
  55. >
  56. {{ badge.name }}
  57. </text>
  58. </view>
  59. </view>
  60. <view class="card-bottom">
  61. <text class="card-status" :class="'status-' + (act.status || 'upcoming')">
  62. {{ statusText(act.status) }}
  63. </text>
  64. <text class="card-price" v-if="act.priceLabel">{{ act.priceLabel }}</text>
  65. <text class="card-price" v-else-if="act.price && act.price > 0">{{ formatPriceWithSymbol(act.price) }}</text>
  66. <text class="card-price-free" v-else>免费</text>
  67. </view>
  68. </view>
  69. </view>
  70. </swiper-item>
  71. </swiper>
  72. <!-- 轮播指示点 -->
  73. <view v-if="displayActivities.length > 1" class="swiper-dots">
  74. <view
  75. class="dot"
  76. v-for="(dot, index) in displayActivities"
  77. :key="index"
  78. :class="{ active: swiperIndex === index }"
  79. ></view>
  80. </view>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. var DIMENSION_MAP = {
  86. body: { name: '身', color: '#FF8C42', icon: '🌏' },
  87. mind: { name: '心', color: '#FF6B9D', icon: '🔥' },
  88. wisdom: { name: '智', color: '#6366F1', icon: '⚡' },
  89. action: { name: '行', color: '#10B981', icon: '🌿' },
  90. wealth: { name: '富', color: '#F59E0B', icon: '💧' }
  91. }
  92. export default {
  93. props: {
  94. dimensionCode: { type: String, required: true },
  95. activities: { type: Array, default: function() { return [] } },
  96. isLoggedIn: { type: Boolean, default: false }
  97. },
  98. data: function() {
  99. return {
  100. swiperIndex: 0
  101. }
  102. },
  103. computed: {
  104. displayActivities: function() {
  105. var self = this
  106. return (this.activities || []).slice(0, 3).map(function(item) {
  107. item._badges = self.parseWeights(item.dimensionWeights)
  108. return item
  109. })
  110. },
  111. dimensionIcon: function() {
  112. var map = { body: '🌏', mind: '🔥', wisdom: '⚡', action: '🌿', wealth: '💧' }
  113. return map[this.dimensionCode] || '🎯'
  114. }
  115. },
  116. methods: {
  117. onSwiperChange: function(e) {
  118. this.swiperIndex = e.detail.current
  119. },
  120. parseWeights: function(str) {
  121. if (!str) return []
  122. try {
  123. var obj = JSON.parse(str)
  124. var result = []
  125. for (var key in obj) {
  126. if (obj[key] > 0 && DIMENSION_MAP[key]) {
  127. result.push({ name: DIMENSION_MAP[key].name, color: DIMENSION_MAP[key].color, weight: obj[key] })
  128. }
  129. }
  130. return result
  131. } catch (e) {
  132. return []
  133. }
  134. },
  135. statusText: function(status) {
  136. var map = { upcoming: '即将开始', ongoing: '进行中', ended: '已结束', cancelled: '已取消' }
  137. return map[status] || '即将开始'
  138. },
  139. formatTime: function(timeStr) {
  140. if (!timeStr) return '待定'
  141. var d = new Date(timeStr)
  142. if (isNaN(d.getTime())) return timeStr
  143. var month = d.getMonth() + 1
  144. var day = d.getDate()
  145. var hour = d.getHours()
  146. var minute = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes()
  147. return month + '月' + day + '日 ' + hour + ':' + minute
  148. },
  149. formatPriceWithSymbol: function(price) {
  150. if (price == null) return '免费'
  151. return '¥' + (Number(price) / 100).toFixed(0)
  152. }
  153. }
  154. }
  155. </script>
  156. <style scoped>
  157. .section {
  158. margin: 16rpx 20rpx;
  159. }
  160. /* ===== 头部 ===== */
  161. .section-header {
  162. display: flex;
  163. flex-direction: row;
  164. justify-content: space-between;
  165. align-items: center;
  166. margin-bottom: 16rpx;
  167. }
  168. .section-header-left {
  169. display: flex;
  170. flex-direction: row;
  171. align-items: center;
  172. }
  173. .section-icon-wrap {
  174. width: 44rpx;
  175. height: 44rpx;
  176. border-radius: 12rpx;
  177. background: linear-gradient(135deg, #FF6B9D, #FF8FB1);
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. margin-right: 12rpx;
  182. }
  183. .section-icon {
  184. font-size: 24rpx;
  185. }
  186. .section-title {
  187. font-size: 32rpx;
  188. font-weight: 700;
  189. color: #1E293B;
  190. letter-spacing: 1rpx;
  191. }
  192. .section-more {
  193. display: flex;
  194. flex-direction: row;
  195. align-items: center;
  196. padding: 8rpx 20rpx;
  197. background: #F1F5F9;
  198. border-radius: 24rpx;
  199. }
  200. .section-more-text {
  201. font-size: 24rpx;
  202. color: #64748B;
  203. margin-right: 4rpx;
  204. }
  205. .section-more-arrow {
  206. font-size: 20rpx;
  207. color: #94A3B8;
  208. }
  209. /* ===== 空状态 ===== */
  210. .empty-state {
  211. display: flex;
  212. flex-direction: column;
  213. align-items: center;
  214. padding: 30rpx 0;
  215. }
  216. .empty-icon {
  217. font-size: 64rpx;
  218. margin-bottom: 16rpx;
  219. }
  220. .empty-tip {
  221. font-size: 26rpx;
  222. color: #94A3B8;
  223. }
  224. /* ===== 活动轮播 ===== */
  225. .activity-carousel {
  226. width: 100%;
  227. margin: 0 -20rpx;
  228. }
  229. .activity-swiper {
  230. width: 100%;
  231. height: 160rpx;
  232. }
  233. .activity-swiper .swiper-slide {
  234. width: 100%;
  235. height: 100%;
  236. }
  237. /* 轮播指示点 */
  238. .swiper-dots {
  239. display: flex;
  240. justify-content: center;
  241. align-items: center;
  242. gap: 8rpx;
  243. margin-top: 12rpx;
  244. }
  245. .dot {
  246. width: 8rpx;
  247. height: 8rpx;
  248. border-radius: 50%;
  249. background: #D1D5DB;
  250. transition: all 0.3s ease;
  251. }
  252. .dot.active {
  253. width: 32rpx;
  254. border-radius: 4rpx;
  255. background: #F97316;
  256. }
  257. /* ===== 活动卡片(行布局) ===== */
  258. .activity-card {
  259. background: #FFFFFF;
  260. border-radius: 16rpx;
  261. overflow: hidden;
  262. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  263. display: flex;
  264. flex-direction: row;
  265. height: 100%;
  266. }
  267. .activity-card:active {
  268. opacity: 0.8;
  269. }
  270. /* 封面图 — 占满卡片高度 */
  271. .card-cover-img {
  272. width: 200rpx;
  273. height: 100%;
  274. flex-shrink: 0;
  275. background: #F1F5F9;
  276. }
  277. /* 右侧信息区 */
  278. .card-info {
  279. flex: 1;
  280. padding: 16rpx;
  281. display: flex;
  282. flex-direction: column;
  283. justify-content: space-between;
  284. min-width: 0;
  285. }
  286. /* 标题 */
  287. .card-title {
  288. font-size: 28rpx;
  289. font-weight: bold;
  290. color: #333;
  291. margin-bottom: 8rpx;
  292. }
  293. .line-clamp-1 {
  294. overflow: hidden;
  295. text-overflow: ellipsis;
  296. white-space: nowrap;
  297. }
  298. /* 时间和维度标签 */
  299. .card-meta-row {
  300. display: flex;
  301. flex-direction: row;
  302. align-items: center;
  303. margin-bottom: 8rpx;
  304. }
  305. .card-time {
  306. display: flex;
  307. flex-direction: row;
  308. align-items: center;
  309. margin-right: 16rpx;
  310. }
  311. .meta-icon {
  312. font-size: 22rpx;
  313. margin-right: 6rpx;
  314. }
  315. .meta-text {
  316. font-size: 24rpx;
  317. color: #64748B;
  318. }
  319. .card-badges {
  320. display: flex;
  321. flex-direction: row;
  322. flex-wrap: wrap;
  323. gap: 8rpx;
  324. }
  325. .card-badge {
  326. font-size: 20rpx;
  327. padding: 4rpx 12rpx;
  328. border-radius: 20rpx;
  329. border: 1rpx solid;
  330. font-weight: 500;
  331. }
  332. /* 底部:状态 + 价格 */
  333. .card-bottom {
  334. display: flex;
  335. flex-direction: row;
  336. align-items: center;
  337. gap: 12rpx;
  338. }
  339. .card-status {
  340. font-size: 20rpx;
  341. padding: 2rpx 10rpx;
  342. border-radius: 8rpx;
  343. background: #E8F5E9;
  344. color: #2E7D32;
  345. }
  346. .card-status.status-upcoming {
  347. background: #E3F2FD;
  348. color: #1565C0;
  349. }
  350. .card-status.status-ended {
  351. background: #F5F5F5;
  352. color: #999;
  353. }
  354. .card-price {
  355. font-size: 24rpx;
  356. font-weight: bold;
  357. color: #F97316;
  358. }
  359. .card-price-free {
  360. font-size: 24rpx;
  361. font-weight: 600;
  362. color: #22C55E;
  363. }
  364. </style>