preview-balance.vue 3.1 KB

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