qrcode.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="qrocde-modal">
  3. <view class="modal-bg" @click="closed()" :style="{zIndex:zindex}"></view>
  4. <view class="modal-box animated fast" :style="{zIndex:zindex+1,background:bg}" :class="show ? 'slideInUp' : 'slideOutDown'">
  5. <!-- #ifdef MP-WEIXIN -->
  6. <view style="padding: 100upx 0px;">
  7. <button open-type="share" style="width: 80%; background: #ff0000; color: #ffffff; height: 100upx;">点击分享</button>
  8. <button @click="closed()" style="width: 80%; background: #ddd; margin-top: 30upx; color: #333; height: 100upx;">取消分享</button>
  9. </view>
  10. <!-- #endif -->
  11. <!-- #ifndef MP-WEIXIN -->
  12. <view class="modal-main">
  13. <view class="closed">
  14. <text @click="closed()" class="iconfont ft20 cl-notice iconbtn_close"></text>
  15. </view>
  16. <view class="lh20 ft16 cl-main ftw600 text-center">我的分享二维码</view>
  17. <view @click="getp()" class="flex center mt40" style="height: 400rpx;">
  18. <image :src="qrcodeImg" style="width: 400rpx; height: 400rpx;"></image>
  19. </view>
  20. <view class="text-center ft14 cl-info2" style="padding: 10upx 80upx;white-space:normal; word-break:break-all; word-wrap:break-word;">
  21. <view class="text-center ft14" @click="copys()" style="padding-bottom: 20upx;">扫码上面的二维码【ID:{{uid}}】</view>
  22. <view class="text-center ft14" @click="copy()">点击复制地址<br>{{qrurl}}</view>
  23. </view>
  24. </view>
  25. <!-- #endif -->
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import QR from '../../static/js/wxqrcode.js';
  31. export default{
  32. props:{
  33. zindex:{
  34. type:Number,
  35. default:401,
  36. },
  37. bg:{
  38. type:String,
  39. default:'#ffffff',
  40. },
  41. },
  42. data(){
  43. return {
  44. show:false,
  45. qrcodeImg:'',
  46. uid:'',
  47. qrurl:'',
  48. }
  49. },
  50. created(){
  51. this.show = true;
  52. this.uid = uni.getStorageSync("userinfo").id;
  53. this.qrurl=this.configs.webUrl+'/h5/#/pages/login/reg?uid='+this.uid
  54. let img = QR.createQrCodeImg(this.qrurl, {
  55. size: 300//二维码大小
  56. })
  57. this.qrcodeImg = img;
  58. },
  59. methods:{
  60. copy(){
  61. var value=this.qrurl
  62. //提示模板
  63. uni.showModal({
  64. content:value,//模板中提示的内容
  65. confirmText:'复制内容',
  66. success:()=>{//点击复制内容的后调函数
  67. //uni.setClipboardData方法就是讲内容复制到粘贴板
  68. uni.setClipboardData({
  69. data:value,//要被复制的内容
  70. success:()=>{//复制成功的回调函数
  71. uni.showToast({//提示
  72. title:'复制成功'
  73. })
  74. }
  75. });
  76. }
  77. });
  78. },
  79. copys(){
  80. console.log(1111)
  81. var value=this.uid
  82. //提示模板
  83. uni.showModal({
  84. content:value,//模板中提示的内容
  85. confirmText:'复制内容',
  86. success:()=>{//点击复制内容的后调函数
  87. //uni.setClipboardData方法就是讲内容复制到粘贴板
  88. uni.setClipboardData({
  89. data:value,//要被复制的内容
  90. success:()=>{//复制成功的回调函数
  91. uni.showToast({//提示
  92. title:'复制成功'
  93. })
  94. }
  95. });
  96. }
  97. });
  98. },
  99. closed(){
  100. this.show = false;
  101. setTimeout(()=>{
  102. this.$emit('closed');
  103. },400);
  104. },
  105. getp(){
  106. let thia=this.qrcodeImg
  107. //#ifdef APP-PLUS
  108. uni.saveImageToPhotosAlbum({
  109. filePath: thia.qrcodeImg,
  110. success: function () {
  111. console.log('save success');
  112. }
  113. });
  114. //#endif
  115. }
  116. }
  117. }
  118. </script>
  119. <style>
  120. .qrocde-modal{
  121. position: relative;
  122. z-index: 400;
  123. }
  124. .qrocde-modal .modal-bg{
  125. position: fixed;
  126. z-index: 400;
  127. left: 0;
  128. top: 0;
  129. width: 100%;
  130. height: 100vh;
  131. background: rgba(0,0,0,.5);
  132. }
  133. .qrocde-modal .modal-box{
  134. position: fixed;
  135. z-index: 401;
  136. background:#FFFFFF;
  137. left: 0;
  138. bottom: 0;
  139. width: 100%;
  140. padding-bottom:0rpx;
  141. padding-bottom:constant(safe-area-inset-bottom);
  142. padding-bottom:env(safe-area-inset-bottom);
  143. border-radius:32rpx 32rpx 0rpx 0rpx;
  144. }
  145. .qrocde-modal .modal-main{
  146. position: relative;
  147. height: auto;
  148. overflow: hidden;
  149. min-height: 1000rpx;
  150. padding-top: 64rpx;
  151. padding-bottom: 40rpx;
  152. }
  153. .qrocde-modal .modal-main .closed{
  154. position: absolute;
  155. right: 40rpx;
  156. top: 40rpx;
  157. }
  158. </style>