微信小店联盟带货小程序

wx-canvas.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. export default class WxCanvas {
  2. constructor(ctx, canvasId, isNew, canvasNode) {
  3. this.ctx = ctx;
  4. this.canvasId = canvasId;
  5. this.chart = null;
  6. this.isNew = isNew
  7. if (isNew) {
  8. this.canvasNode = canvasNode;
  9. }
  10. }
  11. setChart(chart) {
  12. this.chart = chart;
  13. }
  14. attachEvent() {
  15. // noop
  16. }
  17. detachEvent() {
  18. // noop
  19. }
  20. getContext(contextType) {
  21. if (contextType === '2d') {
  22. return this.ctx;
  23. }
  24. }
  25. // canvasToTempFilePath(opt) {
  26. // if (!opt.canvasId) {
  27. // opt.canvasId = this.canvasId;
  28. // }
  29. // return wx.canvasToTempFilePath(opt, this);
  30. // }
  31. setTransform(a, b, c, d, e, f) {
  32. if (this.isNew) {
  33. this.ctx.setTransform(a, b, c, d, e, f);
  34. } else {
  35. this.ctx.transform(a, b, c, d, e, f);
  36. }
  37. }
  38. // context operations
  39. arc(...args) { this.ctx.arc(...args); }
  40. arcTo(...args) { this.ctx.arcTo(...args); }
  41. beginPath(...args) { this.ctx.beginPath(...args); }
  42. bezierCurveTo(...args) { this.ctx.bezierCurveTo(...args); }
  43. clearRect(...args) { this.ctx.clearRect(...args); }
  44. clip(...args) { this.ctx.clip(...args); }
  45. closePath(...args) { this.ctx.closePath(...args); }
  46. createCircularGradient(...args) { return this.ctx.createCircularGradient(...args); }
  47. createLinearGradient(...args) { return this.ctx.createLinearGradient(...args); }
  48. createPattern(...args) { return this.ctx.createPattern(...args); }
  49. createRadialGradient(...args) { return this.ctx.createRadialGradient(...args); }
  50. drawImage(...args) { this.ctx.drawImage(...args); }
  51. fill(...args) { this.ctx.fill(...args); }
  52. fillRect(...args) { this.ctx.fillRect(...args); }
  53. fillText(...args) { this.ctx.fillText(...args); }
  54. lineTo(...args) { this.ctx.lineTo(...args); }
  55. measureText(...args) { return this.ctx.measureText(...args); }
  56. moveTo(...args) { this.ctx.moveTo(...args); }
  57. quadraticCurveTo(...args) { this.ctx.quadraticCurveTo(...args); }
  58. rect(...args) { this.ctx.rect(...args); }
  59. restore(...args) { this.ctx.restore(...args); }
  60. rotate(...args) { this.ctx.rotate(...args); }
  61. save(...args) { this.ctx.save(...args); }
  62. scale(...args) { this.ctx.scale(...args); }
  63. setFillStyle(...args) { this.ctx.setFillStyle(...args); }
  64. setFontSize(...args) { this.ctx.setFontSize(...args); }
  65. setGlobalAlpha(...args) { this.ctx.setGlobalAlpha(...args); }
  66. setLineCap(...args) { this.ctx.setLineCap(...args); }
  67. setLineDash(...args) { this.ctx.setLineDash(...args); }
  68. setLineJoin(...args) { this.ctx.setLineJoin(...args); }
  69. setLineWidth(...args) { this.ctx.setLineWidth(...args); }
  70. setMiterLimit(...args) { this.ctx.setMiterLimit(...args); }
  71. setShadow(...args) { this.ctx.setShadow(...args); }
  72. setStrokeStyle(...args) { this.ctx.setStrokeStyle(...args); }
  73. setTextAlign(...args) { this.ctx.setTextAlign(...args); }
  74. setTextBaseline(...args) { this.ctx.setTextBaseline(...args); }
  75. stroke(...args) { this.ctx.stroke(...args); }
  76. strokeRect(...args) { this.ctx.strokeRect(...args); }
  77. strokeText(...args) { this.ctx.strokeText(...args); }
  78. transform(...args) { this.ctx.transform(...args); }
  79. translate(...args) { this.ctx.translate(...args); }
  80. }