index.js 886 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const app = getApp()
  2. Page({
  3. data: {
  4. menu: {
  5. show: false,
  6. top: 0,
  7. left: 0
  8. }
  9. },
  10. onLoad(options) {
  11. },
  12. onShow() {
  13. if (typeof this.getTabBar === 'function') {
  14. this.getTabBar().setData({
  15. selected: 3
  16. })
  17. }
  18. },
  19. onLongPress(e) {
  20. console.log(e);
  21. let {
  22. currentTarget,
  23. detail,
  24. touches,
  25. target
  26. } = e
  27. let remainingW = app.globalData.windowWidth - touches[0].clientX
  28. let remainingH = app.globalData.windowHeight - touches[0].clientY
  29. let wFlag = remainingW - 145 > 0
  30. let hFlag = remainingH - 200 > 0
  31. this.setData({
  32. menu: {
  33. show: true,
  34. top: hFlag ? touches[0].clientY : touches[0].clientY - 100,
  35. left: wFlag ? touches[0].clientX : touches[0].clientX - 135
  36. }
  37. })
  38. },
  39. cancelMenu() {
  40. this.setData({
  41. 'menu.show': false
  42. })
  43. }
  44. })