header.vm 7.88 KB
#set($homePage = "/main.do")
#set($url_change_dataAuth = "/changeDataAuth.do")

<script type="text/javascript" src="/static/js/modal.js">
</script>
<script type="text/javascript" src="/static/js/tmp.js">
</script>

<script type="text/javascript">

function getMsg(){
    $.ajax({
        type: "GET",
        url: "$!{webUtils.msgUnreadPath}",
        dataType: "jsonp",
        jsonp: "callback",
        success: function(data) {
            handleMsg(data.result);
//            handleMsg([1, 2, 3, 4, 5]);
        }
    });
}

function getLocalTime(unix) {
    var now = new Date(parseInt(unix));
    return now.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
}


getMsg();

$("#msg-menu-btn li").click(function () {
    $('#msg_list').empty();
    getMsg();
});


function handleMsg(msg){
    msg.forEach(function(m){
        var ctx = '<li class="divider"></li><li style="height: 30px;  list-style-type: none;"><div style="line-height: 12px;">' + getLocalTime(m.createdDate) + '</div><div style="line-height: 34px;">' + m.content +'</div></li>';
        $('#msg_list').append(ctx);
        console.log(ctx);
    })
};



var totalCount = 0;
var init = 0;
function sync(){
	$.ajax({
        type: "GET",
        url: "$!{webUtils.messageSyncPath}",
        dataType: "jsonp",
        jsonp: "callback",
        success: function(data) {
            handleSyncCount(data.result);
        }
    });
}

function handleSyncCount(count){
	if(init >= 1 && count > totalCount)
		$.Tips({title: '一条新消息需要处理', link:'${homePage}?returnUrl=$!{webUtils.messageListPath}'}).show();
	init = 1;
	if(count > 0) {
    	totalCount = count;
		$('#msg_count').text((totalCount > 99 ? '99+' : totalCount));
	}
	else
		$('#msg_count').text("0");
}

function async(){
    $.ajax({
        type: "GET",
        url: "$!{webUtils.getMessageAsyncPath($!{user.id})}",
        dataType: "jsonp",
        timeout: 1800000,
        jsonp: "callback",
        success: function(data) {
        	handleCount(data.result);
        },
        complete: function(XMLHttpRequest){
        	async();
        }
    });
}

function handleCount(count){
	if(count > 0)
		$.Tips({title: '一条新消息需要处理', link:'${homePage}?returnUrl=$!{webUtils.messageListPath}'}).show();
	totalCount += count;
	if(totalCount < 0)
		totalCount = 0;
	var count = totalCount > 99 ? '99+' : totalCount;
	if(totalCount == 0){
        $('#msg_count').text("0");
		return;	
	}
	if($('#msg_count').length>0){
    	$('#msg_count').text(count);
    } 
    else
    	$('#msg_count').text(count);
}
sync();
setInterval('sync()',500000);


//sync();
//async();
</script>
<div id="navbar" class="navbar navbar-default header clearfix">
	<div class="navbar-container" id="navbar-container">
		<button type="button" class="navbar-toggle menu-toggler pull-left" id="menu-toggler">
			<span class="sr-only">Toggle sidebar</span>

			<span class="icon-bar"></span>

			<span class="icon-bar"></span>

			<span class="icon-bar"></span>
		</button>
		
		<div class="navbar-header pull-left">
			<a href="${homePage}" class="navbar-brand">
				<small>
					一年四季后台管理系统
				</small>
			</a>
		</div>



        <div class="navbar-buttons navbar-header pull-right" role="navigation">
            <ul class="nav ace-nav">
                <li class="light-blue">
                    <a data-toggle="dropdown" href="#" class="dropdown-toggle">
                        <img class="nav-user-photo" src="$!{webUtils.getAssetsPath("/ace1.3/assets/avatars/user.jpg")}" alt="Jason's Photo" />
						<span class="user-info" userId="$!{user.id}">
							<small>欢迎你</small>
                            $!{user.realName}
						</span>
                        <i class="ace-icon fa fa-caret-down"></i>
                    </a>

                    <ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close">
                        <!-- <li>
                            <a href="#">
                                <i class="ace-icon fa fa-cog"></i>
                                配置
                            </a>
                        </li> -->

                        <li>
                            <a href="/user/show.do?id=$!{user.id}" target="frame3d">
                                <i class="ace-icon fa fa-user"></i>
                                用户信息
                            </a>
                        </li>
                        <li>
                            <a href="/user/preUpdatePwd.do" target="frame3d">
                                <i class="ace-icon fa fa-user"></i>
                                修改密码
                            </a>
                        </li>

                        <li class="divider"></li>

                        <li>
                            <a href="$!{webUtils.getLocalPath("/loginControl/logout.do")}">
                                <i class="ace-icon fa fa-power-off"></i>
                                注销
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>

##        <a href="${homePage}?returnUrl=$!{webUtils.messageListPath}" id="notice" class="ui-icon message"></a>



        <div id="msg-menu-btn" class="navbar-buttons navbar-header pull-right" role="navigation" style="margin-right: 20px;">
            <ul class="nav ace-nav">
                <li class="light-blue">
                    <a data-toggle="dropdown" href="#" class="dropdown-toggle">
                        消息
                        <i class="ace-icon fa fa-caret-down"></i>
                    </a>

                    <ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close msg-menu"
                        style="color:#333;width:450px">

                        <li>
                            <a target="frame3d">
                                <div class="media-body">
                                    <h3 class="media-heading">消息中心 (<span id="msg_count"></span>)</h3>
                                </div>
                            </a>
                        </li>
                        <li ><ul id="msg_list"></ul></li>

                        <li class="divider"></li>
                        <li>
                            <a href="${homePage}?returnUrl=$!{webUtils.messageListPath}">
                                <center><small>更多</small></center>
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>





        #foreach($da in $dataAuths)
			#if(${da.conf.type} == 'city')
				<input type="button" class="btn btn-info pull-right" value="${da.conf.label}:${da.current.value}" onclick="javascript:selectCity(${da.current.name},'${da.conf.type}','${url_change_dataAuth}');"/>
			#else
                <div class="navbar-buttons navbar-header pull-right" role="navigation" style="margin-right: 20px;">
                    <ul class="nav ace-nav">
                        <li class="light-blue">
                            <a data-toggle="dropdown" href="#" class="dropdown-toggle">
                                ${da.conf.label}:${da.current.value}
                                <i class="ace-icon fa fa-caret-down"></i>
                            </a>
    
                            <ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close list-inline"
                                style="color:#333;width:450px">
                                #foreach($item in $da.das)
                                <li><a href="${url_change_dataAuth}?type=${da.conf.type}&current=${item.dataId}">${item.label}</a></li>
                                #end
    
                            </ul>
                        </li>
                    </ul>
                </div>
			#end
        #end




    </div><!-- /.navbar-container -->
</div>