index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // components/l-nav-bar/index.js
  2. const app = getApp();
  3. Component({
  4. attached () { this._init(); this.dom() },
  5. pageLifetimes: { show () { this._init(), this.dom(); } },
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. // nav-bar
  11. title: { type: String, value: "" },
  12. fixed: { type: Boolean, value: true },
  13. back: { type: Boolean, value: true },
  14. bgc: { type: Boolean, value: false },
  15. // tabber
  16. tabber: { type: Boolean, value: false },
  17. active: { type: Number, value: 0 },
  18. },
  19. /**
  20. * 组件的初始数据
  21. */
  22. data: {
  23. // container margin-top
  24. MarginTop: 0,
  25. },
  26. /**
  27. * 组件的方法列表
  28. */
  29. methods: {
  30. // 定义调用组件的js方法
  31. _init () {
  32. wx.lxd = wx.lxd || {}, wx.lxd.Ctr = e => {
  33. // tabber
  34. const { tabber } = app.globalData;
  35. this.setData({
  36. // app.js 固定定义
  37. // tabber
  38. ...tabber,
  39. // 页面传参
  40. ...e,
  41. })
  42. }
  43. },
  44. // nav事件
  45. NavSuccess () {
  46. wx.navigateBack({
  47. delta: 1
  48. })
  49. },
  50. //tabber 跳转事件
  51. TabberSuccess (event) {
  52. let { detail } = event;
  53. let { tabberlist } = this.data;
  54. wx.redirectTo({
  55. url: tabberlist[detail]["url"],
  56. })
  57. },
  58. //container margin-top 计算
  59. dom () {
  60. // 获取状态栏的高度
  61. const { statusBarHeight } = wx.getSystemInfoSync();
  62. // 获取右上角菜单的位置尺寸
  63. const menuButtonObject = wx.getMenuButtonBoundingClientRect();
  64. const { top, height } = menuButtonObject;
  65. // 计算导航栏的高度
  66. // let navBarHeight=height+(top-statusBarHeight)*2;
  67. let navBarHeight = height + top - statusBarHeight + 6;
  68. // 计算状态栏与导航栏的总高度
  69. const Height = statusBarHeight + navBarHeight;
  70. // 计算容器距离顶部距离
  71. const MarginTop = Height;
  72. this.setData({
  73. MarginTop
  74. })
  75. }
  76. }
  77. })