index.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const { DrawCanvas } = require('./drawCanvas')
  2. Page({
  3. data: {
  4. list: [
  5. {
  6. name: '1',
  7. url: './1.png'
  8. },
  9. {
  10. name: '2',
  11. url: './2.png'
  12. },
  13. ],
  14. dicTypePath: {
  15. 2: 'M174.087591,0.514560141 C221.082581,-0.0605323943 258.036942,16.4651639 285.471873,39.3811671 C324.097037,71.644211 343.867653,116.568208 346.20662,144.24652 C350.19951,191.496617 349.953227,225.979727 337.927395,239.136244 C331.547559,246.11592 292.534012,273.500015 156.081032,273.500015 C124.046067,273.249295 88.3649706,267.889441 59.9639811,260.374988 C31.6787425,252.891161 10.4895126,243.339368 7.76631374,234.485863 C0.979316969,215.637975 -3.35222841,169.181427 5.40075043,132.103662 C11.4231177,109.216448 30.4968016,66.3255379 69.7184967,35.7271113 C95.2877064,15.7795392 129.422591,1.06113985 174.087591,0.514560141 Z',
  16. 1: 'M74.5687033,39.0988067 C103.126959,16.3660403 140.601506,-0.229902063 187.512565,0.524738835 C236.745333,1.31672823 274.595793,17.4503114 302.795795,39.6405029 C342.604241,70.9652189 363.185816,114.34989 369.416086,143.644689 C374.911511,169.484239 376.854407,192.671434 374.545889,210.933889 C372.400553,227.905431 366.593006,240.62113 356.481554,247.164644 C356.083446,247.422274 355.666331,247.696637 355.22572,247.986461 C343.683165,255.57889 315.933614,273.789334 190.568062,279.499721 C98.8356514,278.682689 21.1251422,255.234726 10.5947186,240.294075 C-0.7422251,224.209125 -2.04541832,184.937269 4.21868782,146.408753 C8.01362465,123.067308 30.8546268,73.8958162 74.5687033,39.0988067 Z',
  17. 0: 'M186.999991,0.5 C237.942268,0.5 284.114101,20.9396581 317.773259,54.0709856 C351.489638,87.2586372 372.650842,133.181116 373.474962,184.04672 L373.474962,184.04672 L373.49,186.000085 L373.499915,244.5 L0.499991046,244.5 L0.499991046,186.002992 C0.806967785,134.709026 21.789529,88.3201013 55.5288158,54.7612385 C89.2466165,21.2237469 135.704937,0.5 186.999991,0.5 Z'
  18. }
  19. },
  20. drawCanvas: new DrawCanvas(),
  21. onLoad() {
  22. console.log(111, this.drawCanvas);
  23. // 通过 SelectorQuery 获取 Canvas 节点
  24. wx.createSelectorQuery()
  25. .select('#canvas')
  26. .fields({
  27. node: true,
  28. size: true
  29. })
  30. .exec(this.init.bind(this))
  31. },
  32. init(res) {
  33. const width = res[0].width
  34. const height = res[0].height
  35. const canvas = res[0].node
  36. this.drawCanvas._init({ width, height, canvas, dicTypePath: this.data.dicTypePath[2] })
  37. },
  38. start() {
  39. this.drawCanvas.mouseStart()
  40. },
  41. move(e) {
  42. const { x, y } = e.touches[0]
  43. this.drawCanvas.mouseMove({ x, y })
  44. },
  45. end() {
  46. this.drawCanvas.mouseEnd()
  47. },
  48. back() {
  49. this.drawCanvas.mouseBack()
  50. },
  51. clear() {
  52. this.drawCanvas.clear()
  53. },
  54. changeTool(e) {
  55. const { url } = e.target.dataset.item
  56. if (!url) return
  57. this.drawCanvas.changeBrush(url)
  58. },
  59. save() {
  60. this.drawCanvas.save()
  61. }
  62. })