config.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import Taro, { preloadData } from '@tarojs/taro'
  2. /**
  3. * 获取配置
  4. * @returns
  5. */
  6. export function getConfig() {
  7. // https://developers.weixin.qq.com/miniprogram/dev/api/base/system/wx.getSystemInfo.html
  8. const systemInfo = Taro.getStorageSync('systemInfo')
  9. const { windowWidth, pixelRatio: dpr } = systemInfo
  10. // canvas
  11. const canvas = {
  12. width: windowWidth * dpr,
  13. // 设计稿宽高比 2.16 = height / width
  14. height: windowWidth * dpr * 2.16,
  15. }
  16. // 图片
  17. const poster = {
  18. width: canvas.width,
  19. height: canvas.width * 16 / 9, // 图片宽高 9 : 16 占用 canvas 80%
  20. x: 0,
  21. y: 0,
  22. }
  23. const marign = 22.5 * dpr;
  24. const innerMargin = 15 * dpr
  25. // 头像
  26. const avatar = {
  27. arc: true, // arc 代表裁剪为圆形
  28. width: 66 * dpr,
  29. height: 66 * dpr,
  30. x: marign,
  31. y: poster.height + (39 * dpr),
  32. }
  33. // 小程序码
  34. const miniCode = {
  35. arc: true,
  36. width: 99 * dpr,
  37. height: 99 * dpr,
  38. x: canvas.width - (99 * dpr) - marign, // 99 是宽度
  39. y: poster.height + (20 * dpr),
  40. }
  41. // 姓名
  42. const name = {
  43. // https://developer.mozilla.org/zh-CN/docs/Web/CSS/font
  44. font: `${15 * dpr}px serif`,
  45. // https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/fillStyle
  46. fillStyle: '#333333',
  47. // 左右两边边距
  48. // 左右两边文字边距
  49. maxWidth: canvas.width - (marign * 2) - avatar.width - miniCode.width - (innerMargin * 2),
  50. x: marign + avatar.width + innerMargin,
  51. y: poster.height + (65 * dpr),
  52. }
  53. // 说明
  54. const desc = {
  55. font: `${10 * dpr}px serif`,
  56. fillStyle: '#666666',
  57. maxWidth: name.maxWidth,
  58. x: name.x,
  59. y: poster.height + (89.5 * dpr),
  60. }
  61. return {
  62. systemInfo,
  63. canvas,
  64. poster,
  65. miniCode,
  66. avatar,
  67. name,
  68. desc,
  69. }
  70. }