canvas.js 731 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import example from './example.js';
  2. Page({
  3. onLoad() {
  4. this.context = my.createCanvasContext('canvas')
  5. var methods = Object.keys(example)
  6. this.setData({
  7. methods: methods
  8. })
  9. var that = this
  10. methods.forEach(function (method) {
  11. that[method] = function () {
  12. example[method](that.context)
  13. that.context.draw();
  14. }
  15. })
  16. },
  17. log(e) {
  18. console.log('canvas', e);
  19. },
  20. toTempFilePath() {
  21. this.context.toTempFilePath({
  22. success(res) {
  23. my.previewImage({
  24. urls: [res.apFilePath],
  25. });
  26. },
  27. fail(res) {
  28. my.alert({
  29. title: 'toTempFilePath',
  30. content: `error: ${res.error}`,
  31. })
  32. }
  33. })
  34. }
  35. })