top-up.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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">{{ currentCurrencyInfo.chainInfo.chainName }}</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(['topUpDone']);
  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. </script>
  150. <style scoped lang="scss">
  151. .top-up-wrapper {
  152. width: 100%;
  153. height: 100%;
  154. box-sizing: border-box;
  155. padding: 18px;
  156. position: relative;
  157. .content-wrapper {
  158. height: calc(100% - 60px);
  159. .top {
  160. width: 100%;
  161. display: flex;
  162. justify-content: space-between;
  163. .item {
  164. width: 49%;
  165. .label {
  166. color: #A0A0A0;
  167. margin-bottom: 6px;
  168. }
  169. .content {
  170. position: relative;
  171. height: 44px;
  172. width: 100%;
  173. border-radius: 8px;
  174. display: flex;
  175. align-items: center;
  176. border: 1px solid #DBDBDB;
  177. padding: 12px 10px;
  178. box-sizing: border-box;
  179. font-weight: 500;
  180. font-size: 14px;
  181. img {
  182. width: 20px;
  183. height: 20px;
  184. margin-right: 6px;
  185. }
  186. .down {
  187. position: absolute;
  188. right: 10px;
  189. width: 12px;
  190. }
  191. }
  192. &.position {
  193. position: relative;
  194. cursor: pointer;
  195. .currency-pop-select {
  196. position: absolute;
  197. width: 375px;
  198. max-height: 480px;
  199. top: 66px;
  200. right: 0px;
  201. z-index: 1000;
  202. box-shadow: 0px 4px 30px rgba(0, 0, 0, 0.3);
  203. background-color: #fff;
  204. border-radius: 20px;
  205. overflow-y: scroll;
  206. }
  207. }
  208. }
  209. }
  210. .qrcode-wrapper {
  211. margin-top: 22px;
  212. height: 290px;
  213. background: #F7F7F7;
  214. border-radius: 20px;
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. flex-direction: column;
  219. padding: 20px;
  220. box-sizing: border-box;
  221. .address {
  222. padding-bottom: 20px;
  223. box-sizing: border-box;
  224. font-weight: 500;
  225. font-size: 15px;
  226. height: 38px;
  227. }
  228. #canvas {
  229. margin-top: -25px;
  230. }
  231. .copy-btn {
  232. height: 40px;
  233. width: 160px;
  234. border-radius: 1000px;
  235. border: 1px solid #1D9BF0;
  236. font-weight: 600;
  237. font-size: 16px;
  238. color: #1D9BF0;
  239. text-align: center;
  240. line-height: 40px;
  241. cursor: pointer;
  242. }
  243. }
  244. .tips-box {
  245. margin-top: 18px;
  246. font-size: 14px;
  247. border-radius: 8px;
  248. background: #FCF5E5;
  249. padding: 12px 10px;
  250. box-sizing: border-box;
  251. display: flex;
  252. align-items: flex-start;
  253. .icon {
  254. margin-right: 10px;
  255. }
  256. .blod {
  257. color: red;
  258. font-weight: 500;
  259. }
  260. }
  261. }
  262. .btn-done {
  263. background: #1D9BF0;
  264. width: 100%;
  265. height: 46px;
  266. text-align: center;
  267. border-radius: 1000px;
  268. font-weight: 600;
  269. font-size: 16px;
  270. color: #fff;
  271. margin-top: 10px;
  272. display: flex;
  273. align-items: center;
  274. justify-content: center;
  275. cursor: pointer;
  276. }
  277. }
  278. </style>