shareQrCode.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="content">
  3. <!-- <view class="user-logo">
  4. <image :src="userInfo.avatar" mode=""></image>
  5. <view class="user-name">{{userInfo.nickname}}</view>
  6. </view> -->
  7. <image src="../../static/img/sharebase.png" mode="" class="sharebg" ></image>
  8. <view class="code-warpper">
  9. <view class="code-content">
  10. <tki-qrcode
  11. :cid="cid"
  12. ref="qrcode"
  13. :val="val"
  14. :size="size"
  15. :unit="unit"
  16. :background="background"
  17. :foreground="foreground"
  18. :pdground="pdground"
  19. :iconSize="iconSize"
  20. :lv="lv"
  21. :onval="onval"
  22. :loadMake="loadMake"
  23. :usingComponents="usingComponents"
  24. @result="qrR"
  25. />
  26. </view>
  27. <view class="code">
  28. 邀请码:{{userInfo.uid}}
  29. </view>
  30. </view>
  31. <view class="btm">
  32. <!-- 向商家出示二维码 -->
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import { orderDetail } from '@/api/order.js';
  38. import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue';
  39. import { mapState, mapMutations } from 'vuex';
  40. export default {
  41. comments:{
  42. tkiQrcode
  43. },
  44. data() {
  45. return {
  46. id:'',
  47. // code: '10250035810',
  48. cid: 'tki-qrcode-canvas', //canvasId,页面存在多个二维码组件时需设置不同的ID
  49. size: 300, //生成的二维码大小
  50. unit: 'upx', //大小单位尺寸
  51. show: true,//默认使用组件中的image标签显示二维码
  52. val: '', //要生成的内容
  53. background: '#ffffff', //二维码背景色
  54. foreground: '#333333', //二维码前景色
  55. pdground: '#333333', //二维码角标色
  56. icon: '', //二维码图标URL(必须是本地图片,网络图需要先下载至本地)
  57. iconSize: 40, //二维码图标大小
  58. lv: 3, //容错级别
  59. onval: true, //监听val值变化自动重新生成二维码
  60. loadMake: true, //组件初始化完成后自动生成二维码,val需要有值
  61. usingComponents: false, //是否使用了自定义组件模式(主要是为了修复非自定义组件模式时 v-if 无法生成二维码的问题)
  62. showLoading: false, //是否显示loading
  63. loadingText: '二维码生成中', //loading文字
  64. src: '', // 二维码生成后的图片地址或base64
  65. ratio: 1, //页面比例用于计算
  66. ctxSrc: '', //要显示的图片
  67. loading: true,//是否载入图片中
  68. canHeight: '',//画布高度
  69. canWeidth: ''//画布宽度
  70. }
  71. },
  72. computed: {
  73. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin']),
  74. ...mapState(['baseURL'])
  75. },
  76. onShow() {
  77. console.log(this.userInfo)
  78. // 判断是否已经登录
  79. if (this.hasLogin) {
  80. // this.loadBaseData();
  81. // this.getSpreadCount()
  82. console.log(this.userInfo)
  83. // console.log(this.userInfo)
  84. }
  85. },
  86. onLoad(opt) {
  87. this.val = this.baseURL + '/register?spread=' + this.userInfo.uid
  88. // if(opt.id) {
  89. // this.id = opt.id
  90. // orderDetail({}, this.id).then(e => {
  91. // this.val = e.data._verify_code;
  92. // this.val = this.val.replace(/\s/g, '')
  93. // });
  94. // }else {
  95. // this.val = opt.code.replace(/\s/g, '')
  96. // }
  97. // console.log(this.val )
  98. },
  99. methods: {
  100. // 生成二维码后返回base64
  101. qrR(res) {
  102. this.src = res;
  103. },
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. .content {
  109. position: relative;
  110. background-color: #ff341a;
  111. height: 100vh;
  112. min-height: 100%;
  113. }
  114. page {
  115. height: 100vh;
  116. min-height: 100%;
  117. background-color: #ff341a;
  118. }
  119. .user-logo {
  120. height: 300rpx;
  121. display: flex;
  122. flex-direction: column;
  123. justify-content: center;
  124. align-items: center;
  125. image {
  126. width: 102rpx;
  127. height: 102rpx;
  128. border-radius: 50%;
  129. }
  130. .user-name {
  131. padding-top: 25rpx;
  132. font-size: 34rpx;
  133. font-family: SourceHanSansCN;
  134. font-weight: 400;
  135. color: #2B2B2B;
  136. }
  137. }
  138. .code-warpper {
  139. width: 515rpx;
  140. height: 515rpx;
  141. margin: 0 auto;
  142. // border: 3rpx solid #901B21;
  143. padding-top: 46rpx;
  144. position: absolute;
  145. top:600rpx;
  146. left: 0;
  147. right: 0;
  148. margin: auto;
  149. .code-content {
  150. width: 300rpx;
  151. height: 300rpx;
  152. // background-color: red;
  153. margin: 0 auto;
  154. }
  155. .code {
  156. padding-top: 31rpx;
  157. font-size: 36rpx;
  158. font-family: PingFang SC;
  159. font-weight: bold;
  160. color: #333333;
  161. text-align: center;
  162. }
  163. }
  164. .btm {
  165. padding-top: 45rpx;
  166. font-size: 30rpx;
  167. font-family: PingFang SC;
  168. font-weight: bold;
  169. color: #333333;
  170. text-align: center;
  171. }
  172. .sharebg {
  173. width: 750rpx;
  174. height: 1206rpx;
  175. position: absolute;
  176. top: 0;
  177. }
  178. </style>