top-up2.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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" :class="{ position: props.list.length > 1 }" @mouseover="showCurrencyLayer" @mouseout="hideCurrencyLayer">
  14. <div class="token-l">Network</div>
  15. <div class="token-r">
  16. <img class="icon" :src="currentCurrencyInfo.chainInfo.iconPath" />
  17. {{ currentCurrencyInfo.chainInfo.chainName }}
  18. <img v-if="props.list.length > 1" class="down" :src=" require('@/assets/svg/icon-botton-up.svg') " />
  19. </div>
  20. <div class="currency-pop-select" v-show="showCurrencySelect">
  21. <currency-select
  22. :list="props.list"
  23. @selectCurrency="selectCurrency">
  24. </currency-select>
  25. </div>
  26. </div>
  27. <div class="item none">
  28. <div class="token-l">Address</div>
  29. </div>
  30. <div class="qrCode">
  31. <div class="canvas">
  32. <canvas id="canvas"></canvas>
  33. </div>
  34. <div class="code">
  35. <div class="address">{{tokenRechargeAddress}}</div>
  36. <div class="copy-btn" :data-clipboard-text="tokenRechargeAddress">copy</div>
  37. </div>
  38. </div>
  39. <div class="desc">Make sure you also selected <span class="blod">{{ currentCurrencyInfo.chainInfo.chainName }}</span> as the network on the platform where you are withdrawing funds for this deposit. Otherwise, you'll lose your assets.</div>
  40. </div>
  41. </template>
  42. <script setup>
  43. /* eslint-disable */
  44. import { defineProps, defineEmits, onMounted, ref, watch } from "vue";
  45. import { getTokenRechargeAddress } from "@/http/pay";
  46. import { ElMessage } from 'element-plus'
  47. import currencySelect from "@/view/components/currency-select.vue";
  48. let QRCode = require('qrcode')
  49. let ClipboardJS = require('clipboard')
  50. let tokenRechargeAddress = ref('');
  51. let showCurrencySelect = ref(false);
  52. const props = defineProps({
  53. currentCurrencyInfo: {
  54. type: Object,
  55. default: () => {
  56. }
  57. },
  58. asyncIng: {
  59. type: Boolean,
  60. default: false
  61. },
  62. list: {
  63. type: Array,
  64. default: []
  65. },
  66. })
  67. const emits = defineEmits(['topUpDone', 'selectCurrency']);
  68. const createQRCode = (str) => {
  69. var canvas = document.getElementById('canvas')
  70. QRCode.toCanvas(canvas, str, {
  71. width: 130,
  72. height: 130,
  73. scale: 1,
  74. color: {
  75. dark: '#000', // 二维码前景颜色
  76. light: '#fff' // 二维码背景颜色
  77. }
  78. }, function (error) {
  79. if (error) console.error(error)
  80. console.log('success!');
  81. })
  82. }
  83. const copyToken = () => {
  84. var clipboard = new ClipboardJS('.copy-btn');
  85. clipboard.on('success', function (e) {
  86. ElMessage({
  87. message: 'copy success',
  88. grouping: true,
  89. type: 'success',
  90. offset: -16,
  91. appendTo: document.body
  92. })
  93. console.info('Action:', e.action);
  94. console.info('Text:', e.text);
  95. console.info('Trigger:', e.trigger);
  96. e.clearSelection();
  97. });
  98. clipboard.on('error', function (e) {
  99. ElMessage({
  100. message: 'copy error',
  101. grouping: true,
  102. type: 'error',
  103. offset: -16
  104. })
  105. console.error('Action:', e.action);
  106. console.error('Trigger:', e.trigger);
  107. });
  108. }
  109. const selectCurrency = (params) => {
  110. showCurrencySelect.value = false;
  111. emits('selectCurrency', params, false);
  112. }
  113. const showCurrencyLayer = () => {
  114. if (props.list.length > 1) {
  115. showCurrencySelect.value = true;
  116. }
  117. }
  118. const hideCurrencyLayer = () => {
  119. showCurrencySelect.value = false;
  120. }
  121. const doneHandle = () => {
  122. emits('topUpDone', {});
  123. }
  124. const getTokenAddress = () => {
  125. getTokenRechargeAddress({
  126. params: {
  127. tokenChain: props.currentCurrencyInfo.tokenChain
  128. },
  129. }).then((res) => {
  130. if(res.code == 0) {
  131. if (res.data && res.data.rechargeAddress) {
  132. tokenRechargeAddress.value = res.data.rechargeAddress;
  133. createQRCode(res.data.rechargeAddress)
  134. copyToken()
  135. }
  136. }
  137. })
  138. }
  139. onMounted(() => {
  140. getTokenAddress();
  141. })
  142. </script>
  143. <style scoped lang="scss">
  144. .token-content {
  145. padding: 0 16px;
  146. margin-bottom: 16px;
  147. border-radius: 20px;
  148. border: 1px solid #E6E6E6;
  149. .item {
  150. display: flex;
  151. align-items: center;
  152. justify-content: space-between;
  153. clear: both;
  154. height: 42px;
  155. box-shadow: inset 0px -1px 0px #E6E6E6;
  156. &.none {
  157. box-shadow: unset;
  158. }
  159. .token-l {
  160. font-size: 15px;
  161. font-weight: 400;
  162. color: #707070;
  163. }
  164. .token-r {
  165. font-size: 16px;
  166. font-weight: 500;
  167. .down {
  168. width: 9px;
  169. margin-left: 4px;
  170. }
  171. }
  172. img {
  173. width: 20px;
  174. height: 20px;
  175. vertical-align: middle;
  176. margin-right: 6px;
  177. }
  178. &.position {
  179. position: relative;
  180. cursor: pointer;
  181. .currency-pop-select {
  182. position: absolute;
  183. width: 375px;
  184. max-height: 480px;
  185. top: 36px;
  186. right: 0px;
  187. z-index: 1000;
  188. box-shadow: 0px 4px 30px rgba(0, 0, 0, 0.3);
  189. background-color: #fff;
  190. border-radius: 20px;
  191. overflow-y: scroll;
  192. }
  193. }
  194. }
  195. .desc {
  196. color: #A9A9A9;
  197. font-size: 12px;
  198. font-weight: 400;
  199. margin-bottom: 20px;
  200. span {
  201. color: #ff0016;
  202. font-weight: bold;
  203. }
  204. }
  205. .qrCode {
  206. display: flex;
  207. margin-bottom: 12px;
  208. .canvas {
  209. overflow: hidden;
  210. width: 130px;
  211. height: 130px;
  212. canvas {
  213. transform: scale(1.24);
  214. }
  215. }
  216. .code {
  217. flex: 1;
  218. padding: 0 20px;
  219. display: flex;
  220. align-items: center;
  221. flex-direction: column;
  222. justify-content: center;
  223. .address {
  224. font-size: 16px;
  225. font-weight: 500;
  226. line-height: 25px;
  227. margin-bottom: 20px;
  228. word-break: break-all;
  229. }
  230. .copy-btn {
  231. display: flex;
  232. align-items: center;
  233. justify-content: center;
  234. cursor: pointer;
  235. width: 100%;
  236. height: 40px;
  237. color: #1D9BF0;
  238. font-size: 17px;
  239. font-weight: 600;
  240. text-align: center;
  241. border: 1px solid #1D9BF0;
  242. border-radius: 40px;
  243. }
  244. }
  245. }
  246. }
  247. </style>