canvas.js 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const example = require('./example.js')
  2. Page({
  3. onShareAppMessage() {
  4. return {
  5. title: '创建画布',
  6. path: 'packageAPI/pages/page/canvas/canvas'
  7. }
  8. },
  9. onLoad() {
  10. this.setData({
  11. theme: wx.getSystemInfoSync().theme || 'light'
  12. })
  13. if (wx.onThemeChange) {
  14. wx.onThemeChange(({theme}) => {
  15. this.setData({theme})
  16. })
  17. }
  18. this.context = wx.createContext()
  19. const methods = Object.keys(example)
  20. this.setData({
  21. methods
  22. })
  23. const that = this
  24. methods.forEach(function (method) {
  25. that[method] = function () {
  26. example[method](that.context)
  27. const actions = that.context.getActions()
  28. wx.drawCanvas({
  29. canvasId: 'canvas',
  30. actions
  31. })
  32. }
  33. })
  34. },
  35. toTempFilePath() {
  36. wx.canvasToTempFilePath({
  37. canvasId: 'canvas',
  38. success(res) {
  39. console.log(res)
  40. },
  41. fail(res) {
  42. console.log(res)
  43. }
  44. })
  45. }
  46. })