invitationCode.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. uni.getImageInfo({
  86. src: '../../static/image/my/logo.png',
  87. success: image => {
  88. pathToBase64(image.path)
  89. .then(base64 => {
  90. this.logoImg = base64;
  91. })
  92. .catch(error => {});
  93. },
  94. fail: err => {}
  95. });
  96. uni.getImageInfo({
  97. src: '../../static/image/avatar.png',
  98. success: image => {
  99. pathToBase64(image.path)
  100. .then(base64 => {
  101. this.avatarImg = base64;
  102. })
  103. .catch(error => {});
  104. },
  105. fail: err => {}
  106. });
  107. },
  108. computed: {
  109. ...mapState(['userInfo', 'system_code'])
  110. },
  111. methods: {
  112. async getUserInfo() {
  113. let res = await this.$http.get('/appUser/userInfoGet'); //获取人员信息
  114. if (res.code == '200') {
  115. this.Info = res.data
  116. }
  117. },
  118. arr() {
  119. uni.navigateTo({
  120. url: '/pages/registr/h5Registr?systemCode=' + this
  121. .system_code,
  122. })
  123. },
  124. //复制邀请链接
  125. shareLink(value) {
  126. uni.setClipboardData({
  127. data: value, //要被复制的内容
  128. success: () => { //复制成功的回调函数
  129. uni.showToast({ //提示
  130. icon: 'none',
  131. title: '邀请链接已复制成功'
  132. })
  133. }
  134. });
  135. },
  136. //发送到微信
  137. sendPayCode() {
  138. if (this.posterUrl) {
  139. uni.share({
  140. provider: "weixin",
  141. scene: "WXSceneSession",
  142. type: 2,
  143. imageUrl: this.posterUrl
  144. })
  145. }
  146. },
  147. //保存图片
  148. saveImage() {
  149. //posterUrl 由 renderjs + html2canvas 截图生成
  150. if (!this.posterUrl) {
  151. uni.showToast({
  152. title: '海报生成中,请稍后再试',
  153. icon: 'none',
  154. });
  155. return;
  156. }
  157. // #ifdef H5
  158. //zhApp 当前 uni-app 的 H5 运行时未实现 saveImageToPhotosAlbum,
  159. //故手动用 a 标签触发浏览器下载(zgcx 是框架自带下载降级,这里需要自己处理)
  160. const a = document.createElement('a');
  161. a.href = this.posterUrl;
  162. a.download = '邀请海报.png';
  163. document.body.appendChild(a);
  164. a.click();
  165. document.body.removeChild(a);
  166. uni.showToast({
  167. title: '已开始下载,请查看浏览器下载记录',
  168. icon: 'none',
  169. });
  170. // #endif
  171. // #ifdef APP-PLUS
  172. base64ToPath(this.posterUrl)
  173. .then(path => {
  174. uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
  175. filePath: path, //图片文件路径
  176. success: function() {
  177. uni.showToast({
  178. title: '已保存到相册',
  179. icon: 'none',
  180. });
  181. },
  182. fail: function(e) {
  183. uni.showToast({
  184. title: '图片保存失败',
  185. icon: 'none',
  186. });
  187. }
  188. });
  189. })
  190. // #endif
  191. },
  192. //页面截图转路径
  193. receiveRenderData(val) {
  194. this.posterUrl = val.replace(/[\r\n]/g, ''); // 去除base64位中的空格
  195. },
  196. showLoading() {
  197. uni.showLoading({
  198. title: '正在生成图片'
  199. });
  200. },
  201. hideLoading() {
  202. uni.hideLoading();
  203. this.loading = false;
  204. },
  205. }
  206. }
  207. </script>
  208. <script module="canvasImage" lang="renderjs">
  209. import html2canvas from 'html2canvas'
  210. export default {
  211. data() {
  212. return {
  213. }
  214. },
  215. mounted() {
  216. setTimeout(() => {
  217. this.canvasImage.generateImage()
  218. }, 1000);
  219. },
  220. methods: {
  221. generateImage() {
  222. setTimeout(() => {
  223. this.$ownerInstance.callMethod('showLoading')
  224. const dom = document.getElementById('panelcanvas') // 需要生成图片内容的 dom 节点
  225. html2canvas(dom, {
  226. width: dom.clientWidth, //dom 原始宽度
  227. height: dom.clientHeight,
  228. scrollY: 0, // html2canvas默认绘制视图内的页面,需要把scrollY,scrollX设置为0
  229. scrollX: 0,
  230. useCORS: true, //支持跨域
  231. // allowTaint: false,
  232. scale: 2, // 设置生成图片的像素比例,默认是1,如果生成的图片模糊的话可以开启该配置项
  233. }).then((canvas) => {
  234. // 生成成功
  235. this.$ownerInstance.callMethod('hideLoading')
  236. this.$ownerInstance.callMethod('receiveRenderData', canvas.toDataURL('image/png'))
  237. }).catch(err => {
  238. // 生成失败 弹出提示弹窗
  239. this.$ownerInstance.callMethod('_errAlert', `【生成图片失败,请重试】${err}`)
  240. })
  241. }, 300)
  242. }
  243. },
  244. }
  245. </script>
  246. <style lang="scss" scoped>
  247. page {
  248. background-color: #f8f8f8;
  249. padding: 20rpx;
  250. box-sizing: border-box;
  251. }
  252. .bgimg {
  253. width: 100%;
  254. background-image: url("../../static/image/tool/invitationCode-bg1.png");
  255. background-size: 100% 100%;
  256. background-color: #FFFFFF;
  257. border-radius: 10rpx;
  258. .bgimg-header {
  259. image {
  260. width: 90rpx;
  261. height: 90rpx;
  262. border-radius: 50%;
  263. }
  264. .ml-2 {
  265. text:first-child {
  266. font-size: 32rpx;
  267. color: #333;
  268. font-weight: bold;
  269. }
  270. text:last-child {
  271. font-size: 28rpx;
  272. color: #999;
  273. }
  274. }
  275. }
  276. .panelcanvas {
  277. position: relative;
  278. width: 100%;
  279. padding: 40rpx 40rpx 0;
  280. box-sizing: border-box;
  281. .paycodeimg {
  282. width: 340rpx;
  283. height: 340rpx;
  284. }
  285. }
  286. .operation {
  287. width: 100%;
  288. display: grid;
  289. grid-template-columns: repeat(3, 1fr);
  290. grid-template-rows: auto;
  291. row-gap: 30rpx;
  292. column-gap: 20rpx;
  293. margin-bottom: 50rpx;
  294. view {
  295. image {
  296. width: 88rpx;
  297. height: 88rpx;
  298. }
  299. text {
  300. font-size: 24rpx;
  301. color: #333;
  302. }
  303. }
  304. }
  305. }
  306. </style>