sharePage.vue 6.5 KB

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