shareQrCode.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="container" v-if="loaded">
  3. <image @longtap="bc_code" class="backImg" :src="backImg"></image>
  4. <!-- <view class="tki-qrcode"><canvas @longtap="bc_code" canvas-id="qrcode" /></view> -->
  5. <view class="tki-qrcode">
  6. <tki-qrcode :key="'http://shop.zhengyjk1994.com/register?petent=' + userInfo.uid" cid="tki-qrcode-canvas"
  7. ref="qrcode"
  8. :val="'http://shop.zhengyjk1994.com/register?petent=' + userInfo.uid"
  9. :size="300" unit="upx" background="#ffffff" foreground="#333333" pdground="#333333" icon=""
  10. :iconSize="40" :lv="3" :onval="true" :loadMake="true" :usingComponents="true" />
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import {
  16. spreadBanner
  17. } from '@/api/user.js';
  18. import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue'
  19. import {
  20. mapState,
  21. mapMutations
  22. } from 'vuex';
  23. export default {
  24. components: {
  25. tkiQrcode
  26. },
  27. data() {
  28. return {
  29. url: '',
  30. backImg: '',
  31. loaded: false
  32. };
  33. },
  34. onLoad() {
  35. this.spread();
  36. },
  37. computed: {
  38. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin']),
  39. cpSize() {
  40. if (this.unit == "upx") {
  41. return uni.upx2px(this.size)
  42. } else {
  43. return this.size
  44. }
  45. },
  46. },
  47. methods: {
  48. spread() {
  49. let obj = this;
  50. uni.showLoading({
  51. title: '二维码生成中...'
  52. })
  53. spreadBanner({
  54. type: 2
  55. }).then(({
  56. data
  57. }) => {
  58. uni.hideLoading()
  59. console.log(data)
  60. obj.backImg = data[0].pic;
  61. console.log(obj.backImg, 'obj.backImg')
  62. this.loaded = true
  63. }).catch(err => {
  64. console.log(err)
  65. uni.hideLoading()
  66. });
  67. },
  68. bc_code() {
  69. let that = this;
  70. console.log('保存二维码', this.backImg)
  71. uni.downloadFile({ //获得二维码的临时地址
  72. url: this.backImg,
  73. success: (res) => {
  74. //console.log('获取url',res)
  75. if (res.statusCode == 200) {
  76. uni.saveImageToPhotosAlbum({
  77. filePath: res.tempFilePath, //传入临时地址
  78. success() {
  79. that.$api.msg('保存成功') //封装的提示
  80. },
  81. fail() {
  82. that.$api.msg('保存失败')
  83. }
  84. })
  85. }
  86. }
  87. })
  88. },
  89. },
  90. }
  91. </script>
  92. <style lang="scss">
  93. page {
  94. width: 100%;
  95. min-height: 100%;
  96. .container {
  97. width: 100%;
  98. height: 100%;
  99. }
  100. }
  101. .backImg {
  102. position: absolute;
  103. width: 100%;
  104. height: 100%;
  105. }
  106. .portrait {
  107. width: 100%;
  108. text-align: center;
  109. padding-top: 80rpx;
  110. padding-bottom: 30rpx;
  111. image {
  112. width: 250rpx;
  113. height: 250rpx;
  114. }
  115. }
  116. .text {
  117. text-align: center;
  118. width: 100%;
  119. color: #FFFFFF;
  120. font-size: 55rpx;
  121. letter-spacing: 15rpx;
  122. }
  123. .uid-name {
  124. padding: 50rpx 0rpx;
  125. text-align: center;
  126. width: 100%;
  127. color: #FFFFFF;
  128. }
  129. .copy-btn {
  130. color: #FFFFFF;
  131. background-color: #4BA6ED;
  132. border-radius: 50rpx;
  133. width: 170rpx;
  134. line-height: 70rpx;
  135. margin: 0rpx auto;
  136. text-align: center;
  137. }
  138. .tki-qrcode {
  139. position: fixed;
  140. bottom: 10%;
  141. left: 30%;
  142. }
  143. canvas {
  144. width: 150px;
  145. height: 150px;
  146. margin: auto;
  147. }
  148. </style>