invite_fans.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="pages">
  3. <view class="invite-fans flex-col col-center">
  4. <image :src="path" mode="widthFix" class="poster"></image>
  5. <invite-poster v-if="showPoster" :config="{
  6. avatar: userInfo.avatar,
  7. nickname: userInfo.nickname,
  8. code: inviteCode,
  9. link: link,
  10. qrCode: qrCode,
  11. poster: poster
  12. }" @success="handleSuccess" />
  13. <view class="bg-white footer flex-1">
  14. <view class="m-b-40">
  15. <view class="m-b-10 sm lighter">我的邀请码</view>
  16. <view class="flex row-between">
  17. <view class="font-size-44">{{inviteCode}}</view>
  18. <view class="sm m-r-30 copy-btn" @tap="onCopy(inviteCode)">点击复制</view>
  19. </view>
  20. </view>
  21. <!-- #ifndef H5 -->
  22. <button class="save-btn br60" size="lg" @tap="saveImageToAlbum">保存到相册</button>
  23. <!-- #endif -->
  24. <!-- #ifdef H5 -->
  25. <button class="save-btn br60" size="lg">长按保存到相册</button>
  26. <!-- #endif -->
  27. </view>
  28. </view>
  29. <loading-view v-show="loading"></loading-view>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. apiMnpQrCode
  35. } from '@/api/app'
  36. import {
  37. baseURL,
  38. basePath
  39. } from '@/config/app'
  40. import {
  41. mapGetters
  42. } from 'vuex'
  43. import {
  44. apiDistributionPoster
  45. } from '@/api/user'
  46. import {
  47. copy
  48. } from '@/utils/tools.js'
  49. export default {
  50. data() {
  51. return {
  52. path: '',
  53. qrCode: '',
  54. loading: true,
  55. showPoster: false,
  56. poster: ''
  57. };
  58. },
  59. async onLoad() {
  60. await this.getPoster()
  61. // #ifdef MP-WEIXIN
  62. this.getMnpQrCode()
  63. // #endif
  64. // #ifdef APP-PLUS || H5
  65. this.showPoster = true
  66. // #endif
  67. },
  68. methods: {
  69. onCopy(text) {
  70. copy(text)
  71. },
  72. async getPoster() {
  73. const res = await apiDistributionPoster()
  74. this.poster = res.data.poster
  75. },
  76. getMnpQrCode() {
  77. apiMnpQrCode({
  78. type: 0,
  79. url: 'pages/index/index'
  80. }).then(res => {
  81. console.log(res)
  82. this.qrCode = res.data.qr_code
  83. this.showPoster = true
  84. })
  85. },
  86. saveImageToAlbum() {
  87. // #ifndef H5
  88. uni.saveImageToPhotosAlbum({
  89. filePath: this.path,
  90. success: res => {
  91. this.$toast({
  92. title: "保存成功"
  93. });
  94. },
  95. fail: err => {
  96. this.$toast({
  97. title: '保存失败'
  98. });
  99. }
  100. });
  101. // #endif
  102. // #ifdef H5
  103. this.$toast({
  104. title: '请长按图片保存'
  105. })
  106. // #endif
  107. },
  108. handleSuccess(val) {
  109. this.path = val
  110. this.loading = false
  111. }
  112. },
  113. computed: {
  114. ...mapGetters(['inviteCode', 'userInfo']),
  115. link() {
  116. return `${baseURL}${basePath}/pages/register/register?invite_code=${this.inviteCode}`
  117. }
  118. }
  119. };
  120. </script>
  121. <style lang="scss">
  122. page {
  123. padding: 0
  124. }
  125. .invite-fans {
  126. min-height: 100vh;
  127. overflow: hidden;
  128. .poster {
  129. width: 600rpx;
  130. margin: 40rpx 0;
  131. }
  132. .footer {
  133. padding: 30rpx;
  134. width: 100%;
  135. }
  136. .copy-btn {
  137. color: $-color-primary;
  138. }
  139. .save-btn {
  140. color: #fff;
  141. background-color: $-color-primary;
  142. ;
  143. }
  144. }
  145. </style>