mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
success/error从traits\controller\view抽离,移至Response类内部。
移除traits\controller\ajax。
This commit is contained in:
@@ -61,7 +61,7 @@ class Response
|
||||
|
||||
/**
|
||||
* 返回封装后的API数据到客户端
|
||||
* @access protected
|
||||
* @access public
|
||||
* @param mixed $data 要返回的数据
|
||||
* @param integer $code 返回的code
|
||||
* @param mixed $msg 提示信息
|
||||
@@ -79,6 +79,56 @@ class Response
|
||||
self::returnData($result, $type, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回封装后的API数据到客户端
|
||||
* @access public
|
||||
* @param mixed $msg 要返回的数据
|
||||
* @param mixed $data 返回的code
|
||||
* @param mixed $url 提示信息
|
||||
* @param mixed $wait 返回数据格式
|
||||
* @return void
|
||||
*/
|
||||
public static function success($msg = '', $data = '', $url = '', $wait = 3){
|
||||
$result = [
|
||||
'code' => 1,
|
||||
'msg' => $msg,
|
||||
'data' => $data,
|
||||
'url' => $url ? $url: $_SERVER["HTTP_REFERER"],
|
||||
'wait' => $wait,
|
||||
];
|
||||
$type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
||||
if ('html' == $type) {
|
||||
$view = new \think\View();
|
||||
$result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||
}
|
||||
self::returnData($result, $type, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回封装后的API数据到客户端
|
||||
* @access public
|
||||
* @param mixed $msg 要返回的数据
|
||||
* @param mixed $data 返回的code
|
||||
* @param mixed $url 提示信息
|
||||
* @param mixed $wait 返回数据格式
|
||||
* @return void
|
||||
*/
|
||||
public static function error($msg = '', $data = '', $url = '', $wait = 3){
|
||||
$result = [
|
||||
'code' => 0,
|
||||
'msg' => $msg,
|
||||
'data' => $data,
|
||||
'url' => $url ? $url : 'javascript:history.back(-1);',
|
||||
'wait' => $wait,
|
||||
];
|
||||
$type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
||||
if ('html' == $type) {
|
||||
$view = new \think\View();
|
||||
$result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||
}
|
||||
self::returnData($result, $type, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* URL重定向
|
||||
* @access protected
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 用法:
|
||||
* T('controller/ajax');
|
||||
* class index
|
||||
* {
|
||||
* use \traits\controller\ajax;
|
||||
* public function index(){
|
||||
* $this->result();
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
namespace traits\controller;
|
||||
|
||||
trait Ajax
|
||||
{
|
||||
/**
|
||||
* 返回封装后的API数据到客户端
|
||||
* @access protected
|
||||
* @param mixed $data 要返回的数据
|
||||
* @param string $msg 提示信息
|
||||
* @param integer $code 返回的code
|
||||
* @param string $url 重定向地址
|
||||
* @param integer $wait 跳转等待时间
|
||||
* @return void
|
||||
*/
|
||||
public function result($data = '', $msg = '', $code = 0, $url = '', $wait = 0)
|
||||
{
|
||||
IS_AJAX && Config::set('default_return_type', Config::get('default_ajax_return'));
|
||||
return [
|
||||
'code' => $code,
|
||||
'msg' => $msg,
|
||||
'data' => $data,
|
||||
'url' => $url,
|
||||
'wait' => $wait,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作错误跳转的快捷方法
|
||||
* @access protected
|
||||
* @param string $message 错误信息
|
||||
* @param string $jumpUrl 页面跳转地址
|
||||
* @param integer $wait 跳转等待时间
|
||||
* @return void
|
||||
*/
|
||||
protected function error($message, $jumpUrl = '', $wait = 5)
|
||||
{
|
||||
$jumpUrl = $jumpUrl ?: 'javascript:history.back(-1);';
|
||||
return $this->result('', $message, 0, $jumpUrl, $wait);
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作成功跳转的快捷方法
|
||||
* @access protected
|
||||
* @param string $message 提示信息
|
||||
* @param string $jumpUrl 页面跳转地址
|
||||
* @param integer $wait 跳转等待时间
|
||||
* @return void
|
||||
*/
|
||||
protected function success($message, $jumpUrl = '', $wait = 3)
|
||||
{
|
||||
$jumpUrl = $jumpUrl ?: $_SERVER["HTTP_REFERER"];
|
||||
return $this->result('', $message, 1, $jumpUrl, $wait);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -72,60 +72,4 @@ trait View
|
||||
$this->initView();
|
||||
$this->view->assign($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回封装后的API数据到客户端
|
||||
* @access protected
|
||||
* @param mixed $data 要返回的数据
|
||||
* @param string $msg 提示信息
|
||||
* @param integer $code 返回的code
|
||||
* @param string $url 重定向地址
|
||||
* @param integer $wait 跳转等待时间
|
||||
* @return void
|
||||
*/
|
||||
public function result($data = '', $msg = '', $code = 0, $url = '', $wait = 0)
|
||||
{
|
||||
$result = [
|
||||
'code' => $code,
|
||||
'msg' => $msg,
|
||||
'data' => $data,
|
||||
'url' => $url,
|
||||
'wait' => $wait,
|
||||
];
|
||||
IS_AJAX && Config::set('default_return_type', Config::get('default_ajax_return'));
|
||||
if ('html' == Config::get('default_return_type')) {
|
||||
return $this->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作错误跳转的快捷方法
|
||||
* @access protected
|
||||
* @param string $message 错误信息
|
||||
* @param string $jumpUrl 页面跳转地址
|
||||
* @param integer $wait 跳转等待时间
|
||||
* @return void
|
||||
*/
|
||||
protected function error($message, $data = '', $jumpUrl = '', $wait = 5)
|
||||
{
|
||||
$jumpUrl = $jumpUrl ?: 'javascript:history.back(-1);';
|
||||
return $this->result($data, $message, 0, $jumpUrl, $wait);
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作成功跳转的快捷方法
|
||||
* @access protected
|
||||
* @param string $message 提示信息
|
||||
* @param string $jumpUrl 页面跳转地址
|
||||
* @param integer $wait 跳转等待时间
|
||||
* @return void
|
||||
*/
|
||||
protected function success($message, $data = '', $jumpUrl = '', $wait = 3)
|
||||
{
|
||||
$jumpUrl = $jumpUrl ?: $_SERVER["HTTP_REFERER"];
|
||||
return $this->result($data, $message, 1, $jumpUrl, $wait);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user