sharePoster.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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, '')
  64. .then((res) => {
  65. that.storeImageBase64 = res.data.image;
  66. // that.PromotionCode = res.data.code;
  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(
  78. msgPromotionCode) {
  79. arr2[2] = msgPromotionCode;
  80. if (arr2[2] == "")
  81. return that.$util.Tips({
  82. title: i18n.t(
  83. `海报二维码生成失败`
  84. ),
  85. });
  86. that.$util.PosterCanvas(
  87. arr2,
  88. that.storeInfo.store_name,
  89. that.storeInfo.price,
  90. that.storeInfo.ot_price,
  91. function(tempFilePath) {
  92. that.$set(that,
  93. "posterImage",
  94. tempFilePath);
  95. that.$set(that,
  96. "posterImageStatus",
  97. true);
  98. that.$set(that,
  99. "canvasStatus",
  100. false);
  101. that.$set(that,
  102. "actionSheetHidden",
  103. !that
  104. .actionSheetHidden
  105. );
  106. }
  107. );
  108. });
  109. } else {
  110. //生成推广海报
  111. that.$nextTick(e => {
  112. that.$util.PosterCanvas(
  113. arr2,
  114. that.storeInfo.store_name,
  115. that.storeInfo.price,
  116. that.storeInfo.ot_price,
  117. function(tempFilePath) {
  118. that.$set(that,
  119. "posterImage",
  120. tempFilePath);
  121. that.$set(that,
  122. "posterImageStatus",
  123. true);
  124. that.$set(that,
  125. "canvasStatus",
  126. false);
  127. that.$set(that,
  128. "actionSheetHidden",
  129. !that
  130. .actionSheetHidden
  131. );
  132. }
  133. );
  134. })
  135. }
  136. },
  137. fail: function(res) {
  138. // #ifdef H5
  139. return that.$util.Tips({
  140. title: res,
  141. });
  142. // #endif
  143. // #ifdef MP
  144. return that.$util.Tips({
  145. title: i18n.t(`正在下载海报,请稍后再试`),
  146. });
  147. // #endif
  148. },
  149. });
  150. },
  151. /**
  152. * 生成海报
  153. */
  154. async goPoster(type) {
  155. let that = this;
  156. that.posters = false;
  157. that.$set(that, "canvasStatus", true);
  158. let arr2
  159. // #ifdef MP
  160. let met = type === 'scombination' ? scombinationCode(that.id) : type === 'seckill' ? seckillCode(that
  161. .id) : getProductCode(that.id)
  162. met.then((res) => {
  163. uni.downloadFile({
  164. url: that.setDomain(res.data.code),
  165. success: function(res) {
  166. that.$set(that, "isDown", false);
  167. that.$set(that, "PromotionCode", res.tempFilePath)
  168. if (typeof successFn == "function")
  169. successFn && successFn(res.tempFilePath);
  170. arr2 = [that.posterbackgd, that.storeImage, that.PromotionCode];
  171. that.initPoster(arr2)
  172. },
  173. fail: function() {
  174. that.$set(that, "isDown", false);
  175. that.$set(that, "PromotionCode", "");
  176. },
  177. });
  178. })
  179. .catch((err) => {
  180. that.$set(that, "isDown", false);
  181. that.$set(that, "PromotionCode", "");
  182. return that.$util.Tips({
  183. title: err,
  184. });
  185. });
  186. // #endif
  187. // #ifdef H5 || APP-PLUS
  188. arr2 = [that.posterbackgd, that.storeImageBase64, that.PromotionCode];
  189. if (!that.storeImageBase64)
  190. return that.$util.Tips({
  191. title: i18n.t(`正在下载海报,请稍后再试`),
  192. });
  193. that.initPoster(arr2)
  194. // #endif
  195. },
  196. //替换安全域名
  197. setDomain(url) {
  198. url = url ? url.toString() : "";
  199. //本地调试打开,生产请注销
  200. if (url.indexOf("https://") > -1) return url;
  201. else return url.replace("http://", "https://");
  202. },
  203. //获取海报产品图
  204. downloadFilestoreImage() {
  205. let that = this;
  206. uni.downloadFile({
  207. url: that.setDomain(that.storeInfo.image),
  208. success: function(res) {
  209. that.storeImage = res.tempFilePath;
  210. that.storeImageBase64 = res.tempFilePath;
  211. },
  212. fail: function() {
  213. return that.$util.Tips({
  214. title: "",
  215. });
  216. that.storeImage = "";
  217. },
  218. });
  219. },
  220. /**
  221. * 获取产品分销二维码
  222. * @param function successFn 下载完成回调
  223. *
  224. */
  225. downloadFilePromotionCode(successFn) {
  226. let that = this;
  227. // #ifdef MP
  228. getProductCode(that.id)
  229. .then((res) => {
  230. uni.downloadFile({
  231. url: that.setDomain(res.data.code),
  232. success: function(res) {
  233. that.$set(that, "isDown", false);
  234. that.$set(that, "PromotionCode", res.tempFilePath)
  235. if (typeof successFn == "function")
  236. successFn && successFn(res.tempFilePath);
  237. },
  238. fail: function() {
  239. that.$set(that, "isDown", false);
  240. that.$set(that, "PromotionCode", "");
  241. },
  242. });
  243. })
  244. .catch((err) => {
  245. that.$set(that, "isDown", false);
  246. that.$set(that, "PromotionCode", "");
  247. return that.$util.Tips({
  248. title: err,
  249. });
  250. });
  251. // #endif
  252. // #ifdef APP-PLUS
  253. uni.downloadFile({
  254. url: that.setDomain(that.PromotionCode),
  255. success: function(res) {
  256. that.$set(that, "isDown", false);
  257. if (typeof successFn == "function")
  258. successFn && successFn(res.tempFilePath);
  259. else that.$set(that, "PromotionCode", res.tempFilePath);
  260. },
  261. fail: function() {
  262. that.$set(that, "isDown", false);
  263. that.$set(that, "PromotionCode", "");
  264. },
  265. });
  266. // #endif
  267. },
  268. }
  269. };