share.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view>
  3. <navbar ref="navbar" :config="config" backColor="#999999"></navbar>
  4. <canvas @longtap="popShow=true" canvas-id="canvasId" id="canvasId"></canvas>
  5. <view class="ayQrcodeCls">
  6. <ayQrcode ref="qrcode" :modal="modal_qr" :url="url" @result="getCode" :height="125" :width="125" />
  7. </view>
  8. <u-modal v-model="popShow" content="确定保存到手机?" show-cancel-button @confirm="shareB()"></u-modal>
  9. </view>
  10. </template>
  11. <script>
  12. import ayQrcode from "@/components/ay-qrcode/ay-qrcode.vue";
  13. export default {
  14. components: {
  15. ayQrcode
  16. },
  17. data() {
  18. return {
  19. config: {
  20. back: true, //false是tolbar页面 是则不写
  21. title: '分享',
  22. color: 'black',
  23. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  24. backgroundColor: [1, '#fff'],
  25. statusBarFontColor: 'black',
  26. },
  27. // 捐爱心
  28. // text:"感谢您于2022年06月15日捐款100颗爱心。我们将按照您的意愿,全部用于公益慈善事业。",
  29. // 捐钱
  30. // text:"感谢您于2022年06月15日捐款¥1.00元。我们将按照您的意愿,全部用于公益慈善事业。"
  31. // 捐物
  32. text: "感谢您于2022年06月15日捐款100万元的爱心物质。我们将按照您的意愿,全部用于公益慈善事业。",
  33. imgUrl: "",
  34. systemInfo: {},
  35. data: null,
  36. userInfo: {},
  37. code: null,
  38. modal_qr: false,
  39. url: this.$mConfig.redirect_uri + "/pages/register",
  40. imgURL:"",
  41. popShow:false
  42. }
  43. },
  44. onLoad(options) {
  45. uni.getSystemInfo({
  46. success: (res) => {
  47. this.systemInfo = res
  48. }
  49. })
  50. this.userInfo = uni.getStorageSync('personal');
  51. this.data = options.time.replace('-', '年').replace('-', '月') + '日';
  52. this.code = options.code;
  53. this.text = `感谢您于${this.data+options.title}。我们将按照您的意愿,全部用于公益慈善事业。`;
  54. this.showQrcode()
  55. },
  56. methods: {
  57. // 展示二维码
  58. showQrcode() {
  59. let _this = this;
  60. this.modal_qr = true;
  61. // uni.showLoading()
  62. setTimeout(function () {
  63. // uni.hideLoading()
  64. _this.$refs.qrcode.crtQrCode();
  65. }, 50);
  66. },
  67. init() {
  68. let textStr = 0;
  69. let that = this;
  70. uni.getImageInfo({
  71. src: '/static/convenienceService/credentialBg.png',
  72. success: function(image) {
  73. let y = 140;
  74. var context = uni.createCanvasContext('canvasId');
  75. context.drawImage(image.path, 0, 0, that.systemInfo.screenWidth, 570);
  76. context.font = "bold 16px Arial";
  77. context.fillText("亲爱的:", 40, 140);
  78. context.font = "14px Arial";
  79. y += 30
  80. context.fillText("绿马公益" + that.userInfo.real_name, 40, y);
  81. y += 30;
  82. for (let i = 0; i < (Math.ceil(that.text.length / 21)); i++) {
  83. let textX = i !== 0 ? 40 : 68
  84. let num = i !== 0 ? 21 : 24
  85. context.fillText(that.text.substr(textStr, num), textX, y);
  86. y += 20;
  87. if (i !== 0) {
  88. textStr += 21
  89. } else {
  90. textStr += 24
  91. }
  92. }
  93. y += 5;
  94. context.fillText("您的善行义举,将点燃更多希望。再次向您", 68, y);
  95. y += 20;
  96. context.fillText("致以最诚挚的敬意。", 40, y);
  97. y += 25;
  98. context.fillText("特颁此证,深表谢忱。", 40, y);
  99. context.drawImage(that.imgURL, 130, 350, 104, 104);
  100. context.font = "13px Arial";
  101. context.fillText("扫码参与绿马公益", 130, 470);
  102. context.textAlign = "center"
  103. context.fillText("记录编号:" + that.code, that.systemInfo.screenWidth / 2, 520);
  104. context.draw(false, () => {
  105. // 返回canvas图片信息
  106. uni.canvasToTempFilePath({
  107. canvasId: 'canvasId',
  108. success: (res) => {
  109. that.imgUrl = res.tempFilePath
  110. },
  111. fail: function(err) {
  112. console.log(err)
  113. }
  114. })
  115. })
  116. }
  117. });
  118. },
  119. // 保存图片
  120. shareB() {
  121. var _this = this;
  122. uni.saveImageToPhotosAlbum({
  123. filePath: _this.imgUrl,
  124. success() {
  125. uni.showModal({
  126. title: "保存成功",
  127. content: "图片已成功保存到相册",
  128. showCancel: false
  129. })
  130. },
  131. fail(e) {
  132. console.log(e)
  133. }
  134. })
  135. },
  136. getCode(e) {
  137. this.imgURL=e
  138. console.log(e)
  139. this.init()
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. #canvasId {
  146. width: 750rpx;
  147. height: 1200rpx;
  148. }
  149. .ayQrcodeCls{
  150. position: absolute;
  151. left: -999rpx;
  152. }
  153. </style>