top-up2.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <!-- 充值 -->
  2. <template>
  3. <div class="token-content">
  4. <div class="item">
  5. <div class="token-l">Recommended Deposit</div>
  6. <div class="token-r">
  7. <img
  8. class="icon"
  9. :src="currentCurrencyInfo.iconPath"
  10. />{{currentCurrencyInfo.tokenSymbol}}
  11. </div>
  12. </div>
  13. <div class="item">
  14. <div class="token-l">Network</div>
  15. <div class="token-r">
  16. <img
  17. class="icon"
  18. :src="require('@/assets/svg/icon-BNB.svg')"
  19. />
  20. BNB Smart Chain (BEP20)
  21. </div>
  22. </div>
  23. <div class="item none">
  24. <div class="token-l">Address</div>
  25. </div>
  26. <div class="qrCode">
  27. <div class="canvas">
  28. <canvas id="canvas"></canvas>
  29. </div>
  30. <div class="code">
  31. <div class="address">{{tokenRechargeAddress}}</div>
  32. <div class="copy-btn" :data-clipboard-text="tokenRechargeAddress">copy</div>
  33. </div>
  34. </div>
  35. <div class="desc">Make sure you also selected <span class="blod">BNB Smart Chain (BEP20)</span> as the network on the platform where you are withdrawing funds for this deposit. Otherwise, you'll lose your assets.</div>
  36. </div>
  37. </template>
  38. <script setup>
  39. /* eslint-disable */
  40. import { defineProps, defineEmits, onMounted, ref } from "vue";
  41. import { getTokenRechargeAddress } from "@/http/pay";
  42. import { ElMessage } from 'element-plus'
  43. let QRCode = require('qrcode')
  44. let ClipboardJS = require('clipboard')
  45. let tokenRechargeAddress = ref('');
  46. const props = defineProps({
  47. currentCurrencyInfo: {
  48. type: Object,
  49. default: () => {
  50. }
  51. },
  52. asyncIng: {
  53. type: Boolean,
  54. default: false
  55. }
  56. })
  57. const emits = defineEmits(['doneHandle']);
  58. const createQRCode = (str) => {
  59. var canvas = document.getElementById('canvas')
  60. QRCode.toCanvas(canvas, str, {
  61. width: 130,
  62. height: 130,
  63. scale: 1,
  64. color: {
  65. dark: '#000', // 二维码前景颜色
  66. light: '#fff' // 二维码背景颜色
  67. }
  68. }, function (error) {
  69. if (error) console.error(error)
  70. console.log('success!');
  71. })
  72. }
  73. const copyToken = () => {
  74. var clipboard = new ClipboardJS('.copy-btn');
  75. clipboard.on('success', function (e) {
  76. ElMessage({
  77. message: 'copy success',
  78. grouping: true,
  79. type: 'success',
  80. offset: -16,
  81. appendTo: document.body
  82. })
  83. console.info('Action:', e.action);
  84. console.info('Text:', e.text);
  85. console.info('Trigger:', e.trigger);
  86. e.clearSelection();
  87. });
  88. clipboard.on('error', function (e) {
  89. ElMessage({
  90. message: 'copy error',
  91. grouping: true,
  92. type: 'error',
  93. offset: -16
  94. })
  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. .token-content {
  123. padding: 0 16px;
  124. margin-bottom: 16px;
  125. border-radius: 20px;
  126. border: 1px solid #E6E6E6;
  127. .item {
  128. display: flex;
  129. align-items: center;
  130. justify-content: space-between;
  131. clear: both;
  132. height: 42px;
  133. box-shadow: inset 0px -1px 0px #E6E6E6;
  134. &.none {
  135. box-shadow: unset;
  136. }
  137. .token-l {
  138. font-size: 15px;
  139. font-weight: 400;
  140. color: #707070;
  141. }
  142. .token-r {
  143. font-size: 16px;
  144. font-weight: 500;
  145. }
  146. img {
  147. width: 20px;
  148. height: 20px;
  149. vertical-align: middle;
  150. margin-right: 6px;
  151. }
  152. }
  153. .desc {
  154. color: #A9A9A9;
  155. font-size: 12px;
  156. font-weight: 400;
  157. margin-bottom: 20px;
  158. span {
  159. color: #ff0016;
  160. font-weight: bold;
  161. }
  162. }
  163. .qrCode {
  164. display: flex;
  165. margin-bottom: 12px;
  166. .canvas {
  167. overflow: hidden;
  168. width: 130px;
  169. height: 130px;
  170. canvas {
  171. transform: scale(1.24);
  172. }
  173. }
  174. .code {
  175. width: 300px;
  176. padding: 0 20px;
  177. display: flex;
  178. align-items: center;
  179. flex-direction: column;
  180. justify-content: center;
  181. .address {
  182. font-size: 16px;
  183. font-weight: 500;
  184. line-height: 25px;
  185. margin-bottom: 20px;
  186. word-break: break-all;
  187. }
  188. .copy-btn {
  189. display: flex;
  190. align-items: center;
  191. justify-content: center;
  192. cursor: pointer;
  193. width: 100%;
  194. height: 40px;
  195. color: #1D9BF0;
  196. font-size: 17px;
  197. font-weight: 600;
  198. text-align: center;
  199. border: 1px solid #1D9BF0;
  200. border-radius: 40px;
  201. }
  202. }
  203. }
  204. }
  205. </style>