DimensionActivities.vue 10 KB

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