sharePoster.js 7.2 KB

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