川山甲

追求内心的非常平静!瞬间清空所有的杂念,达到物我两忘!

  博客园  :: 首页  ::  :: 联系 :: 订阅 订阅  :: 管理
 
  最近想做个后台系统,想找个简单点的,而且配置也方便的模版。发现现在网上的模版很炫,而且代码搞得有点复杂,后台模版吗?简单易用就行了。所以今天抽个时间做了个简易版的。
 
源码下载
 
博客园下载地址:https://files.cnblogs.com/baochuan/chuanshanjia_adminV1.rar
百度云下载地址:http://yun.baidu.com/share/link?shareid=3580907019&uk=2922571786&third=0
 
要求
 
  1. 点击模块,不会刷新整个页面,只刷新内容页面;
  2. 方便配置,只要在一个文件里配置,就可以满足条件;
  3. 能够访问别的域名下的内容;
  4. 界面简单清晰;
思路
 
  1. 本来不想用iframe,可是发现,在页面里如果有热链接,则要更新当前页面;如果把热标签全都用js监控,制作js控制,那么代码太繁琐了,所以最后还是决定用iframe。——还有个原因,我发现google和qq邮箱,都用iframe,看来iframe还是有其利用价值的。
  2. 本来想自己写一个js框架,但是发现,代码量会自动加大,所以决定用很多人比较熟悉的框架jquery;
  3. 只为方便使用,所以里面的内容区域(也就是iframe里面的样式等,都可以自己去定义)。
草图设计
 

 

实现
 

 js部分,只用了很短的几行代码

var bp = {
    config:{ 
        ask:[{name:'问答管理', url:'/right.html'},{name:'主题管理', url:'/left.html'}],
        comment:[{name:'评论管理', url:'left.html'}, {name:'用户管理', url:'right.html'}]
    },
    init: function(){
            this.switchSystem($('.head li a:first'));
        },
    switchSystem: function(o){
        if(this.config[o.attr('system')] === undefined){
            alert('当前模块:`' + o.attr('system') + '`您还未进行任何配置,请在cmmon.js的bg.config里进行添加!');
            return -1;
        }

        var system = o.attr('system'),
        modules = this.config[system],
        length = modules.length,
        obj = null,
        html = '';
        for(var i = 0; i < length; i++){
            obj = modules[i];
            html += '<li class="' +  (i ==0 ? 'selected' : '') +'"><a onclick="bp.changeUrl(\'' + obj.url + '\', this)" href="javascript:;">' + obj.name + '</a></li>';
        }
        $('#leftNav').html(html);

        this.changeUrl(modules[0].url);
    },
    changeUrl: function(url, o){    // 切换主体内容(iframe的内容)
        //$('#rightBody').load(url, null, function(){ console.log('Loaded!');});  // 用于非iframe结构体
        // left 样式选择控制
        if(o !== undefined){
            $('#leftNav li').each(function(){
                $(this).removeClass();
            });
             o.parentNode.className = 'selected';
        }

        $('#mainFrame').attr('src', url);
    },
    iframeOnload: function(id){
        //console.log($('#' + id));
    },
    iframeFresh: function(){
        $('#mainFrame').attr('src', $('#mainFrame').attr('src'));
    }
};

$(function(){
    $('.head li a').click(function(){
        bp.switchSystem($(this));
    });

    bp.init();
});

 

注意变量bp.config这里面的配置就是右边要显示的内容,注意名字和url。

 

html部分代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  <title>后台管理</title>
  <link rel="stylesheet" type="text/css" href="static/admin.css" />
  <script type="text/javascript" src="static/jquery-1.10.2.js"></script>

 </head>
 <body>
    <div class="top head">
        <div class="logo"><img src="static/logo.png"/></div>
        <ul class="nav">
            <li><a href="javascript:;" system='ask'>问答系统</a></li>
            <li><a href="javascript:;" system='comment'>评论系统</a></li>
        </ul>
    </div>
    <div class="blank">
        <div class="left_blank"></div>
        <div class="right_blank">
            <div class="J-J5-Ji" title="刷新页面" onclick="bp.iframeFresh()">
                <div class="asa"><span class="ask">&nbsp;</span><div class="asf"></div></div>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="left">
            <ul id="leftNav" class="left_nav"></ul>
        </div>
        <div class="right" id="rightBody">
            <iframe onload="bp.iframeOnload('manFrame')" src="http://localhost/right.html" name="mainFrame" id="mainFrame" frameborder="no" scrolling="auto" hidefocus=""></iframe>
        </div>
    </div>
 </body>
 <script type="text/javascript" src="static/common.js"></script>
</html>

 

这里注意A标签里的system参数,要和上面bp.config的属性名称对应上。

 

CSS样式部分,就罗列到下面了。

 html, body, ul, li, ol, dl, dd, dt, p, h1, h2, h3, h4, h5, h6, form, fieldset, legend, img { margin:0; padding:0; }
 ul, ol { list-style:none; } 
a { color:#666; text-decoration:none; }
a:visited { color:#666; }
a:hover, a:active, a:focus { color:#ff8400; text-decoration:underline; }


.top , .content, .blank{margin:0 auto; width:1024px;}

.head{height:71px;background-color:#F1F1F1;border-bottom:1px solid #E7E7E7;}
.logo{float:left;background-color:#fff;margin-right:117px;}
.head li{float:left; margin-left:20px;font-weight:bold;}
    .nav{padding-top:35px;}

.blank{height:41px;border-bottom:1px solid #E7E7E7;}
    .left_blank{width:163px;position: relative;display: inline-block;}
    .right_blank{width:800px;position: relative;display: inline-block;}
    .J-J5-Ji {position: relative;display: inline-block;padding: 0 8px;margin-top:6px;border: 1px solid #c6c6c6;color: #333;min-width: 54px;background-color: #f5f5f5;height: 27px;line-height: 27px;text-align: center;margin-right: 16px;font-size: 14px;}
    .asa {display: inline-block;cursor:pointer;}
    .ask {width: 1px;margin-right: -1px;position: relative;display: inline-block;}
    .asf{position: relative;display: inline-block;margin-top: -3px;vertical-align: middle;background: no-repeat url(general_black.png) 0 -193px;width: 21px;height: 21px;}

.content .left{float:left;width:163px;}
    .left_nav{ background-color:#fff;}
    .left_nav li{height:40px; line-height:70px;font-size:18px; font-weight:bold;}
    .left_nav li a{color:#706F6F;}
    .left_nav .selected a{color:#E10602;}
.content .right{width:857px;float:left;background-color:blue;border-left:1px solid #ddd;}

#mainFrame{position: absolute;_position: relative;width:857px;_width: expression(document.body.offsetWidth - 192 + 'px');height: 100%;z-index: 5;}

 

总结
 
   由于时间问题,没有做过多的调整,包括浏览器的兼容性,还有页面设计的细化方面。我也只在chrome下做的开发、调整。——对于很多人来说,也许只能算是个很粗糙的东西,我这个只是为自己以后做后台开发的时候,做了个简易模版,做一个通用性比较强的模版而已。
 
推荐
 
posted on 2013-08-25 21:03  川山甲  阅读(8156)  评论(2编辑  收藏  举报