invite.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <script>
  2. import { mapState } from 'vuex'
  3. import ShareImg from '@/pagesUser/invite/components/shareImg.vue'
  4. import api from '@/api'
  5. export default {
  6. components: { ShareImg },
  7. data() {
  8. return {
  9. list: [],
  10. curIndex: 0,
  11. cvsTempImg: '',
  12. tempQrcodePath: '',
  13. isCreate: false, // 是否已经点了生成
  14. shareList: [
  15. { label: '复制链接', icon: 'lianjie' },
  16. { label: '保存图片', icon: 'bc_tp' }
  17. ],
  18. invite_code: '',
  19. upInfo: {}
  20. }
  21. },
  22. computed: mapState({
  23. user: state => state.user
  24. }),
  25. methods: {
  26. createCvs(type = '') {
  27. this.isCreate = true
  28. if (type !== 'qr') {
  29. uni.showLoading({
  30. title: '生成海报中...'
  31. })
  32. }
  33. if (!this.tempQrcodePath) return
  34. let w = uni.upx2px(750) // 图片宽
  35. let h = uni.upx2px(1334) // 图片高
  36. let qr = uni.upx2px(192) // 二维码大小
  37. let offset = uni.upx2px(1048)
  38. const ctx = uni.createCanvasContext('myCanvas')
  39. ctx.drawImage(this.list[this.curIndex].img_pic, 0, 0, w, h)
  40. ctx.drawImage(this.tempQrcodePath, (w - qr) / 2, offset, qr, qr)
  41. ctx.draw(true, () => {
  42. uni.canvasToTempFilePath({
  43. canvasId: 'myCanvas',
  44. success: res => {
  45. // 在H5平台下,tempFilePath 为 base64
  46. uni.hideLoading()
  47. this.cvsTempImg = res.tempFilePath
  48. console.log(this.cvsTempImg)
  49. this.$refs.shareImg.show = true
  50. },
  51. fail: error => {
  52. console.log('error', error)
  53. }
  54. })
  55. })
  56. },
  57. async getBanner() {
  58. this.list = await api.getBanner(4)
  59. },
  60. toTempPath({ success }) {
  61. if (success) {
  62. this.$refs.qrcode.toTempFilePath({
  63. success: res => {
  64. this.tempQrcodePath = res.tempFilePath
  65. if (this.isCreate) this.createCvs('qr')
  66. }
  67. })
  68. } else {
  69. this.$refs.qrcode.remake()
  70. }
  71. },
  72. shareJump({ label }) {
  73. switch (label) {
  74. case '复制链接':
  75. this.$common.copy(this.user.share_url, '邀请链接已复制,快粘贴发送好友注册吧~')
  76. break
  77. case '保存图片':
  78. this.createCvs()
  79. break
  80. }
  81. },
  82. async getUpInfo() {
  83. this.upInfo = await api.getUpUserInfo()
  84. console.log(this.upInfo)
  85. },
  86. async bindUp() {
  87. if (!this.invite_code) {
  88. this.$common.toast('请填写邀请码')
  89. return
  90. }
  91. await api.bangUpFriend(this.invite_code)
  92. await this.getUpInfo()
  93. this.$common.toast('绑定成功')
  94. }
  95. },
  96. onLoad() {
  97. this.getBanner()
  98. this.getUpInfo()
  99. }
  100. }
  101. </script>
  102. <template>
  103. <view>
  104. <view class="page flex flex-column">
  105. <view class="top flex">
  106. <image class="top_bg" src="/static/images/me/invite/bg_yaoqing_haoyou_d@2x.png"></image>
  107. </view>
  108. <view class="container flex1">
  109. <view class="form">
  110. <view class="item flex align-center">
  111. <label class="label">我的邀请码</label>
  112. <input class="input flex1" :value="user.code" />
  113. <u-button shape="circle" class="btn" @click="$common.copy(user.code)">复制</u-button>
  114. </view>
  115. <view class="item flex align-center">
  116. <label class="label">我的邀请人</label>
  117. <input
  118. v-if="Array.isArray(this.upInfo)"
  119. v-model="invite_code"
  120. class="input flex1"
  121. placeholder="请填写邀请码"
  122. placeholder-style="color:#B3B3B3"
  123. />
  124. <input
  125. v-else
  126. :value="upInfo.mobile"
  127. class="input flex1"
  128. placeholder-style="color:#B3B3B3"
  129. disabled
  130. />
  131. <u-button v-if="Array.isArray(this.upInfo)" shape="circle" class="btn" @click="bindUp"
  132. >填写</u-button
  133. >
  134. </view>
  135. </view>
  136. <!-- share -->
  137. <view class="share radius flex align-center">
  138. <view class="title flex flex-column">
  139. <text>分</text>
  140. <text>享</text>
  141. <text>至</text>
  142. </view>
  143. <view
  144. class="share_item flex flex-column"
  145. v-for="(s, i) in shareList"
  146. :key="i"
  147. @click="shareJump(s)"
  148. >
  149. <image
  150. :src="`/static/images/me/invite/ic_${s.icon}@2x.png`"
  151. class="share_item_icon"
  152. ></image>
  153. <view class="share_item_label">{{ s.label }}</view>
  154. </view>
  155. </view>
  156. </view>
  157. </view>
  158. <view style="position: fixed; z-index: -1">
  159. <uqrcode
  160. ref="qrcode"
  161. canvas-id="qrcode"
  162. start
  163. :auto="false"
  164. :size="300"
  165. :value="user.share_url_orgin"
  166. @complete="toTempPath"
  167. :options="{
  168. foregroundImageSrc: user.avatar,
  169. foregroundImageWidth: 300 * 0.3,
  170. foregroundImageHeight: 300 * 0.3,
  171. foregroundImagePadding: 4,
  172. foregroundImageBorderRadius: 4,
  173. foregroundImageShadowBlur: 50,
  174. foregroundImageShadowColor: 'rgba(0, 0, 0, 0.68)',
  175. margin: 10
  176. }"
  177. ></uqrcode>
  178. <canvas canvas-id="myCanvas" class="myCanvas"></canvas>
  179. </view>
  180. <share-img ref="shareImg" :cvsTempImg="cvsTempImg" />
  181. </view>
  182. </template>
  183. <style lang="scss" scoped>
  184. .top {
  185. &_bg {
  186. width: 750rpx;
  187. height: 1085rpx;
  188. }
  189. }
  190. .container {
  191. background-color: #373aa3;
  192. .form {
  193. width: 663rpx;
  194. height: 359rpx;
  195. margin: 10rpx auto 240rpx;
  196. background-image: url('/static/images/me/invite/bg_yaoqingma_srk@2x.png');
  197. background-size: 100%;
  198. padding: 87rpx 60rpx 65rpx;
  199. box-sizing: border-box;
  200. .item {
  201. height: 85rpx;
  202. background: #373aa3;
  203. border-radius: calc(85rpx / 2);
  204. padding: 6rpx 7rpx 6rpx 36rpx;
  205. box-sizing: border-box;
  206. & + .item {
  207. margin-top: 37rpx;
  208. }
  209. .label,
  210. .input {
  211. font-size: 30rpx;
  212. font-weight: bold;
  213. color: #ffffff;
  214. }
  215. .input {
  216. margin-left: 20rpx;
  217. }
  218. .btn {
  219. width: 125rpx;
  220. height: 73rpx;
  221. background: linear-gradient(0deg, #feda50, #fdeb6a);
  222. border-radius: calc(73rpx / 2);
  223. font-size: 36rpx;
  224. font-weight: normal;
  225. color: #db3028;
  226. }
  227. }
  228. }
  229. .share {
  230. position: fixed;
  231. bottom: 30rpx;
  232. left: 25rpx;
  233. width: 700rpx;
  234. height: 180rpx;
  235. background: #f8f8f8;
  236. border-radius: 20px;
  237. padding: 22rpx 50rpx;
  238. box-sizing: border-box;
  239. .title {
  240. margin-right: 44rpx;
  241. font-size: 30rpx;
  242. font-weight: 500;
  243. color: #ffb602;
  244. }
  245. &_item {
  246. & + .share_item {
  247. margin-left: 55rpx;
  248. }
  249. &_icon {
  250. width: 90rpx;
  251. height: 90rpx;
  252. }
  253. &_label {
  254. margin-top: 22rpx;
  255. font-size: 22rpx;
  256. font-weight: 500;
  257. color: #959595;
  258. }
  259. }
  260. }
  261. }
  262. .myCanvas {
  263. width: 750rpx;
  264. height: 1334rpx;
  265. }
  266. </style>