DimensionActivities.vue 9.9 KB

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