实现不同用户登录显示不同页面

实现不同用户登录显示不同页面

$(function(){
    var e = getCookie("seller_key");
    // 判断是否有登录
     if (!e) {
         location.href = "login.html"
     }
    if (getQueryString('seller_key') != '') {
        var key = getQueryString('seller_key');
        var seller_name = getQueryString('seller_name');
        addCookie('seller_key', key);
        addCookie('seller_name', seller_name);
    } else {
        var key = getCookie('seller_key');
        var seller_name = getCookie('seller_name');
    }
    if(key && seller_name){
        $.ajax({
            type:'post',
            url:ApiUrl+"/index.php?act=seller_index",
            data:{key:key},
            dataType:'json',
            success:function(result){
                checkSellerLogin(result.login);
                var html = ''
                    + '<div class="member-info">'
                        + '<div class="user-avatar"><img src="' + result.datas.store_info.store_avatar + '"/></div>'
                        + '<div class="user-name"><span>'+result.datas.seller_info.seller_name+'</span></div>'
                    + '</div>';
                $(".member-top").html(html);
                return false;
            }
        });
    } else {
        // 未登录显示
        delCookie('seller_key');
        delCookie('seller_name');
        delCookie('store_name');
        var html = ''
            + '<div class="member-info">'
                + '<a href="login.html" class="default-avatar" style="display:block;"></a>'
                + '<a href="login.html" class="to-login">点击登录</a>'
            + '</div>';
        $(".member-top").html(html);
        return false;
    }
})

封装的函数

function getQueryString(e) {
    //正则去除特殊符号
    var t = new RegExp("(^|&)" + e + "=([^&]*)(&|$)");
    //location.search是从当前URL的?号开始的字符串 
    //如:http://www.runoob.com/try/try.php?filename=tryjsref_search 它的search就是?   filename=tryjsref_search
    //substr(1)去掉?匹配后面的信息
    var a = window.location.search.substr(1).match(t);
    if (a != null) return a[2];
    return ""
}
function addCookie(e, t, a) {
    var n = e + "=" + escape(t) + "; path=/";
    if (a > 0) {
        var r = new Date;
        r.setTime(r.getTime() + a * 3600 * 1e3);
        n = n + ";expires=" + r.toGMTString()
    }
    document.cookie = n
}
function getCookie(e) {
    var t = document.cookie;
    var a = t.split("; ");
    for (var n = 0; n < a.length; n++) {
        var r = a[n].split("=");
        if (r[0] == e) return unescape(r[1])
    }
    return null
}
function delCookie(e) {
    var t = new Date;
    t.setTime(t.getTime() - 1);
    var a = getCookie(e);
    if (a != null) document.cookie = e + "=" + a + "; path=/;expires=" + t.toGMTString()
}
展开阅读全文
博主设置当前文章不允许评论。

没有更多推荐了,返回首页