StakingTeamView.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <script setup lang="ts">
  2. import { computed, onMounted, ref } from 'vue'
  3. import { useI18n } from 'vue-i18n'
  4. import { useRouter } from 'vue-router'
  5. import {
  6. fetchStakingDirectList,
  7. fetchStakingTeamOverview,
  8. type StakingDirectMember,
  9. type StakingTeamOverview,
  10. } from '@/api/staking'
  11. import { stakingNodeLevelI18nKey } from '@/utils/stakingNodeLevel'
  12. const { t, te } = useI18n()
  13. const router = useRouter()
  14. const PAGE_SIZE = 20
  15. const loading = ref(true)
  16. const error = ref<string | null>(null)
  17. const overview = ref<StakingTeamOverview | null>(null)
  18. const directList = ref<StakingDirectMember[]>([])
  19. const listLoading = ref(false)
  20. const listPage = ref(1)
  21. const listHasMore = ref(false)
  22. function fmtNum(n: string | number | undefined, maxFrac = 2) {
  23. const v = Number(n)
  24. if (!Number.isFinite(v)) return '0'
  25. return v.toLocaleString('en-US', {
  26. minimumFractionDigits: 0,
  27. maximumFractionDigits: maxFrac,
  28. })
  29. }
  30. function levelLabel(level: string | undefined) {
  31. const key = stakingNodeLevelI18nKey(level)
  32. return te(key) ? t(key) : t('finance.nodeLevelNormal')
  33. }
  34. const nodeLevelText = computed(() => levelLabel(overview.value?.nodeLevel))
  35. const statCards = computed(() => {
  36. const o = overview.value
  37. return [
  38. { label: t('finance.directNumLabel'), value: fmtNum(o?.directNum ?? 0, 0) },
  39. { label: t('finance.teamNumLabel'), value: fmtNum(o?.teamNum ?? 0, 0) },
  40. { label: t('finance.teamPerformanceLabel'), value: fmtNum(o?.teamPerformance ?? 0) },
  41. { label: t('finance.totalRevenueLabel'), value: fmtNum(o?.totalRevenue ?? 0) },
  42. ]
  43. })
  44. function goBack() {
  45. if (window.history.length > 1) {
  46. router.back()
  47. return
  48. }
  49. router.push({ name: 'finance-ido' })
  50. }
  51. async function loadOverview() {
  52. overview.value = await fetchStakingTeamOverview()
  53. }
  54. async function loadDirectList(page = 1, append = false) {
  55. listLoading.value = true
  56. try {
  57. const pageData = await fetchStakingDirectList(page, PAGE_SIZE)
  58. const rows = Array.isArray(pageData?.content) ? pageData.content : []
  59. directList.value = append ? [...directList.value, ...rows] : rows
  60. listPage.value = page
  61. listHasMore.value = pageData?.last === false
  62. } catch {
  63. if (!append) {
  64. directList.value = []
  65. }
  66. listHasMore.value = false
  67. } finally {
  68. listLoading.value = false
  69. }
  70. }
  71. async function loadAll() {
  72. loading.value = true
  73. error.value = null
  74. try {
  75. await Promise.all([loadOverview(), loadDirectList(1, false)])
  76. } catch (e) {
  77. error.value = e instanceof Error ? e.message : t('common.loadFailed')
  78. overview.value = null
  79. directList.value = []
  80. } finally {
  81. loading.value = false
  82. }
  83. }
  84. function loadMoreDirect() {
  85. if (listLoading.value || !listHasMore.value) return
  86. void loadDirectList(listPage.value + 1, true)
  87. }
  88. onMounted(() => {
  89. void loadAll()
  90. })
  91. </script>
  92. <template>
  93. <main class="team-page page-main">
  94. <header class="team-topbar page-container">
  95. <button type="button" class="team-back" aria-label="back" @click="goBack">‹</button>
  96. <h1 class="team-title">{{ t('finance.myTeam') }}</h1>
  97. <span class="team-topbar-spacer" aria-hidden="true" />
  98. </header>
  99. <div v-if="loading" class="team-loading page-container">
  100. <div class="spinner" />
  101. </div>
  102. <div v-else-if="error" class="team-error page-container">
  103. <p>{{ error }}</p>
  104. <button type="button" class="retry-btn" @click="loadAll">{{ t('common.retry') }}</button>
  105. </div>
  106. <template v-else>
  107. <div class="page-container team-body">
  108. <div class="node-banner">
  109. <span class="node-banner-label">{{ t('finance.currentNodeLevel') }}</span>
  110. <span class="node-banner-value">{{ nodeLevelText }}</span>
  111. </div>
  112. <div class="stats-grid">
  113. <div v-for="(card, i) in statCards" :key="i" class="stat-card dark-card">
  114. <p class="stat-value">{{ card.value }}</p>
  115. <p class="stat-label">{{ card.label }}</p>
  116. </div>
  117. </div>
  118. <h2 class="section-title">{{ t('finance.directListTitle') }}</h2>
  119. <div v-if="listLoading && !directList.length" class="list-loading">
  120. <div class="spinner sm" />
  121. </div>
  122. <div v-else-if="!directList.length" class="list-empty">{{ t('common.noData') }}</div>
  123. <div v-else class="direct-table-wrap">
  124. <table class="direct-table">
  125. <thead>
  126. <tr>
  127. <th>{{ t('finance.directAddress') }}</th>
  128. <th>{{ t('finance.levelCol') }}</th>
  129. <th>{{ t('finance.buyAmountCol') }}</th>
  130. <th>{{ t('finance.myRewardCol') }}</th>
  131. </tr>
  132. </thead>
  133. <tbody>
  134. <tr v-for="(row, idx) in directList" :key="`${row.directAddress}-${idx}`">
  135. <td class="direct-addr">{{ row.directAddress || '—' }}</td>
  136. <td>{{ levelLabel(row.level) }}</td>
  137. <td class="num">{{ fmtNum(row.buyAmount) }}</td>
  138. <td class="num">{{ fmtNum(row.reward) }}</td>
  139. </tr>
  140. </tbody>
  141. </table>
  142. </div>
  143. <div v-if="listHasMore" class="load-more-row">
  144. <button
  145. type="button"
  146. class="load-more-btn"
  147. :disabled="listLoading"
  148. @click="loadMoreDirect"
  149. >
  150. {{ listLoading ? t('common.loading') : t('finance.teamLoadMore') }}
  151. </button>
  152. </div>
  153. </div>
  154. </template>
  155. </main>
  156. </template>
  157. <style scoped>
  158. .team-page {
  159. padding-bottom: var(--space-16);
  160. min-height: 60vh;
  161. }
  162. .team-topbar {
  163. display: flex;
  164. align-items: center;
  165. justify-content: space-between;
  166. padding-top: calc(var(--header-height) + var(--space-4));
  167. padding-bottom: var(--space-4);
  168. }
  169. .team-back {
  170. width: 40px;
  171. height: 40px;
  172. border: none;
  173. background: transparent;
  174. color: var(--color-text-primary);
  175. font-size: 28px;
  176. line-height: 1;
  177. cursor: pointer;
  178. padding: 0;
  179. }
  180. .team-title {
  181. margin: 0;
  182. font-size: 18px;
  183. font-weight: var(--fw-semibold);
  184. color: var(--color-text-primary);
  185. }
  186. .team-topbar-spacer {
  187. width: 40px;
  188. }
  189. .team-body {
  190. max-width: 960px;
  191. }
  192. .team-loading,
  193. .team-error {
  194. padding-top: var(--space-16);
  195. text-align: center;
  196. color: var(--color-text-secondary);
  197. }
  198. .spinner {
  199. width: 36px;
  200. height: 36px;
  201. margin: 0 auto;
  202. border-radius: 50%;
  203. border: 2px solid var(--color-border);
  204. border-top-color: var(--color-primary);
  205. animation: spin 0.8s linear infinite;
  206. }
  207. .spinner.sm {
  208. width: 24px;
  209. height: 24px;
  210. }
  211. @keyframes spin {
  212. to { transform: rotate(360deg); }
  213. }
  214. .retry-btn {
  215. margin-top: var(--space-4);
  216. padding: var(--space-2) var(--space-6);
  217. border-radius: var(--radius-md);
  218. border: 1px solid var(--color-primary);
  219. background: transparent;
  220. color: var(--color-primary);
  221. cursor: pointer;
  222. }
  223. .node-banner {
  224. display: flex;
  225. align-items: center;
  226. justify-content: space-between;
  227. gap: var(--space-4);
  228. padding: var(--space-5) var(--space-6);
  229. margin-bottom: var(--space-4);
  230. border-radius: 12px;
  231. background: linear-gradient(90deg, #c9a227 0%, #e8c547 50%, #c9a227 100%);
  232. color: #1a1408;
  233. }
  234. .node-banner-label {
  235. font-size: 15px;
  236. font-weight: var(--fw-medium);
  237. }
  238. .node-banner-value {
  239. font-size: 16px;
  240. font-weight: var(--fw-bold);
  241. }
  242. .stats-grid {
  243. display: grid;
  244. grid-template-columns: 1fr 1fr;
  245. gap: var(--space-3);
  246. margin-bottom: var(--space-8);
  247. }
  248. .stat-card {
  249. padding: var(--space-5) var(--space-4);
  250. text-align: center;
  251. }
  252. .stat-value {
  253. margin: 0 0 var(--space-2);
  254. font-size: 22px;
  255. font-weight: var(--fw-bold);
  256. color: var(--color-primary);
  257. font-family: var(--font-family-num);
  258. line-height: 1.2;
  259. }
  260. .stat-label {
  261. margin: 0;
  262. font-size: 13px;
  263. color: var(--color-text-secondary);
  264. line-height: 1.4;
  265. }
  266. .section-title {
  267. margin: 0 0 var(--space-4);
  268. font-size: 18px;
  269. font-weight: var(--fw-semibold);
  270. color: var(--color-text-primary);
  271. }
  272. .list-loading,
  273. .list-empty {
  274. text-align: center;
  275. padding: var(--space-8) 0;
  276. color: var(--color-text-secondary);
  277. font-size: var(--text-small);
  278. }
  279. .direct-table-wrap {
  280. overflow-x: auto;
  281. -webkit-overflow-scrolling: touch;
  282. }
  283. .direct-table {
  284. width: 100%;
  285. min-width: 560px;
  286. border-collapse: collapse;
  287. font-size: 13px;
  288. }
  289. .direct-table th {
  290. padding: var(--space-3) var(--space-2);
  291. font-weight: var(--fw-normal);
  292. font-size: 12px;
  293. color: var(--color-text-muted);
  294. text-align: left;
  295. white-space: nowrap;
  296. border-bottom: 1px solid var(--color-border);
  297. }
  298. .direct-table td {
  299. padding: var(--space-4) var(--space-2);
  300. color: var(--color-text-primary);
  301. vertical-align: middle;
  302. border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  303. }
  304. .direct-table td.num {
  305. font-family: var(--font-family-num);
  306. white-space: nowrap;
  307. }
  308. .direct-addr {
  309. max-width: 140px;
  310. overflow: hidden;
  311. text-overflow: ellipsis;
  312. white-space: nowrap;
  313. }
  314. .load-more-row {
  315. display: flex;
  316. justify-content: center;
  317. padding: var(--space-6) 0;
  318. }
  319. .load-more-btn {
  320. padding: var(--space-2) var(--space-8);
  321. border-radius: 999px;
  322. border: 1px solid var(--color-border);
  323. background: transparent;
  324. color: var(--color-text-secondary);
  325. font-size: var(--text-small);
  326. cursor: pointer;
  327. }
  328. .load-more-btn:hover:not(:disabled) {
  329. border-color: var(--color-primary);
  330. color: var(--color-primary);
  331. }
  332. .load-more-btn:disabled {
  333. opacity: 0.5;
  334. cursor: not-allowed;
  335. }
  336. @media (max-width: 640px) {
  337. .stat-value {
  338. font-size: 20px;
  339. }
  340. }
  341. </style>