feat: 本次提交更新内容如下

php有问题,覆盖下
This commit is contained in:
笔记本里的永平
2025-07-07 14:52:56 +08:00
parent c29fbd1bbb
commit c9a3aaab58
338 changed files with 70315 additions and 12737 deletions

View File

@@ -1,7 +1,7 @@
<?php
/**
* 用法:
* load_trait('controller/Jump');
* class index
* {
* use \traits\controller\Jump;
@@ -13,36 +13,37 @@
*/
namespace traits\controller;
use think\Config;
use think\Container;
use think\exception\HttpResponseException;
use think\Request;
use think\Response;
use think\response\Redirect;
use think\Url;
use think\View as ViewTemplate;
trait Jump
{
/**
* 应用实例
* @var \think\App
*/
protected $app;
/**
* 操作成功跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的 URL 地址
* @param mixed $data 返回的数据
* @param int $wait 跳转等待时间
* @param array $header 发送的 Header 信息
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
* @throws HttpResponseException
*/
protected function success($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
if (is_null($url) && !is_null(Request::instance()->server('HTTP_REFERER'))) {
$url = Request::instance()->server('HTTP_REFERER');
} elseif ('' !== $url && !strpos($url, '://') && 0 !== strpos($url, '/')) {
$url = Url::build($url);
if (is_null($url) && isset($_SERVER["HTTP_REFERER"])) {
$url = $_SERVER["HTTP_REFERER"];
} elseif ('' !== $url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : Container::get('url')->build($url);
}
$type = $this->getResponseType();
$result = [
'code' => 1,
'msg' => $msg,
@@ -51,15 +52,13 @@ trait Jump
'wait' => $wait,
];
$type = $this->getResponseType();
// 把跳转模板的渲染下沉,这样在 response_send 行为里通过getData()获得的数据是一致性的格式
if ('html' == strtolower($type)) {
$template = Config::get('template');
$view = Config::get('view_replace_str');
$result = ViewTemplate::instance($template, $view)
->fetch(Config::get('dispatch_success_tmpl'), $result);
$type = 'jump';
}
$response = Response::create($result, $type)->header($header);
$response = Response::create($result, $type)->header($header)->options(['jump_template' => $this->app['config']->get('dispatch_success_tmpl')]);
throw new HttpResponseException($response);
}
@@ -67,23 +66,22 @@ trait Jump
/**
* 操作错误跳转的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳转的 URL 地址
* @param mixed $data 返回的数据
* @param int $wait 跳转等待时间
* @param array $header 发送的 Header 信息
* @param mixed $msg 提示信息
* @param string $url 跳转的URL地址
* @param mixed $data 返回的数据
* @param integer $wait 跳转等待时间
* @param array $header 发送的Header信息
* @return void
* @throws HttpResponseException
*/
protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{
$type = $this->getResponseType();
if (is_null($url)) {
$url = Request::instance()->isAjax() ? '' : 'javascript:history.back(-1);';
} elseif ('' !== $url && !strpos($url, '://') && 0 !== strpos($url, '/')) {
$url = Url::build($url);
$url = $this->app['request']->isAjax() ? '' : 'javascript:history.back(-1);';
} elseif ('' !== $url) {
$url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : $this->app['url']->build($url);
}
$type = $this->getResponseType();
$result = [
'code' => 0,
'msg' => $msg,
@@ -93,37 +91,33 @@ trait Jump
];
if ('html' == strtolower($type)) {
$template = Config::get('template');
$view = Config::get('view_replace_str');
$result = ViewTemplate::instance($template, $view)
->fetch(Config::get('dispatch_error_tmpl'), $result);
$type = 'jump';
}
$response = Response::create($result, $type)->header($header);
$response = Response::create($result, $type)->header($header)->options(['jump_template' => $this->app['config']->get('dispatch_error_tmpl')]);
throw new HttpResponseException($response);
}
/**
* 返回封装后的 API 数据到客户端
* 返回封装后的API数据到客户端
* @access protected
* @param mixed $data 要返回的数据
* @param int $code 返回的 code
* @param mixed $msg 提示信息
* @param string $type 返回数据格式
* @param array $header 发送的 Header 信息
* @param mixed $data 要返回的数据
* @param integer $code 返回的code
* @param mixed $msg 提示信息
* @param string $type 返回数据格式
* @param array $header 发送的Header信息
* @return void
* @throws HttpResponseException
*/
protected function result($data, $code = 0, $msg = '', $type = '', array $header = [])
{
$result = [
'code' => $code,
'msg' => $msg,
'time' => Request::instance()->server('REQUEST_TIME'),
'time' => time(),
'data' => $data,
];
$type = $type ?: $this->getResponseType();
$response = Response::create($result, $type)->header($header);
@@ -131,37 +125,44 @@ trait Jump
}
/**
* URL 重定向
* URL重定向
* @access protected
* @param string $url 跳转的 URL 表达式
* @param array|int $params 其它 URL 参数
* @param int $code http code
* @param array $with 隐式传参
* @param string $url 跳转的URL表达式
* @param array|integer $params 其它URL参数
* @param integer $code http code
* @param array $with 隐式传参
* @return void
* @throws HttpResponseException
*/
protected function redirect($url, $params = [], $code = 302, $with = [])
{
$response = new Redirect($url);
if (is_integer($params)) {
$code = $params;
$params = [];
}
$response = new Redirect($url);
$response->code($code)->params($params)->with($with);
throw new HttpResponseException($response);
}
/**
* 获取当前的 response 输出类型
* 获取当前的response 输出类型
* @access protected
* @return string
*/
protected function getResponseType()
{
return Request::instance()->isAjax()
? Config::get('default_ajax_return')
: Config::get('default_return_type');
if (!$this->app) {
$this->app = Container::get('app');
}
$isAjax = $this->app['request']->isAjax();
$config = $this->app['config'];
return $isAjax
? $config->get('default_ajax_return')
: $config->get('default_return_type');
}
}