index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // components/l-nav-bar/index.js
  2. const app = getApp();
  3. var time = null;
  4. Component({
  5. options: {
  6. multipleSlots: true
  7. },
  8. attached () { this._init(); this.dom() },
  9. detached: function () { clearTimeout(time) },
  10. pageLifetimes: { show () { this._init(), this.tong(); this.dom(); } },
  11. /**
  12. * 组件的属性列表
  13. */
  14. properties: {
  15. // nav-bar
  16. title: { type: String, value: "" },
  17. fixed: { type: Boolean, value: true },
  18. back: { type: Boolean, value: true },
  19. bgc: { type: Boolean, value: false },
  20. // tabber
  21. tabber: { type: Boolean, value: false },
  22. active: { type: Number, value: 0 },
  23. },
  24. /**
  25. * 组件的初始数据
  26. */
  27. data: {
  28. // container margin-top
  29. MarginTop: 0,
  30. },
  31. /**
  32. * 组件的方法列表
  33. */
  34. methods: {
  35. // 定义调用组件的js方法
  36. _init () {
  37. wx.lxd = wx.lxd || {}, wx.lxd.Ctr = e => {
  38. // tabber
  39. const { tabber } = app.globalData;
  40. this.setData({
  41. // app.js 固定定义
  42. // tabber
  43. ...tabber,
  44. // 页面传参
  45. ...e,
  46. })
  47. }
  48. },
  49. // nav事件
  50. NavSuccess () {
  51. wx.navigateBack({
  52. delta: 1
  53. })
  54. },
  55. //tabber 跳转事件
  56. TabberSuccess (event) {
  57. let { detail } = event;
  58. if (detail == this.data.active) return false;
  59. let { tabberlist } = this.data;
  60. wx.redirectTo({
  61. url: tabberlist[detail]["url"],
  62. })
  63. },
  64. //container margin-top 计算
  65. dom () {
  66. // 获取状态栏的高度
  67. const { statusBarHeight } = wx.getSystemInfoSync();
  68. // 获取右上角菜单的位置尺寸
  69. const menuButtonObject = wx.getMenuButtonBoundingClientRect();
  70. const { top, height } = menuButtonObject;
  71. // 计算导航栏的高度
  72. // let navBarHeight=height+(top-statusBarHeight)*2;
  73. let navBarHeight = height + top - statusBarHeight + 6;
  74. // 计算状态栏与导航栏的总高度
  75. const Height = statusBarHeight + navBarHeight;
  76. // 计算容器距离顶部距离
  77. const MarginTop = Height;
  78. this.setData({
  79. MarginTop
  80. })
  81. },
  82. // 必须执行的函数
  83. tong () {
  84. // 去除全局方法过慢问题
  85. function bugfunc () {
  86. if (!!app.globalData.codeSession) return false;
  87. wx.lxd.Overlay({
  88. show: true,
  89. type: 'loading'
  90. })
  91. time = setInterval(() => {
  92. if (!!app.globalData.codeSession) {
  93. clearInterval(time)
  94. wx.lxd.HideOverlay();
  95. var page = getCurrentPages().pop(); //当前页面
  96. if (page == undefined || page == null) return;
  97. page.onShow();
  98. }
  99. }, 100)
  100. }
  101. bugfunc();
  102. }
  103. }
  104. })