detail.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <!-- 头部:维度信息 -->
  4. <view class="dim-header" v-if="dimInfo">
  5. <view class="dim-icon-wrap" :class="'dim-icon--' + elementColor">
  6. <text class="dim-icon">{{ dimInfo.icon }}</text>
  7. </view>
  8. <text class="dim-name">{{ dimInfo.name }}</text>
  9. <text class="dim-element">{{ dimInfo.element }} · {{ dimInfo.code }}</text>
  10. <view class="dim-energy">
  11. <text class="dim-energy-value">{{ dimEnergy }}</text>
  12. <text class="dim-energy-label">能量值</text>
  13. </view>
  14. </view>
  15. <!-- 加载状态 -->
  16. <BaseLoading :loading="loading" text="加载中..." />
  17. <!-- 流水列表 -->
  18. <view class="logs-section" v-if="!loading">
  19. <view class="section-header">
  20. <text class="section-title">📋 能量流水</text>
  21. </view>
  22. <view class="log-item" v-for="(log, idx) in logs" :key="idx" v-if="logs.length > 0">
  23. <view class="log-left">
  24. <text :class="log.amount > 0 ? 'log-amount earn' : 'log-amount spend'">
  25. {{ log.amount > 0 ? '+' : '' }}{{ log.amount }}
  26. </text>
  27. <text class="log-desc">{{ log.description || '能量变动' }}</text>
  28. </view>
  29. <view class="log-right">
  30. <text class="log-balance">余额 {{ log.balanceAfter }}</text>
  31. <text class="log-time">{{ formatTime(log.createdAt) }}</text>
  32. </view>
  33. </view>
  34. <BaseEmpty v-if="logs.length === 0" icon="💧" title="暂无能量流水" description="完成任务可以获取能量值" />
  35. <view class="load-more" v-if="hasMore" @click="loadMore">
  36. <text>加载更多...</text>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import { getEnergyLogs } from '../../utils/api.js'
  43. import BaseLoading from '../../components/BaseLoading.vue'
  44. import BaseEmpty from '../../components/BaseEmpty.vue'
  45. import { parseDate } from '../../utils/format.js'
  46. var ELEMENT_MAP = {
  47. 'mind': 'fire', 'body': 'earth', 'wisdom': 'metal',
  48. 'action': 'wood', 'wealth': 'water'
  49. }
  50. import fontScaleMixin from '@/mixins/font-scale.js'
  51. export default {
  52. mixins: [fontScaleMixin],
  53. components: { BaseLoading, BaseEmpty },
  54. data() {
  55. return {
  56. memberId: '',
  57. code: '',
  58. dimInfo: null,
  59. dimEnergy: 0,
  60. loading: true,
  61. logs: [],
  62. page: 1,
  63. pageSize: 20,
  64. hasMore: true,
  65. elementColor: 'fire'
  66. }
  67. },
  68. onLoad(options) {
  69. if (options.memberId) this.memberId = options.memberId
  70. if (options.code) {
  71. this.code = options.code
  72. this.elementColor = ELEMENT_MAP[options.code] || 'fire'
  73. }
  74. // 如果有传入 dimData(URL编码的JSON),解析维度信息
  75. if (options.dimData) {
  76. try {
  77. var parsed = JSON.parse(decodeURIComponent(options.dimData))
  78. if (parsed) {
  79. this.dimInfo = parsed
  80. this.dimEnergy = parsed.energy || 0
  81. }
  82. } catch (e) { /* ignore */ }
  83. }
  84. this.loadLogs()
  85. },
  86. methods: {
  87. async loadLogs() {
  88. this.loading = true
  89. try {
  90. var res = await getEnergyLogs(this.memberId, this.code, this.page, this.pageSize)
  91. if (res && res.data) {
  92. var records = res.data.records || []
  93. if (this.page === 1) {
  94. this.logs = records
  95. } else {
  96. this.logs = this.logs.concat(records)
  97. }
  98. this.hasMore = records.length >= this.pageSize
  99. }
  100. } catch (e) {
  101. console.log('获取能量流水失败', e)
  102. } finally {
  103. this.loading = false
  104. }
  105. },
  106. loadMore() {
  107. this.page++
  108. this.loadLogs()
  109. },
  110. formatTime(dateStr) {
  111. if (!dateStr) return ''
  112. var d = parseDate(dateStr)
  113. if (!d) return ''
  114. var month = d.getMonth() + 1
  115. var day = d.getDate()
  116. var hour = d.getHours()
  117. var min = d.getMinutes()
  118. if (month < 10) month = '0' + month
  119. if (day < 10) day = '0' + day
  120. if (hour < 10) hour = '0' + hour
  121. if (min < 10) min = '0' + min
  122. return month + '-' + day + ' ' + hour + ':' + min
  123. }
  124. }
  125. }
  126. </script>
  127. <style scoped lang="scss">
  128. .container {
  129. min-height: 100vh;
  130. background: #0F1B2D;
  131. padding-bottom: 40rpx;
  132. }
  133. /* ---- 头部 ---- */
  134. .dim-header {
  135. display: flex;
  136. flex-direction: column;
  137. align-items: center;
  138. padding: 60rpx 0 40rpx;
  139. position: relative;
  140. }
  141. .dim-header::after {
  142. content: '';
  143. position: absolute;
  144. bottom: 0;
  145. left: 10%;
  146. width: 80%;
  147. height: 1rpx;
  148. background: linear-gradient(90deg, transparent, rgba(143,197,232,0.2), transparent);
  149. }
  150. .dim-icon-wrap {
  151. width: 100rpx;
  152. height: 100rpx;
  153. border-radius: 50%;
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. margin-bottom: 16rpx;
  158. box-shadow: 0 0 40rpx rgba(255,255,255,0.15);
  159. }
  160. .dim-icon--fire { background: linear-gradient(135deg, $mind-accent, $mat-orange-strong); }
  161. .dim-icon--water { background: linear-gradient(135deg, $mat-blue-400, $mat-blue-strong); }
  162. .dim-icon--earth { background: linear-gradient(135deg, $brown-warm, #5D4037); }
  163. .dim-icon--metal { background: linear-gradient(135deg, $accent-gold, #FF8F00); }
  164. .dim-icon--wood { background: linear-gradient(135deg, $mat-green, $mat-green-strong); }
  165. .dim-icon { font-size: calc(44rpx * var(--font-scale, 1)); }
  166. .dim-name { font-size: calc(36rpx * var(--font-scale, 1)); font-weight: bold; color: $app-surface; }
  167. .dim-element { font-size: calc(22rpx * var(--font-scale, 1)); color: rgba(143,197,232,0.5); margin-top: 6rpx; }
  168. .dim-energy {
  169. display: flex;
  170. flex-direction: column;
  171. align-items: center;
  172. margin-top: 20rpx;
  173. }
  174. .dim-energy-value { font-size: calc($uni-font-size-display * var(--font-scale, 1)); font-weight: bold; color: $brand-primary; }
  175. .dim-energy-label { font-size: calc(20rpx * var(--font-scale, 1)); color: rgba(143,197,232,0.4); }
  176. /* ---- 流水 ---- */
  177. .logs-section {
  178. padding: $uni-space-lg $uni-space-page 0;
  179. }
  180. .section-header { margin-bottom: 20rpx; }
  181. .section-title { font-size: calc(28rpx * var(--font-scale, 1)); font-weight: bold; color: #8FC5E8; }
  182. .log-item {
  183. display: flex;
  184. justify-content: space-between;
  185. align-items: center;
  186. padding: 24rpx 20rpx;
  187. background: rgba(255,255,255,0.04);
  188. border-radius: 16rpx;
  189. margin-bottom: 12rpx;
  190. }
  191. .log-left { display: flex; flex-direction: column; }
  192. .log-amount { font-size: calc(32rpx * var(--font-scale, 1)); font-weight: bold; }
  193. .log-amount.earn { color: $mat-green; }
  194. .log-amount.spend { color: $mind-accent; }
  195. .log-desc { font-size: calc(22rpx * var(--font-scale, 1)); color: rgba(255,255,255,0.5); margin-top: 4rpx; }
  196. .log-right { display: flex; flex-direction: column; align-items: flex-end; }
  197. .log-balance { font-size: calc(22rpx * var(--font-scale, 1)); color: rgba(255,255,255,0.4); }
  198. .log-time { font-size: calc(20rpx * var(--font-scale, 1)); color: rgba(255,255,255,0.25); margin-top: 4rpx; }
  199. .load-more {
  200. text-align: center;
  201. padding: 24rpx;
  202. color: rgba(143,197,232,0.4);
  203. font-size: calc(24rpx * var(--font-scale, 1));
  204. }
  205. </style>