header-nav-mini.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. var headerNavMini = {
  2. inIframe: window.parent !== window,
  3. headerNavContainer: $('#header-nav-container'),
  4. headerNav: $('#public-nav'),
  5. headerNavPlaceholder: $('#header-nav-mini-placeholder'),
  6. headerNavSecond: $('#pc-header-nav-second'),
  7. _headerNavFixedHeight: $('#public-nav').height(),
  8. // 因为二级菜单有动画延迟,所以直接写计算后的值
  9. // (这个地方需要注意:这里写的值是第二个头部的真实显示高度。但是在未登陆下,第二个头部其实是不会显示的(高度为0),但是这个变量仍然是72。)
  10. _headerNavSecondHeight: 72,
  11. init: function () {
  12. this.initStyle()
  13. this.initEvents()
  14. },
  15. initStyle: function () {
  16. var _this = this
  17. if (this.inIframe) {
  18. this.headerNav.hide()
  19. this.headerNavContainer.hide()
  20. } else {
  21. this.headerNav.show()
  22. }
  23. // 加个延迟让二级导航的slideDown看起来不那么突兀
  24. setTimeout(function () {
  25. _this.secondHeaderShow()
  26. }, 300)
  27. },
  28. headerFixed: function (f) {
  29. if (f) {
  30. // 头部header固定
  31. this.headerNav.removeClass('relative')
  32. this.headerNavPlaceholder.show()
  33. } else {
  34. // 头部不固定
  35. this.headerNav.addClass('relative')
  36. this.headerNavPlaceholder.hide()
  37. }
  38. },
  39. changeHeaderPlaceholder: function () {
  40. // 头部占位
  41. this.headerNavPlaceholder.height(this._headerNavFixedHeight)
  42. },
  43. // 工作台外的页面顶部统一展示(除了首页)
  44. secondHeaderShow: function (login) {
  45. if (this.inIframe) return
  46. // exclude中的页面不会显示第二个头部
  47. var pathname = location.pathname
  48. var excludeReg = [
  49. /^\/$/, // 首页
  50. new RegExp('/free/loading'), // 部分中转页(画像)
  51. // new RegExp('/brand/index'),
  52. ]
  53. var findTarget = false
  54. for (var i = 0; i < excludeReg.length; i++) {
  55. if (excludeReg[i].test(pathname)) {
  56. findTarget = true
  57. break
  58. }
  59. }
  60. if (!findTarget) {
  61. this.headerNavSecond.slideDown({
  62. speed: 200
  63. })
  64. }
  65. },
  66. initEvents: function () {
  67. this.initLoginButtonEvent()
  68. this.initHeaderNavMenuEvents()
  69. this.initHeaderNavUserInfoEvent()
  70. },
  71. initLoginButtonEvent: function () {
  72. var _this = this
  73. $('.login-register-button').on('click', function () {
  74. _this.doLogin()
  75. })
  76. },
  77. initHeaderNavMenuEvents: function () {
  78. // 下载app - 跳转新链接
  79. // $('.header-nav-mini .menu-item.download-app').on('click', function () {
  80. // $('#downloadApp').modal('show')
  81. // })
  82. },
  83. initHeaderNavUserInfoEvent: function () {
  84. function hideUserInfoPop (time) {
  85. clearTimeout(window.hideUserInfoTm)
  86. window.hideUserInfoTm = setTimeout(function () {
  87. $(".work-user-info").hide()
  88. }, time || 0)
  89. }
  90. function addPopListener (selector, time) {
  91. $(selector).mouseenter(function () {
  92. clearTimeout(window.hideUserInfoTm)
  93. $(".work-user-info").show()
  94. })
  95. $(selector).mouseleave(function () {
  96. hideUserInfoPop(time)
  97. })
  98. }
  99. addPopListener('.work-user-info')
  100. addPopListener('#public-nav .nav-avatar', 500)
  101. //隐藏弹窗
  102. $('body').click(function(event){
  103. //获取鼠标点击目标
  104. var target = $(event.target);
  105. //点击目标为头像 弹出或关闭用户信息列表
  106. if(target.is('img[class*=user-avatar]')){
  107. $(".work-user-info").toggle()
  108. }else{
  109. //点击body隐藏
  110. var isSelf = target.hasClass('.work-user-info') || target.parents('.work-user-info').length > 0
  111. if (!isSelf) {
  112. $(".work-user-info").hide()
  113. }
  114. }
  115. })
  116. },
  117. doLogin: function () {
  118. if (location.pathname === '/') {
  119. // 打开登录窗口,登录成功后去工作桌面
  120. openLoginDig(true)
  121. } else {
  122. // 打开登录窗口,登录成功后打开当前页
  123. openLoginDig(false, 'reload')
  124. }
  125. },
  126. checkLogin: function (login) {
  127. if (login) {
  128. // 登录
  129. $('.login-show').show()
  130. $('.no-login-show').hide()
  131. // 登陆按钮
  132. $('.login-register-button').hide()
  133. $('.go-to-workspace').show()
  134. } else {
  135. // 未登录
  136. $('.login-show').hide()
  137. $('.no-login-show').show()
  138. // 登陆按钮
  139. $('.login-register-button').show()
  140. $('.go-to-workspace').hide()
  141. }
  142. this.changeHeaderPlaceholder()
  143. },
  144. changeMenuActive: function (name) {
  145. this.headerNav.find('[name='+name+']').addClass('active')
  146. },
  147. updateUserInfo: function () {},
  148. updateUserPower: function () {},
  149. }
  150. $(function () {
  151. headerNavMini.init()
  152. })
  153. headerNavMini.checkLogin(false)
  154. function loginCallbackHeader (uInfo) {
  155. headerNavMini.checkLogin(loginflag)
  156. window.message = new Message()
  157. try {
  158. LoginPolling.stop()
  159. } catch (error) {
  160. console.log(error)
  161. }
  162. }
  163. function infoListCss () {}