preview-balance.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="card-amount">
  3. <img class="icon" src="@/assets/subject/icon-balance.png" />
  4. <div class="con">
  5. <div class="desc">Balance</div>
  6. <div class="price">{{ currentCurrencyInfo.balance }} {{ props.tokenSymbol }}</div>
  7. </div>
  8. <img class="refresh" :class="{ 'icon-refresh-rotate': refreshRotate }" @click="updateCurrencyBanlce"
  9. :src="require('@/assets/svg/icon-form-refresh-blue.svg')" />
  10. </div>
  11. </template>
  12. <script setup>
  13. import { ref, onMounted, reactive, defineProps, defineEmits } from "vue";
  14. import { syncChainTokenRechargeRecord } from "@/http/publishApi";
  15. const emits = defineEmits(["updateData"]);
  16. const props = defineProps({
  17. dialogVisible: {
  18. type: Object,
  19. default: {},
  20. },
  21. currencyCode: {
  22. type: String,
  23. default: ''
  24. },
  25. tokenSymbol: {
  26. type: String,
  27. default: ''
  28. }
  29. });
  30. /**
  31. * 同步链上交易
  32. */
  33. const asyncTokenRechRecord = () => {
  34. syncChainTokenRechargeRecord({
  35. params: {
  36. currencyCode: props.currencyCode
  37. }
  38. }).then(res => {
  39. if (res.code == 0) {
  40. let data = res.data || []
  41. if (data.length > 0) {
  42. let currencyInfo = data[0];
  43. if (currencyInfo.currencyCode == props.currencyCode) {
  44. currentCurrencyInfo.balance = currencyInfo.balance;
  45. emits('updateData', currentCurrencyInfo)
  46. }
  47. } else {
  48. currentCurrencyInfo.balance = 0
  49. emits('updateData', currentCurrencyInfo)
  50. }
  51. }
  52. })
  53. }
  54. // 刷新按钮旋转
  55. let refreshRotate = ref(false);
  56. // 当前选择的货币信息
  57. let currentCurrencyInfo = reactive({
  58. currencyCode: "",
  59. currencyName: "",
  60. balance: "",
  61. currencyType: "",
  62. iconPath: "",
  63. minAmount: "",
  64. tokenChain: "",
  65. tokenSymbol: "",
  66. usdEstimateBalance: ""
  67. });
  68. /**
  69. * 更新货币余额
  70. */
  71. const updateCurrencyBanlce = () => {
  72. if (!refreshRotate.value) {
  73. refreshRotate.value = true;
  74. setTimeout(() => {
  75. refreshRotate.value = false;
  76. }, 1000)
  77. }
  78. asyncTokenRechRecord()
  79. }
  80. onMounted(() => {
  81. console.log(props.currencyCode)
  82. if (!props.currencyCode) {
  83. return
  84. }
  85. asyncTokenRechRecord()
  86. setInterval(() => {
  87. asyncTokenRechRecord()
  88. }, 10000)
  89. })
  90. </script>
  91. <style lang="scss" scoped>
  92. .card-amount {
  93. overflow: hidden;
  94. display: flex;
  95. align-items: center;
  96. padding: 20px;
  97. border-radius: 20px;
  98. border: 1px solid #E6E6E6;
  99. .icon {
  100. width: 40px;
  101. height: 40px;
  102. }
  103. .con {
  104. flex: 1;
  105. padding: 0 10px;
  106. .desc {
  107. color: rgba($color: #000000, $alpha: 0.5);
  108. font-size: 12px;
  109. margin-bottom: 4px;
  110. line-height: 14px;
  111. }
  112. .price {
  113. font-size: 16px;
  114. font-weight: bold;
  115. line-height: 19px;
  116. }
  117. }
  118. .refresh {
  119. cursor: pointer;
  120. width: 30px;
  121. height: 30px;
  122. margin-top: -5px;
  123. }
  124. }
  125. .icon-refresh-rotate {
  126. transform: rotate(360deg);
  127. transition-duration: 1s;
  128. }
  129. </style>