goods.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import sheep from '@/sheep';
  2. import {
  3. formatImageUrlProtocol
  4. } from './index';
  5. async function getImagePath(imagePath) {
  6. return new Promise((resolve, reject) => {
  7. // #ifdef MP-WEIXIN
  8. // console.log(123)
  9. wx.getImageInfo({
  10. src: imagePath,
  11. success: (res) => {
  12. resolve(res.path);
  13. },
  14. fail: (err) => {
  15. reject(err);
  16. }
  17. });
  18. // #endif
  19. // #ifndef MP-WEIXIN
  20. const fullPath = window.location.origin + imagePath;
  21. resolve(fullPath);
  22. // #endif
  23. });
  24. }
  25. const goods = async (poster) => {
  26. const width = poster.width;
  27. const userInfo = sheep.$store('user').userInfo;
  28. return {
  29. background: await getImagePath('/static/goods-poster-bg.jpg'),
  30. list: [{
  31. name: 'nickname',
  32. type: 'text',
  33. val: userInfo.nickname,
  34. x: width * 0.21,
  35. y: width * 0.06,
  36. paintbrushProps: {
  37. fillStyle: '#333',
  38. font: {
  39. fontSize: 16,
  40. fontFamily: 'sans-serif',
  41. },
  42. },
  43. },
  44. {
  45. name: 'avatar',
  46. type: 'image',
  47. val: poster.avatar,
  48. x: width * 0.04,
  49. y: width * 0.04,
  50. width: width * 0.14,
  51. height: width * 0.14,
  52. d: width * 0.14,
  53. },
  54. {
  55. name: 'goodsBg',
  56. type: 'rect',
  57. x: width * 0.03,
  58. y: width * 0.3,
  59. width: width * 0.94,
  60. height: width * 0.75,
  61. r: 5,
  62. },
  63. {
  64. name: 'goodsImage',
  65. type: 'image',
  66. val: poster.shareInfo.poster.image,
  67. x: width * 0.03,
  68. y: width * 0.3,
  69. width: width * 0.94,
  70. height: width * 0.5,
  71. r: 5,
  72. },
  73. {
  74. name: 'goodsTitle',
  75. type: 'text',
  76. val: poster.shareInfo.poster.title,
  77. x: width * 0.05,
  78. y: width * 0.83,
  79. maxWidth: width * 0.91,
  80. line: 5,
  81. lineHeight: 10,
  82. paintbrushProps: {
  83. fillStyle: '#333',
  84. font: {
  85. fontSize: 16,
  86. },
  87. },
  88. },
  89. {
  90. name: 'goodsIntroduction',
  91. type: 'text',
  92. val: poster.shareInfo.poster.introduction,
  93. x: width * 0.05,
  94. y: width * 0.89,
  95. maxWidth: width * 0.9,
  96. height: width * 0.1,
  97. line: 3,
  98. lineHeight: 4,
  99. paintbrushProps: {
  100. fillStyle: '#333',
  101. font: {
  102. fontSize: 12,
  103. fontFamily: 'OPPOSANS',
  104. },
  105. },
  106. },
  107. {
  108. name: 'goodsOriginalPrice',
  109. type: 'text',
  110. val: poster.shareInfo.poster.original_price > 0 ?
  111. '¥' + poster.shareInfo.poster.original_price :
  112. '',
  113. x: width * 0.3,
  114. y: width * 1.32,
  115. paintbrushProps: {
  116. fillStyle: '#999',
  117. font: {
  118. fontSize: 10,
  119. fontFamily: 'OPPOSANS',
  120. },
  121. },
  122. textDecoration: {
  123. line: 'line-through',
  124. style: 'solide',
  125. },
  126. },
  127. // #ifndef MP-WEIXIN
  128. {
  129. name: 'qrcode',
  130. type: 'qrcode',
  131. val: poster.shareInfo.link,
  132. x: width * 0.75,
  133. y: width * 1.07,
  134. size: width * 0.2,
  135. },
  136. // #endif
  137. // #ifdef MP-WEIXIN
  138. {
  139. name: 'wxacode',
  140. type: 'image',
  141. val: sheep.$api.third.wechat.getWxacode(poster.shareInfo.path),
  142. x: width * 0.75,
  143. y: width * 1.3,
  144. width: width * 0.2,
  145. height: width * 0.2,
  146. },
  147. // #endif
  148. ],
  149. };
  150. };
  151. export default goods;