invitationCode.vue 8.0 KB

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