DimensionActivities.vue 11 KB

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