index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. viewWidth: 375
  20. },
  21. lifetimes: {
  22. attached: function () {
  23. this.setData({
  24. userid: wx.getStorageSync('userMsg').userid
  25. })
  26. let that = this;
  27. wx.getSystemInfo({
  28. success: (res => that.setData({
  29. viewHeight: res.windowHeight,
  30. viewWidth: res.windowWidth // ✅ 加这一行
  31. }))
  32. });
  33. },
  34. },
  35. methods: {
  36. viewTouchMove(e) {
  37. let left = e.touches[0].pageX;
  38. if (left > (this.data.viewWidth - this.data.radius)) left = this.data.viewWidth - (this.data.radius / 2);
  39. if (left < 0 + this.data.radius) left = 0 + this.data.radius;
  40. let top = e.touches[0].pageY;
  41. if (top < 0 + this.data.radius) top = 0 + this.data.radius;
  42. if (top > this.data.viewHeight - this.data.radius) top = this.data.viewHeight - this.data.radius;
  43. this.setData({
  44. left: left + 'px',
  45. top: top + 'px'
  46. })
  47. },
  48. imageOnErr(e) {
  49. console.log("图片加载失败")
  50. this.setData({
  51. alternative: true
  52. })
  53. }
  54. }
  55. })