sharePoster.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. if (arr2[2] == "") {
  95. //海报二维码不存在则从新下载
  96. that.downloadFilePromotionCode(function(msgPromotionCode) {
  97. arr2[2] = msgPromotionCode;
  98. if (arr2[2] == "")
  99. return that.$util.Tips({
  100. title: i18n.t(`海报二维码生成失败`),
  101. });
  102. that.$util.PosterCanvas(
  103. arr2,
  104. that.storeInfo.store_name,
  105. that.storeInfo.price,
  106. that.storeInfo.ot_price,
  107. function(tempFilePath) {
  108. that.$set(that, "posterImage", tempFilePath);
  109. that.$set(that, "posterImageStatus", true);
  110. that.$set(that, "canvasStatus", false);
  111. that.$set(that, "actionSheetHidden", !that
  112. .actionSheetHidden);
  113. }
  114. );
  115. });
  116. } else {
  117. //生成推广海报
  118. that.$nextTick(e => {
  119. that.$util.PosterCanvas(
  120. arr2,
  121. that.storeInfo.store_name,
  122. that.storeInfo.price,
  123. that.storeInfo.ot_price,
  124. function(tempFilePath) {
  125. that.$set(that, "posterImage", tempFilePath);
  126. that.$set(that, "posterImageStatus", true);
  127. that.$set(that, "canvasStatus", false);
  128. that.$set(that, "actionSheetHidden", !that
  129. .actionSheetHidden);
  130. }
  131. );
  132. })
  133. }
  134. },
  135. });
  136. },
  137. //替换安全域名
  138. setDomain(url) {
  139. url = url ? url.toString() : "";
  140. //本地调试打开,生产请注销
  141. if (url.indexOf("https://") > -1) return url;
  142. else return url.replace("http://", "https://");
  143. },
  144. //获取海报产品图
  145. downloadFilestoreImage() {
  146. let that = this;
  147. uni.downloadFile({
  148. url: that.setDomain(that.storeInfo.image),
  149. success: function(res) {
  150. that.storeImage = res.tempFilePath;
  151. that.storeImageBase64 = res.tempFilePath;
  152. },
  153. fail: function() {
  154. return that.$util.Tips({
  155. title: "",
  156. });
  157. that.storeImage = "";
  158. },
  159. });
  160. },
  161. /**
  162. * 获取产品分销二维码
  163. * @param function successFn 下载完成回调
  164. *
  165. */
  166. downloadFilePromotionCode(successFn) {
  167. let that = this;
  168. // #ifdef MP
  169. getProductCode(that.id)
  170. .then((res) => {
  171. uni.downloadFile({
  172. url: that.setDomain(res.data.code),
  173. success: function(res) {
  174. that.$set(that, "isDown", false);
  175. that.$set(that, "PromotionCode", res.tempFilePath)
  176. if (typeof successFn == "function")
  177. successFn && successFn(res.tempFilePath);
  178. },
  179. fail: function() {
  180. that.$set(that, "isDown", false);
  181. that.$set(that, "PromotionCode", "");
  182. },
  183. });
  184. })
  185. .catch((err) => {
  186. that.$set(that, "isDown", false);
  187. that.$set(that, "PromotionCode", "");
  188. return that.$util.Tips({
  189. title: err,
  190. });
  191. });
  192. // #endif
  193. // #ifdef APP-PLUS
  194. uni.downloadFile({
  195. url: that.setDomain(that.PromotionCode),
  196. success: function(res) {
  197. that.$set(that, "isDown", false);
  198. if (typeof successFn == "function")
  199. successFn && successFn(res.tempFilePath);
  200. else that.$set(that, "PromotionCode", res.tempFilePath);
  201. },
  202. fail: function() {
  203. that.$set(that, "isDown", false);
  204. that.$set(that, "PromotionCode", "");
  205. },
  206. });
  207. // #endif
  208. },
  209. }
  210. };