modified Ajax提交的状态码识别异常的BUG

finish 数据模型自动完成和数据增删改查的适配
This commit is contained in:
zhaoxiang 2016-11-06 01:11:50 +08:00
parent 9a957a4692
commit 848a121689
4 changed files with 9 additions and 12 deletions

View File

@ -10,7 +10,7 @@ use think\Controller;
class Base extends Controller { class Base extends Controller {
protected $primaryKey; public $primaryKey;
public function _initialize(){ public function _initialize(){
$this->primaryKey = config('SQL_PRIMARY_KEY'); $this->primaryKey = config('SQL_PRIMARY_KEY');

View File

@ -32,21 +32,18 @@ class User extends Base {
return $this->error('用户名或者密码错误!'); return $this->error('用户名或者密码错误!');
}else{ }else{
if( $userInfo['status'] ){ if( $userInfo['status'] ){
//保存用户信息和登录凭证 //保存用户信息和登录凭证
cache($userInfo[$this->primaryKey], session_id(), config('online_time'));
session('uid', $userInfo[$this->primaryKey]); session('uid', $userInfo[$this->primaryKey]);
cache($userInfo[$this->primaryKey], session_id(), config('online_time'));
//获取跳转链接,做到从哪来到哪去 //获取跳转链接,做到从哪来到哪去
if( $request->has('from', 'get') ){ if( $request->has('from', 'get') ){
$url = $request->get('from'); $url = $request->get('from');
}else{ }else{
$url = url('Index/index'); $url = url('Index/index');
} }
//更新用户数据 //更新用户数据
$userData = UserData::get(['uid' => $userInfo[$this->primaryKey]]); $userData = UserData::get(['uid' => $userInfo[$this->primaryKey]]);
if( $userData->uid ){ if( $userData ){
$userData->loginTimes += 1; $userData->loginTimes += 1;
$userData->save(); $userData->save();
}else{ }else{
@ -55,7 +52,6 @@ class User extends Base {
$newUserData->uid = $userInfo[$this->primaryKey]; $newUserData->uid = $userInfo[$this->primaryKey];
$newUserData->save(); $newUserData->save();
} }
return $this->success('登录成功', $url); return $this->success('登录成功', $url);
}else{ }else{
return $this->error('用户已被封禁,请联系管理员'); return $this->error('用户已被封禁,请联系管理员');

View File

@ -20,7 +20,7 @@
</div> </div>
<div class="login-box-body"> <div class="login-box-body">
<p class="login-box-msg"> <p class="login-box-msg">
<span class="label label-info">请填写您的账号和密码</span> <span class="label label-info">请填写您的账号和密码admin/123123</span>
</p> </p>
<form action="{:url('User/login')}" id="form-login"> <form action="{:url('User/login')}" id="form-login">

View File

@ -31,7 +31,7 @@
}); });
setTimeout(function(){ setTimeout(function(){
dialog.modal('hide'); dialog.modal('hide');
}, 2000); }, 3000);
}; };
$.buildDom = function ( jsonStr ) { $.buildDom = function ( jsonStr ) {
@ -87,20 +87,21 @@
query = form.serialize(); query = form.serialize();
target = form.attr('action'); target = form.attr('action');
$.post(target, query).success(function(data) { $.post(target, query).success(function(data) {
if (data.status == 1) { if (data.code == 1) {
if (data.url) { if (data.url) {
message = data.msg + ' 页面即将自动跳转~'; message = data.msg + ' 页面即将自动跳转...';
} else { } else {
message = data.msg; message = data.msg;
} }
$.alertMsg(message); $.alertMsg(message);
var wait = 1000*data.wait;
setTimeout(function() { setTimeout(function() {
if (data.url) { if (data.url) {
location.href = data.url; location.href = data.url;
} else { } else {
location.reload(); location.reload();
} }
}, 2000); }, wait);
} else { } else {
$.alertMsg(data.msg); $.alertMsg(data.msg);
} }