recharge.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. onLoad() {
  72. uni.setNavigationBarTitle({
  73. title: this.$t("tab.a3"),
  74. });
  75. },
  76. methods: {
  77. // 复制地址
  78. copy(value) {
  79. uni.setClipboardData({
  80. data: value,
  81. success: function () {
  82. //调用方法成功
  83. console.log("success");
  84. },
  85. });
  86. },
  87. savePic(Url){
  88. // Url = this.address //图片路径,也可以传值进来
  89. // var triggerEvent = "touchstart"; //指定下载方式
  90. // var blob=new Blob([''], {type:'application/octet-stream'}); //二进制大型对象blob
  91. // var url = URL.createObjectURL(blob); //创建一个字符串路径空位
  92. // var a = document.createElement('a'); //创建一个 a 标签
  93. // a.href = Url; //把路径赋到a标签的href上
  94. // //正则表达式,这里是把图片文件名分离出来。拿到文件名赋到a.download,作为文件名来使用文本
  95. // a.download = Url.replace(/(.*\/)*([^.]+.*)/ig,"$2").split("?")[0];
  96. // /* var e = document.createEvent('MouseEvents'); //创建事件(MouseEvents鼠标事件)
  97. // e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); //初始化鼠标事件(initMouseEvent已弃用)*/
  98. // var e = new MouseEvent('click', ( true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null));
  99. // //派遣后,它将不再执行任何操作。执行保存到本地
  100. // a.dispatchEvent(e);
  101. // //释放一个已经存在的路径(有创建createObjectURL就要释放revokeObjectURL)
  102. // URL.revokeObjectURL(url);
  103. var canvas = document.getElementById('qrcode'); // 获取二维码所在的canvas元素
  104. var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // 将canvas转换为base64格式的图片数据
  105. var a = document.createElement('a');
  106. a.href = image;
  107. a.download = 'qrcode.png'; // 设置下载的文件名
  108. var event = new MouseEvent('click');
  109. a.dispatchEvent(event);
  110. },
  111. },
  112. };
  113. </script>
  114. <style lang="scss">
  115. .all {
  116. width: 750rpx;
  117. height: 1416rpx;
  118. background-color: $page-color-base;
  119. }
  120. .top {
  121. margin-left: 28rpx;
  122. padding-top: 50rpx;
  123. width: 690rpx;
  124. height: 720rpx;
  125. background: #191a1f;
  126. border-radius: 20rpx;
  127. display: flex;
  128. flex-direction: column;
  129. }
  130. .topO {
  131. height: 31rpx;
  132. font-size: 32rpx;
  133. font-family: PingFang SC;
  134. font-weight: bold;
  135. color: #ffffff;
  136. line-height: 24rpx;
  137. margin-left: 21rpx;
  138. margin-top: 37rpx;
  139. }
  140. .topT {
  141. margin-left: 20rpx;
  142. margin-top: 30rpx;
  143. width: 218rpx;
  144. height: 68rpx;
  145. border: 2px solid #ddba82;
  146. border-radius: 10rpx;
  147. }
  148. .tt {
  149. width: 168rpx;
  150. height: 20rpx;
  151. font-size: 26rpx;
  152. font-weight: bold;
  153. color: #feb041;
  154. line-height: 24rpx;
  155. margin-top: 20rpx;
  156. margin-left: 23rpx;
  157. }
  158. .topS {
  159. display: flex;
  160. justify-content: start;
  161. }
  162. .S {
  163. height: 31rpx;
  164. font-size: 32rpx;
  165. font-weight: bold;
  166. color: #ffffff;
  167. line-height: 24rpx;
  168. margin-left: 23rpx;
  169. margin-top: 26rpx;
  170. }
  171. .SS {
  172. height: 20rpx;
  173. font-size: 26rpx;
  174. font-weight: 500;
  175. color: #ffffff;
  176. line-height: 24rpx;
  177. margin-left: 23rpx;
  178. margin-top: 26rpx;
  179. }
  180. .SSS {
  181. width: 29rpx;
  182. height: 29rpx;
  183. margin-left: 23rpx;
  184. margin-top: 24rpx;
  185. }
  186. .buttom {
  187. margin-left: 30rpx;
  188. margin-top: 30rpx;
  189. width: 690rpx;
  190. // height: 100vh;
  191. background: #191a1f;
  192. border-radius: 20rpx;
  193. }
  194. .but {
  195. margin-left: 27rpx;
  196. padding-top: 50rpx;
  197. padding-bottom: 50rpx;
  198. width: 625rpx;
  199. // height: 114rpx;
  200. font-size: 26rpx;
  201. font-weight: 500;
  202. color: #ffffff;
  203. line-height: 45rpx;
  204. }
  205. .topF {
  206. // flex: 1;
  207. margin-top: 34rpx;
  208. display: flex;
  209. align-items: center;
  210. justify-content: center;
  211. }
  212. .qr{
  213. width: 275rpx;
  214. height: 275rpx;
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. background-color: #fff;
  219. }
  220. .last {
  221. display: flex;
  222. justify-content: center;
  223. }
  224. .le {
  225. margin-top: 43rpx;
  226. width: 201rpx;
  227. height: 59rpx;
  228. border: 2px solid #DDBA82;
  229. border-radius: 10rpx;
  230. }
  231. .lef {
  232. margin-top: 12rpx;
  233. margin-left: 49rpx;
  234. height: 25rpx;
  235. font-size: 26rpx;
  236. font-family: PingFang SC;
  237. font-weight: bold;
  238. color: #FEB041;
  239. line-height: 24rpx;
  240. }
  241. </style>