share.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view id="share_container">
  3. <view id="erweima" style="display: none;"></view>
  4. <image style="width: 0; height: 0;" src="../../static/avatar.jpg"></image>
  5. <!-- <view class="qrimg">
  6. <tki-qrcode
  7. ref="qrcode"
  8. :val="val"
  9. :icon="icon"
  10. :size="size"
  11. :background="background"
  12. :foreground="foreground"
  13. :pdground="pdground"
  14. :lv="lv"
  15. :onval="onval"
  16. :loadMake="loadMake"/>
  17. <view class="text">
  18. 长按识别二维码填写表单
  19. </view>
  20. </view> -->
  21. <view id="imgWrapper">
  22. <image class="showCan" v-if="src" :src="src" ></image>
  23. </view>
  24. <view class="basecolor sharetext">{{ src ? '长按二维码发送给客户即可邀请加入' : '' }}</view>
  25. </view>
  26. </template>
  27. <script>
  28. import { _API_GzhWebInit } from '@/apis/verify.js'
  29. import tkiQrcode from "@/components/tki-qrcode/tki-qrcode.vue"
  30. import { mapState } from 'vuex'
  31. export default {
  32. components: {tkiQrcode},
  33. name: 'ShareIndex',
  34. data() {
  35. return {
  36. src: '',
  37. imp:'../../static/index.html',
  38. platform:'',
  39. val: 'http://192.168.0.12:8080/api/gzh?id=1347', // 要生成的二维值 可以跳转一个新界面
  40. size: 450, // 二维码大小
  41. background: '#fff', // 背景色
  42. foreground: '#000000', // 前景色
  43. pdground: '#000000', // 角标色
  44. lv: 3, // 二维码容错级别 , 一般不用设置,默认就行
  45. onval: true, // val值变化时自动重新生成二维码 (一定要注意这个值的设置 刷新二维码使用的)
  46. loadMake: true, // 组件加载完成后自动生成二维码
  47. icon:'../../static/avatar.jpg'
  48. }
  49. },
  50. onShow() {
  51. // var that = this
  52. // uni.getSystemInfo({
  53. // success(res) {
  54. // that.platform=res.platform
  55. // }
  56. // })
  57. // _API_GzhWebInit().then(res => {
  58. // this.val=res.url
  59. // console.log(res.url)
  60. // })
  61. },
  62. computed: {
  63. ...mapState([
  64. 'userinfo'
  65. ])
  66. },
  67. onShow() {
  68. const script = document.createElement('script')
  69. script.type = 'text/javascript'
  70. script.src = 'http://res.wx.qq.com/open/js/jweixin-1.4.0.js'
  71. document.getElementsByTagName('head')[0].appendChild(script)
  72. let { nickname, id } = this.userinfo
  73. script.onload = () => {
  74. _API_GzhWebInit().then(res => {
  75. setTimeout(() => {
  76. // res.url = "http://192.168.0.12:8080/api/gzh?id=1347"
  77. const img = document.getElementsByTagName('img')[0]
  78. $('#erweima').qrcode({ width: 333, height: 333, text: res.url })
  79. document.getElementsByTagName('canvas')[0].getContext('2d').drawImage(img, 123, 123, 80, 80)
  80. wx.config(res)
  81. wx.ready(() => {
  82. wx.updateAppMessageShareData({
  83. title: `我是${this.$store.state.userinfo.nickname}, 邀请你加入大卫博士`,
  84. desc: '传递健康,改变命运。',
  85. link: res.url,
  86. imgUrl: 'http://api.woaidakele.cn/public/uploads/logo.jpg'
  87. })
  88. })
  89. wx.error(res => window.history.replaceState({}, '', `/api/gzh/david`))
  90. uni.hideLoading()
  91. const can = document.createElement('canvas')
  92. const ctx = can.getContext('2d')
  93. const ratio = window.devicePixelRatio || 1
  94. can.width = uni.upx2px(680)
  95. can.height = uni.upx2px(960)
  96. ctx.fillStyle="#ffffff";
  97. ctx.fillRect(0, 0, uni.upx2px(680), uni.upx2px(960));
  98. ctx.fillStyle="#000000";
  99. ctx.font=`${uni.upx2px(42)}px Arial`;
  100. ctx.textAlign="center";
  101. ctx.drawImage(img, uni.upx2px(276), uni.upx2px(16), uni.upx2px(128), uni.upx2px(128))
  102. ctx.fillText(`“${nickname.length > 18 ? nickname.slice(0, 18) + '...' : nickname }”`, uni.upx2px(340), uni.upx2px(206))
  103. ctx.fillStyle="#333333";
  104. ctx.font=`${uni.upx2px(36)}px Arial`;
  105. ctx.fillText(`邀请你加入大卫博士`, uni.upx2px(340), uni.upx2px(271))
  106. ctx.drawImage(document.getElementsByTagName('canvas')[0], uni.upx2px(80), uni.upx2px(332), uni.upx2px(517), uni.upx2px(518))
  107. ctx.font=`${uni.upx2px(36)}px Arial`;
  108. ctx.fillStyle="#F76454";
  109. ctx.fillText(`长按-识别二维码-填写信息`, uni.upx2px(340), uni.upx2px(910))
  110. this.src = can.toDataURL("image/png")
  111. })
  112. })
  113. }
  114. }
  115. }
  116. </script>
  117. <style scoped lang="scss">
  118. .qrimg{
  119. height: 1000rpx;
  120. display: flex;
  121. justify-content: center;
  122. align-items: center;
  123. flex-direction: column;
  124. .text{
  125. font-size: 36rpx;
  126. font-weight: bold;
  127. margin-top: 30rpx;
  128. }
  129. }
  130. #share_container {
  131. // height: 100%;
  132. display: flex;
  133. justify-content: space-between;
  134. flex-direction: column;
  135. }
  136. #imgWrapper {
  137. flex: 1;
  138. @include flex();
  139. .showCan {
  140. width: 680rpx;
  141. height: 960rpx;
  142. border-radius: 14rpx;
  143. box-shadow:0px 0px 23px 2px rgba(194,133,58,0.5);
  144. }
  145. }
  146. .sharetext {
  147. font-size: 80rpx;
  148. text-align: center;
  149. margin: 8rpx 0;
  150. box-sizing: border-box;
  151. padding: 30rpx 24rpx;
  152. }
  153. </style>