AppShare.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view class="share-container">
  3. <uni-popup ref="popup" type="center">
  4. <view class="wrapper" v-if="popShow">
  5. <canvas canvas-id="shareCanvas" class="canvas" style="width: 250px;height:430px;"></canvas>
  6. <view class="bottom">
  7. <button class="bottom-btn" open-type="share">
  8. <image :src="static + 'wechat.png'"></image>
  9. <view class="text">分享好友</view>
  10. </button>
  11. <view class="bottom-btn" @click="saveImageToPhotos('shareCanvas')">
  12. <image :src="static + 'download.png'"></image>
  13. <view class="text">保存图片</view>
  14. </view>
  15. </view>
  16. </view>
  17. </uni-popup>
  18. </view>
  19. </template>
  20. <script lang="ts">
  21. // @ts-nocheck
  22. import {
  23. Component,
  24. Prop,
  25. Vue,
  26. Emit,
  27. Mixins
  28. } from 'vue-property-decorator';
  29. import {
  30. types
  31. } from '@/common/store';
  32. import {
  33. OSS_STATIC
  34. } from '@/common/constants';
  35. import canvasMixin from '@/common/mixins/canvasMixin.ts';
  36. import {
  37. namespace
  38. } from 'vuex-class';
  39. const canvasModule = namespace('canvas');
  40. const baseModule = namespace('base');
  41. @Component({})
  42. export default class ShopShare extends Mixins(canvasMixin) {
  43. @canvasModule.Getter('_canvasData') _canvasData: any;
  44. @baseModule.Getter('_userInfo') _userInfo: any;
  45. popShow: boolean = false;
  46. static: string = OSS_STATIC;
  47. closePop(): void {
  48. (this.$refs.popup as any).close();
  49. this.popShow = false;
  50. }
  51. openPop(): void {
  52. (this.$refs.popup as any).open();
  53. this.popShow = true;
  54. uni.showLoading({
  55. title: '加载中'
  56. });
  57. this.drawPoster();
  58. }
  59. mounted() {}
  60. drawPoster(): void {
  61. // 绘制海报
  62. // 注意:page页面canvas-id获取ctx,组件需传this
  63. const that = this;
  64. const ctx = uni.createCanvasContext('shareCanvas', this);
  65. // 绘制白色底
  66. this.roundRect(ctx, 0, 0, 250, 460, '#ffffff', 8, 8, 8, 8);
  67. this.roundRect(ctx, 0, 0, 250, 48, '#fff', 8, 0, 0, 8);
  68. // 绘制头像
  69. this.drawCircular(ctx, 24, 24, 13, 15, that._canvasData.avatar);
  70. this.ellipsisText(
  71. ctx,
  72. that._userInfo.nickname,
  73. 200,
  74. 43,
  75. 13,
  76. '#999',
  77. '10px',
  78. 14
  79. );
  80. // 绘制宣传语
  81. this.ellipsisText(
  82. ctx,
  83. that._canvasData.tips,
  84. 200,
  85. 43,
  86. 27,
  87. '#454545',
  88. '10px',
  89. 14
  90. );
  91. this.textSet(ctx, '”', '45px', 135, 20, '#ddd');
  92. // 绘制店铺图片
  93. this.drawImgInfo(
  94. ctx,
  95. 10,
  96. 50,
  97. 230,
  98. 230,
  99. that._canvasData.shareImg,
  100. // that._canvasData.width,
  101. // that._canvasData.height
  102. );
  103. // this.textSet(ctx, that._canvasData.title, '24px', 13, 360, '#333', 'bold ');
  104. this.textSet(ctx, '标题', '10px', 13, 348, '#999');
  105. this.textSet(ctx, '绿价比', '14px', 13, 365, '#000', 'bold ');
  106. // // 小程序码
  107. ctx.drawImage(that._canvasData.qr, 150, 295, 90, 90);
  108. this.textSet(ctx, '长按识别进店铺', '10px', 90, 400, '#999999');
  109. ctx.draw(true, () => {
  110. console.log('draw,true');
  111. uni.hideLoading();
  112. });
  113. }
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. .wrapper {
  118. @include flex-y();
  119. width: 250px;
  120. }
  121. .canvas {
  122. border-radius: vw(5);
  123. overflow: hidden;
  124. margin-top: vw(50);
  125. }
  126. .bottom {
  127. width: 230px;
  128. margin-top: vw(15);
  129. @include flex-x();
  130. .text {
  131. @include word-vw(14, white);
  132. line-height: vw(20);
  133. margin-top: vw(5);
  134. }
  135. image {
  136. width: vw(60);
  137. height: vw(60);
  138. }
  139. }
  140. button {
  141. background: none;
  142. line-height: 1;
  143. padding: 0;
  144. margin: 0;
  145. }
  146. button::after {
  147. border: 0px;
  148. }
  149. .button-hover {
  150. background: none;
  151. }
  152. </style>