top-up.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <!-- 充值 -->
  2. <template>
  3. <div class="top-up-wrapper">
  4. <div class="content-wrapper">
  5. <div class="top">
  6. <div class="item">
  7. <div class="label">
  8. Token
  9. </div>
  10. <div class="content">
  11. <img
  12. class="icon"
  13. :src="currentCurrencyInfo.iconPath"
  14. />{{currentCurrencyInfo.tokenSymbol}}
  15. </div>
  16. </div>
  17. <div class="item">
  18. <div class="label">
  19. Network
  20. </div>
  21. <div class="content">
  22. <img
  23. class="icon"
  24. :src="require('@/assets/svg/icon-BNB.svg')"
  25. />
  26. BNB Chain
  27. </div>
  28. </div>
  29. </div>
  30. <div class="qrcode-wrapper">
  31. <canvas id="canvas"></canvas>
  32. <div class="address">{{tokenRechargeAddress}}</div>
  33. <div class="copy-btn" :data-clipboard-text="tokenRechargeAddress">copy</div>
  34. </div>
  35. <div class="tips-box">
  36. <img :src="require('@/assets/svg/icon-top-up-tips-warning.svg')" >
  37. Make sure you also selected BNB Smart Chain (BEP20) as the Network on the platform where you are withdrawing funds for this deposiit. Otherwise, you'll lose your assets.
  38. </div>
  39. </div>
  40. <a-button class="btn-done"
  41. type="primary"
  42. shape="circle"
  43. :loading="asyncIng"
  44. @click="doneHandle">
  45. DONE
  46. </a-button>
  47. </div>
  48. </template>
  49. <script setup>
  50. /* eslint-disable */
  51. import { defineProps, defineEmits, onMounted, ref } from "vue";
  52. import { getTokenRechargeAddress } from "@/http/pay";
  53. import { message } from 'ant-design-vue';
  54. let QRCode = require('qrcode')
  55. let ClipboardJS = require('clipboard')
  56. let tokenRechargeAddress = ref('');
  57. const props = defineProps({
  58. currentCurrencyInfo: {
  59. type: Object,
  60. default: () => {
  61. }
  62. },
  63. asyncIng: {
  64. type: Boolean,
  65. default: false
  66. }
  67. })
  68. const emits = defineEmits(['doneHandle']);
  69. const createQRCode = (str) => {
  70. var canvas = document.getElementById('canvas')
  71. QRCode.toCanvas(canvas, str, {
  72. width: 180,
  73. height: 180,
  74. scale: 10,
  75. color: {
  76. dark: '#000', // 二维码前景颜色
  77. light: '#F7F7F7' // 二维码背景颜色
  78. }
  79. }, function (error) {
  80. if (error) console.error(error)
  81. console.log('success!');
  82. })
  83. }
  84. const copyToken = () => {
  85. var clipboard = new ClipboardJS('.copy-btn');
  86. clipboard.on('success', function (e) {
  87. message.success('copy success');
  88. console.info('Action:', e.action);
  89. console.info('Text:', e.text);
  90. console.info('Trigger:', e.trigger);
  91. e.clearSelection();
  92. });
  93. clipboard.on('error', function (e) {
  94. message.error('copy error');
  95. console.error('Action:', e.action);
  96. console.error('Trigger:', e.trigger);
  97. });
  98. }
  99. const doneHandle = () => {
  100. emits('topUpDone', {});
  101. }
  102. const getTokenAddress = () => {
  103. getTokenRechargeAddress({
  104. params: {
  105. tokenChain: props.currentCurrencyInfo.tokenChain
  106. },
  107. }).then((res) => {
  108. if(res.code == 0) {
  109. if (res.data && res.data.rechargeAddress) {
  110. tokenRechargeAddress.value = res.data.rechargeAddress;
  111. createQRCode(res.data.rechargeAddress)
  112. copyToken()
  113. }
  114. }
  115. })
  116. }
  117. onMounted(() => {
  118. getTokenAddress();
  119. })
  120. </script>
  121. <style scoped lang="scss">
  122. .top-up-wrapper {
  123. width: 100%;
  124. height: 100%;
  125. box-sizing: border-box;
  126. padding: 18px;
  127. position: relative;
  128. .content-wrapper {
  129. height: calc(100% - 60px);
  130. overflow-y: scroll;
  131. .top {
  132. width: 100%;
  133. display: flex;
  134. justify-content: space-between;
  135. .item {
  136. width: 48%;
  137. .label {
  138. color: #A0A0A0;
  139. margin-bottom: 6px;
  140. }
  141. .content {
  142. height: 44px;
  143. width: 100%;
  144. border-radius: 8px;
  145. display: flex;
  146. align-items: center;
  147. border: 1px solid #DBDBDB;
  148. padding: 12px 10px;
  149. box-sizing: border-box;
  150. font-weight: 500;
  151. font-size: 14px;
  152. img {
  153. width: 20px;
  154. height: 20px;
  155. margin-right: 6px;
  156. }
  157. }
  158. }
  159. }
  160. .qrcode-wrapper {
  161. margin-top: 22px;
  162. height: 290px;
  163. background: #F7F7F7;
  164. border-radius: 20px;
  165. display: flex;
  166. align-items: center;
  167. justify-content: center;
  168. flex-direction: column;
  169. padding: 20px;
  170. box-sizing: border-box;
  171. .address {
  172. padding-bottom: 20px;
  173. box-sizing: border-box;
  174. font-weight: 500;
  175. font-size: 15px;
  176. height: 38px;
  177. }
  178. #canvas {
  179. margin-top: -25px;
  180. }
  181. .copy-btn {
  182. height: 40px;
  183. width: 160px;
  184. border-radius: 1000px;
  185. border: 1px solid #1D9BF0;
  186. font-weight: 600;
  187. font-size: 16px;
  188. color: #1D9BF0;
  189. text-align: center;
  190. line-height: 40px;
  191. cursor: pointer;
  192. }
  193. }
  194. .tips-box {
  195. margin-top: 18px;
  196. font-size: 14px;
  197. border-radius: 8px;
  198. background: #FCF5E5;
  199. padding: 12px 10px;
  200. box-sizing: border-box;
  201. }
  202. }
  203. .btn-done {
  204. background: #1D9BF0;
  205. width: 100%;
  206. height: 46px;
  207. text-align: center;
  208. border-radius: 1000px;
  209. font-weight: 600;
  210. font-size: 16px;
  211. color: #fff;
  212. margin-top: 10px;
  213. cursor: pointer;
  214. }
  215. }
  216. </style>