sharePage.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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="130" :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="130" :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" @click.stop="copyLink()">
  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. import {
  56. Way_getSetting
  57. } from "@/utils/common-request.js"
  58. export default {
  59. name: "sharePage",
  60. components: {
  61. shareInvite,
  62. shareOrder
  63. },
  64. props: {
  65. tabBar: {
  66. type: Boolean,
  67. default: true
  68. },
  69. shareType: {
  70. type: Number,
  71. default: 1 // 1:邀请分享 2:订单分享
  72. },
  73. },
  74. data() {
  75. return {
  76. register_url:'',
  77. shareCode: '',
  78. shareVal: {}
  79. };
  80. },
  81. computed: {
  82. ...mapGetters([
  83. 'statusBarHeight'
  84. ])
  85. },
  86. watch:{
  87. register_url:{
  88. // http: //register.okenx.com
  89. handler(newUrl){
  90. if(newUrl){
  91. this.qrcodeVal = `${newUrl}/#/pages/register?extension_code=${this.shareCode}`
  92. console.log('this.qrcodeVal = ' , this.qrcodeVal)
  93. this.drawCode()
  94. }
  95. },
  96. immediate:true
  97. }
  98. },
  99. created() {
  100. this.shareCode = this.$getStorageSync('shareCode')
  101. this.register_url = this.$getStorageSync('register_url') || ''
  102. if (!this.register_url) {
  103. Way_getSetting().then(res => {
  104. this.register_url = res.register_url
  105. })
  106. }
  107. // this.qrcodeVal = `${this.$config.shareLink}${this.shareCode}`;
  108. },
  109. mounted() {
  110. // this.$refs.popupRef.open()
  111. // setTimeout(() => {
  112. // this.$refs.qrcodeRef._makeCode()
  113. // console.log('$config', this.$refs.qrcodeRef)
  114. // },3000)
  115. },
  116. methods: {
  117. copyLink() {
  118. uni.setClipboardData({
  119. data: this.qrcodeVal,
  120. success: res => {
  121. uni.showToast({
  122. title: '复制成功',
  123. icon: 'none'
  124. })
  125. }
  126. });
  127. },
  128. drawCode() {
  129. if (this.$refs.qrcodeRef) {
  130. this.$refs.qrcodeRef._makeCode()
  131. } else {
  132. setTimeout(() => {
  133. this.drawCode()
  134. }, 50)
  135. }
  136. },
  137. openShare(val) {
  138. this.shareVal = val
  139. this.$nextTick(() => {
  140. this.showTabBar(false)
  141. this.$refs.popupRef.open()
  142. })
  143. },
  144. cancelShare() {
  145. this.$refs.popupRef.close()
  146. this.showTabBar()
  147. },
  148. showTabBar(type = true) {
  149. if (this.tabBar) {
  150. try {
  151. if (type) {
  152. uni.showTabBar();
  153. } else {
  154. uni.hideTabBar();
  155. }
  156. } catch {}
  157. }
  158. },
  159. saveBase64(imageStr) {
  160. uni.showLoading({
  161. title: "保存中",
  162. })
  163. try {
  164. let bitmap = new plus.nativeObj.Bitmap();
  165. bitmap.loadBase64Data(imageStr, function() {
  166. console.log('加载base64图片数据成功');
  167. //图片名称命名
  168. bitmap.save('_doc/' + new Date().getTime() + '.png', {
  169. quality: 100
  170. }, function(i) {
  171. // 将图片保存到相册
  172. uni.saveImageToPhotosAlbum({
  173. filePath: i.target,
  174. success: function() {
  175. bitmap.clear(); //销毁Bitmap图片
  176. // uni.$u.toast('保存图片成功')
  177. uni.showToast({
  178. title: '保存图片成功',
  179. icon: 'none',
  180. duration: 2000
  181. });
  182. // that.noPhoto = true;
  183. }
  184. });
  185. }, function(e) {
  186. console.log('保存图片失败:' + JSON.stringify(e));
  187. });
  188. }, function(e) {
  189. console.log('截屏绘制图片失败:' + JSON.stringify(e));
  190. });
  191. } catch {
  192. uni.hideLoading()
  193. }
  194. },
  195. }
  196. }
  197. </script>
  198. <script module="my_js" lang="renderjs">
  199. import html2canvas from 'html2canvas';
  200. export default {
  201. data() {
  202. return {}
  203. },
  204. methods: {
  205. onclicks(event, ownerInstance) {
  206. console.log(99)
  207. html2canvas(document.getElementById('share-content'), {
  208. backgroundColor: '#fff',
  209. useCORS: true,
  210. taintTest: true,
  211. timeout: 2000
  212. }).then(canvas => {
  213. let imgurl = canvas.toDataURL('image/jpg');
  214. ownerInstance.callMethod('saveBase64', imgurl)
  215. })
  216. }
  217. }
  218. }
  219. </script>
  220. <style lang="scss" scoped>
  221. .share-box {
  222. width: 750rpx;
  223. height: 100vh;
  224. display: flex;
  225. flex-direction: column;
  226. .share-status-bar {
  227. flex-shrink: 0;
  228. width: 100%;
  229. background-color: rgba(255, 255, 255, 0.5);
  230. }
  231. .share-content {
  232. flex: 1;
  233. padding: 30rpx 40rpx;
  234. }
  235. .share-footer {
  236. flex-shrink: 0;
  237. .share-list {
  238. border-radius: 40rpx 40rpx 0 0;
  239. width: 100%;
  240. padding: 30rpx 30rpx;
  241. display: flex;
  242. justify-content: space-between;
  243. align-items: stretch;
  244. background-color: #f6f7fc;
  245. }
  246. .share-icons {
  247. display: flex;
  248. flex-direction: column;
  249. justify-content: center;
  250. align-items: center;
  251. .share-icon {
  252. font-size: 100rpx;
  253. color: red;
  254. }
  255. .share-text {
  256. font-size: 24rpx;
  257. padding-top: 10rpx;
  258. }
  259. }
  260. .share-cancel {
  261. width: 100%;
  262. height: 100rpx;
  263. line-height: 100rpx;
  264. background-color: #fff;
  265. text-align: center;
  266. font-size: 34rpx;
  267. color: #c0c0c0;
  268. }
  269. }
  270. // <view class="share-content"></view>
  271. // <view class="share-share"></view>
  272. }
  273. </style>