sharePage.vue 5.8 KB

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