sharePage.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <uni-popup ref="popupRef">
  3. <view class="share-box">
  4. <view class="share-status-bar" :style="{'height': `${statusBarHeight}px`}"></view>
  5. <!-- statusBarHeight -->
  6. <view class="share-content">
  7. <shareInvite v-if="shareType === 1">
  8. <template #qrcode>
  9. <tki-qrcode ref="qrcodeRef" :size="100" :showLoading="false" :val="qrcodeVal" />
  10. </template>
  11. </shareInvite>
  12. <shareOrder :shareVal="shareVal" v-if="shareType === 2">
  13. <template #qrcode>
  14. <tki-qrcode ref="qrcodeRef" :size="100" :showLoading="false" :val="qrcodeVal" />
  15. </template>
  16. </shareOrder>
  17. </view>
  18. <view class="share-footer">
  19. <view class="share-list">
  20. <view class="share-icons">
  21. <text class="share-icon iconfont" style="color: #00b1ff;">&#xe65b;</text>
  22. <text class="share-text">复制链接</text>
  23. </view>
  24. <view class="share-icons">
  25. <text class="share-icon iconfont" style="color: #029a73;">&#xe631;</text>
  26. <text class="share-text">微信</text>
  27. </view>
  28. <view class="share-icons">
  29. <text class="share-icon iconfont" style="color: #02d9a2;">&#xe623;</text>
  30. <text class="share-text">朋友圈</text>
  31. </view>
  32. <view class="share-icons">
  33. <text class="share-icon iconfont" style="color: #1890ff;">&#xe66a;</text>
  34. <text class="share-text">QQ</text>
  35. </view>
  36. <view class="share-icons" @click="my_js.onclicks">
  37. <text class="share-icon iconfont" style="color: #83a0e5">&#xe63a;</text>
  38. <text class="share-text">保存图片</text>
  39. </view>
  40. </view>
  41. <view class="share-cancel" @click.stop="cancelShare">
  42. 取消
  43. </view>
  44. </view>
  45. </view>
  46. </uni-popup>
  47. </template>
  48. <script>
  49. import {
  50. mapGetters
  51. } from 'vuex'
  52. import shareInvite from "./share_01.vue"
  53. import shareOrder from "./share_02.vue"
  54. export default {
  55. name: "sharePage",
  56. components: {
  57. shareInvite,
  58. shareOrder
  59. },
  60. props: {
  61. tabBar: {
  62. type: Boolean,
  63. default: true
  64. },
  65. shareType: {
  66. type: Number,
  67. default: 1 // 1:邀请分享 2:订单分享
  68. },
  69. },
  70. data() {
  71. return {
  72. shareCode: '',
  73. shareVal:{}
  74. };
  75. },
  76. computed: {
  77. ...mapGetters([
  78. 'statusBarHeight'
  79. ])
  80. },
  81. created() {
  82. this.shareCode = this.$getStorageSync('shareCode')
  83. this.qrcodeVal = `${this.$config.shareLink}${this.shareCode}`;
  84. },
  85. mounted() {
  86. // this.$refs.popupRef.open()
  87. // setTimeout(() => {
  88. // this.$refs.qrcodeRef._makeCode()
  89. // console.log('$config', this.$refs.qrcodeRef)
  90. // },3000)
  91. },
  92. methods: {
  93. drawCode() {
  94. if (this.$refs.qrcodeRef) {
  95. this.$refs.qrcodeRef._makeCode()
  96. } else {
  97. setTimeout(() => {
  98. this.drawCode()
  99. }, 100)
  100. }
  101. },
  102. openShare(val) {
  103. this.shareVal = val
  104. this.drawCode()
  105. this.$nextTick(() => {
  106. this.showTabBar(false)
  107. this.$refs.popupRef.open()
  108. })
  109. },
  110. cancelShare() {
  111. this.$refs.popupRef.close()
  112. this.showTabBar()
  113. },
  114. showTabBar(type = true) {
  115. if (this.tabBar) {
  116. try {
  117. if (type) {
  118. uni.showTabBar();
  119. } else {
  120. uni.hideTabBar();
  121. }
  122. } catch {}
  123. }
  124. },
  125. saveBase64(imageStr) {
  126. uni.showLoading({
  127. title: "保存中",
  128. })
  129. try {
  130. let bitmap = new plus.nativeObj.Bitmap();
  131. bitmap.loadBase64Data(imageStr, function() {
  132. console.log('加载base64图片数据成功');
  133. //图片名称命名
  134. bitmap.save('_doc/' + new Date().getTime() + '.png', {
  135. quality: 100
  136. }, function(i) {
  137. // 将图片保存到相册
  138. uni.saveImageToPhotosAlbum({
  139. filePath: i.target,
  140. success: function() {
  141. bitmap.clear(); //销毁Bitmap图片
  142. // uni.$u.toast('保存图片成功')
  143. uni.showToast({
  144. title: '保存图片成功',
  145. icon: 'none',
  146. duration: 2000
  147. });
  148. // that.noPhoto = true;
  149. }
  150. });
  151. }, function(e) {
  152. console.log('保存图片失败:' + JSON.stringify(e));
  153. });
  154. }, function(e) {
  155. console.log('截屏绘制图片失败:' + JSON.stringify(e));
  156. });
  157. } catch {
  158. uni.hideLoading()
  159. }
  160. },
  161. }
  162. }
  163. </script>
  164. <script module="my_js" lang="renderjs">
  165. import html2canvas from 'html2canvas';
  166. export default {
  167. data() {
  168. return {}
  169. },
  170. methods: {
  171. onclicks(event, ownerInstance) {
  172. console.log(99)
  173. html2canvas(document.getElementById('share-content'), {
  174. backgroundColor: '#fff',
  175. useCORS: true,
  176. taintTest: true,
  177. timeout: 2000
  178. }).then(canvas => {
  179. let imgurl = canvas.toDataURL('image/jpg');
  180. ownerInstance.callMethod('saveBase64', imgurl)
  181. })
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. .share-box {
  188. width: 750rpx;
  189. height: 100vh;
  190. display: flex;
  191. flex-direction: column;
  192. .share-status-bar {
  193. flex-shrink: 0;
  194. width: 100%;
  195. background-color: rgba(255, 255, 255, 0.5);
  196. }
  197. .share-content {
  198. flex: 1;
  199. padding: 30rpx 40rpx;
  200. }
  201. .share-footer {
  202. flex-shrink: 0;
  203. .share-list {
  204. border-radius: 40rpx 40rpx 0 0;
  205. width: 100%;
  206. padding: 30rpx 30rpx;
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: stretch;
  210. background-color: #f6f7fc;
  211. }
  212. .share-icons {
  213. display: flex;
  214. flex-direction: column;
  215. justify-content: center;
  216. align-items: center;
  217. .share-icon {
  218. font-size: 100rpx;
  219. color: red;
  220. }
  221. .share-text {
  222. font-size: 24rpx;
  223. padding-top: 10rpx;
  224. }
  225. }
  226. .share-cancel {
  227. width: 100%;
  228. height: 100rpx;
  229. line-height: 100rpx;
  230. background-color: #fff;
  231. text-align: center;
  232. font-size: 34rpx;
  233. color: #c0c0c0;
  234. }
  235. }
  236. // <view class="share-content"></view>
  237. // <view class="share-share"></view>
  238. }
  239. </style>