disseminatePage.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="poster-img-content">
  3. <image v-if="enable==1" @click="canvasGet" src="https://hzstatic.hzinsights.com/yb_xcx/download-img.png" class="download-img">
  4. <image @click="detailGo" src="https://hzstatic.hzinsights.com/static/icon/hzyb/default_avatar.png" class="download-img download-img-two">
  5. <image v-if="imgBg" mode="widthFix" :src="imgBg"></image>
  6. <view class="code">
  7. <image v-if="imgBg" show-menu-by-longpress mode="widthFix" :src="qrcodeImg"></image>
  8. </view>
  9. <canvas
  10. class="canvas-bg"
  11. canvas-id="canvasDom"
  12. id="canvasDom"
  13. bindtouchstart=""
  14. bindtouchmove=""
  15. bindtouchend=""
  16. bindtouchcancel=""
  17. bindlongtap=""
  18. binderror=""
  19. :style="{ width: canvasW + 'px', height: canvasH + 'px' }"
  20. ></canvas>
  21. </view>
  22. </template>
  23. <script>
  24. import { bannerGetQrcode } from "@/api/report";
  25. export default {
  26. data() {
  27. return {
  28. imgBg: "",
  29. title: "",
  30. canvasH: 0,
  31. canvasW: 0,
  32. bannerId: "",
  33. qrcodeImg: "",
  34. enable: 0,
  35. };
  36. },
  37. onLoad(op) {
  38. this.imgBg = decodeURIComponent(op.imgHb);
  39. this.title = op.title;
  40. this.bannerId = op.id;
  41. this.enable = op.enable;
  42. this.enable == 1 && this.getQrcCode();
  43. uni.setNavigationBarTitle({
  44. title: this.title,
  45. });
  46. },
  47. onShareAppMessage() {
  48. return {
  49. title: this.title,
  50. path:
  51. "/pages-report/disseminatePage/disseminatePage?imgHb=" +
  52. this.imgBg +
  53. "&title=" +
  54. this.title +
  55. "&id=" +
  56. this.bannerId +
  57. "&InviteShareCode=" +
  58. this.userInfo.user_id +
  59. "&enable=" +
  60. item.enable,
  61. };
  62. },
  63. methods: {
  64. // 背景图的canvas
  65. renderCanvas() {
  66. const SystemInfo = uni.getSystemInfoSync();
  67. wx.getImageInfo({
  68. src: this.imgBg,
  69. success: (res) => {
  70. const temPath = res.path;
  71. this.canvasW = SystemInfo.windowWidth * 2;
  72. this.canvasH = res.height / (res.width / this.canvasW);
  73. this.drawImg(temPath);
  74. },
  75. fail(err) {
  76. reject(err);
  77. },
  78. });
  79. },
  80. // 二维码的canvas
  81. drawImg(path) {
  82. let ctx = uni.createCanvasContext("canvasDom", this);
  83. ctx.drawImage(path, 0, 0, this.canvasW, this.canvasH);
  84. wx.getImageInfo({
  85. src: this.qrcodeImg,
  86. success: (res) => {
  87. ctx.drawImage(
  88. res.path,
  89. this.canvasW * 0.5 - res.width / 2,
  90. this.canvasH - 430,
  91. res.width,
  92. res.height
  93. );
  94. ctx.draw();
  95. },
  96. fail(err) {
  97. reject(err);
  98. },
  99. });
  100. },
  101. // 上线前删除
  102. detailGo() {
  103. const title = encodeURIComponent("迪拜&阿布扎比");
  104. uni.navigateTo({
  105. url:
  106. "/pages-report/signUpPage/signUpPage?RealName=席子文&CompanyName=杭州大式数字科技有限公司&Mobile=15906624664&BannerId=4&Title=" +
  107. title,
  108. });
  109. return;
  110. },
  111. // 保存二维码到本地
  112. canvasGet() {
  113. uni.canvasToTempFilePath({
  114. canvasId: "canvasDom",
  115. success: (res) => {
  116. wx.saveImageToPhotosAlbum({
  117. filePath: res.tempFilePath,
  118. success: function (data) {
  119. uni.showToast({
  120. title: "保存成功",
  121. duration: 2000,
  122. });
  123. },
  124. fail: function (err) {
  125. if (
  126. err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" ||
  127. err.errMsg === "saveImageToPhotosAlbum:fail auth deny" ||
  128. err.errMsg ===
  129. "saveImageToPhotosAlbum:fail authorize no response"
  130. ) {
  131. // 这边微信做过调整,必须要在按钮中触发,因此需要在弹框回调中进行调用
  132. wx.showModal({
  133. title: "提示",
  134. content: "需要您授权保存相册",
  135. showCancel: false,
  136. success: (modalSuccess) => {
  137. wx.openSetting({
  138. success(settingdata) {
  139. if (settingdata.authSetting["scope.writePhotosAlbum"]) {
  140. wx.showModal({
  141. title: "提示",
  142. content: "获取权限成功,再次点击图片即可保存",
  143. showCancel: false,
  144. });
  145. } else {
  146. wx.showModal({
  147. title: "提示",
  148. content: "获取权限失败,将无法保存到相册哦~",
  149. showCancel: false,
  150. });
  151. }
  152. },
  153. fail(failData) {
  154. // console.log("failData", failData);
  155. },
  156. complete(finishData) {
  157. // console.log("finishData", finishData);
  158. },
  159. });
  160. },
  161. });
  162. }
  163. },
  164. });
  165. },
  166. fail: () => {
  167. // console.log("下载失败");
  168. },
  169. });
  170. },
  171. // 获取code 二维码
  172. async getQrcCode() {
  173. const res = await bannerGetQrcode({
  174. UserId: this.userInfo.user_id,
  175. BannerId: this.bannerId,
  176. Remark: this.title,
  177. });
  178. if (res.code == 200) {
  179. this.qrcodeImg = res.data;
  180. }
  181. },
  182. },
  183. onShow() {
  184. this.enable == 1 && this.renderCanvas();
  185. },
  186. };
  187. </script>
  188. <style>
  189. page {
  190. padding: 0;
  191. }
  192. </style>
  193. <style lang="scss" scoped>
  194. .poster-img-content {
  195. width: 100%;
  196. overflow: hidden;
  197. position: relative;
  198. image {
  199. width: 100%;
  200. height: 100%;
  201. }
  202. .code {
  203. position: absolute;
  204. width: 300rpx;
  205. height: 300rpx;
  206. left: 50%;
  207. bottom: 180rpx;
  208. transform: translateX(-50%);
  209. }
  210. .canvas-bg {
  211. position: absolute;
  212. left: 10000rpx;
  213. }
  214. .download-img {
  215. position: fixed;
  216. display: block;
  217. width: 100rpx;
  218. height: 100rpx;
  219. right: 35rpx;
  220. bottom: 200rpx;
  221. z-index: 99;
  222. }
  223. .download-img-two {
  224. bottom: 300rpx;
  225. }
  226. }
  227. </style>