disseminatePage.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 v-if="imgBg" :show-menu-by-longpress="enable != 1 ? true : false" mode="widthFix" :src="imgBg"></image>
  5. <view class="code">
  6. <image v-if="imgBg" show-menu-by-longpress mode="widthFix" :src="qrcodeImg"></image>
  7. </view>
  8. <canvas
  9. class="canvas-bg"
  10. canvas-id="canvasDom"
  11. id="canvasDom"
  12. bindtouchstart=""
  13. bindtouchmove=""
  14. bindtouchend=""
  15. bindtouchcancel=""
  16. bindlongtap=""
  17. binderror=""
  18. :style="{ width: canvasW + 'px', height: canvasH + 'px' }"
  19. ></canvas>
  20. </view>
  21. </template>
  22. <script>
  23. import { bannerGetQrcode, bannerDownload } from "@/api/report";
  24. import { h5BaseUrl } from "@/utils/config";
  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. encodeURIComponent(this.imgBg) +
  53. "&title=" +
  54. this.title +
  55. "&id=" +
  56. this.bannerId +
  57. "&InviteShareCode=" +
  58. this.userInfo.user_id +
  59. "&enable=" +
  60. this.enable,
  61. };
  62. },
  63. methods: {
  64. // 保存二维码到本地
  65. async canvasGet() {
  66. const token = this.$store.state.user.token;
  67. let userId = this.$store.state.report.inviteShareCode || this.userInfo.user_id;
  68. let url = `${h5BaseUrl}/hzyb/surveyDetail?token=${token}&userId=${userId}&bannerId=${this.bannerId}&remark=${this.title}#wechat_redirect`;
  69. const res = await bannerDownload({
  70. banner_url: url,
  71. banner_id: +this.bannerId,
  72. user_id: +userId,
  73. });
  74. if (res.code === 200) {
  75. wx.getImageInfo({
  76. src: res.data,
  77. success: (res) => {
  78. wx.saveImageToPhotosAlbum({
  79. filePath: res.path,
  80. success: function (data) {
  81. uni.showToast({
  82. title: "保存成功",
  83. duration: 2000,
  84. });
  85. },
  86. fail: function (err) {
  87. if (
  88. err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" ||
  89. err.errMsg === "saveImageToPhotosAlbum:fail auth deny" ||
  90. err.errMsg ===
  91. "saveImageToPhotosAlbum:fail authorize no response"
  92. ) {
  93. // 这边微信做过调整,必须要在按钮中触发,因此需要在弹框回调中进行调用
  94. wx.showModal({
  95. title: "提示",
  96. content: "需要您授权保存相册",
  97. showCancel: false,
  98. success: (modalSuccess) => {
  99. wx.openSetting({
  100. success(settingdata) {
  101. if (
  102. settingdata.authSetting["scope.writePhotosAlbum"]
  103. ) {
  104. wx.showModal({
  105. title: "提示",
  106. content: "获取权限成功,再次点击图片即可保存",
  107. showCancel: false,
  108. });
  109. } else {
  110. wx.showModal({
  111. title: "提示",
  112. content: "获取权限失败,将无法保存到相册哦~",
  113. showCancel: false,
  114. });
  115. }
  116. },
  117. fail(failData) {
  118. // console.log("failData", failData);
  119. },
  120. complete(finishData) {
  121. // console.log("finishData", finishData);
  122. },
  123. });
  124. },
  125. });
  126. } else {
  127. uni.showToast({
  128. title: "保存失败",
  129. duration: 2000,
  130. icon: "error",
  131. });
  132. }
  133. },
  134. });
  135. },
  136. fail(err) {
  137. uni.showToast({
  138. title: "保存失败",
  139. duration: 2000,
  140. icon: "error",
  141. });
  142. },
  143. });
  144. }
  145. },
  146. // 获取code 二维码
  147. async getQrcCode() {
  148. const res = await bannerGetQrcode({
  149. UserId:
  150. this.$store.state.report.inviteShareCode || this.userInfo.user_id,
  151. BannerId: this.bannerId,
  152. Remark: this.title,
  153. });
  154. if (res.code == 200) {
  155. this.qrcodeImg = res.data;
  156. }
  157. },
  158. },
  159. };
  160. </script>
  161. <style>
  162. page {
  163. padding: 0;
  164. }
  165. </style>
  166. <style lang="scss" scoped>
  167. .poster-img-content {
  168. width: 100%;
  169. overflow: hidden;
  170. position: relative;
  171. image {
  172. width: 100%;
  173. height: 100%;
  174. }
  175. .code {
  176. position: absolute;
  177. width: 300rpx;
  178. height: 300rpx;
  179. left: 50%;
  180. bottom: 180rpx;
  181. transform: translateX(-50%);
  182. }
  183. .canvas-bg {
  184. position: absolute;
  185. left: 10000rpx;
  186. }
  187. .download-img {
  188. position: fixed;
  189. display: block;
  190. width: 100rpx;
  191. height: 100rpx;
  192. right: 35rpx;
  193. bottom: 200rpx;
  194. z-index: 99;
  195. }
  196. .download-img-two {
  197. bottom: 300rpx;
  198. }
  199. }
  200. </style>