index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!-- 钱包 -->
  2. <template>
  3. <app-view class="wallet">
  4. <div class="g-account-total" style="padding: 0 16px;">
  5. <div class="g-account-total__inner">
  6. <div class="g-account-total__header">
  7. <div class="g-account-total__title">
  8. <span>{{ $t('digital.total') }} (USDT)</span>
  9. <img :src="`./img/icons/${isAmountVisible ? 'eye' : 'eye-hidden'}.svg`"
  10. @click="isAmountVisible = !isAmountVisible" />
  11. </div>
  12. </div>
  13. <div class="g-account-total__balance">
  14. <span v-if="isAmountVisible">{{ totalBalance }}</span>
  15. <span v-else>**********</span>
  16. </div>
  17. </div>
  18. </div>
  19. <app-grid :items="gridItems" />
  20. <app-switch-tab v-model="currentTabIndex" :options="tabs" />
  21. <contract-account @click="navigateToContractDetail" v-if="currentTabIndex === 0" />
  22. <spot-account @click="navigateToSpotDetail" v-if="currentTabIndex === 1" />
  23. </app-view>
  24. </template>
  25. <script lang="ts" setup>
  26. import { shallowRef, computed, watch, onActivated } from 'vue'
  27. import { Decimal } from 'decimal.js'
  28. import { useNavigation } from '@mobile/router/navigation'
  29. import { useAccountStore } from '@/stores'
  30. import { useSpotAccountStore } from './components/spot/composables'
  31. import { i18n } from '@/stores'
  32. import { GridItem } from '@/packages/digital/components/grid/types'
  33. import AppGrid from '@/packages/digital/components/grid/index.vue'
  34. import AppSwitchTab from '@/packages/digital/components/switch-tab/index.vue'
  35. import SpotAccount from './components/spot/index.vue'
  36. import ContractAccount from './components/contract/index.vue'
  37. const { t } = i18n.global
  38. const { router } = useNavigation()
  39. const currentTabIndex = shallowRef(0)
  40. const isAmountVisible = shallowRef(true)
  41. const accountStore = useAccountStore()
  42. const spotAccountStore = useSpotAccountStore()
  43. const totalBalance = computed(() => {
  44. const { balance = 0, currencydecimalplace = 2 } = accountStore.getAccountItem({ currencyid: 102 }) ?? {}
  45. const { currentbalance = 0 } = spotAccountStore.getAccountItem({ currencyid: 102 }) ?? {}
  46. return Decimal(balance).plus(currentbalance).toFixed(currencydecimalplace)
  47. })
  48. const tabs = computed(() => ([
  49. { label: t('tabbar.contract') },
  50. { label: t('tabbar.spot') }
  51. ]))
  52. const gridItems = computed<GridItem[]>(() => ([
  53. {
  54. text: t('digital.wallet-deposit'),
  55. icon: './img/icons/deposit.svg',
  56. to: { name: 'wallet-deposit-currency' }
  57. },
  58. {
  59. text: t('digital.wallet-withdraw'),
  60. icon: './img/icons/withdraw.svg',
  61. to: { name: 'wallet-withdraw-currency' }
  62. },
  63. {
  64. text: t('digital.wallet-transfer'),
  65. icon: './img/icons/transfer.svg',
  66. to: { name: 'wallet-transfer' }
  67. },
  68. {
  69. text: t('digital.setting'),
  70. icon: './img/icons/setting.svg',
  71. to: { name: 'setting' }
  72. }
  73. ]))
  74. const navigateToSpotDetail = (currencyId: number) => {
  75. router.push({
  76. name: 'spot-detail',
  77. query: {
  78. id: currencyId
  79. }
  80. })
  81. }
  82. const navigateToContractDetail = (accountId: string) => {
  83. router.push({
  84. name: 'contract-detail',
  85. query: {
  86. id: accountId
  87. }
  88. })
  89. }
  90. watch(isAmountVisible, (val) => {
  91. localStorage.setItem('isAmountVisible', JSON.stringify(val))
  92. })
  93. onActivated(() => {
  94. const visible = localStorage.getItem('isAmountVisible') || 'true'
  95. isAmountVisible.value = JSON.parse(visible)
  96. })
  97. </script>