top-up.vue 8.7 KB

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