DimensionActivities.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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 = this._parseDate(timeStr)
  142. if (!d || 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. // iOS 不兼容 Java "EEE MMM dd HH:mm:ss zzz yyyy" 格式,需提前归一化
  150. _parseDate: function(timeStr) {
  151. if (!timeStr) return null
  152. // 尝试标准格式
  153. var d = new Date(timeStr)
  154. if (!isNaN(d.getTime())) return d
  155. // Java 格式: "Sat Aug 22 14:00:00 CST 2026" → 转换为 iOS 兼容格式
  156. var javaRe = /^\w{3}\s+(\w{3})\s+(\d{1,2})\s+(\d{2}:\d{2}:\d{2})\s+\w{3}\s+(\d{4})$/
  157. var m = timeStr.match(javaRe)
  158. if (m) {
  159. var months = {Jan:'01',Feb:'02',Mar:'03',Apr:'04',May:'05',Jun:'06',Jul:'07',Aug:'08',Sep:'09',Oct:'10',Nov:'11',Dec:'12'}
  160. var iso = m[4] + '/' + (months[m[1]] || '01') + '/' + (m[2].length === 1 ? '0' + m[2] : m[2]) + ' ' + m[3]
  161. d = new Date(iso)
  162. if (!isNaN(d.getTime())) return d
  163. }
  164. return null
  165. },
  166. formatPriceWithSymbol: function(price) {
  167. if (price == null) return '免费'
  168. return '¥' + (Number(price) / 100).toFixed(0)
  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: 160rpx;
  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. /* 封面图 — 占满卡片高度 */
  288. .card-cover-img {
  289. width: 200rpx;
  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. min-width: 0;
  302. }
  303. /* 标题 */
  304. .card-title {
  305. font-size: 28rpx;
  306. font-weight: bold;
  307. color: #333;
  308. margin-bottom: 8rpx;
  309. }
  310. .line-clamp-1 {
  311. overflow: hidden;
  312. text-overflow: ellipsis;
  313. white-space: nowrap;
  314. }
  315. /* 时间和维度标签 */
  316. .card-meta-row {
  317. display: flex;
  318. flex-direction: row;
  319. align-items: center;
  320. margin-bottom: 8rpx;
  321. }
  322. .card-time {
  323. display: flex;
  324. flex-direction: row;
  325. align-items: center;
  326. margin-right: 16rpx;
  327. }
  328. .meta-icon {
  329. font-size: 22rpx;
  330. margin-right: 6rpx;
  331. }
  332. .meta-text {
  333. font-size: 24rpx;
  334. color: #64748B;
  335. }
  336. .card-badges {
  337. display: flex;
  338. flex-direction: row;
  339. flex-wrap: wrap;
  340. gap: 8rpx;
  341. }
  342. .card-badge {
  343. font-size: 20rpx;
  344. padding: 4rpx 12rpx;
  345. border-radius: 20rpx;
  346. border: 1rpx solid;
  347. font-weight: 500;
  348. }
  349. /* 底部:状态 + 价格 */
  350. .card-bottom {
  351. display: flex;
  352. flex-direction: row;
  353. align-items: center;
  354. gap: 12rpx;
  355. }
  356. .card-status {
  357. font-size: 20rpx;
  358. padding: 2rpx 10rpx;
  359. border-radius: 8rpx;
  360. background: #E8F5E9;
  361. color: #2E7D32;
  362. }
  363. .card-status.status-upcoming {
  364. background: #E3F2FD;
  365. color: #1565C0;
  366. }
  367. .card-status.status-ended {
  368. background: #F5F5F5;
  369. color: #999;
  370. }
  371. .card-price {
  372. font-size: 24rpx;
  373. font-weight: bold;
  374. color: #F97316;
  375. }
  376. .card-price-free {
  377. font-size: 24rpx;
  378. font-weight: 600;
  379. color: #22C55E;
  380. }
  381. </style>