DimensionActivities.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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, default: '' },
  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. // Java 格式: "Sat Aug 22 14:00:00 CST 2026" — iOS 不支持,必须先于 new Date() 处理
  153. var javaRe = /^\w{3}\s+(\w{3})\s+(\d{1,2})\s+(\d{2}:\d{2}:\d{2})\s+\w{3}\s+(\d{4})$/
  154. var m = timeStr.match(javaRe)
  155. if (m) {
  156. 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'}
  157. var iso = m[4] + '/' + (months[m[1]] || '01') + '/' + (m[2].length === 1 ? '0' + m[2] : m[2]) + ' ' + m[3]
  158. return new Date(iso)
  159. }
  160. // 标准格式尝试(iOS 支持 yyyy/MM/dd、yyyy-MM-dd、ISO 8601 等)
  161. var d = new Date(timeStr)
  162. if (!isNaN(d.getTime())) return d
  163. return null
  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: 16rpx 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: 16rpx;
  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: 30rpx 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: 160rpx;
  248. }
  249. .activity-swiper .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: 12rpx;
  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: 16rpx;
  277. overflow: hidden;
  278. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  279. display: flex;
  280. flex-direction: row;
  281. height: 100%;
  282. }
  283. .activity-card:active {
  284. opacity: 0.8;
  285. }
  286. /* 封面图 — 占满卡片高度 */
  287. .card-cover-img {
  288. width: 200rpx;
  289. height: 100%;
  290. flex-shrink: 0;
  291. background: #F1F5F9;
  292. }
  293. /* 右侧信息区 */
  294. .card-info {
  295. flex: 1;
  296. padding: 16rpx;
  297. display: flex;
  298. flex-direction: column;
  299. justify-content: space-between;
  300. min-width: 0;
  301. }
  302. /* 标题 */
  303. .card-title {
  304. font-size: 28rpx;
  305. font-weight: bold;
  306. color: #333;
  307. margin-bottom: 8rpx;
  308. }
  309. .line-clamp-1 {
  310. overflow: hidden;
  311. text-overflow: ellipsis;
  312. white-space: nowrap;
  313. }
  314. /* 时间和维度标签 */
  315. .card-meta-row {
  316. display: flex;
  317. flex-direction: row;
  318. align-items: center;
  319. margin-bottom: 8rpx;
  320. }
  321. .card-time {
  322. display: flex;
  323. flex-direction: row;
  324. align-items: center;
  325. margin-right: 16rpx;
  326. }
  327. .meta-icon {
  328. font-size: 22rpx;
  329. margin-right: 6rpx;
  330. }
  331. .meta-text {
  332. font-size: 24rpx;
  333. color: #64748B;
  334. }
  335. .card-badges {
  336. display: flex;
  337. flex-direction: row;
  338. flex-wrap: wrap;
  339. gap: 8rpx;
  340. }
  341. .card-badge {
  342. font-size: 20rpx;
  343. padding: 4rpx 12rpx;
  344. border-radius: 20rpx;
  345. border: 1rpx solid;
  346. font-weight: 500;
  347. }
  348. /* 底部:状态 + 价格 */
  349. .card-bottom {
  350. display: flex;
  351. flex-direction: row;
  352. align-items: center;
  353. gap: 12rpx;
  354. }
  355. .card-status {
  356. font-size: 20rpx;
  357. padding: 2rpx 10rpx;
  358. border-radius: 8rpx;
  359. background: #E8F5E9;
  360. color: #2E7D32;
  361. }
  362. .card-status.status-upcoming {
  363. background: #E3F2FD;
  364. color: #1565C0;
  365. }
  366. .card-status.status-ended {
  367. background: #F5F5F5;
  368. color: #999;
  369. }
  370. .card-price {
  371. font-size: 24rpx;
  372. font-weight: bold;
  373. color: #F97316;
  374. }
  375. .card-price-free {
  376. font-size: 24rpx;
  377. font-weight: 600;
  378. color: #22C55E;
  379. }
  380. </style>