invitationCode.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. Info: {}
  61. }
  62. },
  63. onShow() {
  64. },
  65. async onLoad() {
  66. await this.getUserInfo()//获取用户信息
  67. this.paycodeimg = QR.createQrCodeImg(this.$base.h5BaseUrl + "/#/pages/registr/h5Registr?systemCode=" + this
  68. .system_code+'&info='+JSON.stringify({
  69. name: this.Info.name,
  70. infoId: this.Info.infoId,
  71. id: this.Info.id,
  72. headSculpture: this.Info.headSculpture,
  73. deptName: this.Info.deptName,
  74. }), {
  75. size: parseInt(200), //二维码大小
  76. })
  77. this.recommendUrl = this.$base.h5BaseUrl + "/#/pages/registr/h5Registr?systemCode=" + this
  78. .system_code+'&info='+JSON.stringify({
  79. name: this.Info.name,
  80. infoId: this.Info.infoId,
  81. id: this.Info.id,
  82. headSculpture: this.Info.headSculpture,
  83. deptName: this.Info.deptName,
  84. });
  85. console.log(this.recommendUrl);
  86. uni.getImageInfo({
  87. src: '../../static/image/my/logo.png',
  88. success: image => {
  89. pathToBase64(image.path)
  90. .then(base64 => {
  91. console.log(base64);
  92. this.logoImg = base64;
  93. })
  94. .catch(error => {});
  95. },
  96. fail: err => {}
  97. });
  98. uni.getImageInfo({
  99. src: '../../static/image/avatar.png',
  100. success: image => {
  101. pathToBase64(image.path)
  102. .then(base64 => {
  103. this.avatarImg = base64;
  104. })
  105. .catch(error => {});
  106. },
  107. fail: err => {}
  108. });
  109. },
  110. computed: {
  111. ...mapState(['userInfo', 'system_code'])
  112. },
  113. methods: {
  114. async getUserInfo() {
  115. let res = await this.$http.get('/appUser/userInfoGet'); //获取人员信息
  116. if (res.code == '200') {
  117. this.Info = res.data
  118. }
  119. },
  120. arr() {
  121. uni.navigateTo({
  122. url: '/pages/registr/h5Registr?systemCode=' + this
  123. .system_code,
  124. })
  125. },
  126. //复制邀请链接
  127. shareLink(value) {
  128. uni.setClipboardData({
  129. data: value, //要被复制的内容
  130. success: () => { //复制成功的回调函数
  131. uni.showToast({ //提示
  132. icon: 'none',
  133. title: '邀请链接已复制成功'
  134. })
  135. }
  136. });
  137. },
  138. //发送到微信
  139. sendPayCode() {
  140. if (this.posterUrl) {
  141. uni.share({
  142. provider: "weixin",
  143. scene: "WXSceneSession",
  144. type: 2,
  145. imageUrl: this.posterUrl
  146. })
  147. }
  148. },
  149. //保存图片
  150. saveImage() {
  151. console.log(this.posterUrl);
  152. base64ToPath(this.posterUrl)
  153. .then(path => {
  154. uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
  155. filePath: path, //图片文件路径
  156. success: function() {
  157. uni.showToast({
  158. title: '已保存到相册',
  159. icon: 'none',
  160. });
  161. },
  162. fail: function(e) {
  163. uni.showToast({
  164. title: '图片保存失败',
  165. icon: 'none',
  166. });
  167. }
  168. });
  169. })
  170. },
  171. //页面截图转路径
  172. receiveRenderData(val) {
  173. this.posterUrl = val.replace(/[\r\n]/g, ''); // 去除base64位中的空格
  174. },
  175. showLoading() {
  176. uni.showLoading({
  177. title: '正在生成图片'
  178. });
  179. },
  180. hideLoading() {
  181. uni.hideLoading();
  182. this.loading = false;
  183. },
  184. }
  185. }
  186. </script>
  187. <script module="canvasImage" lang="renderjs">
  188. import html2canvas from 'html2canvas'
  189. export default {
  190. data() {
  191. return {
  192. }
  193. },
  194. mounted() {
  195. setTimeout(() => {
  196. this.canvasImage.generateImage()
  197. }, 1000);
  198. },
  199. methods: {
  200. generateImage() {
  201. setTimeout(() => {
  202. this.$ownerInstance.callMethod('showLoading')
  203. const dom = document.getElementById('panelcanvas') // 需要生成图片内容的 dom 节点
  204. html2canvas(dom, {
  205. width: dom.clientWidth, //dom 原始宽度
  206. height: dom.clientHeight,
  207. scrollY: 0, // html2canvas默认绘制视图内的页面,需要把scrollY,scrollX设置为0
  208. scrollX: 0,
  209. useCORS: true, //支持跨域
  210. // allowTaint: false,
  211. scale: 2, // 设置生成图片的像素比例,默认是1,如果生成的图片模糊的话可以开启该配置项
  212. }).then((canvas) => {
  213. console.log(canvas);
  214. // 生成成功
  215. this.$ownerInstance.callMethod('hideLoading')
  216. this.$ownerInstance.callMethod('receiveRenderData', canvas.toDataURL('image/png'))
  217. }).catch(err => {
  218. console.log('22222222222222', err);
  219. // 生成失败 弹出提示弹窗
  220. this.$ownerInstance.callMethod('_errAlert', `【生成图片失败,请重试】${err}`)
  221. })
  222. }, 300)
  223. }
  224. },
  225. }
  226. </script>
  227. <style lang="scss" scoped>
  228. page {
  229. background-color: #f8f8f8;
  230. padding: 20rpx;
  231. box-sizing: border-box;
  232. }
  233. .bgimg {
  234. width: 100%;
  235. background-image: url("../../static/image/tool/invitationCode-bg1.png");
  236. background-size: 100% 100%;
  237. background-color: #FFFFFF;
  238. border-radius: 10rpx;
  239. .bgimg-header {
  240. image {
  241. width: 90rpx;
  242. height: 90rpx;
  243. border-radius: 50%;
  244. }
  245. .ml-2 {
  246. text:first-child {
  247. font-size: 32rpx;
  248. color: #333;
  249. font-weight: bold;
  250. }
  251. text:last-child {
  252. font-size: 28rpx;
  253. color: #999;
  254. }
  255. }
  256. }
  257. .panelcanvas {
  258. position: relative;
  259. width: 100%;
  260. padding: 40rpx 40rpx 0;
  261. box-sizing: border-box;
  262. .paycodeimg {
  263. width: 340rpx;
  264. height: 340rpx;
  265. }
  266. }
  267. .operation {
  268. width: 100%;
  269. display: grid;
  270. grid-template-columns: repeat(3, 1fr);
  271. grid-template-rows: auto;
  272. row-gap: 30rpx;
  273. column-gap: 20rpx;
  274. margin-bottom: 50rpx;
  275. view {
  276. image {
  277. width: 88rpx;
  278. height: 88rpx;
  279. }
  280. text {
  281. font-size: 24rpx;
  282. color: #333;
  283. }
  284. }
  285. }
  286. }
  287. </style>