forward.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="default_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='转发推荐'></cus-header>
  4. <div class="all adffc">
  5. <div class="box adffcac">
  6. <div class="box-code adffcac">
  7. <div class="box-code-ewm">
  8. <canvas canvas-id="qrcode" style="width:274rpx;height:274rpx; position: fixed;left: -9999px;top: -9999px;"></canvas>
  9. <image v-if="qrCodeDataURL" :src="qrCodeDataURL" mode="scaleToFill" show-menu-by-longpress></image>
  10. </div>
  11. </div>
  12. <div class="box-code-tip">扫码立即体验</div>
  13. <button class="share-btn" open-type="share">
  14. <image :src="imgBase+'btn_share.png'"></image>
  15. </button>
  16. </div>
  17. </div>
  18. </view>
  19. </template>
  20. <script>
  21. import { BaseApi } from '@/http/baseApi.js'
  22. import UQrcode from '@/uqrcode.js'
  23. export default {
  24. data(){
  25. return {
  26. imgBase:this.$imgBase,
  27. qrCodeDataURL:'',
  28. qrVal:'https://wxapp.transcend-intl.cn',
  29. }
  30. },
  31. onLoad() {
  32. this.generateQRCode();
  33. if(uni.getStorageSync('userInfo')){
  34. this.qrVal = `https://wxapp.transcend-intl.cn?shareUserId=${JSON.parse(uni.getStorageSync('userInfo'))?.id||''}`;
  35. }
  36. },
  37. methods:{
  38. onShareAppMessage(res) {
  39. const sharerId = JSON.parse(uni.getStorageSync('userInfo'))?.id||'';
  40. return {
  41. title: '致力于帮助企业打造高价值创造团队',
  42. path: `/pages/home?shareUserId=${sharerId}&shareType=Forward`,
  43. };
  44. },
  45. async generateQRCode(){
  46. try {
  47. let that = this;
  48. const canvasSizePx = uni.upx2px(266);
  49. // 确保DOM已经更新,canvas元素已准备好
  50. this.$nextTick(() => {
  51. UQrcode.make({
  52. canvasId: 'qrcode',
  53. componentInstance: this,
  54. text: that.qrVal,
  55. size: canvasSizePx, // 对应 266rpx 的物理像素大小
  56. margin: 0,
  57. backgroundColor: '#ffffff',
  58. foregroundColor: '#000000',
  59. fileType: 'png',
  60. errorCorrectLevel: UQrcode.errorCorrectLevel.H,
  61. success: res => {
  62. uni.canvasToTempFilePath({
  63. canvasId: 'qrcode',
  64. fileType: 'png',
  65. quality: 1,
  66. success: (canvasRes) => {
  67. that.qrCodeDataURL = canvasRes.tempFilePath;
  68. },
  69. fail: (err) => {
  70. that.qrCodeDataURL = res;
  71. }
  72. }, this);
  73. }
  74. });
  75. });
  76. } catch { }
  77. },
  78. }
  79. }
  80. </script>
  81. <style scoped lang="scss">
  82. .share-btn {
  83. width: 226rpx;
  84. height: 56rpx;
  85. background: linear-gradient( 180deg, #CFD9A4 0%, #029292 100%);
  86. border-radius: 28rpx;
  87. border: none;
  88. padding: 0;
  89. margin: 0;
  90. margin-top: 46rpx;
  91. line-height: inherit;
  92. &::after {
  93. border: none;
  94. }
  95. image{
  96. width: 100%;
  97. height: 100%;
  98. }
  99. }
  100. .default_page{
  101. box-sizing: border-box;
  102. .all{
  103. width: 100%;
  104. flex: 1;
  105. padding: 0 30rpx 62rpx;
  106. box-sizing: border-box;
  107. justify-content: flex-end;
  108. background: url('https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/forward_bg.png') no-repeat;
  109. background-size: 100% 100%;
  110. }
  111. .box{
  112. width: 100%;
  113. background: rgba(255,255,255,0.14);
  114. border-radius: 16rpx;
  115. padding: 36rpx 172rpx;
  116. box-sizing: border-box;
  117. &-code{
  118. background: #FFFFFF;
  119. border-radius: 16rpx;
  120. padding: 27rpx 40rpx;
  121. &-ewm{
  122. width: 266rpx;
  123. height: 266rpx;
  124. image{
  125. width: 100%;
  126. height: 100%;
  127. }
  128. }
  129. &-tip{
  130. font-family: PingFangSC, PingFang SC;
  131. font-weight: 600;
  132. font-size: 50rpx;
  133. color: #FFFFFF;
  134. line-height: 50rpx;
  135. letter-spacing: 2px;
  136. margin-top: 24rpx;
  137. }
  138. }
  139. }
  140. }
  141. </style>