sharePoster.js 6.2 KB

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