pref: 增加服务类优化UI版面
This commit is contained in:
@@ -23,6 +23,16 @@ use system\Random;
|
||||
|
||||
class Request extends \Webman\Http\Request
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $userId = 0;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $userInfo = [];
|
||||
|
||||
/**
|
||||
* 生成请求令牌
|
||||
* @access public
|
||||
|
||||
@@ -29,8 +29,35 @@ class Template extends ThinkPHP
|
||||
*/
|
||||
public static function render(string $template, array $vars, string $app = null, string $plugin = null): string
|
||||
{
|
||||
$content = parent::render($template, $vars, $app);
|
||||
if (saenv('minify_page')) {
|
||||
$request = request();
|
||||
$app = $app === null ? $request->app : $app;
|
||||
$viewPath = app_path() . "/$app/view/";
|
||||
$defaultOptions = [
|
||||
'view_path' => $viewPath,
|
||||
'cache_path' => runtime_path() . '/views/',
|
||||
'view_suffix' => 'html'
|
||||
];
|
||||
$options = $defaultOptions + config("view.options", []);
|
||||
$options['taglib_pre_load'] = rtrim($options['taglib_pre_load'], ',');
|
||||
foreach (get_plugin_list() as $index => $item) {
|
||||
if (empty($item['status'])) {
|
||||
continue;
|
||||
}
|
||||
$name = $item['name'];
|
||||
$taglibPath = plugin_path($name . DIRECTORY_SEPARATOR . 'taglib');
|
||||
$tagList = glob($taglibPath . '*.php');
|
||||
foreach ($tagList as $key => $tag) {
|
||||
$tag = pathinfo($tag, PATHINFO_FILENAME);
|
||||
$options['taglib_pre_load'] .= ',plugin\\' . $name . '\\taglib\\' . $tag;
|
||||
}
|
||||
}
|
||||
$views = new \think\Template($options);
|
||||
ob_start();
|
||||
$vars = array_merge(static::$vars, $vars);
|
||||
$views->fetch($template, $vars);
|
||||
$content = ob_get_clean();
|
||||
static::$vars = [];
|
||||
if (saenv('minify_page') && strtolower($app) == 'index') {
|
||||
$content = preg_replace('/\s+/i', ' ', $content);
|
||||
}
|
||||
return $content;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
use app\common\exception\DumpException;
|
||||
use support\Container;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
@@ -113,19 +114,25 @@ if (!function_exists('halt')) {
|
||||
/**
|
||||
* 调试变量并且中断输出
|
||||
* @param mixed $vars 调试变量或者信息
|
||||
* @throws DumpException
|
||||
* @return void
|
||||
*/
|
||||
function halt(...$vars)
|
||||
function halt(...$vars): void
|
||||
{
|
||||
ob_start();
|
||||
$cloner = new VarCloner();
|
||||
$cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);
|
||||
$dumper = new HtmlDumper();
|
||||
$dumper = new ContextualizedDumper($dumper, [new SourceContextProvider()]);
|
||||
foreach ($vars as $var) {
|
||||
$dumper->dump($cloner->cloneVar($var));
|
||||
try {
|
||||
ob_start();
|
||||
$cloner = new VarCloner();
|
||||
$cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO);
|
||||
$dumper = new HtmlDumper();
|
||||
$dumper = new ContextualizedDumper($dumper, [new SourceContextProvider()]);
|
||||
foreach ($vars as $var) {
|
||||
$dumper->dump($cloner->cloneVar($var));
|
||||
}
|
||||
$ob_response = (string)ob_get_clean();
|
||||
} catch (\Throwable $e) {
|
||||
$ob_response = $e->getMessage();
|
||||
}
|
||||
$ob_response = (string)ob_get_clean();
|
||||
throw new \RuntimeException($ob_response, 600);
|
||||
throw new DumpException($ob_response, 600);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user