DimensionActivities.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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">&#x203A;</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. <view class="card-cover">
  37. <image
  38. class="card-cover-img"
  39. :src="act.coverImage || '/static/default-activity.png'"
  40. mode="aspectFill"
  41. />
  42. <!-- 渐变遮罩 -->
  43. <view class="card-cover-mask"></view>
  44. <!-- 状态标签 -->
  45. <view class="card-status" :class="'status-' + (act.status || 'upcoming')">
  46. <text class="card-status-dot" v-if="act.status === 'ongoing'"></text>
  47. <text class="card-status-text">{{ statusText(act.status) }}</text>
  48. </view>
  49. <!-- 标题 -->
  50. <view class="card-title-wrap">
  51. <text class="card-title">{{ act.title }}</text>
  52. </view>
  53. </view>
  54. <!-- 内容区域 -->
  55. <view class="card-content">
  56. <!-- 时间和维度标签 -->
  57. <view class="card-meta-row">
  58. <view class="card-time">
  59. <text class="meta-icon">&#x1F552;</text>
  60. <text class="meta-text">{{ formatTime(act.startTime) }}</text>
  61. </view>
  62. <view class="card-badges" v-if="act._badges && act._badges.length">
  63. <text
  64. class="card-badge"
  65. v-for="badge in act._badges"
  66. :key="badge.name"
  67. :style="{ color: badge.color, borderColor: badge.color + '40' }"
  68. >
  69. {{ badge.name }}
  70. </text>
  71. </view>
  72. </view>
  73. <!-- 底部:价格和按钮 -->
  74. <view class="card-footer">
  75. <view class="card-price-wrap">
  76. <text class="card-price" v-if="act.priceLabel">{{ act.priceLabel }}</text>
  77. <text class="card-price" v-else-if="act.price && act.price > 0">{{ formatPriceWithSymbol(act.price) }}</text>
  78. <text class="card-price-free" v-else>免费</text>
  79. </view>
  80. <view class="card-action-btn">
  81. <text class="card-action-text">了解详情</text>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </swiper-item>
  87. </swiper>
  88. <!-- 轮播指示点 -->
  89. <view v-if="displayActivities.length > 1" class="swiper-dots">
  90. <view
  91. class="dot"
  92. v-for="(dot, index) in displayActivities"
  93. :key="index"
  94. :class="{ active: swiperIndex === index }"
  95. ></view>
  96. </view>
  97. </view>
  98. </view>
  99. </template>
  100. <script>
  101. var DIMENSION_MAP = {
  102. body: { name: '身', color: '#FF8C42', icon: '🌏' },
  103. mind: { name: '心', color: '#FF6B9D', icon: '🔥' },
  104. wisdom: { name: '智', color: '#6366F1', icon: '⚡' },
  105. action: { name: '行', color: '#10B981', icon: '🌿' },
  106. wealth: { name: '富', color: '#F59E0B', icon: '💧' }
  107. }
  108. export default {
  109. props: {
  110. dimensionCode: { type: String, required: true },
  111. activities: { type: Array, default: function() { return [] } },
  112. isLoggedIn: { type: Boolean, default: false }
  113. },
  114. data: function() {
  115. return {
  116. swiperIndex: 0
  117. }
  118. },
  119. computed: {
  120. displayActivities: function() {
  121. var self = this
  122. return (this.activities || []).slice(0, 3).map(function(item) {
  123. item._badges = self.parseWeights(item.dimensionWeights)
  124. return item
  125. })
  126. },
  127. dimensionIcon: function() {
  128. var map = { body: '🌏', mind: '🔥', wisdom: '⚡', action: '🌿', wealth: '💧' }
  129. return map[this.dimensionCode] || '🎯'
  130. }
  131. },
  132. methods: {
  133. onSwiperChange: function(e) {
  134. this.swiperIndex = e.detail.current
  135. },
  136. parseWeights: function(str) {
  137. if (!str) return []
  138. try {
  139. var obj = JSON.parse(str)
  140. var result = []
  141. for (var key in obj) {
  142. if (obj[key] > 0 && DIMENSION_MAP[key]) {
  143. result.push({ name: DIMENSION_MAP[key].name, color: DIMENSION_MAP[key].color, weight: obj[key] })
  144. }
  145. }
  146. return result
  147. } catch (e) {
  148. return []
  149. }
  150. },
  151. statusText: function(status) {
  152. var map = { upcoming: '即将开始', ongoing: '进行中', ended: '已结束', cancelled: '已取消' }
  153. return map[status] || '即将开始'
  154. },
  155. formatTime: function(timeStr) {
  156. if (!timeStr) return '待定'
  157. var d = new Date(timeStr)
  158. if (isNaN(d.getTime())) return timeStr
  159. var month = d.getMonth() + 1
  160. var day = d.getDate()
  161. var hour = d.getHours()
  162. var minute = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes()
  163. return month + '月' + day + '日 ' + hour + ':' + minute
  164. },
  165. formatPriceWithSymbol: function(price) {
  166. if (price == null) return '免费'
  167. return '¥' + (Number(price) / 100).toFixed(0)
  168. }
  169. }
  170. }
  171. </script>
  172. <style scoped>
  173. .section {
  174. margin: 24rpx 20rpx;
  175. }
  176. /* ===== 头部 ===== */
  177. .section-header {
  178. display: flex;
  179. flex-direction: row;
  180. justify-content: space-between;
  181. align-items: center;
  182. margin-bottom: 24rpx;
  183. }
  184. .section-header-left {
  185. display: flex;
  186. flex-direction: row;
  187. align-items: center;
  188. }
  189. .section-icon-wrap {
  190. width: 44rpx;
  191. height: 44rpx;
  192. border-radius: 12rpx;
  193. background: linear-gradient(135deg, #FF6B9D, #FF8FB1);
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. margin-right: 12rpx;
  198. }
  199. .section-icon {
  200. font-size: 24rpx;
  201. }
  202. .section-title {
  203. font-size: 32rpx;
  204. font-weight: 700;
  205. color: #1E293B;
  206. letter-spacing: 1rpx;
  207. }
  208. .section-more {
  209. display: flex;
  210. flex-direction: row;
  211. align-items: center;
  212. padding: 8rpx 20rpx;
  213. background: #F1F5F9;
  214. border-radius: 24rpx;
  215. }
  216. .section-more-text {
  217. font-size: 24rpx;
  218. color: #64748B;
  219. margin-right: 4rpx;
  220. }
  221. .section-more-arrow {
  222. font-size: 20rpx;
  223. color: #94A3B8;
  224. }
  225. /* ===== 空状态 ===== */
  226. .empty-state {
  227. display: flex;
  228. flex-direction: column;
  229. align-items: center;
  230. padding: 60rpx 0;
  231. }
  232. .empty-icon {
  233. font-size: 64rpx;
  234. margin-bottom: 16rpx;
  235. }
  236. .empty-tip {
  237. font-size: 26rpx;
  238. color: #94A3B8;
  239. }
  240. /* ===== 活动轮播 ===== */
  241. .activity-carousel {
  242. width: 100%;
  243. margin: 0 -20rpx;
  244. }
  245. .activity-swiper {
  246. width: 100%;
  247. height: 600rpx;
  248. }
  249. .activity-swiper ::deep .swiper-slide {
  250. width: 100%;
  251. height: 100%;
  252. }
  253. /* 轮播指示点 */
  254. .swiper-dots {
  255. display: flex;
  256. justify-content: center;
  257. align-items: center;
  258. gap: 8rpx;
  259. margin-top: 20rpx;
  260. }
  261. .dot {
  262. width: 8rpx;
  263. height: 8rpx;
  264. border-radius: 50%;
  265. background: #D1D5DB;
  266. transition: all 0.3s ease;
  267. }
  268. .dot.active {
  269. width: 32rpx;
  270. border-radius: 4rpx;
  271. background: #F97316;
  272. }
  273. /* ===== 活动卡片 ===== */
  274. .activity-card {
  275. background: #FFFFFF;
  276. border-radius: 24rpx;
  277. overflow: hidden;
  278. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
  279. }
  280. /* 封面图 */
  281. .card-cover {
  282. position: relative;
  283. width: 100%;
  284. height: 320rpx;
  285. overflow: hidden;
  286. }
  287. .card-cover-img {
  288. width: 100%;
  289. height: 100%;
  290. background: #F1F5F9;
  291. }
  292. /* 渐变遮罩 */
  293. .card-cover-mask {
  294. position: absolute;
  295. bottom: 0;
  296. left: 0;
  297. right: 0;
  298. height: 150rpx;
  299. background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent);
  300. }
  301. /* 状态标签 */
  302. .card-status {
  303. position: absolute;
  304. top: 16rpx;
  305. right: 16rpx;
  306. display: flex;
  307. flex-direction: row;
  308. align-items: center;
  309. padding: 6rpx 16rpx;
  310. border-radius: 20rpx;
  311. background: rgba(0, 0, 0, 0.4);
  312. backdrop-filter: blur(10rpx);
  313. }
  314. .card-status-dot {
  315. width: 8rpx;
  316. height: 8rpx;
  317. border-radius: 50%;
  318. background: #22C55E;
  319. margin-right: 6rpx;
  320. animation: pulse 2s infinite;
  321. }
  322. @keyframes pulse {
  323. 0%, 100% { opacity: 1; }
  324. 50% { opacity: 0.4; }
  325. }
  326. .card-status-text {
  327. font-size: 22rpx;
  328. color: #FFFFFF;
  329. font-weight: 500;
  330. }
  331. /* 标题 */
  332. .card-title-wrap {
  333. position: absolute;
  334. bottom: 20rpx;
  335. left: 20rpx;
  336. right: 20rpx;
  337. }
  338. .card-title {
  339. font-size: 32rpx;
  340. font-weight: 700;
  341. color: #FFFFFF;
  342. text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.3);
  343. display: -webkit-box;
  344. -webkit-line-clamp: 2;
  345. -webkit-box-orient: vertical;
  346. overflow: hidden;
  347. }
  348. /* 内容区域 */
  349. .card-content {
  350. padding: 20rpx;
  351. }
  352. /* 时间和维度标签 */
  353. .card-meta-row {
  354. display: flex;
  355. flex-direction: row;
  356. align-items: center;
  357. margin-bottom: 16rpx;
  358. }
  359. .card-time {
  360. display: flex;
  361. flex-direction: row;
  362. align-items: center;
  363. margin-right: 16rpx;
  364. }
  365. .meta-icon {
  366. font-size: 22rpx;
  367. margin-right: 6rpx;
  368. }
  369. .meta-text {
  370. font-size: 24rpx;
  371. color: #64748B;
  372. }
  373. .card-badges {
  374. display: flex;
  375. flex-direction: row;
  376. flex-wrap: wrap;
  377. gap: 8rpx;
  378. }
  379. .card-badge {
  380. font-size: 20rpx;
  381. padding: 4rpx 12rpx;
  382. border-radius: 20rpx;
  383. border: 1rpx solid;
  384. font-weight: 500;
  385. }
  386. /* 底部 */
  387. .card-footer {
  388. display: flex;
  389. flex-direction: row;
  390. justify-content: space-between;
  391. align-items: center;
  392. padding-top: 16rpx;
  393. border-top: 1rpx solid #F1F5F9;
  394. }
  395. .card-price-wrap {
  396. display: flex;
  397. flex-direction: row;
  398. align-items: baseline;
  399. }
  400. .card-price {
  401. font-size: 30rpx;
  402. font-weight: 700;
  403. color: #FF6B9D;
  404. }
  405. .card-price-free {
  406. font-size: 28rpx;
  407. font-weight: 600;
  408. color: #22C55E;
  409. }
  410. .card-action-btn {
  411. padding: 10rpx 24rpx;
  412. background: linear-gradient(135deg, #FF6B9D, #FF8FB1);
  413. border-radius: 24rpx;
  414. }
  415. .card-action-text {
  416. font-size: 22rpx;
  417. color: #FFFFFF;
  418. font-weight: 600;
  419. }
  420. .card-action-btn:active {
  421. opacity: 0.8;
  422. }
  423. </style>