123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- var headerNavMini = {
- inIframe: window.parent !== window,
- headerNavContainer: $('#header-nav-container'),
- headerNav: $('#public-nav'),
- headerNavPlaceholder: $('#header-nav-mini-placeholder'),
- headerNavSecond: $('#pc-header-nav-second'),
- _headerNavFixedHeight: $('#public-nav').height(),
- // 因为二级菜单有动画延迟,所以直接写计算后的值
- // (这个地方需要注意:这里写的值是第二个头部的真实显示高度。但是在未登陆下,第二个头部其实是不会显示的(高度为0),但是这个变量仍然是72。)
- _headerNavSecondHeight: 72,
- init: function () {
- this.initStyle()
- this.initEvents()
- },
- initStyle: function () {
- var _this = this
- if (this.inIframe) {
- this.headerNav.hide()
- this.headerNavContainer.hide()
- } else {
- this.headerNav.show()
- }
- // 加个延迟让二级导航的slideDown看起来不那么突兀
- setTimeout(function () {
- _this.secondHeaderShow()
- }, 300)
- },
- headerFixed: function (f) {
- if (f) {
- // 头部header固定
- this.headerNav.removeClass('relative')
- this.headerNavPlaceholder.show()
- } else {
- // 头部不固定
- this.headerNav.addClass('relative')
- this.headerNavPlaceholder.hide()
- }
- },
- changeHeaderPlaceholder: function () {
- // 头部占位
- this.headerNavPlaceholder.height(this._headerNavFixedHeight)
- },
- // 工作台外的页面顶部统一展示(除了首页)
- secondHeaderShow: function (login) {
- if (this.inIframe) return
- // exclude中的页面不会显示第二个头部
- var pathname = location.pathname
- var excludeReg = [
- /^\/$/, // 首页
- new RegExp('/free/loading'), // 部分中转页(画像)
- // new RegExp('/brand/index'),
- ]
- var findTarget = false
- for (var i = 0; i < excludeReg.length; i++) {
- if (excludeReg[i].test(pathname)) {
- findTarget = true
- break
- }
- }
- if (!findTarget) {
- this.headerNavSecond.slideDown({
- speed: 200
- })
- }
- },
- initEvents: function () {
- this.initLoginButtonEvent()
- this.initHeaderNavMenuEvents()
- this.initHeaderNavUserInfoEvent()
- },
- initLoginButtonEvent: function () {
- var _this = this
- $('.login-register-button').on('click', function () {
- _this.doLogin()
- })
- },
- initHeaderNavMenuEvents: function () {
- // 下载app - 跳转新链接
- // $('.header-nav-mini .menu-item.download-app').on('click', function () {
- // $('#downloadApp').modal('show')
- // })
- },
- initHeaderNavUserInfoEvent: function () {
- function hideUserInfoPop (time) {
- clearTimeout(window.hideUserInfoTm)
- window.hideUserInfoTm = setTimeout(function () {
- $(".work-user-info").hide()
- }, time || 0)
- }
- function addPopListener (selector, time) {
- $(selector).mouseenter(function () {
- clearTimeout(window.hideUserInfoTm)
- $(".work-user-info").show()
- })
- $(selector).mouseleave(function () {
- hideUserInfoPop(time)
- })
- }
- addPopListener('.work-user-info')
- addPopListener('#public-nav .nav-avatar', 500)
- //隐藏弹窗
- $('body').click(function(event){
- //获取鼠标点击目标
- var target = $(event.target);
- //点击目标为头像 弹出或关闭用户信息列表
- if(target.is('img[class*=user-avatar]')){
- $(".work-user-info").toggle()
- }else{
- //点击body隐藏
- var isSelf = target.hasClass('.work-user-info') || target.parents('.work-user-info').length > 0
- if (!isSelf) {
- $(".work-user-info").hide()
- }
- }
- })
- },
- doLogin: function () {
- if (location.pathname === '/') {
- // 打开登录窗口,登录成功后去工作桌面
- openLoginDig(true)
- } else {
- // 打开登录窗口,登录成功后打开当前页
- openLoginDig(false, 'reload')
- }
- },
- checkLogin: function (login) {
- if (login) {
- // 登录
- $('.login-show').show()
- $('.no-login-show').hide()
- // 登陆按钮
- $('.login-register-button').hide()
- $('.go-to-workspace').show()
- } else {
- // 未登录
- $('.login-show').hide()
- $('.no-login-show').show()
- // 登陆按钮
- $('.login-register-button').show()
- $('.go-to-workspace').hide()
- }
- this.changeHeaderPlaceholder()
- },
- changeMenuActive: function (name) {
- this.headerNav.find('[name='+name+']').addClass('active')
- },
- updateUserInfo: function () {},
- updateUserPower: function () {},
- }
- $(function () {
- headerNavMini.init()
- })
- headerNavMini.checkLogin(false)
- function loginCallbackHeader (uInfo) {
- headerNavMini.checkLogin(loginflag)
- window.message = new Message()
- try {
- LoginPolling.stop()
- } catch (error) {
- console.log(error)
- }
- }
- function infoListCss () {}
|