user.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import sheep from '@/sheep';
  2. import { formatImageUrlProtocol } from './index';
  3. async function getImagePath(imagePath) {
  4. return new Promise((resolve, reject) => {
  5. // #ifdef MP-WEIXIN
  6. console.log(imagePath);
  7. wx.getImageInfo({
  8. src: imagePath,
  9. success: (res) => {
  10. resolve(res.path);
  11. },
  12. fail: (err) => {
  13. reject(err);
  14. }
  15. });
  16. // #endif
  17. // #ifndef MP-WEIXIN
  18. const fullPath = window.location.origin + imagePath;
  19. resolve(fullPath);
  20. // #endif
  21. });
  22. }
  23. const user = async (poster) => {
  24. const width = poster.width;
  25. const userInfo = sheep.$store('user').userInfo;
  26. return {
  27. background: await getImagePath('/static/user-poster-bg.jpg'),
  28. // background: window.location.origin + '/static/user-poster-bg.jpg',
  29. list: [
  30. {
  31. name: 'nickname',
  32. type: 'text',
  33. val: userInfo.nickname,
  34. x: width / 2,
  35. y: width * 0.4,
  36. paintbrushProps: {
  37. textAlign: 'center',
  38. fillStyle: '#333',
  39. font: {
  40. fontSize: 14,
  41. fontFamily: 'sans-serif',
  42. },
  43. },
  44. },
  45. {
  46. name: 'avatar',
  47. type: 'image',
  48. val: poster.avatar,
  49. x: width * 0.4,
  50. y: width * 0.16,
  51. width: width * 0.2,
  52. height: width * 0.2,
  53. d: width * 0.2,
  54. },
  55. // #ifndef MP-WEIXIN
  56. {
  57. name: 'qrcode',
  58. type: 'qrcode',
  59. val: poster.shareInfo.link,
  60. x: width * 0.35,
  61. y: width * 0.74,
  62. size: width * 0.3,
  63. },
  64. // #endif
  65. // #ifdef MP-WEIXIN
  66. {
  67. name: 'wxacode',
  68. type: 'image',
  69. val: sheep.$api.third.wechat.getWxacode(poster.shareInfo.path),
  70. x: width * 0.35,
  71. y: width * 0.84,
  72. width: width * 0.3,
  73. height: width * 0.3,
  74. },
  75. // #endif
  76. ],
  77. };
  78. };
  79. export default user;