mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
优化Response::success/error(),支持$msg传入数字作为code
This commit is contained in:
@@ -165,16 +165,21 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public static function success($msg = '', $data = '', $url = '', $wait = 3)
|
public static function success($msg = '', $data = '', $url = '', $wait = 3)
|
||||||
{
|
{
|
||||||
$result = [
|
$code = 1;
|
||||||
'code' => 1,
|
if(is_numeric($msg)){
|
||||||
|
$code = $msg;
|
||||||
|
$msg = '';
|
||||||
|
}
|
||||||
|
$result = [
|
||||||
|
'code' => $code,
|
||||||
'msg' => $msg,
|
'msg' => $msg,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'url' => $url ?: $_SERVER["HTTP_REFERER"],
|
'url' => $url ?: $_SERVER["HTTP_REFERER"],
|
||||||
'wait' => $wait,
|
'wait' => $wait,
|
||||||
];
|
];
|
||||||
$type = Config::get('default_return_type');
|
$type = Config::get('default_return_type');
|
||||||
if (IS_AJAX) {
|
if (IS_AJAX) {
|
||||||
$type = Config::get('default_ajax_return');
|
$type = Config::get('default_ajax_return');
|
||||||
}
|
}
|
||||||
if ('html' == $type) {
|
if ('html' == $type) {
|
||||||
$result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
$result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||||
@@ -194,16 +199,21 @@ class Response
|
|||||||
*/
|
*/
|
||||||
public static function error($msg = '', $data = '', $url = '', $wait = 3)
|
public static function error($msg = '', $data = '', $url = '', $wait = 3)
|
||||||
{
|
{
|
||||||
$result = [
|
$code = 0;
|
||||||
'code' => 0,
|
if(is_numeric($msg)){
|
||||||
|
$code = $msg;
|
||||||
|
$msg = '';
|
||||||
|
}
|
||||||
|
$result = [
|
||||||
|
'code' => $code,
|
||||||
'msg' => $msg,
|
'msg' => $msg,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'url' => $url ?: 'javascript:history.back(-1);',
|
'url' => $url ?: 'javascript:history.back(-1);',
|
||||||
'wait' => $wait,
|
'wait' => $wait,
|
||||||
];
|
];
|
||||||
$type = Config::get('default_return_type');
|
$type = Config::get('default_return_type');
|
||||||
if (IS_AJAX) {
|
if (IS_AJAX) {
|
||||||
$type = Config::get('default_ajax_return');
|
$type = Config::get('default_ajax_return');
|
||||||
}
|
}
|
||||||
if ('html' == $type) {
|
if ('html' == $type) {
|
||||||
$result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
$result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||||
|
|||||||
Reference in New Issue
Block a user