sharePoster.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import {
  11. imageBase64
  12. } from "@/api/public";
  13. import {
  14. getProductCode
  15. } from "@/api/store.js";
  16. let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  17. export const sharePoster = {
  18. data() {
  19. return {
  20. //二维码参数
  21. codeShow: false,
  22. cid: '1',
  23. codeVal: "", // 要生成的二维码值
  24. size: 200, // 二维码大小
  25. unit: 'upx', // 单位
  26. background: '#FFF', // 背景色
  27. foreground: '#000', // 前景色
  28. pdground: '#000', // 角标色
  29. codeIcon: '', // 二维码图标
  30. iconsize: 40, // 二维码图标大小
  31. lv: 3, // 二维码容错级别 , 一般不用设置,默认就行
  32. onval: true, // val值变化时自动重新生成二维码
  33. loadMake: true, // 组件加载完成后自动生成二维码
  34. base64Show: 0,
  35. shareQrcode: 0,
  36. followCode: '',
  37. selectSku: {},
  38. currentPage: false,
  39. sysHeight: sysHeight,
  40. isShow: 0,
  41. storeImageBase64: ''
  42. };
  43. },
  44. methods: {
  45. qrR(res) {
  46. // #ifdef H5
  47. if (!this.$wechat.isWeixin() || this.shareQrcode != '1') {
  48. this.PromotionCode = res;
  49. this.followCode = ''
  50. }
  51. // #endif
  52. // #ifdef APP-PLUS
  53. this.PromotionCode = res;
  54. // #endif
  55. },
  56. getImageBase64() {
  57. let that = this;
  58. imageBase64(that.storeImage, '')
  59. .then((res) => {
  60. that.storeImageBase64 = res.data.image;
  61. // that.PromotionCode = res.data.code;
  62. })
  63. .catch(() => {});
  64. },
  65. /**
  66. * 生成海报
  67. */
  68. goPoster() {
  69. let that = this;
  70. that.posters = false;
  71. that.$set(that, "canvasStatus", true);
  72. let arr2
  73. // #ifdef MP
  74. arr2 = [that.posterbackgd, that.storeImage, that.PromotionCode];
  75. if (that.isDown)
  76. return that.$util.Tips({
  77. title: "正在下载海报,请稍后再试",
  78. });
  79. // #endif
  80. // #ifdef H5 || APP-PLUS
  81. arr2 = [that.posterbackgd, that.storeImageBase64, that.PromotionCode];
  82. if (!that.storeImageBase64)
  83. return that.$util.Tips({
  84. title: "正在下载海报,请稍后再试",
  85. });
  86. // #endif
  87. uni.getImageInfo({
  88. src: that.PromotionCode,
  89. fail: function(res) {
  90. // #ifdef H5
  91. return that.$util.Tips({
  92. title: res,
  93. });
  94. // #endif
  95. // #ifdef MP
  96. return that.$util.Tips({
  97. title: "正在下载海报,请稍后再试",
  98. });
  99. // #endif
  100. },
  101. success() {
  102. if (arr2[2] == "") {
  103. //海报二维码不存在则从新下载
  104. that.downloadFilePromotionCode(function(msgPromotionCode) {
  105. arr2[2] = msgPromotionCode;
  106. if (arr2[2] == "")
  107. return that.$util.Tips({
  108. title: "海报二维码生成失败!",
  109. });
  110. that.$util.PosterCanvas(
  111. arr2,
  112. that.storeInfo.store_name,
  113. that.storeInfo.price,
  114. that.storeInfo.ot_price,
  115. function(tempFilePath) {
  116. that.$set(that, "posterImage", tempFilePath);
  117. that.$set(that, "posterImageStatus", true);
  118. that.$set(that, "canvasStatus", false);
  119. that.$set(that, "actionSheetHidden", !that
  120. .actionSheetHidden);
  121. }
  122. );
  123. });
  124. } else {
  125. //生成推广海报
  126. that.$nextTick(e => {
  127. that.$util.PosterCanvas(
  128. arr2,
  129. that.storeInfo.store_name,
  130. that.storeInfo.price,
  131. that.storeInfo.ot_price,
  132. function(tempFilePath) {
  133. that.$set(that, "posterImage", tempFilePath);
  134. that.$set(that, "posterImageStatus", true);
  135. that.$set(that, "canvasStatus", false);
  136. that.$set(that, "actionSheetHidden", !that
  137. .actionSheetHidden);
  138. }
  139. );
  140. })
  141. }
  142. },
  143. });
  144. },
  145. //替换安全域名
  146. setDomain: function(url) {
  147. url = url ? url.toString() : "";
  148. //本地调试打开,生产请注销
  149. if (url.indexOf("https://") > -1) return url;
  150. else return url.replace("http://", "https://");
  151. },
  152. //获取海报产品图
  153. downloadFilestoreImage: function() {
  154. let that = this;
  155. uni.downloadFile({
  156. url: that.setDomain(that.storeInfo.image),
  157. success: function(res) {
  158. that.storeImage = res.tempFilePath;
  159. that.storeImageBase64 = res.tempFilePath;
  160. },
  161. fail: function() {
  162. return that.$util.Tips({
  163. title: "",
  164. });
  165. that.storeImage = "";
  166. },
  167. });
  168. },
  169. /**
  170. * 获取产品分销二维码
  171. * @param function successFn 下载完成回调
  172. *
  173. */
  174. downloadFilePromotionCode: function(successFn) {
  175. let that = this;
  176. // #ifdef MP
  177. getProductCode(that.id)
  178. .then((res) => {
  179. uni.downloadFile({
  180. url: that.setDomain(res.data.code),
  181. success: function(res) {
  182. that.$set(that, "isDown", false);
  183. that.$set(that, "PromotionCode", res.tempFilePath)
  184. if (typeof successFn == "function")
  185. successFn && successFn(res.tempFilePath);
  186. },
  187. fail: function() {
  188. that.$set(that, "isDown", false);
  189. that.$set(that, "PromotionCode", "");
  190. },
  191. });
  192. })
  193. .catch((err) => {
  194. that.$set(that, "isDown", false);
  195. that.$set(that, "PromotionCode", "");
  196. });
  197. // #endif
  198. // #ifdef APP-PLUS
  199. uni.downloadFile({
  200. url: that.setDomain(that.PromotionCode),
  201. success: function(res) {
  202. that.$set(that, "isDown", false);
  203. if (typeof successFn == "function")
  204. successFn && successFn(res.tempFilePath);
  205. else that.$set(that, "PromotionCode", res.tempFilePath);
  206. },
  207. fail: function() {
  208. that.$set(that, "isDown", false);
  209. that.$set(that, "PromotionCode", "");
  210. },
  211. });
  212. // #endif
  213. },
  214. }
  215. };