sharePoster.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 { imageBase64 } from "@/api/public";
  11. import {
  12. getProductCode, // 普通商品小程序code
  13. } from "@/api/store.js";
  14. import {
  15. scombinationCode, // 拼团code
  16. seckillCode, // 秒杀
  17. } from "@/api/activity.js";
  18. import i18n from "../utils/lang.js";
  19. let sysHeight = uni.getWindowInfo().statusBarHeight + "px";
  20. export const sharePoster = {
  21. data() {
  22. return {
  23. //二维码参数
  24. codeShow: false,
  25. cid: "1",
  26. codeVal: "", // 要生成的二维码值
  27. size: 200, // 二维码大小
  28. unit: "upx", // 单位
  29. background: "#FFF", // 背景色
  30. foreground: "#000", // 前景色
  31. pdground: "#000", // 角标色
  32. codeIcon: "", // 二维码图标
  33. iconsize: 40, // 二维码图标大小
  34. lv: 3, // 二维码容错级别 , 一般不用设置,默认就行
  35. onval: true, // val值变化时自动重新生成二维码
  36. loadMake: true, // 组件加载完成后自动生成二维码
  37. base64Show: 0,
  38. shareQrcode: 0,
  39. followCode: "",
  40. selectSku: {},
  41. currentPage: false,
  42. sysHeight: sysHeight,
  43. isShow: 0,
  44. storeImageBase64: "",
  45. };
  46. },
  47. methods: {
  48. qrR(res) {
  49. // #ifdef H5
  50. if (!this.$wechat.isWeixin() || this.shareQrcode != "1") {
  51. this.PromotionCode = res;
  52. this.followCode = "";
  53. }
  54. // #endif
  55. // #ifdef APP-PLUS
  56. this.PromotionCode = res;
  57. // #endif
  58. },
  59. getImageBase64() {
  60. let that = this;
  61. imageBase64(that.storeImage, this.storeInfo.wechat_code)
  62. .then((res) => {
  63. that.storeImageBase64 = res.data.image;
  64. if (this.storeInfo.wechat_code) {
  65. that.PromotionCode = res.data.code;
  66. }
  67. })
  68. .catch(() => {});
  69. },
  70. initPoster(arr2) {
  71. let that = this;
  72. uni.getImageInfo({
  73. src: that.PromotionCode,
  74. success() {
  75. if (arr2[2] == "") {
  76. //海报二维码不存在则从新下载
  77. that.downloadFilePromotionCode(function (msgPromotionCode) {
  78. arr2[2] = msgPromotionCode;
  79. if (arr2[2] == "")
  80. return that.$util.Tips({
  81. title: i18n.t(`海报二维码生成失败`),
  82. });
  83. that.$util.PosterCanvas(
  84. arr2,
  85. that.storeInfo.store_name,
  86. that.storeInfo.price,
  87. that.storeInfo.ot_price,
  88. function (tempFilePath) {
  89. that.$set(that, "posterImage", tempFilePath);
  90. that.$set(that, "posterImageStatus", true);
  91. that.$set(that, "canvasStatus", false);
  92. that.$set(that, "actionSheetHidden", !that.actionSheetHidden);
  93. }
  94. );
  95. });
  96. } else {
  97. //生成推广海报
  98. that.$nextTick((e) => {
  99. that.$util.PosterCanvas(
  100. arr2,
  101. that.storeInfo.store_name,
  102. that.storeInfo.price,
  103. that.storeInfo.ot_price,
  104. function (tempFilePath) {
  105. that.$set(that, "posterImage", tempFilePath);
  106. that.$set(that, "posterImageStatus", true);
  107. that.$set(that, "canvasStatus", false);
  108. that.$set(that, "actionSheetHidden", !that.actionSheetHidden);
  109. }
  110. );
  111. });
  112. }
  113. },
  114. fail: function (res) {
  115. // #ifdef H5
  116. return that.$util.Tips({
  117. title: res,
  118. });
  119. // #endif
  120. // #ifdef MP
  121. return that.$util.Tips({
  122. title: i18n.t(`正在下载海报,请稍后再试`),
  123. });
  124. // #endif
  125. },
  126. });
  127. },
  128. /**
  129. * 生成海报
  130. */
  131. async goPoster(type) {
  132. let that = this;
  133. that.posters = false;
  134. that.$set(that, "canvasStatus", true);
  135. let arr2;
  136. // #ifdef MP
  137. let met =
  138. type === "scombination"
  139. ? scombinationCode(that.id)
  140. : type === "seckill"
  141. ? seckillCode(that.id, { time_id: this.time_id })
  142. : getProductCode(that.id);
  143. met
  144. .then((res) => {
  145. uni.downloadFile({
  146. url: that.setDomain(res.data.code),
  147. success: function (res) {
  148. that.$set(that, "isDown", false);
  149. that.$set(that, "PromotionCode", res.tempFilePath);
  150. if (typeof successFn == "function")
  151. successFn && successFn(res.tempFilePath);
  152. arr2 = [that.posterbackgd, that.storeImage, that.PromotionCode];
  153. that.initPoster(arr2);
  154. },
  155. fail: function () {
  156. that.$set(that, "isDown", false);
  157. that.$set(that, "PromotionCode", "");
  158. },
  159. });
  160. })
  161. .catch((err) => {
  162. that.$set(that, "isDown", false);
  163. that.$set(that, "PromotionCode", "");
  164. return that.$util.Tips({
  165. title: err,
  166. });
  167. });
  168. // #endif
  169. // #ifdef H5 || APP-PLUS
  170. arr2 = [that.posterbackgd, that.storeImageBase64, that.PromotionCode];
  171. if (!that.storeImageBase64)
  172. return that.$util.Tips({
  173. title: i18n.t(`正在下载海报,请稍后再试`),
  174. });
  175. that.initPoster(arr2);
  176. // #endif
  177. },
  178. //替换安全域名
  179. setDomain(url) {
  180. url = url ? url.toString() : "";
  181. //本地调试打开,生产请注销
  182. if (url.indexOf("https://") > -1) return url;
  183. else return url.replace("http://", "https://");
  184. },
  185. //获取海报产品图
  186. downloadFilestoreImage() {
  187. let that = this;
  188. uni.downloadFile({
  189. url: that.setDomain(that.storeInfo.image),
  190. success: function (res) {
  191. that.storeImage = res.tempFilePath;
  192. that.storeImageBase64 = res.tempFilePath;
  193. },
  194. fail: function () {
  195. return that.$util.Tips({
  196. title: "",
  197. });
  198. that.storeImage = "";
  199. },
  200. });
  201. },
  202. /**
  203. * 获取产品分销二维码
  204. * @param function successFn 下载完成回调
  205. *
  206. */
  207. downloadFilePromotionCode(successFn) {
  208. let that = this;
  209. // #ifdef MP
  210. getProductCode(that.id)
  211. .then((res) => {
  212. uni.downloadFile({
  213. url: that.setDomain(res.data.code),
  214. success: function (res) {
  215. that.$set(that, "isDown", false);
  216. that.$set(that, "PromotionCode", res.tempFilePath);
  217. if (typeof successFn == "function")
  218. successFn && successFn(res.tempFilePath);
  219. },
  220. fail: function () {
  221. that.$set(that, "isDown", false);
  222. that.$set(that, "PromotionCode", "");
  223. },
  224. });
  225. })
  226. .catch((err) => {
  227. that.$set(that, "isDown", false);
  228. that.$set(that, "PromotionCode", "");
  229. return that.$util.Tips({
  230. title: err,
  231. });
  232. });
  233. // #endif
  234. // #ifdef APP-PLUS
  235. uni.downloadFile({
  236. url: that.setDomain(that.PromotionCode),
  237. success: function (res) {
  238. that.$set(that, "isDown", false);
  239. if (typeof successFn == "function")
  240. successFn && successFn(res.tempFilePath);
  241. else that.$set(that, "PromotionCode", res.tempFilePath);
  242. },
  243. fail: function () {
  244. that.$set(that, "isDown", false);
  245. that.$set(that, "PromotionCode", "");
  246. },
  247. });
  248. // #endif
  249. },
  250. },
  251. };