index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Component({
  2. properties: {
  3. radius: {
  4. type: Number
  5. }, //半径 单位px
  6. useSlot: {
  7. type: Boolean
  8. },
  9. zIndex: {
  10. type: Number,
  11. value: 99
  12. }
  13. },
  14. data: {
  15. top: "550px",
  16. left: "345px",
  17. viewHeight: null,
  18. alternative:false
  19. },
  20. lifetimes: {
  21. attached: function () {
  22. let that = this;
  23. wx.getSystemInfo({
  24. success: (res => that.setData({
  25. viewHeight: res.windowHeight
  26. }))
  27. });
  28. },
  29. },
  30. methods: {
  31. viewTouchMove(e) {
  32. let left = e.touches[0].pageX;
  33. if (left > (375 - this.data.radius)) left = 375 - (this.data.radius / 2);
  34. if (left < 0 + this.data.radius) left = 0 + this.data.radius;
  35. let top = e.touches[0].pageY;
  36. if (top < 0 + this.data.radius) top = 0 + this.data.radius;
  37. if (top > this.data.viewHeight - this.data.radius) top = this.data.viewHeight - this.data.radius;
  38. this.setData({
  39. left: left + 'px',
  40. top: top + 'px'
  41. })
  42. },
  43. imageOnErr(e){
  44. console.log("图片加载失败")
  45. this.setData({
  46. alternative:true
  47. })
  48. }
  49. }
  50. })