recharge.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="all">
  3. <view class="top">
  4. <view class="topO"> {{$t('userinfo.u4')}} </view>
  5. <view class="topT">
  6. <view class="tt">USDT-TRC20</view>
  7. </view>
  8. <view class="topS">
  9. <view class="S">{{$t('userinfo.u1')}}</view>
  10. <view
  11. class="SS"
  12. >{{ address }}</view
  13. >
  14. <image
  15. class="SSS"
  16. src="/static/icon/cz.png"
  17. mode=""
  18. @click="copy(address)">
  19. </image>
  20. </view>
  21. <!-- 根据地址生成二维码 -->
  22. <view class="topF">
  23. <view class="qr">
  24. <canvas
  25. id="qrcode"
  26. canvas-id="qrcode"
  27. style="width: 120px; height: 120px"></canvas>
  28. </view>
  29. </view>
  30. <view class="last">
  31. <view class="le" @click="savePic">
  32. <view class="lef">{{$t('userinfo.u2')}}</view>
  33. </view>
  34. <view class="le" style="margin-left: 30rpx;">
  35. <view class="lef" @click="copy(address)">{{$t('userinfo.u3')}}</view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="buttom">
  40. <view class="but">
  41. {{$t('userinfo.u5')}}
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import UQRCode from "@/components/uqrcodejs/uqrcode.js"; // npm install uqrcodejs
  48. export default {
  49. data() {
  50. return {
  51. address: "ca87ca68ca68c6a986c98a678c7a8",
  52. };
  53. },
  54. mounted() {},
  55. onReady() {
  56. // 获取uQRCode实例
  57. var qr = new UQRCode();
  58. // 设置二维码内容
  59. qr.data = this.address;
  60. // 设置二维码大小,必须与canvas设置的宽高一致
  61. qr.size = 120;
  62. // 调用制作二维码方法
  63. qr.make();
  64. // 获取canvas上下文
  65. var canvasContext = uni.createCanvasContext("qrcode", this); // 如果是组件,this必须传入
  66. // 设置uQRCode实例的canvas上下文
  67. qr.canvasContext = canvasContext;
  68. // 调用绘制方法将二维码图案绘制到canvas上
  69. qr.drawCanvas();
  70. },
  71. methods: {
  72. // 复制地址
  73. copy(value) {
  74. uni.setClipboardData({
  75. data: value,
  76. success: function () {
  77. //调用方法成功
  78. console.log("success");
  79. },
  80. });
  81. },
  82. savePic(Url){
  83. Url = this.address //图片路径,也可以传值进来
  84. var triggerEvent = "touchstart"; //指定下载方式
  85. var blob=new Blob([''], {type:'application/octet-stream'}); //二进制大型对象blob
  86. var url = URL.createObjectURL(blob); //创建一个字符串路径空位
  87. var a = document.createElement('a'); //创建一个 a 标签
  88. a.href = Url; //把路径赋到a标签的href上
  89. //正则表达式,这里是把图片文件名分离出来。拿到文件名赋到a.download,作为文件名来使用文本
  90. a.download = Url.replace(/(.*\/)*([^.]+.*)/ig,"$2").split("?")[0];
  91. /* var e = document.createEvent('MouseEvents'); //创建事件(MouseEvents鼠标事件)
  92. e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); //初始化鼠标事件(initMouseEvent已弃用)*/
  93. var e = new MouseEvent('click', ( true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null));
  94. //派遣后,它将不再执行任何操作。执行保存到本地
  95. a.dispatchEvent(e);
  96. //释放一个已经存在的路径(有创建createObjectURL就要释放revokeObjectURL)
  97. URL.revokeObjectURL(url);
  98. },
  99. },
  100. };
  101. </script>
  102. <style lang="scss">
  103. .all {
  104. width: 750rpx;
  105. height: 1416rpx;
  106. background-color: $page-color-base;
  107. }
  108. .top {
  109. margin-left: 28rpx;
  110. padding-top: 50rpx;
  111. width: 690rpx;
  112. height: 720rpx;
  113. background: #191a1f;
  114. border-radius: 20rpx;
  115. display: flex;
  116. flex-direction: column;
  117. }
  118. .topO {
  119. height: 31rpx;
  120. font-size: 32rpx;
  121. font-family: PingFang SC;
  122. font-weight: bold;
  123. color: #ffffff;
  124. line-height: 24rpx;
  125. margin-left: 21rpx;
  126. margin-top: 37rpx;
  127. }
  128. .topT {
  129. margin-left: 20rpx;
  130. margin-top: 30rpx;
  131. width: 218rpx;
  132. height: 68rpx;
  133. border: 2px solid #ddba82;
  134. border-radius: 10rpx;
  135. }
  136. .tt {
  137. width: 168rpx;
  138. height: 20rpx;
  139. font-size: 26rpx;
  140. font-weight: bold;
  141. color: #feb041;
  142. line-height: 24rpx;
  143. margin-top: 20rpx;
  144. margin-left: 23rpx;
  145. }
  146. .topS {
  147. display: flex;
  148. justify-content: start;
  149. }
  150. .S {
  151. height: 31rpx;
  152. font-size: 32rpx;
  153. font-weight: bold;
  154. color: #ffffff;
  155. line-height: 24rpx;
  156. margin-left: 23rpx;
  157. margin-top: 26rpx;
  158. }
  159. .SS {
  160. height: 20rpx;
  161. font-size: 26rpx;
  162. font-weight: 500;
  163. color: #ffffff;
  164. line-height: 24rpx;
  165. margin-left: 23rpx;
  166. margin-top: 26rpx;
  167. }
  168. .SSS {
  169. width: 29rpx;
  170. height: 29rpx;
  171. margin-left: 23rpx;
  172. margin-top: 24rpx;
  173. }
  174. .buttom {
  175. margin-left: 30rpx;
  176. margin-top: 30rpx;
  177. width: 690rpx;
  178. // height: 100vh;
  179. background: #191a1f;
  180. border-radius: 20rpx;
  181. }
  182. .but {
  183. margin-left: 27rpx;
  184. padding-top: 50rpx;
  185. padding-bottom: 50rpx;
  186. width: 625rpx;
  187. // height: 114rpx;
  188. font-size: 26rpx;
  189. font-weight: 500;
  190. color: #ffffff;
  191. line-height: 45rpx;
  192. }
  193. .topF {
  194. // flex: 1;
  195. margin-top: 34rpx;
  196. display: flex;
  197. align-items: center;
  198. justify-content: center;
  199. }
  200. .qr{
  201. width: 275rpx;
  202. height: 275rpx;
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. background-color: #fff;
  207. }
  208. .last {
  209. display: flex;
  210. justify-content: center;
  211. }
  212. .le {
  213. margin-top: 43rpx;
  214. width: 201rpx;
  215. height: 59rpx;
  216. border: 2px solid #DDBA82;
  217. border-radius: 10rpx;
  218. }
  219. .lef {
  220. margin-top: 12rpx;
  221. margin-left: 49rpx;
  222. height: 25rpx;
  223. font-size: 26rpx;
  224. font-family: PingFang SC;
  225. font-weight: bold;
  226. color: #FEB041;
  227. line-height: 24rpx;
  228. }
  229. </style>