index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // nova-werun/components/my/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. },
  8. /**
  9. * 组件的初始数据
  10. */
  11. data: {
  12. //屏幕高度
  13. statusBarHeight: 0, // 状态栏高度
  14. screenHeight: 0, // 屏幕高度
  15. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  16. bottomNavHeight: 0, // 底部导航栏高度
  17. contentHeight: 0, // 可用内容高度
  18. contentpadding: 0, //顶部padding高度
  19. },
  20. lifetimes: {
  21. detached: function () {
  22. // 在组件实例被从页面节点树移除时执行
  23. },
  24. attached: async function () {
  25. // 在组件实例进入页面节点树时执行
  26. // 计算
  27. const systemInfo = wx.getSystemInfoSync();
  28. const statusBarHeight = systemInfo.statusBarHeight || 0;
  29. const screenHeight = systemInfo.screenHeight || 0;
  30. const custom = wx.getMenuButtonBoundingClientRect();
  31. const customHeight = custom.height + 10 + 2 || 0;
  32. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  33. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  34. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  35. this.setData({
  36. statusBarHeight,
  37. screenHeight,
  38. customHeight,
  39. bottomNavHeight,
  40. contentHeight,
  41. contentpadding
  42. });
  43. },
  44. },
  45. /**
  46. * 组件的方法列表
  47. */
  48. methods: {
  49. gourl(e) {
  50. const url = e.currentTarget.dataset.url
  51. wx.navigateTo({
  52. url: `${url}` // 目标页面的路径
  53. });
  54. },
  55. }
  56. })