invitationCode.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. //posterUrl 由 renderjs + html2canvas 截图生成
  152. if (!this.posterUrl) {
  153. uni.showToast({
  154. title: '海报生成中,请稍后再试',
  155. icon: 'none',
  156. });
  157. return;
  158. }
  159. // #ifdef H5
  160. //zhApp 当前 uni-app 的 H5 运行时未实现 saveImageToPhotosAlbum,
  161. //故手动用 a 标签触发浏览器下载(zgcx 是框架自带下载降级,这里需要自己处理)
  162. const a = document.createElement('a');
  163. a.href = this.posterUrl;
  164. a.download = '邀请海报.png';
  165. document.body.appendChild(a);
  166. a.click();
  167. document.body.removeChild(a);
  168. uni.showToast({
  169. title: '已开始下载,请查看浏览器下载记录',
  170. icon: 'none',
  171. });
  172. // #endif
  173. // #ifdef APP-PLUS
  174. base64ToPath(this.posterUrl)
  175. .then(path => {
  176. uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
  177. filePath: path, //图片文件路径
  178. success: function() {
  179. uni.showToast({
  180. title: '已保存到相册',
  181. icon: 'none',
  182. });
  183. },
  184. fail: function(e) {
  185. uni.showToast({
  186. title: '图片保存失败',
  187. icon: 'none',
  188. });
  189. }
  190. });
  191. })
  192. // #endif
  193. },
  194. //页面截图转路径
  195. receiveRenderData(val) {
  196. this.posterUrl = val.replace(/[\r\n]/g, ''); // 去除base64位中的空格
  197. },
  198. showLoading() {
  199. uni.showLoading({
  200. title: '正在生成图片'
  201. });
  202. },
  203. hideLoading() {
  204. uni.hideLoading();
  205. this.loading = false;
  206. },
  207. }
  208. }
  209. </script>
  210. <script module="canvasImage" lang="renderjs">
  211. import html2canvas from 'html2canvas'
  212. export default {
  213. data() {
  214. return {
  215. }
  216. },
  217. mounted() {
  218. setTimeout(() => {
  219. this.canvasImage.generateImage()
  220. }, 1000);
  221. },
  222. methods: {
  223. generateImage() {
  224. setTimeout(() => {
  225. this.$ownerInstance.callMethod('showLoading')
  226. const dom = document.getElementById('panelcanvas') // 需要生成图片内容的 dom 节点
  227. html2canvas(dom, {
  228. width: dom.clientWidth, //dom 原始宽度
  229. height: dom.clientHeight,
  230. scrollY: 0, // html2canvas默认绘制视图内的页面,需要把scrollY,scrollX设置为0
  231. scrollX: 0,
  232. useCORS: true, //支持跨域
  233. // allowTaint: false,
  234. scale: 2, // 设置生成图片的像素比例,默认是1,如果生成的图片模糊的话可以开启该配置项
  235. }).then((canvas) => {
  236. console.log(canvas);
  237. // 生成成功
  238. this.$ownerInstance.callMethod('hideLoading')
  239. this.$ownerInstance.callMethod('receiveRenderData', canvas.toDataURL('image/png'))
  240. }).catch(err => {
  241. console.log('22222222222222', err);
  242. // 生成失败 弹出提示弹窗
  243. this.$ownerInstance.callMethod('_errAlert', `【生成图片失败,请重试】${err}`)
  244. })
  245. }, 300)
  246. }
  247. },
  248. }
  249. </script>
  250. <style lang="scss" scoped>
  251. page {
  252. background-color: #f8f8f8;
  253. padding: 20rpx;
  254. box-sizing: border-box;
  255. }
  256. .bgimg {
  257. width: 100%;
  258. background-image: url("../../static/image/tool/invitationCode-bg1.png");
  259. background-size: 100% 100%;
  260. background-color: #FFFFFF;
  261. border-radius: 10rpx;
  262. .bgimg-header {
  263. image {
  264. width: 90rpx;
  265. height: 90rpx;
  266. border-radius: 50%;
  267. }
  268. .ml-2 {
  269. text:first-child {
  270. font-size: 32rpx;
  271. color: #333;
  272. font-weight: bold;
  273. }
  274. text:last-child {
  275. font-size: 28rpx;
  276. color: #999;
  277. }
  278. }
  279. }
  280. .panelcanvas {
  281. position: relative;
  282. width: 100%;
  283. padding: 40rpx 40rpx 0;
  284. box-sizing: border-box;
  285. .paycodeimg {
  286. width: 340rpx;
  287. height: 340rpx;
  288. }
  289. }
  290. .operation {
  291. width: 100%;
  292. display: grid;
  293. grid-template-columns: repeat(3, 1fr);
  294. grid-template-rows: auto;
  295. row-gap: 30rpx;
  296. column-gap: 20rpx;
  297. margin-bottom: 50rpx;
  298. view {
  299. image {
  300. width: 88rpx;
  301. height: 88rpx;
  302. }
  303. text {
  304. font-size: 24rpx;
  305. color: #333;
  306. }
  307. }
  308. }
  309. }
  310. </style>