index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div class="wallet-total">
  3. <div class="wallet-total__inner">
  4. <div class="wallet-total__header">
  5. <div class="wallet-total__title">
  6. <span>{{ `${t('digital.total')}${currency}` }}</span>
  7. <img :src="`./img/icons/${isBalanceVisible ? 'eye' : 'eye-hidden'}.svg`"
  8. @click="isBalanceVisible = !isBalanceVisible" />
  9. </div>
  10. </div>
  11. <div class="wallet-total__balance">
  12. <span v-if="isBalanceVisible">{{ totalBalance }}</span>
  13. <span v-else>**********</span>
  14. </div>
  15. <div class="wallet-total__footer">
  16. </div>
  17. </div>
  18. </div>
  19. </template>
  20. <script lang="ts" setup>
  21. import { shallowRef, computed, watch, onActivated } from 'vue'
  22. import { i18n, useAccountStore } from '@/stores'
  23. import { useSpotAccountStore } from '../../views/wallet/components/spot/composables'
  24. import { Decimal } from 'decimal.js'
  25. const props = defineProps({
  26. currency: {
  27. type: String,
  28. default: 'USDT'
  29. },
  30. balance: String,
  31. })
  32. const { global: { t } } = i18n
  33. const accountStore = useAccountStore()
  34. const spotAccountStore = useSpotAccountStore()
  35. const isBalanceVisible = shallowRef(true)
  36. const totalBalance = computed(() => {
  37. if (props.balance) return props.balance
  38. const { balance = 0, currencydecimalplace = 2 } = accountStore.getAccountItem({ currencyid: 102 }) ?? {}
  39. const { currentbalance = 0 } = spotAccountStore.getAccountItem({ currencyid: 102 }) ?? {}
  40. return Decimal(balance).plus(currentbalance).toFixed(currencydecimalplace)
  41. })
  42. watch(isBalanceVisible, (val) => {
  43. localStorage.setItem('isBalanceVisible', JSON.stringify(val))
  44. })
  45. onActivated(() => {
  46. const visible = localStorage.getItem('isBalanceVisible') || 'true'
  47. isBalanceVisible.value = JSON.parse(visible)
  48. })
  49. </script>
  50. <style lang="less">
  51. @import "./index.less";
  52. </style>