index.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. Component({
  2. properties: {
  3. // 是否开始绘图
  4. isCanDraw: {
  5. type: Boolean,
  6. value: false,
  7. observer(newVal) {
  8. newVal && this.handleStartDrawImg()
  9. }
  10. },
  11. drawMsg: {
  12. type: Object,
  13. value: {}
  14. }
  15. },
  16. data: {
  17. imgDraw: {}, // 绘制图片的大对象
  18. sharePath: '' // 生成的分享图
  19. },
  20. methods: {
  21. handleStartDrawImg() {
  22. console.log(this.data.drawMsg)
  23. let data = this.data.drawMsg;
  24. wx.showLoading({
  25. title: '生成中'
  26. })
  27. this.setData({
  28. imgDraw: {
  29. width: '750rpx',
  30. height: '982rpx',
  31. background: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/share/shareImage.png', //背景图片
  32. views: [
  33. /* 顶部蓝色背景 */
  34. {
  35. type: 'rect',
  36. css: {
  37. top: '36rpx',
  38. left: '30rpx',
  39. width: '690rpx',
  40. height: '114rpx',
  41. borderRadius: '6rpx 6rpx 0px 0px',
  42. color: '#00C1D2'
  43. }
  44. },
  45. /* Logo */
  46. {
  47. type: 'image',
  48. url: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/tacitly-approve/MRuserImg.png',
  49. css: {
  50. top: '64rpx',
  51. left: '50rpx',
  52. width: '58rpx',
  53. height: '58rpx',
  54. borderColor: '#FFF',
  55. borderRadius: '29rpx'
  56. }
  57. },
  58. /* 数据盒子 */
  59. {
  60. type: 'rect',
  61. css: {
  62. top: '66rpx',
  63. left: '368rpx',
  64. width: '312rpx',
  65. height: '54rpx',
  66. color: '#ffffff',
  67. borderRadius: '4rpx'
  68. }
  69. },
  70. /* 数据文字 */
  71. {
  72. type: 'text',
  73. text: '数据',
  74. css: {
  75. height: '40rpx',
  76. top: '74rpx',
  77. left: '525rpx',
  78. fontSize: '28rpx',
  79. align: 'center',
  80. color: '#00C1D2',
  81. lineHeight: '40rpx',
  82. fontWeight: '500',
  83. }
  84. },
  85. /* 供需数据盒子 */
  86. {
  87. type: 'rect',
  88. css: {
  89. top: '150rpx',
  90. left: '30rpx',
  91. width: '690rpx',
  92. height: '282rpx',
  93. borderRadius: '0px 0px 6rpx 6rpx',
  94. color: '#ffffff'
  95. }
  96. },
  97. /* 用户头像 */
  98. {
  99. type: 'image',
  100. url: data.headportraiturl || 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/userCenter/userImg.png',
  101. css: {
  102. top: '184rpx',
  103. left: '70rpx',
  104. width: '32rpx',
  105. height: '32rpx',
  106. borderColor: '#FFF',
  107. borderRadius: '16rpx'
  108. }
  109. },
  110. /* 用户名称 */
  111. {
  112. type: 'text',
  113. text: `${data.createby}`,
  114. css: {
  115. top: '182rpx',
  116. left: '110rpx',
  117. fontSize: '28rpx',
  118. color: '#000'
  119. }
  120. },
  121. /* 用户地址 */
  122. {
  123. type: 'text',
  124. text: `${data.tposition||'暂无地址'}`,
  125. css: {
  126. top: '226rpx',
  127. left: '108rpx',
  128. fontSize: '24rpx',
  129. height: '34rpx',
  130. lineHeight: '34rpx',
  131. width: '588rpx',
  132. color: 'rgba(0,0,0,.7)',
  133. maxLines: '1'
  134. }
  135. },
  136. /* 供需标题 */
  137. {
  138. type: 'text',
  139. text: `[${data.ftype}] ${data.ftitle}`,
  140. css: {
  141. top: '270rpx',
  142. left: '70rpx',
  143. fontSize: '32rpx',
  144. height: '44rpx',
  145. lineHeight: '44rpx',
  146. width: '630rpx',
  147. color: 'rgb(0,0,0)',
  148. fontWeight: '500',
  149. maxLines: '1'
  150. }
  151. },
  152. /* 供需详情 */
  153. {
  154. type: 'text',
  155. text: `${data.fcontent}`,
  156. css: {
  157. top: '322rpx',
  158. left: '70rpx',
  159. fontSize: '28rpx',
  160. height: '80rpx',
  161. lineHeight: '40rpx',
  162. width: '620rpx',
  163. color: 'rgba(0,0,0,.7)',
  164. maxLines: '2'
  165. }
  166. },
  167. /* 第二行盒子 */
  168. {
  169. type: 'rect',
  170. css: {
  171. top: '462rpx',
  172. left: '30rpx',
  173. width: '690rpx',
  174. height: '276rpx',
  175. borderRadius: '6rpx',
  176. color: '#ffffff'
  177. }
  178. },
  179. /* 2-1 */
  180. {
  181. type: 'rect',
  182. css: {
  183. top: '502rpx',
  184. left: '60rpx',
  185. width: '196rpx',
  186. height: '196rpx',
  187. color: '#F6F7F8'
  188. }
  189. },
  190. /* No.1 */
  191. {
  192. type: 'text',
  193. text: `No.1`,
  194. css: {
  195. top: '522rpx',
  196. left: '80rpx',
  197. fontSize: '20rpx',
  198. height: '28rpx',
  199. lineHeight: '28rpx',
  200. color: 'rgb(0,0,0)',
  201. }
  202. },
  203. /* 分享数 */
  204. {
  205. type: 'text',
  206. text: `分享数`,
  207. css: {
  208. top: '555rpx',
  209. left: '80rpx',
  210. fontSize: '24rpx',
  211. height: '34rpx',
  212. lineHeight: '34rpx',
  213. color: 'rgb(0,0,0)',
  214. fontWeight: '600'
  215. }
  216. },
  217. /* 数量 */
  218. {
  219. type: 'text',
  220. text: `${data.fsharetimes}`,
  221. css: {
  222. top: '618rpx',
  223. left: '80rpx',
  224. fontSize: '36rpx',
  225. height: '50rpx',
  226. lineHeight: '50rpx',
  227. color: '#00C1D2',
  228. fontWeight: '600'
  229. }
  230. },
  231. /* 2-2 */
  232. {
  233. type: 'rect',
  234. css: {
  235. top: '502rpx',
  236. left: '276rpx',
  237. width: '196rpx',
  238. height: '196rpx',
  239. color: '#F6F7F8'
  240. }
  241. },
  242. /* No.2 */
  243. {
  244. type: 'text',
  245. text: `No.2`,
  246. css: {
  247. top: '522rpx',
  248. left: '296rpx',
  249. fontSize: '20rpx',
  250. height: '28rpx',
  251. lineHeight: '28rpx',
  252. color: 'rgb(0,0,0)',
  253. }
  254. },
  255. /* 电话数 */
  256. {
  257. type: 'text',
  258. text: `电话数`,
  259. css: {
  260. top: '555rpx',
  261. left: '296rpx',
  262. fontSize: '24rpx',
  263. height: '34rpx',
  264. lineHeight: '34rpx',
  265. color: 'rgb(0,0,0)',
  266. fontWeight: '600'
  267. }
  268. },
  269. /* 数量 */
  270. {
  271. type: 'text',
  272. text: `${data.fphonetimes}`,
  273. css: {
  274. top: '618rpx',
  275. left: '296rpx',
  276. fontSize: '36rpx',
  277. height: '50rpx',
  278. lineHeight: '50rpx',
  279. color: '#00C1D2',
  280. fontWeight: '600'
  281. }
  282. },
  283. /* 2-3 */
  284. {
  285. type: 'rect',
  286. css: {
  287. top: '502rpx',
  288. left: '492rpx',
  289. width: '196rpx',
  290. height: '196rpx',
  291. color: '#F6F7F8'
  292. }
  293. },
  294. /* No.3 */
  295. {
  296. type: 'text',
  297. text: `No.3`,
  298. css: {
  299. top: '522rpx',
  300. left: '512rpx',
  301. fontSize: '20rpx',
  302. height: '28rpx',
  303. lineHeight: '28rpx',
  304. color: 'rgb(0,0,0)',
  305. }
  306. },
  307. /* 浏览数 */
  308. {
  309. type: 'text',
  310. text: `浏览数`,
  311. css: {
  312. top: '555rpx',
  313. left: '512rpx',
  314. fontSize: '24rpx',
  315. height: '34rpx',
  316. lineHeight: '34rpx',
  317. color: 'rgb(0,0,0)',
  318. fontWeight: '600'
  319. }
  320. },
  321. /* 数量 */
  322. {
  323. type: 'text',
  324. text: `${data.freadtimes}`,
  325. css: {
  326. top: '618rpx',
  327. left: '512rpx',
  328. fontSize: '36rpx',
  329. height: '50rpx',
  330. lineHeight: '50rpx',
  331. color: '#00C1D2',
  332. fontWeight: '600'
  333. }
  334. },
  335. /* 第三行盒子 */
  336. {
  337. type: 'rect',
  338. css: {
  339. top: '768rpx',
  340. left: '30rpx',
  341. width: '690rpx',
  342. height: '184rpx',
  343. borderRadius: '6rpx',
  344. color: '#ffffff'
  345. }
  346. },
  347. /* 扫码了解更多资讯 */
  348. {
  349. type: 'text',
  350. text: `扫码了解更多资讯`,
  351. css: {
  352. top: '838rpx',
  353. left: '142rpx',
  354. fontSize: '32rpx',
  355. height: '44rpx',
  356. lineHeight: '44rpx',
  357. color: 'rgba(0,0,0,.7)',
  358. fontWeight: '600'
  359. }
  360. },
  361. /* 箭头 */
  362. {
  363. type: 'image',
  364. url: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/share/right.png',
  365. css: {
  366. top: '842rpx',
  367. left: '408rpx',
  368. width: '52rpx',
  369. height: '36rpx',
  370. }
  371. },
  372. /* 用户头像 */
  373. {
  374. type: 'image',
  375. url: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/WeChat/qrCode.png',
  376. css: {
  377. top: '798rpx',
  378. left: '524rpx',
  379. width: '120rpx',
  380. height: '120rpx',
  381. }
  382. },
  383. ]
  384. }
  385. })
  386. },
  387. onImgErr(e) {
  388. wx.hideLoading()
  389. wx.showToast({
  390. title: '生成分享图失败,请刷新页面重试'
  391. })
  392. //通知外部绘制完成,重置isCanDraw为false
  393. this.triggerEvent('initData')
  394. },
  395. onImgOK(e) {
  396. wx.hideLoading()
  397. // 展示分享图
  398. wx.showShareImageMenu({
  399. path: e.detail.path,
  400. fail: err => {
  401. console.log(err)
  402. }
  403. })
  404. //通知外部绘制完成,重置isCanDraw为false
  405. this.triggerEvent('initData')
  406. }
  407. }
  408. })