Skip to content

Commit

Permalink
完成成绩清单前端接入
Browse files Browse the repository at this point in the history
  • Loading branch information
icharle committed Dec 6, 2017
1 parent d8a466f commit 624d732
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 9 deletions.
63 changes: 57 additions & 6 deletions app/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Course;
use App\Score;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use HtmlParser\ParserDom;
Expand Down Expand Up @@ -112,7 +113,8 @@ public function login_post()
$xm = mb_convert_encoding($xm, "gb2312", "UTF-8");
$xm = urlencode($xm);
session(['xm' => $xm]);
$this->Getkebiao();
$this->Getkebiao(); //向学校服务器爬取课表
$this->Getchengji(); //向学校服务器爬取成绩
$data = [
'status' => 1,
'msg' => '登录成功'
Expand Down Expand Up @@ -198,10 +200,39 @@ public function kebiao()
}
}

/**
* 成绩清单展示
*/
public function score()
{
$xh = session('xh');
return view('Index.score',compact('xh'));
}


/**
* 服务器端获取课表并且存库
* @return mixed|void
* 客户端请求成绩数据
*/
public function chengji()
{
$input = Input::except('_token');
$result = Score::where('student_id',$input['xh'])->first();
if ($result){

return $result['student_scores'];

}else{

return $this->Getchengji();

}
}



/**
* 向学校服务器端爬取课表并且存库
*/
public function Getkebiao()
{
Expand Down Expand Up @@ -337,9 +368,9 @@ public function Getkebiao()
}

/**
* 获取成绩
* 向学校服务器爬取成绩并且入库
*/
public function chenji()
public function Getchengji()
{
header("Content-type: text/html; charset=utf-8");
$cookie = dirname(dirname(dirname(dirname(__FILE__)))) . '/Public/cookie/' . session('id') . '.txt';
Expand Down Expand Up @@ -383,8 +414,28 @@ public function chenji()
$score[$k]['course_score']=$tr->find('td',12)->plaintext; //成绩
}
array_shift($score);
$temp = json_encode($score, JSON_UNESCAPED_UNICODE);
dd($temp);
$scores = json_encode($score, JSON_UNESCAPED_UNICODE);


//储存课表在数据库
$result = Score::where('student_id', session('xh') )->first();
if ($result != null){

$data['student_scores'] = $scores;
$data['time'] = time();
Score::where('student_id',session('xh'))->update($data);

}else{

$data['student_id'] = session('xh');
$data['student_scores'] = $scores;
$data['time'] = time();
Score::create($data);
}


return $scores;

}


Expand Down
11 changes: 11 additions & 0 deletions app/Score.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Score extends Model
{
public $timestamps = false;
protected $guarded = [];
}
33 changes: 33 additions & 0 deletions database/migrations/2017_12_06_142125_create_scores_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateScoresTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('scores', function (Blueprint $table) {
$table->increments('id');
$table->string('student_id');
$table->text('student_scores');
$table->string('time');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('scores');
}
}
73 changes: 73 additions & 0 deletions public/css/score.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
html{
height:100%;
font-size:62.5%;
}


.header{
width: 100%;
height: 6rem;
padding-top: 2.5rem;
position: relative;
}

.header div{
display: inline;
color: #1E9FFF;
}

.header .back{
padding-left: 3%;
float: left;
}

.header .score{
top: 1.7rem;
left: auto;
float: right;
padding-right: 42.5%;
font-size: 4rem;
position: relative;
}

#score_list{
width: 85%;
position: relative;
top: 3.5rem;
margin: 0 auto;
}

.layui-collapse{
margin-top: 2rem;
border-radius: 1.5rem;
height: 10rem;
border: none;
}

.layui-colla-title{
background-color: #1E9FFF;
border-radius: 1.5rem;
color: white;
height: 10rem;
font-size: 5rem;
text-align: center;
line-height: 10rem;
}

.layui-colla-item{
margin-top: 5rem;
}

.layui-colla-icon{
font-size: 5rem;
}

.layui-colla-content{
border-top: none;
background: #fff;
border-radius: 1.5rem;
}
.layui-table td{
font-size: 4rem;
line-height: 9rem;
}
2 changes: 1 addition & 1 deletion public/js/course.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ layui.use(['jquery','layer'],function () {
url: url,
data:{
week: weeks,
xh : xh,
xh : xh
},
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
Expand Down
83 changes: 83 additions & 0 deletions public/js/score.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
layui.use(['element'], function(){
var layer = layui.layer;
var element = layui.element;


ajax(xh); //执行向后台加载数据

//监听返回链接
$('#back').click(function () {
location.href = url1;
});



function ajax(xh) {
$.ajax({
type: 'POST',
url: url,
data: {
xh: xh
},
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
dataType: "json",
success:function (data) {
var content = data;
var html = '';

//统计json条数
function JSONLength(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
}

//获取学期总数
var arr = new Array();
var j=0;
for (var i=0; i<JSONLength(content); i++){
if (j==0 || arr[j-1] != content[i].course_year+content[i].course_term ){
arr[j] = content[i].course_year+content[i].course_term;
j++;
}
}


//动态生成多个成绩面板
for (var i=0; i<arr.length; i++){

html += '<div class="layui-colla-item">'+'<h2 class="layui-colla-title">'+arr[i].substring(0,9)+'学年 第'+arr[i].substring(9,10)+'学期'+'</h2>'+'<div class="layui-colla-content">'+'<table class="layui-table">'+
'<tr>'+
'<td>课程</td>'+
'<td>分数</td>'+
'<td>绩点</td>'+
'<td>学分</td>'+
'</tr>';

for(var j=0; j<JSONLength(content); j++){

if (arr[i] == content[j].course_year+content[j].course_term){
html += '<tr>'+
'<td>'+content[j].course_name+'</td>'+
'<td>'+content[j].course_score+'</td>'+
'<td>'+content[j].course_points+'</td>'+
'<td>'+content[j].course_credit+'</td>'+
'</tr>'
}

}
html +='</table>'+'</div>'+'</div>';
}

$('#colla').html(html); //嵌入HTML中
element.init('collapse'); //重新加载面板

}
})
}

});
2 changes: 1 addition & 1 deletion resources/views/Index/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</div>
<div>
<label>成绩:</label>
<a href="#">我的成绩</a>
<a href="{{ url('score') }}">我的成绩</a>
</div>
</div>

Expand Down
42 changes: 42 additions & 0 deletions resources/views/Index/score.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="keywords" content="成绩清单"/>
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="description" content="成绩清单" />
<title>成绩清单</title>
<link rel="stylesheet" href="{{ asset('public/js/layui/css/layui.css') }}" type="text/css" >
<link rel="stylesheet" href="{{ asset('public/css/score.css') }}" type="text/css">
</head>
<style type="text/css">
</style>
<body style="background: rgb(236, 239, 246);">

<!--顶部-->
<div class="header">
<div class="back" id="back"><i class="layui-icon" style="font-size: 7rem;">&#xe65c;</i></div>
<div class="score">成绩清单</div>
</div>


<!--各学期的成绩-->
<div id="score_list">
<div class="layui-collapse">
<div id="colla">
</div>
</div>
</div>

<script src="{{ asset('public/js/layui/layui.js') }}"></script>
<script src="{{ asset('public/js/jquery.min.js') }}"></script>
<script src="{{ asset('public/js/jquery.cookie.js') }}"></script>
<script type="text/javascript" src="{{ asset('public/js/score.js') }}"></script>
<script>
var url = '{{ url('chengji') }}'; //后台请求数据
var url1 = '{{ url('index') }}'; //主页面
var xh = '{{ $xh }}'; //学号
</script>
</body>
</html>
10 changes: 9 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
|
*/

//主页面
Route::get('index','IndexController@index');

//登录
Route::get('yzm','IndexController@yzm');
Route::get('login','IndexController@login');
Route::post('login','IndexController@login_post');

//课表
Route::get('course','IndexController@course');
Route::any('kebiao','IndexController@kebiao');
Route::any('chenji','IndexController@chenji');

//成绩
Route::get('score','IndexController@score');
Route::any('chengji','IndexController@chengji');

0 comments on commit 624d732

Please sign in to comment.