sharePoster.js 7.2 KB

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