sharePoster.js 6.0 KB

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