首页 > 技术文章 > php随笔5-thinkphp OA系统 人力资源管理

GaoAnLee 2015-11-04 15:00 原文

最近闲来无事,自己尝试通过thinkphp3.1.3框架开发一套自己的OA系统,目前已完成了人力资源管理部分的内容,遇到并解决了几个问题。

1.由于刚开始不太熟悉thinkphp的框架,花费了一些功夫去了解。重点阅读了开发手册:http://doc.thinkphp.cn/manual/preface.html

2.问题:HTML 布局  规划布局为 header(头部)+side(左侧导航)+content(内容)的布局。

  学习点:div 布局 

      1)position:absolute :

      2)top:30px;left:30px; :相对于整个页面距离顶部和左边的距离

      3)height:150px;width:1900px;:div 的高度和宽度

#header{position:absolute;height:150px;width:1900px;color:#fff;background:#666;line-height:50px;z-index:4;top:0px;left:0px}
#content{position:absolute;width:1895px;color:#fff;float:right;margin-left:-170px;margin-top:0px;z-index:3;top:145px;left:175px}
#content_inner{position:absolute;width:1725px;height:665px;background:#333300;top:15px;left:170px}
#side{position:absolute;width:265px;height:760px;color:#fff;background:#FFFFFF;float:left;margin-top:0px;z-index:5;;top:160px;left:0px}
#side_inner{position:absolute;width:265;heigth:550px;top:0px}
#footer{position:absolute;height:50px;color:#fff;background:#666;margin-top:10px;z-index:2}

  thinkphp模板包含整合:<include file="./Tpl/Home/index/index_layout.html"/>  注:有使用分组Home,Admin

    问题:模板包含导致读取的CSS,JS无效的问题:<script src="/app/public/js/jquery-1.11.2.min.js" type="text/javascript"></script>    使用这样的地址方式才有效

3.问题:模板读取信息ajax至指定控制器方法并返回json数据集,并对json数据集进行遍历输出。期间遇到编码的问题,显示中文为乱码,需要调整全部的编码方式为UTF-8,首先调整编辑器的编码方式,然后是thinkphp的编码方式,以及数据库的编码方式。

  PersonnelmattersAction.class.php  的 handlename()

     //getmember ajax name
        public function handlename()
        {
            if( IS_POST ) 
            {
                $Data = M('Personnelmatters');
                $cate = $_POST['name'];
                //$cate  = iconv("UTF-8","GB2312//TRANSLIT",$cate); 
                $field ="id,aid,department,station,entry_time,name,privatephone,companyphone,idnumber,education,maritalstatus,drivinglicense,email,job";
                $result = $Data->field($field)->where(array('name'=> $cate))->select();
                //$this->ajaxReturn($result,"OK",1);
                echo json_encode($result,true);
            }else
            {
                echo json_encode("",true);
            }
        }

  PersonnelmattersModel.class.php

<?php

    class PersonnelmattersModel extends Model{
        //指定数据库
        protected $dbName = 'yloa';
        
        //定义模型字段
        protected $fields = array(
            'id', 
            'aid', 
            'department', 
            'station', 
            'entry_time',
            'name',
            'privatephone',
            'companyphone',
            'idnumber',
            'education',
            'maritalstatus',
            'drivinglicense',
            'email',
            'job',
            '_pk' => 'id', 
            '_autoinc' => true
        );
        
        // 定义自动验证
           protected $_validate    =   array(
            array('aid','require','工号必须'),
            array('department','require','部门必须'),
            array('station','require','岗位必须'),
            array('entry_time','require','入职时间必须'),
            array('name','require','工号必须'),
            array('privatephone','require','个人电话必须'),
            array('idnumber','require','身份证必须'),
            array('education','require','学历必须'),
            array('maritalstatus','require','婚否必须'),
            array('drivinglicense','require','是否有驾照必须'),
            array('email','require','邮箱必须'),
            array('job','require','是否在职必须'),
        );
            
    }

  getmember.html

<select id="name" style="height:30px;width:75px">   
        <volist name="search" id="vo">      
          <option value="{$vo.name}">{$vo.name}</option>
        </volist>
</select>
     $(function(){
         var ajaxUrl = "/app/index.php/Personnelmatters/handlename";
         $("#name").change(function(){ 
              var name = $("#name").val(); 
             $.post(ajaxUrl,{"name":name},function(json){
                 printPersonnelmatters(json);
             },'json');
         });
     })
  //员工资料展示
    function printPersonnelmatters(json)
    {
         if(json == null || json == undefined || json == '')
         {
            $("#result").html("返回值为空!");
         }
         else
         {
             var len = json.length; 
             var tableStr ="<table class='imagetable'>";
             tableStr = tableStr + "<tr><th>序号</th><th>工号</th><th>部门</th><th>职务</th><th>入职时间</th><th>姓名</th><th>私人电话</th><th>公司电话</th><th>身份证</th><th>学历</th><th>婚否</th><th>是否有驾照</th><th>邮箱</th><th>是否在职</th><th>操作</th></tr>";
             for(var i=0;i<len;i++)
             {
                tableStr = tableStr + "<tr><td id='myid'>"+ json[i].id +"</td>"
                +"<td>"+  json[i].aid + "</td>"
                +"<td>"+  json[i].department + "</td>"
                +"<td>"+  json[i].station + "</td>"
                +"<td>"+  json[i].entry_time + "</td>"
                +"<td>"+  json[i].name + "</td>"
                +"<td>"+  json[i].privatephone + "</td>"
                +"<td>"+  json[i].companyphone + "</td>"
                +"<td>"+  json[i].idnumber + "</td>"
                +"<td>"+  json[i].education + "</td>"
                +"<td>"+  json[i].maritalstatus + "</td>"
                +"<td>"+  json[i].drivinglicense + "</td>"
                +"<td>"+  json[i].email + "</td>"
                +"<td>"+  json[i].job + "</td>"
                +"<td>"+  "<nobr><input type='button' id='edit' value='编辑' onclick='javascript:edit_id("+json[i].id+");' /><input type='button' id='delete' value='删除'  onclick='javascript:delete_id("+json[i].id+");' /></nobr>"+ "</td></tr>"; 
             }
             tableStr = tableStr + "</table>";
             $("#result").html(tableStr); 
         }
    }

  问题:获取指定行id。直接在展示方法中传值

4.问题:thinkphp数据分页,thinkphp有自带的数据分页类。

  PersonnelmattersAction.class.php  的 getmember()

 

         //获取职员信息
        public function getmember(){
            $Data = M('Personnelmatters');
            import('ORG.Util.Page');// 导入分页类
            $count = $Data->count();// 查询满足要求的总记录数
            $lastpage = floor(($count/10)+1);
            $Page  = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
            $show = $Page->show();// 分页显示输出
            // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
            $list = $Data->limit($Page->firstRow.','.$Page->listRows)->select();
            $this->assign('list',$list);// 赋值数据集
            $this->assign('page',$show);// 赋值分页输出
            $this->assign('lastpage',$lastpage);    
            //echo $Data->getLastSql();
            $this->search = $Data ->select();
            $this->display();
        }                    

 

  getmember.html

<div id="result">
        <table class='imagetable'>
            <tr>
                <th>序号</th>
                <th>工号</th>
                <th>部门</th>
                <th>职务</th>
                <th>入职时间</th>
                <th>姓名</th>
                <th>私人电话</th>
                <th>公司电话</th>
                <th>身份证</th>
                <th>学历</th>
                <th>婚否</th>
                <th>是否有驾照</th>
                <th>邮箱</th>
                <th>是否在职</th>
                <th>操作</th>
            </tr>
        <volist name="list" id="vo" key="k"> 
            <tr align="center">
                <td>{$vo.id}</td>
                <td>{$vo.aid}</td>
                <td>{$vo.department}</td>
                <td>{$vo.station}</td>
                <td>{$vo.entry_time}</td>
                <td>{$vo.name}</td>
                <td>{$vo.privatephone}</td>
                <td>{$vo.companyphone}</td>
                <td>{$vo.idnumber}</td>
                <td>{$vo.education}</td>
                <td>{$vo.maritalstatus}</td>
                <td>{$vo.drivinglicense}</td>
                <td>{$vo.email}</td>
                <td>{$vo.job}</td>
                <td>
                    <nobr><input type="button" id="edit" value="编辑" onclick="javascript:edit_id({$vo.id});" /><input type="button" id="delete" value="删除" onclick="javascript:delete_id({$vo.id});"  /></nobr>
                </td>
            </tr>
        </volist>
        </table>
        <div style="position:absolute;width:1425px;heigth:30px;top:500px;" align="center">
        <hr>{$page}&nbsp;<a href="/app/index.php/Personnelmatters/getmember/p/1">首页</a>&nbsp;<a href="/app/index.php/Personnelmatters/getmember/p/{$lastpage}">末页</a><hr>
        </div>

 

推荐阅读