forward.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. // 确保DOM已经更新,canvas元素已准备好
  49. this.$nextTick(() => {
  50. UQrcode.make({
  51. canvasId: 'qrcode',
  52. componentInstance: this,
  53. text: that.qrVal,
  54. size: 133, // 对应 266rpx 的物理像素大小
  55. margin: 0,
  56. backgroundColor: '#ffffff',
  57. foregroundColor: '#000000',
  58. fileType: 'png',
  59. errorCorrectLevel: UQrcode.errorCorrectLevel.H,
  60. success: res => {
  61. uni.canvasToTempFilePath({
  62. canvasId: 'qrcode',
  63. fileType: 'png',
  64. quality: 1,
  65. success: (canvasRes) => {
  66. that.qrCodeDataURL = canvasRes.tempFilePath;
  67. },
  68. fail: (err) => {
  69. that.qrCodeDataURL = res;
  70. }
  71. }, this);
  72. }
  73. });
  74. });
  75. } catch { }
  76. },
  77. }
  78. }
  79. </script>
  80. <style scoped lang="scss">
  81. .share-btn {
  82. width: 226rpx;
  83. height: 56rpx;
  84. background: linear-gradient( 180deg, #CFD9A4 0%, #029292 100%);
  85. border-radius: 28rpx;
  86. border: none;
  87. padding: 0;
  88. margin: 0;
  89. margin-top: 46rpx;
  90. line-height: inherit;
  91. &::after {
  92. border: none;
  93. }
  94. image{
  95. width: 100%;
  96. height: 100%;
  97. }
  98. }
  99. .default_page{
  100. box-sizing: border-box;
  101. .all{
  102. width: 100%;
  103. flex: 1;
  104. padding: 0 30rpx 62rpx;
  105. box-sizing: border-box;
  106. justify-content: flex-end;
  107. background: url('https://gitee.com/hw_0302/chuang-heng-wechat-images/raw/master/forward_bg.png') no-repeat;
  108. background-size: 100% 100%;
  109. }
  110. .box{
  111. width: 100%;
  112. background: rgba(255,255,255,0.14);
  113. border-radius: 16rpx;
  114. padding: 36rpx 172rpx;
  115. box-sizing: border-box;
  116. &-code{
  117. background: #FFFFFF;
  118. border-radius: 16rpx;
  119. padding: 27rpx 40rpx;
  120. &-ewm{
  121. width: 266rpx;
  122. height: 266rpx;
  123. image{
  124. width: 100%;
  125. height: 100%;
  126. }
  127. }
  128. &-tip{
  129. font-family: PingFangSC, PingFang SC;
  130. font-weight: 600;
  131. font-size: 50rpx;
  132. color: #FFFFFF;
  133. line-height: 50rpx;
  134. letter-spacing: 2px;
  135. margin-top: 24rpx;
  136. }
  137. }
  138. }
  139. }
  140. </style>