invitationCode.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="page">
  3. <view class="bgimg">
  4. <view class="dis f-c a-c">
  5. <view class="panelcanvas dis f-c a-c" id="panelcanvas">
  6. <view class="bgimg-header dis a-c mb-3" style="margin-right: auto;">
  7. <image :src="userInfo.sysUser.headSculpture? userInfo.sysUser.headSculpture :avatarImg" mode="">
  8. </image>
  9. <view class="dis f-c ml-2">
  10. <text>{{userInfo.sysUser.name ||'未知'}}</text>
  11. <text>{{userInfo.sysUser.deptName || '未知'}}</text>
  12. </view>
  13. </view>
  14. <image class="paycodeimg" :src="paycodeimg" mode="widthFix" lazy-load style="position: relative;">
  15. <image :src="logoImg" mode=""
  16. style="width: 26px;height: 26px;position: absolute;top: 0;left: 0;right: 0;bottom: 0; margin: auto;">
  17. </image>
  18. </image>
  19. <text class="mt-3 mb-5" style="font-size: 28rpx;color: #666;">扫描二维码,加入我的团队</text>
  20. </view>
  21. <view class="operation dis a-c j-c">
  22. <view class="dis f-c a-c" @click="saveImage">
  23. <image src="/static/icon/tool/saveImg.png" mode=""></image>
  24. <text class="mt-1">保存图片</text>
  25. </view>
  26. <view class="dis f-c a-c" @click="shareLink(recommendUrl)">
  27. <image src="/static/icon/tool/link.png" mode=""></image>
  28. <text class="mt-1">复制链接</text>
  29. </view>
  30. <!-- #ifdef APP-PLUS -->
  31. <view class="dis f-c a-c" @click="sendPayCode">
  32. <image src="/static/icon/tool/share.png" mode=""></image>
  33. <text class="mt-1">分享</text>
  34. </view>
  35. <!-- #endif -->
  36. </view>
  37. </view>
  38. </view>
  39. <!-- <text @click="arr">注册</text> -->
  40. </view>
  41. </template>
  42. <script>
  43. import {
  44. pathToBase64,
  45. base64ToPath
  46. } from '@/common/pdf.js'
  47. import QR from "@/common/wxqrcode.js"
  48. import {
  49. mapState,
  50. mapMutations
  51. } from "vuex"
  52. export default {
  53. data() {
  54. return {
  55. paycodeimg: '',
  56. posterUrl: "",
  57. recommendUrl: "", //邀请链接
  58. logoImg: "", //logo图片
  59. avatarImg: '', //头像
  60. }
  61. },
  62. onShow() {
  63. },
  64. onLoad() {
  65. this.paycodeimg = QR.createQrCodeImg(this.$base.h5BaseUrl + "/#/pages/registr/h5Registr?systemCode=" + this
  66. .system_code, {
  67. size: parseInt(200), //二维码大小
  68. })
  69. this.recommendUrl = this.$base.h5BaseUrl + "/#/pages/registr/h5Registr?systemCode=" + this
  70. .system_code;
  71. uni.getImageInfo({
  72. src: '../../static/image/my/logo.png',
  73. success: image => {
  74. pathToBase64(image.path)
  75. .then(base64 => {
  76. console.log(base64);
  77. this.logoImg = base64;
  78. })
  79. .catch(error => {});
  80. },
  81. fail: err => {}
  82. });
  83. uni.getImageInfo({
  84. src: '../../static/image/avatar.png',
  85. success: image => {
  86. pathToBase64(image.path)
  87. .then(base64 => {
  88. this.avatarImg = base64;
  89. })
  90. .catch(error => {});
  91. },
  92. fail: err => {}
  93. });
  94. },
  95. computed: {
  96. ...mapState(['userInfo', 'system_code'])
  97. },
  98. methods: {
  99. arr() {
  100. uni.navigateTo({
  101. url: '/pages/registr/h5Registr?systemCode=' + this
  102. .system_code,
  103. })
  104. },
  105. //复制邀请链接
  106. shareLink(value) {
  107. uni.setClipboardData({
  108. data: value, //要被复制的内容
  109. success: () => { //复制成功的回调函数
  110. uni.showToast({ //提示
  111. icon: 'none',
  112. title: '邀请链接已复制成功'
  113. })
  114. }
  115. });
  116. },
  117. //发送到微信
  118. sendPayCode() {
  119. if (this.posterUrl) {
  120. uni.share({
  121. provider: "weixin",
  122. scene: "WXSceneSession",
  123. type: 2,
  124. imageUrl: this.posterUrl
  125. })
  126. }
  127. },
  128. //保存图片
  129. saveImage() {
  130. console.log(this.posterUrl);
  131. base64ToPath(this.posterUrl)
  132. .then(path => {
  133. uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
  134. filePath: path, //图片文件路径
  135. success: function() {
  136. uni.showToast({
  137. title: '已保存到相册',
  138. icon: 'none',
  139. });
  140. },
  141. fail: function(e) {
  142. uni.showToast({
  143. title: '图片保存失败',
  144. icon: 'none',
  145. });
  146. }
  147. });
  148. })
  149. },
  150. //页面截图转路径
  151. receiveRenderData(val) {
  152. this.posterUrl = val.replace(/[\r\n]/g, ''); // 去除base64位中的空格
  153. },
  154. showLoading() {
  155. uni.showLoading({
  156. title: '正在生成图片'
  157. });
  158. },
  159. hideLoading() {
  160. uni.hideLoading();
  161. this.loading = false;
  162. },
  163. }
  164. }
  165. </script>
  166. <script module="canvasImage" lang="renderjs">
  167. import html2canvas from 'html2canvas'
  168. export default {
  169. data() {
  170. return {
  171. }
  172. },
  173. mounted() {
  174. setTimeout(() => {
  175. this.canvasImage.generateImage()
  176. }, 1000);
  177. },
  178. methods: {
  179. generateImage() {
  180. setTimeout(() => {
  181. this.$ownerInstance.callMethod('showLoading')
  182. const dom = document.getElementById('panelcanvas') // 需要生成图片内容的 dom 节点
  183. html2canvas(dom, {
  184. width: dom.clientWidth, //dom 原始宽度
  185. height: dom.clientHeight,
  186. scrollY: 0, // html2canvas默认绘制视图内的页面,需要把scrollY,scrollX设置为0
  187. scrollX: 0,
  188. useCORS: true, //支持跨域
  189. // allowTaint: false,
  190. scale: 2, // 设置生成图片的像素比例,默认是1,如果生成的图片模糊的话可以开启该配置项
  191. }).then((canvas) => {
  192. console.log(canvas);
  193. // 生成成功
  194. this.$ownerInstance.callMethod('hideLoading')
  195. this.$ownerInstance.callMethod('receiveRenderData', canvas.toDataURL('image/png'))
  196. }).catch(err => {
  197. console.log('22222222222222', err);
  198. // 生成失败 弹出提示弹窗
  199. this.$ownerInstance.callMethod('_errAlert', `【生成图片失败,请重试】${err}`)
  200. })
  201. }, 300)
  202. }
  203. },
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. page {
  208. background-color: #f8f8f8;
  209. padding: 20rpx;
  210. box-sizing: border-box;
  211. }
  212. .bgimg {
  213. width: 100%;
  214. background-image: url("../../static/image/tool/invitationCode-bg1.png");
  215. background-size: 100% 100%;
  216. background-color: #FFFFFF;
  217. border-radius: 10rpx;
  218. .bgimg-header {
  219. image {
  220. width: 90rpx;
  221. height: 90rpx;
  222. border-radius: 50%;
  223. }
  224. .ml-2 {
  225. text:first-child {
  226. font-size: 32rpx;
  227. color: #333;
  228. font-weight: bold;
  229. }
  230. text:last-child {
  231. font-size: 28rpx;
  232. color: #999;
  233. }
  234. }
  235. }
  236. .panelcanvas {
  237. position: relative;
  238. width: 100%;
  239. padding: 40rpx 40rpx 0;
  240. box-sizing: border-box;
  241. .paycodeimg {
  242. width: 340rpx;
  243. height: 340rpx;
  244. }
  245. }
  246. .operation {
  247. width: 100%;
  248. display: grid;
  249. grid-template-columns: repeat(3, 1fr);
  250. grid-template-rows: auto;
  251. row-gap: 30rpx;
  252. column-gap: 20rpx;
  253. margin-bottom: 50rpx;
  254. view {
  255. image {
  256. width: 88rpx;
  257. height: 88rpx;
  258. }
  259. text {
  260. font-size: 24rpx;
  261. color: #333;
  262. }
  263. }
  264. }
  265. }
  266. </style>